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