summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2016-10-18 02:15:29 +0200
committerandroid-build-merger <android-build-merger@google.com>2016-10-18 02:15:29 +0200
commit430b7ae4699eb3685dcc0f7c736a9aebd76829a8 (patch)
treee237b84e2e6f4cd6a562f88ab3e491eca8767e9f /tests
parentMerge "init: move healthd to late-init" (diff)
parentMerge "Change StringValue to use std::string" (diff)
downloadandroid_bootable_recovery-430b7ae4699eb3685dcc0f7c736a9aebd76829a8.tar
android_bootable_recovery-430b7ae4699eb3685dcc0f7c736a9aebd76829a8.tar.gz
android_bootable_recovery-430b7ae4699eb3685dcc0f7c736a9aebd76829a8.tar.bz2
android_bootable_recovery-430b7ae4699eb3685dcc0f7c736a9aebd76829a8.tar.lz
android_bootable_recovery-430b7ae4699eb3685dcc0f7c736a9aebd76829a8.tar.xz
android_bootable_recovery-430b7ae4699eb3685dcc0f7c736a9aebd76829a8.tar.zst
android_bootable_recovery-430b7ae4699eb3685dcc0f7c736a9aebd76829a8.zip
Diffstat (limited to '')
-rw-r--r--tests/component/applypatch_test.cpp132
-rw-r--r--tests/component/edify_test.cpp8
-rw-r--r--tests/component/updater_test.cpp8
3 files changed, 67 insertions, 81 deletions
diff --git a/tests/component/applypatch_test.cpp b/tests/component/applypatch_test.cpp
index 2f7cb02f4..75f2e1014 100644
--- a/tests/component/applypatch_test.cpp
+++ b/tests/component/applypatch_test.cpp
@@ -153,25 +153,16 @@ class ApplyPatchFullTest : public ApplyPatchCacheTest {
struct FileContents fc;
ASSERT_EQ(0, LoadFileContents(&rand_file[0], &fc));
- Value* patch1 = new Value();
- patch1->type = VAL_BLOB;
- patch1->size = fc.data.size();
- patch1->data = static_cast<char*>(malloc(fc.data.size()));
- memcpy(patch1->data, fc.data.data(), fc.data.size());
+ Value* patch1 = new Value(VAL_BLOB, std::string(fc.data.begin(), fc.data.end()));
patches.push_back(patch1);
ASSERT_EQ(0, LoadFileContents(&patch_file[0], &fc));
- Value* patch2 = new Value();
- patch2->type = VAL_BLOB;
- patch2->size = fc.st.st_size;
- patch2->data = static_cast<char*>(malloc(fc.data.size()));
- memcpy(patch2->data, fc.data.data(), fc.data.size());
+ Value* patch2 = new Value(VAL_BLOB, std::string(fc.data.begin(), fc.data.end()));
patches.push_back(patch2);
}
static void TearDownTestCase() {
delete output_f;
for (auto it = patches.begin(); it != patches.end(); ++it) {
- free((*it)->data);
delete *it;
}
patches.clear();
@@ -210,88 +201,87 @@ TemporaryFile* ApplyPatchFullTest::output_f;
std::string ApplyPatchFullTest::output_loc;
TEST_F(ApplyPatchTest, CheckModeSingle) {
- char* s = &old_sha1[0];
- ASSERT_EQ(0, applypatch_check(&old_file[0], 1, &s));
+ std::vector<std::string> sha1s = { old_sha1 };
+ ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
}
TEST_F(ApplyPatchTest, CheckModeMultiple) {
- char* argv[3] = {
- &bad_sha1_a[0],
- &old_sha1[0],
- &bad_sha1_b[0]
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ old_sha1,
+ bad_sha1_b
};
- ASSERT_EQ(0, applypatch_check(&old_file[0], 3, argv));
+ ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
}
TEST_F(ApplyPatchTest, CheckModeFailure) {
- char* argv[2] = {
- &bad_sha1_a[0],
- &bad_sha1_b[0]
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ bad_sha1_b
};
- ASSERT_NE(0, applypatch_check(&old_file[0], 2, argv));
+ ASSERT_NE(0, applypatch_check(&old_file[0], sha1s));
}
TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedSingle) {
mangle_file(old_file);
- char* s = &old_sha1[0];
- ASSERT_EQ(0, applypatch_check(&old_file[0], 1, &s));
+ std::vector<std::string> sha1s = { old_sha1 };
+ ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
}
TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedMultiple) {
mangle_file(old_file);
- char* argv[3] = {
- &bad_sha1_a[0],
- &old_sha1[0],
- &bad_sha1_b[0]
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ old_sha1,
+ bad_sha1_b
};
- ASSERT_EQ(0, applypatch_check(&old_file[0], 3, argv));
+ ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
}
TEST_F(ApplyPatchCacheTest, CheckCacheCorruptedFailure) {
mangle_file(old_file);
- char* argv[2] = {
- &bad_sha1_a[0],
- &bad_sha1_b[0]
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ bad_sha1_b
};
- ASSERT_NE(0, applypatch_check(&old_file[0], 2, argv));
+ ASSERT_NE(0, applypatch_check(&old_file[0], sha1s));
}
TEST_F(ApplyPatchCacheTest, CheckCacheMissingSingle) {
unlink(&old_file[0]);
- char* s = &old_sha1[0];
- ASSERT_EQ(0, applypatch_check(&old_file[0], 1, &s));
+ std::vector<std::string> sha1s = { old_sha1 };
+ ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
}
TEST_F(ApplyPatchCacheTest, CheckCacheMissingMultiple) {
unlink(&old_file[0]);
- char* argv[3] = {
- &bad_sha1_a[0],
- &old_sha1[0],
- &bad_sha1_b[0]
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ old_sha1,
+ bad_sha1_b
};
- ASSERT_EQ(0, applypatch_check(&old_file[0], 3, argv));
+ ASSERT_EQ(0, applypatch_check(&old_file[0], sha1s));
}
TEST_F(ApplyPatchCacheTest, CheckCacheMissingFailure) {
unlink(&old_file[0]);
- char* argv[2] = {
- &bad_sha1_a[0],
- &bad_sha1_b[0]
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ bad_sha1_b
};
- ASSERT_NE(0, applypatch_check(&old_file[0], 2, argv));
+ ASSERT_NE(0, applypatch_check(&old_file[0], sha1s));
}
TEST_F(ApplyPatchFullTest, ApplyInPlace) {
- std::vector<char*> sha1s;
- sha1s.push_back(&bad_sha1_a[0]);
- sha1s.push_back(&old_sha1[0]);
-
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ old_sha1
+ };
int ap_result = applypatch(&old_file[0],
"-",
&new_sha1[0],
new_size,
- 2,
- sha1s.data(),
+ sha1s,
patches.data(),
nullptr);
ASSERT_EQ(0, ap_result);
@@ -301,8 +291,7 @@ TEST_F(ApplyPatchFullTest, ApplyInPlace) {
"-",
&new_sha1[0],
new_size,
- 2,
- sha1s.data(),
+ sha1s,
patches.data(),
nullptr);
ASSERT_EQ(0, ap_result);
@@ -310,15 +299,15 @@ TEST_F(ApplyPatchFullTest, ApplyInPlace) {
}
TEST_F(ApplyPatchFullTest, ApplyInNewLocation) {
- std::vector<char*> sha1s;
- sha1s.push_back(&bad_sha1_a[0]);
- sha1s.push_back(&old_sha1[0]);
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ old_sha1
+ };
int ap_result = applypatch(&old_file[0],
&output_loc[0],
&new_sha1[0],
new_size,
- 2,
- sha1s.data(),
+ sha1s,
patches.data(),
nullptr);
ASSERT_EQ(0, ap_result);
@@ -327,8 +316,7 @@ TEST_F(ApplyPatchFullTest, ApplyInNewLocation) {
&output_loc[0],
&new_sha1[0],
new_size,
- 2,
- sha1s.data(),
+ sha1s,
patches.data(),
nullptr);
ASSERT_EQ(0, ap_result);
@@ -337,15 +325,15 @@ TEST_F(ApplyPatchFullTest, ApplyInNewLocation) {
TEST_F(ApplyPatchFullTest, ApplyCorruptedInNewLocation) {
mangle_file(old_file);
- std::vector<char*> sha1s;
- sha1s.push_back(&bad_sha1_a[0]);
- sha1s.push_back(&old_sha1[0]);
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ old_sha1
+ };
int ap_result = applypatch(&old_file[0],
&output_loc[0],
&new_sha1[0],
new_size,
- 2,
- sha1s.data(),
+ sha1s,
patches.data(),
nullptr);
ASSERT_EQ(0, ap_result);
@@ -354,8 +342,7 @@ TEST_F(ApplyPatchFullTest, ApplyCorruptedInNewLocation) {
&output_loc[0],
&new_sha1[0],
new_size,
- 2,
- sha1s.data(),
+ sha1s,
patches.data(),
nullptr);
ASSERT_EQ(0, ap_result);
@@ -366,15 +353,15 @@ TEST_F(ApplyPatchDoubleCacheTest, ApplyDoubleCorruptedInNewLocation) {
mangle_file(old_file);
mangle_file(cache_file);
- std::vector<char*> sha1s;
- sha1s.push_back(&bad_sha1_a[0]);
- sha1s.push_back(&old_sha1[0]);
+ std::vector<std::string> sha1s = {
+ bad_sha1_a,
+ old_sha1
+ };
int ap_result = applypatch(&old_file[0],
&output_loc[0],
&new_sha1[0],
new_size,
- 2,
- sha1s.data(),
+ sha1s,
patches.data(),
nullptr);
ASSERT_NE(0, ap_result);
@@ -383,8 +370,7 @@ TEST_F(ApplyPatchDoubleCacheTest, ApplyDoubleCorruptedInNewLocation) {
&output_loc[0],
&new_sha1[0],
new_size,
- 2,
- sha1s.data(),
+ sha1s,
patches.data(),
nullptr);
ASSERT_NE(0, ap_result);
diff --git a/tests/component/edify_test.cpp b/tests/component/edify_test.cpp
index a4dbb9fbe..287e40cc6 100644
--- a/tests/component/edify_test.cpp
+++ b/tests/component/edify_test.cpp
@@ -28,15 +28,15 @@ static void expect(const char* expr_str, const char* expected) {
State state(expr_str, nullptr);
- char* result = Evaluate(&state, e);
+ std::string result;
+ bool status = Evaluate(&state, e, &result);
if (expected == nullptr) {
- EXPECT_EQ(nullptr, result);
+ EXPECT_FALSE(status);
} else {
- EXPECT_STREQ(expected, result);
+ EXPECT_STREQ(expected, result.c_str());
}
- free(result);
}
class EdifyTest : public ::testing::Test {
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index 64a6b37ce..a859f11c1 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -32,12 +32,13 @@ static void expect(const char* expected, const char* expr_str, CauseCode cause_c
State state(expr_str, nullptr);
- char* result = Evaluate(&state, e);
+ std::string result;
+ bool status = Evaluate(&state, e, &result);
if (expected == nullptr) {
- EXPECT_EQ(nullptr, result);
+ EXPECT_FALSE(status);
} else {
- EXPECT_STREQ(expected, result);
+ EXPECT_STREQ(expected, result.c_str());
}
// Error code is set in updater/updater.cpp only, by parsing State.errmsg.
@@ -46,7 +47,6 @@ static void expect(const char* expected, const char* expr_str, CauseCode cause_c
// Cause code should always be available.
EXPECT_EQ(cause_code, state.cause_code);
- free(result);
}
class UpdaterTest : public ::testing::Test {