Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: base/files/file_util_unittest.cc

Issue 614893004: Refactor AppendToFile and WriteFileDescriptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/files/file_util_posix.cc ('k') | base/files/file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 ASSERT_TRUE(CreateDirectory(data_dir)); 1970 ASSERT_TRUE(CreateDirectory(data_dir));
1971 1971
1972 // Create a fresh, empty copy of this directory. 1972 // Create a fresh, empty copy of this directory.
1973 if (PathExists(data_dir)) { 1973 if (PathExists(data_dir)) {
1974 ASSERT_TRUE(DeleteFile(data_dir, true)); 1974 ASSERT_TRUE(DeleteFile(data_dir, true));
1975 } 1975 }
1976 ASSERT_TRUE(CreateDirectory(data_dir)); 1976 ASSERT_TRUE(CreateDirectory(data_dir));
1977 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); 1977 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt")));
1978 1978
1979 std::string data("hello"); 1979 std::string data("hello");
1980 EXPECT_EQ(-1, AppendToFile(foobar, data.c_str(), data.length())); 1980 EXPECT_FALSE(AppendToFile(foobar, data.c_str(), data.size()));
1981 EXPECT_EQ(static_cast<int>(data.length()), 1981 EXPECT_EQ(static_cast<int>(data.length()),
1982 WriteFile(foobar, data.c_str(), data.length())); 1982 WriteFile(foobar, data.c_str(), data.length()));
1983 EXPECT_EQ(static_cast<int>(data.length()), 1983 EXPECT_TRUE(AppendToFile(foobar, data.c_str(), data.size()));
1984 AppendToFile(foobar, data.c_str(), data.length()));
1985 1984
1986 const std::wstring read_content = ReadTextFile(foobar); 1985 const std::wstring read_content = ReadTextFile(foobar);
1987 EXPECT_EQ(L"hellohello", read_content); 1986 EXPECT_EQ(L"hellohello", read_content);
1988 } 1987 }
1989 1988
1990 TEST_F(FileUtilTest, ReadFile) { 1989 TEST_F(FileUtilTest, ReadFile) {
1991 // Create a test file to be read. 1990 // Create a test file to be read.
1992 const std::string kTestData("The quick brown fox jumps over the lazy dog."); 1991 const std::string kTestData("The quick brown fox jumps over the lazy dog.");
1993 FilePath file_path = 1992 FilePath file_path =
1994 temp_dir_.path().Append(FILE_PATH_LITERAL("ReadFileTest")); 1993 temp_dir_.path().Append(FILE_PATH_LITERAL("ReadFileTest"));
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 // Trying to close it should crash. This is important for security. 2586 // Trying to close it should crash. This is important for security.
2588 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); 2587 EXPECT_DEATH(CloseWithScopedFD(fds[1]), "");
2589 #endif 2588 #endif
2590 } 2589 }
2591 2590
2592 #endif // defined(OS_POSIX) 2591 #endif // defined(OS_POSIX)
2593 2592
2594 } // namespace 2593 } // namespace
2595 2594
2596 } // namespace base 2595 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_util_posix.cc ('k') | base/files/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698