integration_test.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2021 The Chromium OS Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <string>
  5. #include <vector>
  6. #include "gtest/gtest.h"
  7. #include "puffin/memory_stream.h"
  8. #include "puffin/src/include/puffin/puffdiff.h"
  9. #include "puffin/src/include/puffin/puffpatch.h"
  10. #include "puffin/src/include/puffin/utils.h"
  11. #include "puffin/src/puffin_stream.h"
  12. #include "puffin/src/unittest_common.h"
  13. namespace puffin {
  14. namespace {
  15. // xxd -i <name>.zip
  16. const Buffer kTestZipA = {
  17. 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x79,
  18. 0x0d, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19. 0x00, 0x00, 0x01, 0x00, 0x1c, 0x00, 0x31, 0x55, 0x54, 0x09, 0x00, 0x03,
  20. 0x5c, 0xed, 0x16, 0x61, 0x5c, 0xed, 0x16, 0x61, 0x75, 0x78, 0x0b, 0x00,
  21. 0x01, 0x04, 0x8f, 0x66, 0x05, 0x00, 0x04, 0x53, 0x5f, 0x01, 0x00, 0x50,
  22. 0x4b, 0x01, 0x02, 0x1e, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e,
  23. 0x79, 0x0d, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  24. 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  25. 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00, 0x00, 0x00, 0x00, 0x31, 0x55, 0x54,
  26. 0x05, 0x00, 0x03, 0x5c, 0xed, 0x16, 0x61, 0x75, 0x78, 0x0b, 0x00, 0x01,
  27. 0x04, 0x8f, 0x66, 0x05, 0x00, 0x04, 0x53, 0x5f, 0x01, 0x00, 0x50, 0x4b,
  28. 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x47, 0x00,
  29. 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x00, 0x00};
  30. const Buffer kTestZipB = {
  31. 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x79,
  32. 0x0d, 0x53, 0x4e, 0x81, 0x88, 0x47, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00,
  33. 0x00, 0x00, 0x01, 0x00, 0x1c, 0x00, 0x32, 0x55, 0x54, 0x09, 0x00, 0x03,
  34. 0x88, 0xed, 0x16, 0x61, 0x88, 0xed, 0x16, 0x61, 0x75, 0x78, 0x0b, 0x00,
  35. 0x01, 0x04, 0x8f, 0x66, 0x05, 0x00, 0x04, 0x53, 0x5f, 0x01, 0x00, 0x61,
  36. 0x62, 0x63, 0x0a, 0x50, 0x4b, 0x01, 0x02, 0x1e, 0x03, 0x0a, 0x00, 0x00,
  37. 0x00, 0x00, 0x00, 0x26, 0x79, 0x0d, 0x53, 0x4e, 0x81, 0x88, 0x47, 0x04,
  38. 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00,
  39. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00, 0x00, 0x00,
  40. 0x00, 0x32, 0x55, 0x54, 0x05, 0x00, 0x03, 0x88, 0xed, 0x16, 0x61, 0x75,
  41. 0x78, 0x0b, 0x00, 0x01, 0x04, 0x8f, 0x66, 0x05, 0x00, 0x04, 0x53, 0x5f,
  42. 0x01, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  43. 0x01, 0x00, 0x47, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00};
  44. } // namespace
  45. class PuffinIntegrationTest : public testing::TestWithParam<PatchAlgorithm> {
  46. protected:
  47. PatchAlgorithm getPatchType() { return GetParam(); }
  48. };
  49. TEST_P(PuffinIntegrationTest, PuffinDiffPatchTest) {
  50. std::vector<BitExtent> src_deflates;
  51. ASSERT_TRUE(LocateDeflatesInZipArchive(kTestZipA, &src_deflates));
  52. std::vector<BitExtent> dst_deflates;
  53. ASSERT_TRUE(LocateDeflatesInZipArchive(kTestZipB, &dst_deflates));
  54. std::string tmp_file;
  55. ASSERT_TRUE(MakeTempFile(&tmp_file));
  56. Buffer patch;
  57. ASSERT_TRUE(PuffDiff(MemoryStream::CreateForRead(kTestZipA),
  58. MemoryStream::CreateForRead(kTestZipB), src_deflates,
  59. dst_deflates, {puffin::CompressorType::kBrotli},
  60. getPatchType(), tmp_file, &patch));
  61. Buffer patched;
  62. auto src_stream = MemoryStream::CreateForRead(kTestZipA);
  63. auto dst_stream = MemoryStream::CreateForWrite(&patched);
  64. ASSERT_TRUE(PuffPatch(MemoryStream::CreateForRead(kTestZipA),
  65. MemoryStream::CreateForWrite(&patched), patch.data(),
  66. patch.size()));
  67. ASSERT_EQ(kTestZipB, patched);
  68. }
  69. INSTANTIATE_TEST_SUITE_P(TestWithPatchType,
  70. PuffinIntegrationTest,
  71. testing::Values(PatchAlgorithm::kZucchini));
  72. } // namespace puffin