summaryrefslogtreecommitdiffstats
path: root/tests/component
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-07-10 00:08:50 +0200
committerTao Bao <tbao@google.com>2018-07-10 19:38:47 +0200
commitbafd6c7afb134b78673b4d8ff680082cb3d5a805 (patch)
treef2780106455f5bc6c318f8949b81aa480bfdf47d /tests/component
parentMerge "edify: Rename parse_string to ParseString and let it take std::string." (diff)
downloadandroid_bootable_recovery-bafd6c7afb134b78673b4d8ff680082cb3d5a805.tar
android_bootable_recovery-bafd6c7afb134b78673b4d8ff680082cb3d5a805.tar.gz
android_bootable_recovery-bafd6c7afb134b78673b4d8ff680082cb3d5a805.tar.bz2
android_bootable_recovery-bafd6c7afb134b78673b4d8ff680082cb3d5a805.tar.lz
android_bootable_recovery-bafd6c7afb134b78673b4d8ff680082cb3d5a805.tar.xz
android_bootable_recovery-bafd6c7afb134b78673b4d8ff680082cb3d5a805.tar.zst
android_bootable_recovery-bafd6c7afb134b78673b4d8ff680082cb3d5a805.zip
Diffstat (limited to 'tests/component')
-rw-r--r--tests/component/updater_test.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index 91e5cc1aa..9fcf17f13 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -51,6 +51,8 @@
#include "updater/install.h"
#include "updater/updater.h"
+using namespace std::string_literals;
+
using PackageEntries = std::unordered_map<std::string, std::string>;
static constexpr size_t kTransferListHeaderLines = 4;
@@ -366,6 +368,27 @@ TEST_F(UpdaterTest, package_extract_file) {
CloseArchive(handle);
}
+TEST_F(UpdaterTest, read_file) {
+ // read_file() expects one argument.
+ expect(nullptr, "read_file()", kArgsParsingFailure);
+ expect(nullptr, "read_file(\"arg1\", \"arg2\")", kArgsParsingFailure);
+
+ // Write some value to file and read back.
+ TemporaryFile temp_file;
+ std::string script("write_value(\"foo\", \""s + temp_file.path + "\");");
+ expect("t", script, kNoCause);
+
+ script = "read_file(\""s + temp_file.path + "\") == \"foo\"";
+ expect("t", script, kNoCause);
+
+ script = "read_file(\""s + temp_file.path + "\") == \"bar\"";
+ expect("", script, kNoCause);
+
+ // It should fail gracefully when read fails.
+ script = "read_file(\"/doesntexist\")";
+ expect("", script, kNoCause);
+}
+
TEST_F(UpdaterTest, write_value) {
// write_value() expects two arguments.
expect(nullptr, "write_value()", kArgsParsingFailure);