| 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 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1988 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); |
| 1989 EXPECT_EQ(static_cast<int>(data.length()), | 1989 EXPECT_EQ(static_cast<int>(data.length()), |
| 1990 file_util::WriteFile(foobar, data.c_str(), data.length())); | 1990 file_util::WriteFile(foobar, data.c_str(), data.length())); |
| 1991 EXPECT_EQ(static_cast<int>(data.length()), | 1991 EXPECT_EQ(static_cast<int>(data.length()), |
| 1992 file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1992 file_util::AppendToFile(foobar, data.c_str(), data.length())); |
| 1993 | 1993 |
| 1994 const std::wstring read_content = ReadTextFile(foobar); | 1994 const std::wstring read_content = ReadTextFile(foobar); |
| 1995 EXPECT_EQ(L"hellohello", read_content); | 1995 EXPECT_EQ(L"hellohello", read_content); |
| 1996 } | 1996 } |
| 1997 | 1997 |
| 1998 TEST_F(FileUtilTest, Contains) { | |
| 1999 FilePath data_dir = | |
| 2000 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | |
| 2001 | |
| 2002 // Create a fresh, empty copy of this directory. | |
| 2003 if (file_util::PathExists(data_dir)) { | |
| 2004 ASSERT_TRUE(file_util::Delete(data_dir, true)); | |
| 2005 } | |
| 2006 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | |
| 2007 | |
| 2008 FilePath foo(data_dir.Append(FILE_PATH_LITERAL("foo"))); | |
| 2009 FilePath bar(foo.Append(FILE_PATH_LITERAL("bar.txt"))); | |
| 2010 FilePath baz(data_dir.Append(FILE_PATH_LITERAL("baz.txt"))); | |
| 2011 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | |
| 2012 | |
| 2013 // Annoyingly, the directories must actually exist in order for realpath(), | |
| 2014 // which Contains() relies on in posix, to work. | |
| 2015 ASSERT_TRUE(file_util::CreateDirectory(foo)); | |
| 2016 std::string data("hello"); | |
| 2017 ASSERT_TRUE(file_util::WriteFile(bar, data.c_str(), data.length())); | |
| 2018 ASSERT_TRUE(file_util::WriteFile(baz, data.c_str(), data.length())); | |
| 2019 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); | |
| 2020 | |
| 2021 EXPECT_TRUE(file_util::ContainsPath(foo, bar)); | |
| 2022 EXPECT_FALSE(file_util::ContainsPath(foo, baz)); | |
| 2023 EXPECT_FALSE(file_util::ContainsPath(foo, foobar)); | |
| 2024 EXPECT_FALSE(file_util::ContainsPath(foo, foo)); | |
| 2025 | |
| 2026 // Platform-specific concerns. | |
| 2027 FilePath foo_caps(data_dir.Append(FILE_PATH_LITERAL("FOO"))); | |
| 2028 #if defined(OS_WIN) | |
| 2029 EXPECT_TRUE(file_util::ContainsPath(foo, | |
| 2030 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | |
| 2031 EXPECT_TRUE(file_util::ContainsPath(foo, | |
| 2032 FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt")))); | |
| 2033 #elif defined(OS_MACOSX) | |
| 2034 // We can't really do this test on OS X since the case-sensitivity of the | |
| 2035 // filesystem is configurable. | |
| 2036 #elif defined(OS_POSIX) | |
| 2037 EXPECT_FALSE(file_util::ContainsPath(foo, | |
| 2038 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | |
| 2039 #endif | |
| 2040 } | |
| 2041 | |
| 2042 TEST_F(FileUtilTest, TouchFile) { | 1998 TEST_F(FileUtilTest, TouchFile) { |
| 2043 FilePath data_dir = | 1999 FilePath data_dir = |
| 2044 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 2000 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
| 2045 | 2001 |
| 2046 // Create a fresh, empty copy of this directory. | 2002 // Create a fresh, empty copy of this directory. |
| 2047 if (file_util::PathExists(data_dir)) { | 2003 if (file_util::PathExists(data_dir)) { |
| 2048 ASSERT_TRUE(file_util::Delete(data_dir, true)); | 2004 ASSERT_TRUE(file_util::Delete(data_dir, true)); |
| 2049 } | 2005 } |
| 2050 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 2006 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); |
| 2051 | 2007 |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2456 file_util::VerifyPathControlledByUser( | 2412 file_util::VerifyPathControlledByUser( |
| 2457 base_dir_, text_file_, uid_, ok_gids_)); | 2413 base_dir_, text_file_, uid_, ok_gids_)); |
| 2458 EXPECT_TRUE( | 2414 EXPECT_TRUE( |
| 2459 file_util::VerifyPathControlledByUser( | 2415 file_util::VerifyPathControlledByUser( |
| 2460 sub_dir_, text_file_, uid_, ok_gids_)); | 2416 sub_dir_, text_file_, uid_, ok_gids_)); |
| 2461 } | 2417 } |
| 2462 | 2418 |
| 2463 #endif // defined(OS_POSIX) | 2419 #endif // defined(OS_POSIX) |
| 2464 | 2420 |
| 2465 } // namespace | 2421 } // namespace |
| OLD | NEW |