OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
971 FilePath::StringType result; | 971 FilePath::StringType result; |
972 for (size_t j = 0; j < comps.size(); ++j) { | 972 for (size_t j = 0; j < comps.size(); ++j) { |
973 result.append(comps[j]); | 973 result.append(comps[j]); |
974 if (j < comps.size() - 1) | 974 if (j < comps.size() - 1) |
975 result.append(FILE_PATH_LITERAL("|"), 1); | 975 result.append(FILE_PATH_LITERAL("|"), 1); |
976 } | 976 } |
977 EXPECT_EQ(kPathComponents[i].result, result); | 977 EXPECT_EQ(kPathComponents[i].result, result); |
978 } | 978 } |
979 } | 979 } |
980 | 980 |
981 TEST_F(FileUtilTest, Contains) { | |
982 FilePath data_dir; | |
983 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &data_dir)); | |
984 data_dir = data_dir.Append(FILE_PATH_LITERAL("FilePathTest")); | |
985 | |
986 // Create a fresh, empty copy of this directory. | |
987 ASSERT_TRUE(file_util::Delete(data_dir, true)); | |
988 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | |
989 | |
990 FilePath foo(data_dir.Append(FILE_PATH_LITERAL("foo"))); | |
991 FilePath bar(foo.Append(FILE_PATH_LITERAL("bar.txt"))); | |
992 FilePath baz(data_dir.Append(FILE_PATH_LITERAL("baz.txt"))); | |
993 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | |
994 | |
995 // Annoyingly, the directories must actually exist in order for realpath(), | |
996 // which Contains() relies on in posix, to work. | |
997 ASSERT_TRUE(file_util::CreateDirectory(foo)); | |
998 std::string data("hello"); | |
999 ASSERT_TRUE(file_util::WriteFile(bar.ToWStringHack(), data.c_str(), | |
1000 data.length())); | |
1001 ASSERT_TRUE(file_util::WriteFile(baz.ToWStringHack(), data.c_str(), | |
1002 data.length())); | |
1003 ASSERT_TRUE(file_util::WriteFile(foobar.ToWStringHack(), data.c_str(), | |
1004 data.length())); | |
1005 | |
1006 EXPECT_TRUE(file_util::ContainsPath(foo, bar)); | |
1007 EXPECT_FALSE(file_util::ContainsPath(foo, baz)); | |
1008 EXPECT_FALSE(file_util::ContainsPath(foo, foobar)); | |
1009 EXPECT_FALSE(file_util::ContainsPath(foo, foo)); | |
1010 | |
1011 // Platform-specific concerns | |
Erik does not do reviews
2009/01/12 17:14:05
missing indent
| |
1012 FilePath foo_caps(data_dir.Append(FILE_PATH_LITERAL("FOO"))); | |
1013 #if defined(OS_WIN) | |
1014 EXPECT_TRUE(file_util::ContainsPath(foo, | |
1015 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | |
1016 EXPECT_TRUE(file_util::ContainsPath(foo, | |
1017 FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt")))); | |
1018 #elif defined(OS_LINUX) | |
1019 EXPECT_FALSE(file_util::ContainsPath(foo, | |
1020 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | |
1021 #else | |
1022 // We can't really do this test on osx since the case-sensitivity of the | |
1023 // filesystem is configurable. | |
1024 #endif | |
1025 } | |
1026 | |
981 } // namespace | 1027 } // namespace |
OLD | NEW |