summaryrefslogtreecommitdiffstats
path: root/tests/component/updater_test.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-07-09 22:32:28 +0200
committerTao Bao <tbao@google.com>2018-07-10 08:27:50 +0200
commitd8d514fa33a2f2f9504732a19fdba81a6ccccbd7 (patch)
tree1b4ad7625bdb4f4b7a56fe855d8c5199b691dd88 /tests/component/updater_test.cpp
parentMerge "applypatch: Restrict applypatch_check to eMMC targets." (diff)
downloadandroid_bootable_recovery-d8d514fa33a2f2f9504732a19fdba81a6ccccbd7.tar
android_bootable_recovery-d8d514fa33a2f2f9504732a19fdba81a6ccccbd7.tar.gz
android_bootable_recovery-d8d514fa33a2f2f9504732a19fdba81a6ccccbd7.tar.bz2
android_bootable_recovery-d8d514fa33a2f2f9504732a19fdba81a6ccccbd7.tar.lz
android_bootable_recovery-d8d514fa33a2f2f9504732a19fdba81a6ccccbd7.tar.xz
android_bootable_recovery-d8d514fa33a2f2f9504732a19fdba81a6ccccbd7.tar.zst
android_bootable_recovery-d8d514fa33a2f2f9504732a19fdba81a6ccccbd7.zip
Diffstat (limited to '')
-rw-r--r--tests/component/updater_test.cpp60
1 files changed, 30 insertions, 30 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index f50e861b0..81ea3b61b 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -57,11 +57,11 @@ static constexpr size_t kTransferListHeaderLines = 4;
struct selabel_handle* sehandle = nullptr;
-static void expect(const char* expected, const char* expr_str, CauseCode cause_code,
+static void expect(const char* expected, const std::string& expr_str, CauseCode cause_code,
UpdaterInfo* info = nullptr) {
std::unique_ptr<Expr> e;
int error_count = 0;
- ASSERT_EQ(0, parse_string(expr_str, &e, &error_count));
+ ASSERT_EQ(0, ParseString(expr_str, &e, &error_count));
ASSERT_EQ(0, error_count);
State state(expr_str, info);
@@ -126,7 +126,7 @@ static void RunBlockImageUpdate(bool is_verify, const PackageEntries& entries,
std::string script = is_verify ? "block_image_verify" : "block_image_update";
script += R"((")" + image_file + R"(", package_extract_file("transfer_list"), ")" + new_data +
R"(", "patch_data"))";
- expect(result.c_str(), script.c_str(), cause_code, &updater_info);
+ expect(result.c_str(), script, cause_code, &updater_info);
ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
CloseArchive(handle);
@@ -230,7 +230,7 @@ TEST_F(UpdaterTest, apply_patch_check) {
std::string filename = android::base::Join(
std::vector<std::string>{ "EMMC", src_file, std::to_string(src_size), src_hash }, ":");
std::string cmd = "apply_patch_check(\"" + filename + "\")";
- expect("t", cmd.c_str(), kNoCause);
+ expect("t", cmd, kNoCause);
// EMMC:file:(size-1):sha1:(size+1):sha1 should fail the check.
std::string filename_bad = android::base::Join(
@@ -238,7 +238,7 @@ TEST_F(UpdaterTest, apply_patch_check) {
std::to_string(src_size + 1), src_hash },
":");
cmd = "apply_patch_check(\"" + filename_bad + "\")";
- expect("", cmd.c_str(), kNoCause);
+ expect("", cmd, kNoCause);
// EMMC:file:(size-1):sha1:size:sha1:(size+1):sha1 should pass the check.
filename_bad =
@@ -247,21 +247,21 @@ TEST_F(UpdaterTest, apply_patch_check) {
std::to_string(src_size + 1), src_hash },
":");
cmd = "apply_patch_check(\"" + filename_bad + "\")";
- expect("t", cmd.c_str(), kNoCause);
+ expect("t", cmd, kNoCause);
// Multiple arguments.
// As long as it successfully loads the partition specified in filename, it won't check against
// any given SHAs.
cmd = "apply_patch_check(\"" + filename + "\", \"wrong_sha1\", \"wrong_sha2\")";
- expect("t", cmd.c_str(), kNoCause);
+ expect("t", cmd, kNoCause);
cmd = "apply_patch_check(\"" + filename + "\", \"wrong_sha1\", \"" + src_hash +
"\", \"wrong_sha2\")";
- expect("t", cmd.c_str(), kNoCause);
+ expect("t", cmd, kNoCause);
cmd = "apply_patch_check(\"" + filename_bad + "\", \"wrong_sha1\", \"" + src_hash +
"\", \"wrong_sha2\")";
- expect("t", cmd.c_str(), kNoCause);
+ expect("t", cmd, kNoCause);
}
TEST_F(UpdaterTest, file_getprop) {
@@ -288,28 +288,28 @@ TEST_F(UpdaterTest, file_getprop) {
std::string script1("file_getprop(\"" + std::string(temp_file2.path) +
"\", \"ro.product.name\")");
- expect("tardis", script1.c_str(), kNoCause);
+ expect("tardis", script1, kNoCause);
std::string script2("file_getprop(\"" + std::string(temp_file2.path) +
"\", \"ro.product.board\")");
- expect("magic", script2.c_str(), kNoCause);
+ expect("magic", script2, kNoCause);
// No match.
std::string script3("file_getprop(\"" + std::string(temp_file2.path) +
"\", \"ro.product.wrong\")");
- expect("", script3.c_str(), kNoCause);
+ expect("", script3, kNoCause);
std::string script4("file_getprop(\"" + std::string(temp_file2.path) +
"\", \"ro.product.name=\")");
- expect("", script4.c_str(), kNoCause);
+ expect("", script4, kNoCause);
std::string script5("file_getprop(\"" + std::string(temp_file2.path) +
"\", \"ro.product.nam\")");
- expect("", script5.c_str(), kNoCause);
+ expect("", script5, kNoCause);
std::string script6("file_getprop(\"" + std::string(temp_file2.path) +
"\", \"ro.product.model\")");
- expect("", script6.c_str(), kNoCause);
+ expect("", script6, kNoCause);
}
// TODO: Test extracting to block device.
@@ -329,7 +329,7 @@ TEST_F(UpdaterTest, package_extract_file) {
// Two-argument version.
TemporaryFile temp_file1;
std::string script("package_extract_file(\"a.txt\", \"" + std::string(temp_file1.path) + "\")");
- expect("t", script.c_str(), kNoCause, &updater_info);
+ expect("t", script, kNoCause, &updater_info);
// Verify the extracted entry.
std::string data;
@@ -338,30 +338,30 @@ TEST_F(UpdaterTest, package_extract_file) {
// Now extract another entry to the same location, which should overwrite.
script = "package_extract_file(\"b.txt\", \"" + std::string(temp_file1.path) + "\")";
- expect("t", script.c_str(), kNoCause, &updater_info);
+ expect("t", script, kNoCause, &updater_info);
ASSERT_TRUE(android::base::ReadFileToString(temp_file1.path, &data));
ASSERT_EQ(kBTxtContents, data);
// Missing zip entry. The two-argument version doesn't abort.
script = "package_extract_file(\"doesntexist\", \"" + std::string(temp_file1.path) + "\")";
- expect("", script.c_str(), kNoCause, &updater_info);
+ expect("", script, kNoCause, &updater_info);
// Extract to /dev/full should fail.
script = "package_extract_file(\"a.txt\", \"/dev/full\")";
- expect("", script.c_str(), kNoCause, &updater_info);
+ expect("", script, kNoCause, &updater_info);
// One-argument version. package_extract_file() gives a VAL_BLOB, which needs to be converted to
// VAL_STRING for equality test.
script = "blob_to_string(package_extract_file(\"a.txt\")) == \"" + kATxtContents + "\"";
- expect("t", script.c_str(), kNoCause, &updater_info);
+ expect("t", script, kNoCause, &updater_info);
script = "blob_to_string(package_extract_file(\"b.txt\")) == \"" + kBTxtContents + "\"";
- expect("t", script.c_str(), kNoCause, &updater_info);
+ expect("t", script, kNoCause, &updater_info);
// Missing entry. The one-argument version aborts the evaluation.
script = "package_extract_file(\"doesntexist\")";
- expect(nullptr, script.c_str(), kPackageExtractFileFailure, &updater_info);
+ expect(nullptr, script, kPackageExtractFileFailure, &updater_info);
CloseArchive(handle);
}
@@ -379,7 +379,7 @@ TEST_F(UpdaterTest, write_value) {
TemporaryFile temp_file;
std::string value = "magicvalue";
std::string script("write_value(\"" + value + "\", \"" + std::string(temp_file.path) + "\")");
- expect("t", script.c_str(), kNoCause);
+ expect("t", script, kNoCause);
// Verify the content.
std::string content;
@@ -388,7 +388,7 @@ TEST_F(UpdaterTest, write_value) {
// Allow writing empty string.
script = "write_value(\"\", \"" + std::string(temp_file.path) + "\")";
- expect("t", script.c_str(), kNoCause);
+ expect("t", script, kNoCause);
// Verify the content.
ASSERT_TRUE(android::base::ReadFileToString(temp_file.path, &content));
@@ -396,7 +396,7 @@ TEST_F(UpdaterTest, write_value) {
// It should fail gracefully when write fails.
script = "write_value(\"value\", \"/proc/0/file1\")";
- expect("", script.c_str(), kNoCause);
+ expect("", script, kNoCause);
}
TEST_F(UpdaterTest, get_stage) {
@@ -415,11 +415,11 @@ TEST_F(UpdaterTest, get_stage) {
// Can read the stage value.
std::string script("get_stage(\"" + temp_file + "\")");
- expect("2/3", script.c_str(), kNoCause);
+ expect("2/3", script, kNoCause);
// Bad BCB path.
script = "get_stage(\"doesntexist\")";
- expect("", script.c_str(), kNoCause);
+ expect("", script, kNoCause);
}
TEST_F(UpdaterTest, set_stage) {
@@ -439,7 +439,7 @@ TEST_F(UpdaterTest, set_stage) {
// Write with set_stage().
std::string script("set_stage(\"" + temp_file + "\", \"1/3\")");
- expect(tf.path, script.c_str(), kNoCause);
+ expect(tf.path, script, kNoCause);
// Verify.
bootloader_message boot_verify;
@@ -451,10 +451,10 @@ TEST_F(UpdaterTest, set_stage) {
// Bad BCB path.
script = "set_stage(\"doesntexist\", \"1/3\")";
- expect("", script.c_str(), kNoCause);
+ expect("", script, kNoCause);
script = "set_stage(\"/dev/full\", \"1/3\")";
- expect("", script.c_str(), kNoCause);
+ expect("", script, kNoCause);
}
TEST_F(UpdaterTest, set_progress) {