diff options
author | Tianjie Xu <xunchang@google.com> | 2017-03-07 04:14:43 +0100 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-03-07 04:14:43 +0100 |
commit | a4e0bb321b1bbbfa1849c6036ebac75f9b0d91d8 (patch) | |
tree | 74fd772799ff22569f91345ef33785571165ffb5 /tests | |
parent | Merge "Fix an error on bootloadermessager test teardown" am: b694ba8aab am: 536989892c (diff) | |
parent | Merge "Refractor the code for imgdiff" am: a2e7a07031 (diff) | |
download | android_bootable_recovery-a4e0bb321b1bbbfa1849c6036ebac75f9b0d91d8.tar android_bootable_recovery-a4e0bb321b1bbbfa1849c6036ebac75f9b0d91d8.tar.gz android_bootable_recovery-a4e0bb321b1bbbfa1849c6036ebac75f9b0d91d8.tar.bz2 android_bootable_recovery-a4e0bb321b1bbbfa1849c6036ebac75f9b0d91d8.tar.lz android_bootable_recovery-a4e0bb321b1bbbfa1849c6036ebac75f9b0d91d8.tar.xz android_bootable_recovery-a4e0bb321b1bbbfa1849c6036ebac75f9b0d91d8.tar.zst android_bootable_recovery-a4e0bb321b1bbbfa1849c6036ebac75f9b0d91d8.zip |
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Android.mk | 1 | ||||
-rw-r--r-- | tests/component/imgdiff_test.cpp | 56 |
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/Android.mk b/tests/Android.mk index c7d33256a..ec971b38c 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -177,6 +177,7 @@ LOCAL_STATIC_LIBRARIES := \ libbsdiff \ libbspatch \ libziparchive \ + libutils \ libbase \ libcrypto \ libbz \ diff --git a/tests/component/imgdiff_test.cpp b/tests/component/imgdiff_test.cpp index 7ad330783..be2dd385b 100644 --- a/tests/component/imgdiff_test.cpp +++ b/tests/component/imgdiff_test.cpp @@ -236,6 +236,62 @@ TEST(ImgdiffTest, zip_mode_smoke_compressed) { ASSERT_EQ(tgt, patched); } +TEST(ImgdiffTest, zip_mode_smoke_trailer_zeros) { + // Construct src and tgt zip files. + TemporaryFile src_file; + FILE* src_file_ptr = fdopen(src_file.fd, "wb"); + ZipWriter src_writer(src_file_ptr); + ASSERT_EQ(0, src_writer.StartEntry("file1.txt", ZipWriter::kCompress)); + const std::string src_content("abcdefg"); + ASSERT_EQ(0, src_writer.WriteBytes(src_content.data(), src_content.size())); + ASSERT_EQ(0, src_writer.FinishEntry()); + ASSERT_EQ(0, src_writer.Finish()); + ASSERT_EQ(0, fclose(src_file_ptr)); + + TemporaryFile tgt_file; + FILE* tgt_file_ptr = fdopen(tgt_file.fd, "wb"); + ZipWriter tgt_writer(tgt_file_ptr); + ASSERT_EQ(0, tgt_writer.StartEntry("file1.txt", ZipWriter::kCompress)); + const std::string tgt_content("abcdefgxyz"); + ASSERT_EQ(0, tgt_writer.WriteBytes(tgt_content.data(), tgt_content.size())); + ASSERT_EQ(0, tgt_writer.FinishEntry()); + ASSERT_EQ(0, tgt_writer.Finish()); + // Add trailing zeros to the target zip file. + std::vector<uint8_t> zeros(10); + ASSERT_EQ(zeros.size(), fwrite(zeros.data(), sizeof(uint8_t), zeros.size(), tgt_file_ptr)); + ASSERT_EQ(0, fclose(tgt_file_ptr)); + + // Compute patch. + TemporaryFile patch_file; + std::vector<const char*> args = { + "imgdiff", "-z", src_file.path, tgt_file.path, patch_file.path, + }; + ASSERT_EQ(0, imgdiff(args.size(), args.data())); + + // Verify. + std::string tgt; + ASSERT_TRUE(android::base::ReadFileToString(tgt_file.path, &tgt)); + std::string src; + ASSERT_TRUE(android::base::ReadFileToString(src_file.path, &src)); + std::string patch; + ASSERT_TRUE(android::base::ReadFileToString(patch_file.path, &patch)); + + // Expect three entries: CHUNK_RAW (header) + CHUNK_DEFLATE (data) + CHUNK_RAW (footer). + size_t num_normal; + size_t num_raw; + size_t num_deflate; + verify_patch_header(patch, &num_normal, &num_raw, &num_deflate); + ASSERT_EQ(0U, num_normal); + ASSERT_EQ(1U, num_deflate); + ASSERT_EQ(2U, num_raw); + + std::string patched; + ASSERT_EQ(0, ApplyImagePatch(reinterpret_cast<const unsigned char*>(src.data()), src.size(), + reinterpret_cast<const unsigned char*>(patch.data()), patch.size(), + MemorySink, &patched)); + ASSERT_EQ(tgt, patched); +} + TEST(ImgdiffTest, image_mode_simple) { // src: "abcdefgh" + gzipped "xyz" (echo -n "xyz" | gzip -f | hd). const std::vector<char> src_data = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', |