OLD | NEW |
---|---|
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 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1917 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1917 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); |
1918 EXPECT_EQ(static_cast<int>(data.length()), | 1918 EXPECT_EQ(static_cast<int>(data.length()), |
1919 file_util::WriteFile(foobar, data.c_str(), data.length())); | 1919 file_util::WriteFile(foobar, data.c_str(), data.length())); |
1920 EXPECT_EQ(static_cast<int>(data.length()), | 1920 EXPECT_EQ(static_cast<int>(data.length()), |
1921 file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1921 file_util::AppendToFile(foobar, data.c_str(), data.length())); |
1922 | 1922 |
1923 const std::wstring read_content = ReadTextFile(foobar); | 1923 const std::wstring read_content = ReadTextFile(foobar); |
1924 EXPECT_EQ(L"hellohello", read_content); | 1924 EXPECT_EQ(L"hellohello", read_content); |
1925 } | 1925 } |
1926 | 1926 |
1927 TEST_F(FileUtilTest, ReadFileToString) { | |
1928 const char kTestData[] = "0123"; | |
1929 std::string data; | |
1930 | |
1931 FilePath file_path = | |
1932 temp_dir_.path().Append(FILE_PATH_LITERAL("ReadFileToStringTest")); | |
1933 | |
1934 ASSERT_EQ(4, file_util::WriteFile(file_path, kTestData, 4)); | |
1935 | |
1936 EXPECT_TRUE(ReadFileToString(file_path, &data)); | |
1937 EXPECT_EQ(kTestData, data); | |
1938 | |
1939 data.clear(); | |
1940 EXPECT_FALSE(ReadFileToString(file_path, &data, 0)); | |
1941 EXPECT_EQ(data.length(), (size_t)0); | |
bartfab (slow)
2014/02/11 12:51:12
Nit: Use C++-style casts, not C-style casts. In th
kaliamoorthi
2014/02/11 16:29:16
Done.
| |
1942 | |
1943 data.clear(); | |
1944 EXPECT_FALSE(ReadFileToString(file_path, &data, 2)); | |
1945 EXPECT_EQ(data.length(), (size_t)0); | |
1946 | |
1947 data.clear(); | |
1948 EXPECT_FALSE(ReadFileToString(file_path, &data, 3)); | |
1949 EXPECT_EQ(data.length(), (size_t)0); | |
1950 | |
1951 data.clear(); | |
1952 EXPECT_TRUE(ReadFileToString(file_path, &data, 4)); | |
1953 EXPECT_EQ("0123", data); | |
1954 | |
1955 data.clear(); | |
1956 EXPECT_TRUE(ReadFileToString(file_path, &data, 6)); | |
1957 EXPECT_EQ("0123", data); | |
1958 | |
1959 EXPECT_TRUE(ReadFileToString(file_path, NULL, 6)); | |
1960 | |
1961 EXPECT_TRUE(ReadFileToString(file_path, NULL)); | |
1962 | |
1963 // Make sure we can & do delete the created file to prevent leaks on the bots. | |
bartfab (slow)
2014/02/11 12:51:12
Nit 1: Avoid abbreviations, s/&/and/.
Nit 2: The c
kaliamoorthi
2014/02/11 16:29:16
Done.
| |
1964 EXPECT_TRUE(base::DeleteFile(file_path, false)); | |
bartfab (slow)
2014/02/11 12:51:12
Nit: For readability, add a blank like after this
kaliamoorthi
2014/02/11 16:29:16
Done.
| |
1965 EXPECT_FALSE(ReadFileToString(file_path, &data)); | |
1966 EXPECT_FALSE(ReadFileToString(file_path, &data, 6)); | |
1967 } | |
1968 | |
1927 TEST_F(FileUtilTest, TouchFile) { | 1969 TEST_F(FileUtilTest, TouchFile) { |
1928 FilePath data_dir = | 1970 FilePath data_dir = |
1929 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1971 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
1930 | 1972 |
1931 // Create a fresh, empty copy of this directory. | 1973 // Create a fresh, empty copy of this directory. |
1932 if (PathExists(data_dir)) { | 1974 if (PathExists(data_dir)) { |
1933 ASSERT_TRUE(DeleteFile(data_dir, true)); | 1975 ASSERT_TRUE(DeleteFile(data_dir, true)); |
1934 } | 1976 } |
1935 ASSERT_TRUE(CreateDirectory(data_dir)); | 1977 ASSERT_TRUE(CreateDirectory(data_dir)); |
1936 | 1978 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2386 int fd = OpenContentUriForRead(path); | 2428 int fd = OpenContentUriForRead(path); |
2387 EXPECT_EQ(-1, fd); | 2429 EXPECT_EQ(-1, fd); |
2388 } | 2430 } |
2389 #endif | 2431 #endif |
2390 | 2432 |
2391 #endif // defined(OS_POSIX) | 2433 #endif // defined(OS_POSIX) |
2392 | 2434 |
2393 } // namespace | 2435 } // namespace |
2394 | 2436 |
2395 } // namespace base | 2437 } // namespace base |
OLD | NEW |