Remove FileWriter from common/utils.h
The FileWriter abstraction is used to write the payload to the
DeltaPerformer. This patch removes its usage from the utils.h and
replaces it with the WriteAll() function already existing in utils.h
Bug: None
Test: Added unittests.
Change-Id: I2d9251565c8978af41ee55f7eae2cede56a72ac2
diff --git a/common/utils_unittest.cc b/common/utils_unittest.cc
index 634de01..7852910 100644
--- a/common/utils_unittest.cc
+++ b/common/utils_unittest.cc
@@ -52,6 +52,21 @@
EXPECT_EQ("", utils::ParseECVersion("b=1231a fw_version a=fasd2"));
}
+TEST(UtilsTest, WriteFileOpenFailure) {
+ EXPECT_FALSE(utils::WriteFile("/this/doesn't/exist", "hello", 5));
+}
+
+TEST(UtilsTest, WriteFileReadFile) {
+ base::FilePath file;
+ EXPECT_TRUE(base::CreateTemporaryFile(&file));
+ ScopedPathUnlinker unlinker(file.value());
+ EXPECT_TRUE(utils::WriteFile(file.value().c_str(), "hello", 5));
+
+ brillo::Blob readback;
+ EXPECT_TRUE(utils::ReadFile(file.value().c_str(), &readback));
+ EXPECT_EQ("hello", string(readback.begin(), readback.end()));
+}
+
TEST(UtilsTest, ReadFileFailure) {
brillo::Blob empty;
EXPECT_FALSE(utils::ReadFile("/this/doesn't/exist", &empty));