update_engine: Move test-only utils to test_utils.{h,cc}.
utils.{h,cc} contains a collections of basic or small functions used
in different parts of the codebase. The test_utils.{h,cc} instead
contains functions only required during testing split out to a
separated file to be reused in different tests.
This CL moves without changes some functions defined in utils.h that
were only used during unittests. Two other basic functions were replaced
by the same function already present in base/ (StringHasSuffix and
StringHasPrefix). The functions in test_utils.h now have their own
namespace chromeos_update_engine::test_utils so is clear they come
from the test_utils file, in the same way the ones from utils are
in their own namespace.
Some othe minor linter fixes included here.
BUG=chromium:351429
TEST=Unittest still pass.
Change-Id: I73ab72a14158cb21c8e1f404cbc728423bc8f34f
Reviewed-on: https://chromium-review.googlesource.com/229021
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/filesystem_copier_action_unittest.cc b/filesystem_copier_action_unittest.cc
index 131feb8..c551adf 100644
--- a/filesystem_copier_action_unittest.cc
+++ b/filesystem_copier_action_unittest.cc
@@ -143,15 +143,15 @@
// Make random data for a, zero filled data for b.
const size_t kLoopFileSize = 10 * 1024 * 1024 + 512;
vector<char> a_loop_data(kLoopFileSize);
- FillWithData(&a_loop_data);
+ test_utils::FillWithData(&a_loop_data);
vector<char> b_loop_data(run_out_of_space ?
(kLoopFileSize - 1) :
kLoopFileSize,
'\0'); // Fill with 0s
// Write data to disk
- if (!(WriteFileVector(a_loop_file, a_loop_data) &&
- WriteFileVector(b_loop_file, b_loop_data))) {
+ if (!(test_utils::WriteFileVector(a_loop_file, a_loop_data) &&
+ test_utils::WriteFileVector(b_loop_file, b_loop_data))) {
ADD_FAILURE();
return false;
}
@@ -160,8 +160,8 @@
string a_dev;
string b_dev;
- ScopedLoopbackDeviceBinder a_dev_releaser(a_loop_file, &a_dev);
- ScopedLoopbackDeviceBinder b_dev_releaser(b_loop_file, &b_dev);
+ test_utils::ScopedLoopbackDeviceBinder a_dev_releaser(a_loop_file, &a_dev);
+ test_utils::ScopedLoopbackDeviceBinder b_dev_releaser(b_loop_file, &b_dev);
if (!(a_dev_releaser.is_bound() && b_dev_releaser.is_bound())) {
ADD_FAILURE();
return false;
@@ -262,7 +262,8 @@
ADD_FAILURE();
return false;
}
- const bool is_a_file_reading_eq = ExpectVectorsEq(a_loop_data, a_out);
+ const bool is_a_file_reading_eq =
+ test_utils::ExpectVectorsEq(a_loop_data, a_out);
EXPECT_TRUE(is_a_file_reading_eq);
success = success && is_a_file_reading_eq;
if (!verify_hash) {
@@ -271,7 +272,7 @@
ADD_FAILURE();
return false;
}
- const bool is_b_file_reading_eq = ExpectVectorsEq(a_out, b_out);
+ const bool is_b_file_reading_eq = test_utils::ExpectVectorsEq(a_out, b_out);
EXPECT_TRUE(is_b_file_reading_eq);
success = success && is_b_file_reading_eq;
}
@@ -408,9 +409,9 @@
string img;
EXPECT_TRUE(utils::MakeTempFile("img.XXXXXX", &img, nullptr));
ScopedPathUnlinker img_unlinker(img);
- CreateExtImageAtPath(img, nullptr);
+ test_utils::CreateExtImageAtPath(img, nullptr);
// Extend the "partition" holding the file system from 10MiB to 20MiB.
- EXPECT_EQ(0, System(base::StringPrintf(
+ EXPECT_EQ(0, test_utils::System(base::StringPrintf(
"dd if=/dev/zero of=%s seek=20971519 bs=1 count=1",
img.c_str())));
EXPECT_EQ(20 * 1024 * 1024, utils::FileSize(img));