| 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 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1954 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); |
| 1955 EXPECT_EQ(static_cast<int>(data.length()), | 1955 EXPECT_EQ(static_cast<int>(data.length()), |
| 1956 file_util::WriteFile(foobar, data.c_str(), data.length())); | 1956 file_util::WriteFile(foobar, data.c_str(), data.length())); |
| 1957 EXPECT_EQ(static_cast<int>(data.length()), | 1957 EXPECT_EQ(static_cast<int>(data.length()), |
| 1958 file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1958 file_util::AppendToFile(foobar, data.c_str(), data.length())); |
| 1959 | 1959 |
| 1960 const std::wstring read_content = ReadTextFile(foobar); | 1960 const std::wstring read_content = ReadTextFile(foobar); |
| 1961 EXPECT_EQ(L"hellohello", read_content); | 1961 EXPECT_EQ(L"hellohello", read_content); |
| 1962 } | 1962 } |
| 1963 | 1963 |
| 1964 TEST_F(FileUtilTest, Contains) { | |
| 1965 FilePath data_dir = | |
| 1966 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | |
| 1967 | |
| 1968 // Create a fresh, empty copy of this directory. | |
| 1969 if (file_util::PathExists(data_dir)) { | |
| 1970 ASSERT_TRUE(file_util::Delete(data_dir, true)); | |
| 1971 } | |
| 1972 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | |
| 1973 | |
| 1974 FilePath foo(data_dir.Append(FILE_PATH_LITERAL("foo"))); | |
| 1975 FilePath bar(foo.Append(FILE_PATH_LITERAL("bar.txt"))); | |
| 1976 FilePath baz(data_dir.Append(FILE_PATH_LITERAL("baz.txt"))); | |
| 1977 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | |
| 1978 | |
| 1979 // Annoyingly, the directories must actually exist in order for realpath(), | |
| 1980 // which Contains() relies on in posix, to work. | |
| 1981 ASSERT_TRUE(file_util::CreateDirectory(foo)); | |
| 1982 std::string data("hello"); | |
| 1983 ASSERT_TRUE(file_util::WriteFile(bar, data.c_str(), data.length())); | |
| 1984 ASSERT_TRUE(file_util::WriteFile(baz, data.c_str(), data.length())); | |
| 1985 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); | |
| 1986 | |
| 1987 EXPECT_TRUE(file_util::ContainsPath(foo, bar)); | |
| 1988 EXPECT_FALSE(file_util::ContainsPath(foo, baz)); | |
| 1989 EXPECT_FALSE(file_util::ContainsPath(foo, foobar)); | |
| 1990 EXPECT_FALSE(file_util::ContainsPath(foo, foo)); | |
| 1991 | |
| 1992 // Platform-specific concerns. | |
| 1993 FilePath foo_caps(data_dir.Append(FILE_PATH_LITERAL("FOO"))); | |
| 1994 #if defined(OS_WIN) | |
| 1995 EXPECT_TRUE(file_util::ContainsPath(foo, | |
| 1996 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | |
| 1997 EXPECT_TRUE(file_util::ContainsPath(foo, | |
| 1998 FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt")))); | |
| 1999 #elif defined(OS_MACOSX) | |
| 2000 // We can't really do this test on OS X since the case-sensitivity of the | |
| 2001 // filesystem is configurable. | |
| 2002 #elif defined(OS_POSIX) | |
| 2003 EXPECT_FALSE(file_util::ContainsPath(foo, | |
| 2004 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | |
| 2005 #endif | |
| 2006 } | |
| 2007 | |
| 2008 TEST_F(FileUtilTest, TouchFile) { | 1964 TEST_F(FileUtilTest, TouchFile) { |
| 2009 FilePath data_dir = | 1965 FilePath data_dir = |
| 2010 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1966 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
| 2011 | 1967 |
| 2012 // Create a fresh, empty copy of this directory. | 1968 // Create a fresh, empty copy of this directory. |
| 2013 if (file_util::PathExists(data_dir)) { | 1969 if (file_util::PathExists(data_dir)) { |
| 2014 ASSERT_TRUE(file_util::Delete(data_dir, true)); | 1970 ASSERT_TRUE(file_util::Delete(data_dir, true)); |
| 2015 } | 1971 } |
| 2016 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1972 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); |
| 2017 | 1973 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2422 file_util::VerifyPathControlledByUser( | 2378 file_util::VerifyPathControlledByUser( |
| 2423 base_dir_, text_file_, uid_, ok_gids_)); | 2379 base_dir_, text_file_, uid_, ok_gids_)); |
| 2424 EXPECT_TRUE( | 2380 EXPECT_TRUE( |
| 2425 file_util::VerifyPathControlledByUser( | 2381 file_util::VerifyPathControlledByUser( |
| 2426 sub_dir_, text_file_, uid_, ok_gids_)); | 2382 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2427 } | 2383 } |
| 2428 | 2384 |
| 2429 #endif // defined(OS_POSIX) | 2385 #endif // defined(OS_POSIX) |
| 2430 | 2386 |
| 2431 } // namespace | 2387 } // namespace |
| OLD | NEW |