summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-18 02:18:19 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-11-18 02:18:19 +0100
commit4f0685b93c080d2b61c4978c83403f26e3858b02 (patch)
tree8bd936c5c8bc1aab735e7cc0714c72ff438c8ce7 /tests
parentMerge "applypatch: Clean up LoadPartitionContents()." am: c6ee8cf8df am: 9e4ba70b7f am: c43acc9938 (diff)
parentMerge "updater: Add "write_value()" function." am: d00046b691 am: 100dba35f9 (diff)
downloadandroid_bootable_recovery-4f0685b93c080d2b61c4978c83403f26e3858b02.tar
android_bootable_recovery-4f0685b93c080d2b61c4978c83403f26e3858b02.tar.gz
android_bootable_recovery-4f0685b93c080d2b61c4978c83403f26e3858b02.tar.bz2
android_bootable_recovery-4f0685b93c080d2b61c4978c83403f26e3858b02.tar.lz
android_bootable_recovery-4f0685b93c080d2b61c4978c83403f26e3858b02.tar.xz
android_bootable_recovery-4f0685b93c080d2b61c4978c83403f26e3858b02.tar.zst
android_bootable_recovery-4f0685b93c080d2b61c4978c83403f26e3858b02.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/component/updater_test.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index a029cf449..d34c0e54c 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -322,3 +322,36 @@ TEST_F(UpdaterTest, package_extract_file) {
CloseArchive(handle);
}
+
+TEST_F(UpdaterTest, write_value) {
+ // write_value() expects two arguments.
+ expect(nullptr, "write_value()", kArgsParsingFailure);
+ expect(nullptr, "write_value(\"arg1\")", kArgsParsingFailure);
+ expect(nullptr, "write_value(\"arg1\", \"arg2\", \"arg3\")", kArgsParsingFailure);
+
+ // filename cannot be empty.
+ expect(nullptr, "write_value(\"value\", \"\")", kArgsParsingFailure);
+
+ // Write some value to file.
+ TemporaryFile temp_file;
+ std::string value = "magicvalue";
+ std::string script("write_value(\"" + value + "\", \"" + std::string(temp_file.path) + "\")");
+ expect("t", script.c_str(), kNoCause);
+
+ // Verify the content.
+ std::string content;
+ ASSERT_TRUE(android::base::ReadFileToString(temp_file.path, &content));
+ ASSERT_EQ(value, content);
+
+ // Allow writing empty string.
+ script = "write_value(\"\", \"" + std::string(temp_file.path) + "\")";
+ expect("t", script.c_str(), kNoCause);
+
+ // Verify the content.
+ ASSERT_TRUE(android::base::ReadFileToString(temp_file.path, &content));
+ ASSERT_EQ("", content);
+
+ // It should fail gracefully when write fails.
+ script = "write_value(\"value\", \"/proc/0/file1\")";
+ expect("", script.c_str(), kNoCause);
+}