summaryrefslogtreecommitdiffstats
path: root/tests/component
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-04 07:52:01 +0100
committerTao Bao <tbao@google.com>2016-11-17 00:51:53 +0100
commitd0f3088aa95e255b39ed4b83da6b08866c2c3e0c (patch)
tree52cf01bb60ce8decc5854d02e85be3dcb0d2f991 /tests/component
parentMerge "Remove unnecessary uses of reinterpret_cast." (diff)
downloadandroid_bootable_recovery-d0f3088aa95e255b39ed4b83da6b08866c2c3e0c.tar
android_bootable_recovery-d0f3088aa95e255b39ed4b83da6b08866c2c3e0c.tar.gz
android_bootable_recovery-d0f3088aa95e255b39ed4b83da6b08866c2c3e0c.tar.bz2
android_bootable_recovery-d0f3088aa95e255b39ed4b83da6b08866c2c3e0c.tar.lz
android_bootable_recovery-d0f3088aa95e255b39ed4b83da6b08866c2c3e0c.tar.xz
android_bootable_recovery-d0f3088aa95e255b39ed4b83da6b08866c2c3e0c.tar.zst
android_bootable_recovery-d0f3088aa95e255b39ed4b83da6b08866c2c3e0c.zip
Diffstat (limited to 'tests/component')
-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);
+}