summaryrefslogtreecommitdiffstats
path: root/tests/component/install_test.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-04-19 20:57:22 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-04-19 20:57:22 +0200
commit7b9b77f445eb71febb5cd8d7cb627e3f60e2ef26 (patch)
treee29fa09d2b4f1fa75ad80202aada267df7c42b12 /tests/component/install_test.cpp
parentMerge "Minor clean up to install.cpp." am: 08146728c1 (diff)
parentMerge "Add tests for read_metadata_from_package()." (diff)
downloadandroid_bootable_recovery-7b9b77f445eb71febb5cd8d7cb627e3f60e2ef26.tar
android_bootable_recovery-7b9b77f445eb71febb5cd8d7cb627e3f60e2ef26.tar.gz
android_bootable_recovery-7b9b77f445eb71febb5cd8d7cb627e3f60e2ef26.tar.bz2
android_bootable_recovery-7b9b77f445eb71febb5cd8d7cb627e3f60e2ef26.tar.lz
android_bootable_recovery-7b9b77f445eb71febb5cd8d7cb627e3f60e2ef26.tar.xz
android_bootable_recovery-7b9b77f445eb71febb5cd8d7cb627e3f60e2ef26.tar.zst
android_bootable_recovery-7b9b77f445eb71febb5cd8d7cb627e3f60e2ef26.zip
Diffstat (limited to 'tests/component/install_test.cpp')
-rw-r--r--tests/component/install_test.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/component/install_test.cpp b/tests/component/install_test.cpp
index fd3b28b07..2143dd7bb 100644
--- a/tests/component/install_test.cpp
+++ b/tests/component/install_test.cpp
@@ -62,6 +62,56 @@ TEST(InstallTest, verify_package_compatibility_invalid_entry) {
CloseArchive(zip);
}
+TEST(InstallTest, read_metadata_from_package_smoke) {
+ TemporaryFile temp_file;
+ FILE* zip_file = fdopen(temp_file.fd, "w");
+ ZipWriter writer(zip_file);
+ ASSERT_EQ(0, writer.StartEntry("META-INF/com/android/metadata", kCompressStored));
+ const std::string content("abcdefg");
+ ASSERT_EQ(0, writer.WriteBytes(content.data(), content.size()));
+ ASSERT_EQ(0, writer.FinishEntry());
+ ASSERT_EQ(0, writer.Finish());
+ ASSERT_EQ(0, fclose(zip_file));
+
+ ZipArchiveHandle zip;
+ ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
+ std::string metadata;
+ ASSERT_TRUE(read_metadata_from_package(zip, &metadata));
+ ASSERT_EQ(content, metadata);
+ CloseArchive(zip);
+
+ TemporaryFile temp_file2;
+ FILE* zip_file2 = fdopen(temp_file2.fd, "w");
+ ZipWriter writer2(zip_file2);
+ ASSERT_EQ(0, writer2.StartEntry("META-INF/com/android/metadata", kCompressDeflated));
+ ASSERT_EQ(0, writer2.WriteBytes(content.data(), content.size()));
+ ASSERT_EQ(0, writer2.FinishEntry());
+ ASSERT_EQ(0, writer2.Finish());
+ ASSERT_EQ(0, fclose(zip_file2));
+
+ ASSERT_EQ(0, OpenArchive(temp_file2.path, &zip));
+ metadata.clear();
+ ASSERT_TRUE(read_metadata_from_package(zip, &metadata));
+ ASSERT_EQ(content, metadata);
+ CloseArchive(zip);
+}
+
+TEST(InstallTest, read_metadata_from_package_no_entry) {
+ TemporaryFile temp_file;
+ FILE* zip_file = fdopen(temp_file.fd, "w");
+ ZipWriter writer(zip_file);
+ ASSERT_EQ(0, writer.StartEntry("dummy_entry", kCompressStored));
+ ASSERT_EQ(0, writer.FinishEntry());
+ ASSERT_EQ(0, writer.Finish());
+ ASSERT_EQ(0, fclose(zip_file));
+
+ ZipArchiveHandle zip;
+ ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
+ std::string metadata;
+ ASSERT_FALSE(read_metadata_from_package(zip, &metadata));
+ CloseArchive(zip);
+}
+
TEST(InstallTest, update_binary_command_smoke) {
#ifdef AB_OTA_UPDATER
TemporaryFile temp_file;