summaryrefslogtreecommitdiffstats
path: root/tests/component/updater_test.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-04 05:47:15 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-11-04 05:47:15 +0100
commit3e8666172bf1cc7f35d8ca425476e57b86299320 (patch)
treeb64de3607b9e39f2be75b926183fa0c75b54d18f /tests/component/updater_test.cpp
parentMerge "tests: Set up testdata path for continuous native tests." am: 4011bb161a am: a98b4e4bef am: f35ce240a1 (diff)
parentMerge "updater: Fix an off-by-1 bug in file_getprop()." am: da2b34b5d0 am: 917be35f0f (diff)
downloadandroid_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.gz
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.bz2
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.lz
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.xz
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.zst
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.zip
Diffstat (limited to 'tests/component/updater_test.cpp')
-rw-r--r--tests/component/updater_test.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index a859f11c1..bd1df558e 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -16,7 +16,9 @@
#include <string>
+#include <android-base/file.h>
#include <android-base/properties.h>
+#include <android-base/test_utils.h>
#include <gtest/gtest.h>
#include "edify/expr.h"
@@ -97,3 +99,51 @@ TEST_F(UpdaterTest, sha1_check) {
// sha1_check() expects at least one argument.
expect(nullptr, "sha1_check()", kArgsParsingFailure);
}
+
+TEST_F(UpdaterTest, file_getprop) {
+ // file_getprop() expects two arguments.
+ expect(nullptr, "file_getprop()", kArgsParsingFailure);
+ expect(nullptr, "file_getprop(\"arg1\")", kArgsParsingFailure);
+ expect(nullptr, "file_getprop(\"arg1\", \"arg2\", \"arg3\")", kArgsParsingFailure);
+
+ // File doesn't exist.
+ expect(nullptr, "file_getprop(\"/doesntexist\", \"key1\")", kFileGetPropFailure);
+
+ // Reject too large files (current limit = 65536).
+ TemporaryFile temp_file1;
+ std::string buffer(65540, '\0');
+ ASSERT_TRUE(android::base::WriteStringToFile(buffer, temp_file1.path));
+
+ // Read some keys.
+ TemporaryFile temp_file2;
+ std::string content("ro.product.name=tardis\n"
+ "# comment\n\n\n"
+ "ro.product.model\n"
+ "ro.product.board = magic \n");
+ ASSERT_TRUE(android::base::WriteStringToFile(content, temp_file2.path));
+
+ std::string script1("file_getprop(\"" + std::string(temp_file2.path) +
+ "\", \"ro.product.name\")");
+ expect("tardis", script1.c_str(), kNoCause);
+
+ std::string script2("file_getprop(\"" + std::string(temp_file2.path) +
+ "\", \"ro.product.board\")");
+ expect("magic", script2.c_str(), kNoCause);
+
+ // No match.
+ std::string script3("file_getprop(\"" + std::string(temp_file2.path) +
+ "\", \"ro.product.wrong\")");
+ expect("", script3.c_str(), kNoCause);
+
+ std::string script4("file_getprop(\"" + std::string(temp_file2.path) +
+ "\", \"ro.product.name=\")");
+ expect("", script4.c_str(), kNoCause);
+
+ std::string script5("file_getprop(\"" + std::string(temp_file2.path) +
+ "\", \"ro.product.nam\")");
+ expect("", script5.c_str(), kNoCause);
+
+ std::string script6("file_getprop(\"" + std::string(temp_file2.path) +
+ "\", \"ro.product.model\")");
+ expect("", script6.c_str(), kNoCause);
+}