1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "gn/file_writer.h" 6 7 #include "base/files/file_path.h" 8 #include "base/files/scoped_temp_dir.h" 9 #include "gn/filesystem_utils.h" 10 11 #include "util/test/test.h" 12 TEST(FileWriter,SingleWrite)13TEST(FileWriter, SingleWrite) { 14 base::ScopedTempDir temp_dir; 15 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 16 17 std::string data = "foo"; 18 19 base::FilePath file_path = temp_dir.GetPath().AppendASCII("foo.txt"); 20 21 FileWriter writer; 22 EXPECT_TRUE(writer.Create(file_path)); 23 EXPECT_TRUE(writer.Write(data)); 24 EXPECT_TRUE(writer.Close()); 25 26 EXPECT_TRUE(ContentsEqual(file_path, data)); 27 } 28 TEST(FileWriter,MultipleWrites)29TEST(FileWriter, MultipleWrites) { 30 base::ScopedTempDir temp_dir; 31 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 32 33 std::string data = "Hello World!"; 34 35 base::FilePath file_path = temp_dir.GetPath().AppendASCII("foo.txt"); 36 37 FileWriter writer; 38 EXPECT_TRUE(writer.Create(file_path)); 39 EXPECT_TRUE(writer.Write("Hello ")); 40 EXPECT_TRUE(writer.Write("World!")); 41 EXPECT_TRUE(writer.Close()); 42 43 EXPECT_TRUE(ContentsEqual(file_path, data)); 44 } 45