diff options
author | Sen Jiang <senj@google.com> | 2018-07-02 17:34:56 -0700 |
---|---|---|
committer | Sen Jiang <senj@google.com> | 2018-07-03 18:24:09 -0700 |
commit | 0779a151e585ac465de4ea03e710b24f60037724 (patch) | |
tree | 8aee0e5625b8316a95628831f535d272b3f50fee /payload_consumer/file_writer_unittest.cc | |
parent | 0a582fbf50cd420198d29ee64505dd6785a68184 (diff) |
Use ScopedTempFile in unit test.
Replace these 3 lines of code:
string path;
ASSERT_TRUE(utils::MakeTempFile("name-XXXXXX", &path, nullptr));
ScopedPathUnlinker path_unlinker(path);
with one liner:
test_utils::ScopedTempFile file("name-XXXXXX");
Bug: None
Test: unit test
Change-Id: Ic5be7dc8339842270023055bcc3a97e526953f04
Diffstat (limited to 'payload_consumer/file_writer_unittest.cc')
-rw-r--r-- | payload_consumer/file_writer_unittest.cc | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/payload_consumer/file_writer_unittest.cc b/payload_consumer/file_writer_unittest.cc index 92837c88..05df307c 100644 --- a/payload_consumer/file_writer_unittest.cc +++ b/payload_consumer/file_writer_unittest.cc @@ -36,19 +36,17 @@ class FileWriterTest : public ::testing::Test { }; TEST(FileWriterTest, SimpleTest) { // Create a uniquely named file for testing. - string path; - ASSERT_TRUE(utils::MakeTempFile("FileWriterTest-XXXXXX", &path, nullptr)); - ScopedPathUnlinker path_unlinker(path); - + test_utils::ScopedTempFile file("FileWriterTest-XXXXXX"); DirectFileWriter file_writer; - EXPECT_EQ(0, file_writer.Open(path.c_str(), - O_CREAT | O_LARGEFILE | O_TRUNC | O_WRONLY, - 0644)); + EXPECT_EQ(0, + file_writer.Open(file.path().c_str(), + O_CREAT | O_LARGEFILE | O_TRUNC | O_WRONLY, + 0644)); EXPECT_TRUE(file_writer.Write("test", 4)); brillo::Blob actual_data; - EXPECT_TRUE(utils::ReadFile(path, &actual_data)); + EXPECT_TRUE(utils::ReadFile(file.path(), &actual_data)); - EXPECT_FALSE(memcmp("test", actual_data.data(), actual_data.size())); + EXPECT_EQ("test", string(actual_data.begin(), actual_data.end())); EXPECT_EQ(0, file_writer.Close()); } @@ -61,14 +59,12 @@ TEST(FileWriterTest, ErrorTest) { TEST(FileWriterTest, WriteErrorTest) { // Create a uniquely named file for testing. - string path; - ASSERT_TRUE(utils::MakeTempFile("FileWriterTest-XXXXXX", &path, nullptr)); - ScopedPathUnlinker path_unlinker(path); - + test_utils::ScopedTempFile file("FileWriterTest-XXXXXX"); DirectFileWriter file_writer; - EXPECT_EQ(0, file_writer.Open(path.c_str(), - O_CREAT | O_LARGEFILE | O_TRUNC | O_RDONLY, - 0644)); + EXPECT_EQ(0, + file_writer.Open(file.path().c_str(), + O_CREAT | O_LARGEFILE | O_TRUNC | O_RDONLY, + 0644)); EXPECT_FALSE(file_writer.Write("x", 1)); EXPECT_EQ(0, file_writer.Close()); } |