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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 { FPL("//aa/bb"), FPL("//aa") }, | 79 { FPL("//aa/bb"), FPL("//aa") }, |
80 { FPL("//aa/"), FPL("//") }, | 80 { FPL("//aa/"), FPL("//") }, |
81 { FPL("//aa"), FPL("//") }, | 81 { FPL("//aa"), FPL("//") }, |
82 { FPL("0:"), FPL(".") }, | 82 { FPL("0:"), FPL(".") }, |
83 { FPL("@:"), FPL(".") }, | 83 { FPL("@:"), FPL(".") }, |
84 { FPL("[:"), FPL(".") }, | 84 { FPL("[:"), FPL(".") }, |
85 { FPL("`:"), FPL(".") }, | 85 { FPL("`:"), FPL(".") }, |
86 { FPL("{:"), FPL(".") }, | 86 { FPL("{:"), FPL(".") }, |
87 { FPL("\xB3:"), FPL(".") }, | 87 { FPL("\xB3:"), FPL(".") }, |
88 { FPL("\xC5:"), FPL(".") }, | 88 { FPL("\xC5:"), FPL(".") }, |
89 #if defined(OS_WIN) | |
90 { FPL("\x0143:"), FPL(".") }, | |
91 #endif // OS_WIN | |
92 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 89 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
93 { FPL("c:"), FPL("c:") }, | 90 { FPL("c:"), FPL("c:") }, |
94 { FPL("C:"), FPL("C:") }, | 91 { FPL("C:"), FPL("C:") }, |
95 { FPL("A:"), FPL("A:") }, | 92 { FPL("A:"), FPL("A:") }, |
96 { FPL("Z:"), FPL("Z:") }, | 93 { FPL("Z:"), FPL("Z:") }, |
97 { FPL("a:"), FPL("a:") }, | 94 { FPL("a:"), FPL("a:") }, |
98 { FPL("z:"), FPL("z:") }, | 95 { FPL("z:"), FPL("z:") }, |
99 { FPL("c:aa"), FPL("c:") }, | 96 { FPL("c:aa"), FPL("c:") }, |
100 { FPL("c:/"), FPL("c:/") }, | 97 { FPL("c:/"), FPL("c:/") }, |
101 { FPL("c://"), FPL("c://") }, | 98 { FPL("c://"), FPL("c://") }, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 { FPL("//aa/bb"), FPL("bb") }, | 164 { FPL("//aa/bb"), FPL("bb") }, |
168 { FPL("//aa/"), FPL("aa") }, | 165 { FPL("//aa/"), FPL("aa") }, |
169 { FPL("//aa"), FPL("aa") }, | 166 { FPL("//aa"), FPL("aa") }, |
170 { FPL("0:"), FPL("0:") }, | 167 { FPL("0:"), FPL("0:") }, |
171 { FPL("@:"), FPL("@:") }, | 168 { FPL("@:"), FPL("@:") }, |
172 { FPL("[:"), FPL("[:") }, | 169 { FPL("[:"), FPL("[:") }, |
173 { FPL("`:"), FPL("`:") }, | 170 { FPL("`:"), FPL("`:") }, |
174 { FPL("{:"), FPL("{:") }, | 171 { FPL("{:"), FPL("{:") }, |
175 { FPL("\xB3:"), FPL("\xB3:") }, | 172 { FPL("\xB3:"), FPL("\xB3:") }, |
176 { FPL("\xC5:"), FPL("\xC5:") }, | 173 { FPL("\xC5:"), FPL("\xC5:") }, |
177 #if defined(OS_WIN) | |
178 { FPL("\x0143:"), FPL("\x0143:") }, | |
179 #endif // OS_WIN | |
180 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 174 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
181 { FPL("c:"), FPL("") }, | 175 { FPL("c:"), FPL("") }, |
182 { FPL("C:"), FPL("") }, | 176 { FPL("C:"), FPL("") }, |
183 { FPL("A:"), FPL("") }, | 177 { FPL("A:"), FPL("") }, |
184 { FPL("Z:"), FPL("") }, | 178 { FPL("Z:"), FPL("") }, |
185 { FPL("a:"), FPL("") }, | 179 { FPL("a:"), FPL("") }, |
186 { FPL("z:"), FPL("") }, | 180 { FPL("z:"), FPL("") }, |
187 { FPL("c:aa"), FPL("aa") }, | 181 { FPL("c:aa"), FPL("aa") }, |
188 { FPL("c:/"), FPL("/") }, | 182 { FPL("c:/"), FPL("/") }, |
189 { FPL("c://"), FPL("//") }, | 183 { FPL("c://"), FPL("//") }, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 FilePath::StringType leaf(cases[i].inputs[1]); | 300 FilePath::StringType leaf(cases[i].inputs[1]); |
307 FilePath observed_str = root.Append(leaf); | 301 FilePath observed_str = root.Append(leaf); |
308 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) << | 302 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) << |
309 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; | 303 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; |
310 FilePath observed_path = root.Append(FilePath(leaf)); | 304 FilePath observed_path = root.Append(FilePath(leaf)); |
311 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_path.value()) << | 305 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_path.value()) << |
312 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; | 306 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; |
313 | 307 |
314 // TODO(erikkay): It would be nice to have a unicode test append value to | 308 // TODO(erikkay): It would be nice to have a unicode test append value to |
315 // handle the case when AppendASCII is passed UTF8 | 309 // handle the case when AppendASCII is passed UTF8 |
316 #if defined(OS_WIN) | |
317 std::string ascii = WideToUTF8(leaf); | |
318 #elif defined(OS_POSIX) | |
319 std::string ascii = leaf; | 310 std::string ascii = leaf; |
320 #endif | |
321 observed_str = root.AppendASCII(ascii); | 311 observed_str = root.AppendASCII(ascii); |
322 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) << | 312 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) << |
323 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; | 313 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; |
324 } | 314 } |
325 } | 315 } |
326 | 316 |
327 TEST_F(FilePathTest, StripTrailingSeparators) { | 317 TEST_F(FilePathTest, StripTrailingSeparators) { |
328 const struct UnaryTestData cases[] = { | 318 const struct UnaryTestData cases[] = { |
329 { FPL(""), FPL("") }, | 319 { FPL(""), FPL("") }, |
330 { FPL("/"), FPL("/") }, | 320 { FPL("/"), FPL("/") }, |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 973 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
984 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false}, | 974 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false}, |
985 { { FPL("c:/foo.txt"), FPL(".txt") }, true}, | 975 { { FPL("c:/foo.txt"), FPL(".txt") }, true}, |
986 #endif // FILE_PATH_USES_DRIVE_LETTERS | 976 #endif // FILE_PATH_USES_DRIVE_LETTERS |
987 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 977 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
988 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false}, | 978 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false}, |
989 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true}, | 979 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true}, |
990 #endif // FILE_PATH_USES_DRIVE_LETTERS | 980 #endif // FILE_PATH_USES_DRIVE_LETTERS |
991 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false}, | 981 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false}, |
992 { { FPL("/bar/foo.txt"), FPL(".txt") }, true}, | 982 { { FPL("/bar/foo.txt"), FPL(".txt") }, true}, |
993 #if defined(OS_WIN) || defined(OS_MACOSX) | 983 #if defined(OS_MACOSX) |
994 // Umlauts A, O, U: direct comparison, and upper case vs. lower case | 984 // Umlauts A, O, U: direct comparison, and upper case vs. lower case |
995 { { FPL("foo.\u00E4\u00F6\u00FC"), FPL(".\u00E4\u00F6\u00FC") }, true}, | 985 { { FPL("foo.\u00E4\u00F6\u00FC"), FPL(".\u00E4\u00F6\u00FC") }, true}, |
996 { { FPL("foo.\u00C4\u00D6\u00DC"), FPL(".\u00E4\u00F6\u00FC") }, true}, | 986 { { FPL("foo.\u00C4\u00D6\u00DC"), FPL(".\u00E4\u00F6\u00FC") }, true}, |
997 // C with circumflex: direct comparison, and upper case vs. lower case | 987 // C with circumflex: direct comparison, and upper case vs. lower case |
998 { { FPL("foo.\u0109"), FPL(".\u0109") }, true}, | 988 { { FPL("foo.\u0109"), FPL(".\u0109") }, true}, |
999 { { FPL("foo.\u0108"), FPL(".\u0109") }, true}, | 989 { { FPL("foo.\u0108"), FPL(".\u0109") }, true}, |
1000 #endif | 990 #endif |
1001 }; | 991 }; |
1002 | 992 |
1003 for (size_t i = 0; i < arraysize(cases); ++i) { | 993 for (size_t i = 0; i < arraysize(cases); ++i) { |
(...skipping 26 matching lines...) Expand all Loading... |
1030 { { FPL("FOO"), FPL("BAR") }, 1}, | 1020 { { FPL("FOO"), FPL("BAR") }, 1}, |
1031 // German "Eszett" (lower case and the new-fangled upper case) | 1021 // German "Eszett" (lower case and the new-fangled upper case) |
1032 // Note that uc(<lowercase eszett>) => "SS", NOT <uppercase eszett>! | 1022 // Note that uc(<lowercase eszett>) => "SS", NOT <uppercase eszett>! |
1033 // However, neither Windows nor Mac OSX converts these. | 1023 // However, neither Windows nor Mac OSX converts these. |
1034 // (or even have glyphs for <uppercase eszett>) | 1024 // (or even have glyphs for <uppercase eszett>) |
1035 { { FPL("\u00DF"), FPL("\u00DF") }, 0}, | 1025 { { FPL("\u00DF"), FPL("\u00DF") }, 0}, |
1036 { { FPL("\u1E9E"), FPL("\u1E9E") }, 0}, | 1026 { { FPL("\u1E9E"), FPL("\u1E9E") }, 0}, |
1037 { { FPL("\u00DF"), FPL("\u1E9E") }, -1}, | 1027 { { FPL("\u00DF"), FPL("\u1E9E") }, -1}, |
1038 { { FPL("SS"), FPL("\u00DF") }, -1}, | 1028 { { FPL("SS"), FPL("\u00DF") }, -1}, |
1039 { { FPL("SS"), FPL("\u1E9E") }, -1}, | 1029 { { FPL("SS"), FPL("\u1E9E") }, -1}, |
1040 #if defined(OS_WIN) || defined(OS_MACOSX) | 1030 #if defined(OS_MACOSX) |
1041 // Umlauts A, O, U: direct comparison, and upper case vs. lower case | 1031 // Umlauts A, O, U: direct comparison, and upper case vs. lower case |
1042 { { FPL("\u00E4\u00F6\u00FC"), FPL("\u00E4\u00F6\u00FC") }, 0}, | 1032 { { FPL("\u00E4\u00F6\u00FC"), FPL("\u00E4\u00F6\u00FC") }, 0}, |
1043 { { FPL("\u00C4\u00D6\u00DC"), FPL("\u00E4\u00F6\u00FC") }, 0}, | 1033 { { FPL("\u00C4\u00D6\u00DC"), FPL("\u00E4\u00F6\u00FC") }, 0}, |
1044 // C with circumflex: direct comparison, and upper case vs. lower case | 1034 // C with circumflex: direct comparison, and upper case vs. lower case |
1045 { { FPL("\u0109"), FPL("\u0109") }, 0}, | 1035 { { FPL("\u0109"), FPL("\u0109") }, 0}, |
1046 { { FPL("\u0108"), FPL("\u0109") }, 0}, | 1036 { { FPL("\u0108"), FPL("\u0109") }, 0}, |
1047 // Cyrillic letter SHA: direct comparison, and upper case vs. lower case | 1037 // Cyrillic letter SHA: direct comparison, and upper case vs. lower case |
1048 { { FPL("\u0428"), FPL("\u0428") }, 0}, | 1038 { { FPL("\u0428"), FPL("\u0428") }, 0}, |
1049 { { FPL("\u0428"), FPL("\u0448") }, 0}, | 1039 { { FPL("\u0428"), FPL("\u0448") }, 0}, |
1050 // Greek letter DELTA: direct comparison, and upper case vs. lower case | 1040 // Greek letter DELTA: direct comparison, and upper case vs. lower case |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 // Test the PrintTo overload for FilePath (used when a test fails to compare two | 1276 // Test the PrintTo overload for FilePath (used when a test fails to compare two |
1287 // FilePaths). | 1277 // FilePaths). |
1288 TEST_F(FilePathTest, PrintTo) { | 1278 TEST_F(FilePathTest, PrintTo) { |
1289 std::stringstream ss; | 1279 std::stringstream ss; |
1290 FilePath fp(FPL("foo")); | 1280 FilePath fp(FPL("foo")); |
1291 base::PrintTo(fp, &ss); | 1281 base::PrintTo(fp, &ss); |
1292 EXPECT_EQ("foo", ss.str()); | 1282 EXPECT_EQ("foo", ss.str()); |
1293 } | 1283 } |
1294 | 1284 |
1295 } // namespace base | 1285 } // namespace base |
OLD | NEW |