summaryrefslogtreecommitdiffstats
path: root/tests/component/applypatch_test.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-03-15 09:10:58 +0100
committerTao Bao <tbao@google.com>2017-03-16 08:49:49 +0100
commit40e144dae877654f75e65242535036058ea48f58 (patch)
treef73bb425e9a49ca0fd2c5f951c346852f7c7e6ff /tests/component/applypatch_test.cpp
parentMerge "Revert "Print SHA-1 in hex for corrupted blocks"" (diff)
downloadandroid_bootable_recovery-40e144dae877654f75e65242535036058ea48f58.tar
android_bootable_recovery-40e144dae877654f75e65242535036058ea48f58.tar.gz
android_bootable_recovery-40e144dae877654f75e65242535036058ea48f58.tar.bz2
android_bootable_recovery-40e144dae877654f75e65242535036058ea48f58.tar.lz
android_bootable_recovery-40e144dae877654f75e65242535036058ea48f58.tar.xz
android_bootable_recovery-40e144dae877654f75e65242535036058ea48f58.tar.zst
android_bootable_recovery-40e144dae877654f75e65242535036058ea48f58.zip
Diffstat (limited to 'tests/component/applypatch_test.cpp')
-rw-r--r--tests/component/applypatch_test.cpp124
1 files changed, 0 insertions, 124 deletions
diff --git a/tests/component/applypatch_test.cpp b/tests/component/applypatch_test.cpp
index d178303aa..5cba68f8a 100644
--- a/tests/component/applypatch_test.cpp
+++ b/tests/component/applypatch_test.cpp
@@ -280,66 +280,6 @@ TEST_F(ApplyPatchCacheTest, CheckCacheMissingFailure) {
ASSERT_NE(0, applypatch_check(&old_file[0], sha1s));
}
-TEST_F(ApplyPatchFullTest, ApplyInPlace) {
- std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
- ASSERT_EQ(0, applypatch(&old_file[0], "-", &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(old_file, new_file));
-
- // reapply, applypatch is idempotent so it should succeed
- ASSERT_EQ(0, applypatch(&old_file[0], "-", &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(old_file, new_file));
-}
-
-TEST_F(ApplyPatchFullTest, ApplyInNewLocation) {
- std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
- // Apply bsdiff patch to new location.
- ASSERT_EQ(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(output_loc, new_file));
-
- // Reapply to the same location.
- ASSERT_EQ(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(output_loc, new_file));
-}
-
-TEST_F(ApplyPatchFullTest, ApplyCorruptedInNewLocation) {
- std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
- // Apply bsdiff patch to new location with corrupted source.
- mangle_file(old_file);
- ASSERT_EQ(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(output_loc, new_file));
-
- // Reapply bsdiff patch to new location with corrupted source.
- ASSERT_EQ(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(output_loc, new_file));
-}
-
-TEST_F(ApplyPatchDoubleCacheTest, ApplyDoubleCorruptedInNewLocation) {
- std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
-
- // Apply bsdiff patch to new location with corrupted source and copy (no new file).
- // Expected to fail.
- mangle_file(old_file);
- mangle_file(cache_file);
- ASSERT_NE(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_FALSE(file_cmp(output_loc, new_file));
-
- // Expected to fail again on retry.
- ASSERT_NE(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_FALSE(file_cmp(output_loc, new_file));
-
- // Expected to fail with incorrect new file.
- mangle_file(output_loc);
- ASSERT_NE(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_FALSE(file_cmp(output_loc, new_file));
-}
-
TEST(ApplyPatchModesTest, InvalidArgs) {
// At least two args (including the filename).
ASSERT_EQ(2, applypatch_modes(1, (const char* []){ "applypatch" }));
@@ -348,70 +288,6 @@ TEST(ApplyPatchModesTest, InvalidArgs) {
ASSERT_EQ(2, applypatch_modes(2, (const char* []){ "applypatch", "-x" }));
}
-TEST(ApplyPatchModesTest, PatchMode) {
- std::string boot_img = from_testdata_base("boot.img");
- size_t boot_img_size;
- std::string boot_img_sha1;
- sha1sum(boot_img, &boot_img_sha1, &boot_img_size);
-
- std::string recovery_img = from_testdata_base("recovery.img");
- std::string recovery_img_sha1;
- size_t size;
- sha1sum(recovery_img, &recovery_img_sha1, &size);
- std::string recovery_img_size = std::to_string(size);
- std::string bonus_file = from_testdata_base("bonus.file");
-
- // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch>
- TemporaryFile tmp1;
- std::string patch = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p");
- std::vector<const char*> args = {
- "applypatch",
- "-b",
- bonus_file.c_str(),
- boot_img.c_str(),
- tmp1.path,
- recovery_img_sha1.c_str(),
- recovery_img_size.c_str(),
- patch.c_str()
- };
- ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
-
- // applypatch <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch>
- TemporaryFile tmp2;
- patch = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot-with-bonus.p");
- std::vector<const char*> args2 = {
- "applypatch",
- boot_img.c_str(),
- tmp2.path,
- recovery_img_sha1.c_str(),
- recovery_img_size.c_str(),
- patch.c_str()
- };
- ASSERT_EQ(0, applypatch_modes(args2.size(), args2.data()));
-
- // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> \
- // <src-sha1-fake>:<patch1> <src-sha1>:<patch2>
- TemporaryFile tmp3;
- std::string bad_sha1_a = android::base::StringPrintf("%040x", rand());
- std::string bad_sha1_b = android::base::StringPrintf("%040x", rand());
- std::string patch1 = bad_sha1_a + ":" + from_testdata_base("recovery-from-boot.p");
- std::string patch2 = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p");
- std::string patch3 = bad_sha1_b + ":" + from_testdata_base("recovery-from-boot.p");
- std::vector<const char*> args3 = {
- "applypatch",
- "-b",
- bonus_file.c_str(),
- boot_img.c_str(),
- tmp3.path,
- recovery_img_sha1.c_str(),
- recovery_img_size.c_str(),
- patch1.c_str(),
- patch2.c_str(),
- patch3.c_str()
- };
- ASSERT_EQ(0, applypatch_modes(args3.size(), args3.data()));
-}
-
TEST(ApplyPatchModesTest, PatchModeEmmcTarget) {
std::string boot_img = from_testdata_base("boot.img");
size_t boot_img_size;