summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-18 01:16:41 +0100
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-11-18 01:16:41 +0100
commitd00046b6913367eec7d7e328dc9a1e84498f0bfb (patch)
treefd5ef152c73ef1e068bc5a44e9811be6aa80a3fa /tests
parentMerge "applypatch: Clean up LoadPartitionContents()." (diff)
parentupdater: Add "write_value()" function. (diff)
downloadandroid_bootable_recovery-d00046b6913367eec7d7e328dc9a1e84498f0bfb.tar
android_bootable_recovery-d00046b6913367eec7d7e328dc9a1e84498f0bfb.tar.gz
android_bootable_recovery-d00046b6913367eec7d7e328dc9a1e84498f0bfb.tar.bz2
android_bootable_recovery-d00046b6913367eec7d7e328dc9a1e84498f0bfb.tar.lz
android_bootable_recovery-d00046b6913367eec7d7e328dc9a1e84498f0bfb.tar.xz
android_bootable_recovery-d00046b6913367eec7d7e328dc9a1e84498f0bfb.tar.zst
android_bootable_recovery-d00046b6913367eec7d7e328dc9a1e84498f0bfb.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);
+}