summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-18 01:42:42 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-11-18 01:42:42 +0100
commit100dba35f9f4e3f9e5a3fff50f25db563831ec21 (patch)
treeb25cdfdc1420388f44e95ed80e670075d7f7a7c5 /tests
parentMerge "applypatch: Clean up LoadPartitionContents()." (diff)
parentMerge "updater: Add "write_value()" function." (diff)
downloadandroid_bootable_recovery-100dba35f9f4e3f9e5a3fff50f25db563831ec21.tar
android_bootable_recovery-100dba35f9f4e3f9e5a3fff50f25db563831ec21.tar.gz
android_bootable_recovery-100dba35f9f4e3f9e5a3fff50f25db563831ec21.tar.bz2
android_bootable_recovery-100dba35f9f4e3f9e5a3fff50f25db563831ec21.tar.lz
android_bootable_recovery-100dba35f9f4e3f9e5a3fff50f25db563831ec21.tar.xz
android_bootable_recovery-100dba35f9f4e3f9e5a3fff50f25db563831ec21.tar.zst
android_bootable_recovery-100dba35f9f4e3f9e5a3fff50f25db563831ec21.zip
Diffstat (limited to '')
-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);
+}