Update broken references to image assets
[chromium-blink-merge.git] / base / files / file_path_unittest.cc
blobbc0e8432e0e1466581a37208d8b8d29e343b458b
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
3 // found in the LICENSE file.
5 #include <sstream>
7 #include "base/basictypes.h"
8 #include "base/files/file_path.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
13 #if defined(OS_POSIX)
14 #include "base/test/scoped_locale.h"
15 #endif
17 // This macro helps avoid wrapped lines in the test structs.
18 #define FPL(x) FILE_PATH_LITERAL(x)
20 // This macro constructs strings which can contain NULs.
21 #define FPS(x) FilePath::StringType(FPL(x), arraysize(FPL(x)) - 1)
23 namespace base {
25 struct UnaryTestData {
26 const FilePath::CharType* input;
27 const FilePath::CharType* expected;
30 struct UnaryBooleanTestData {
31 const FilePath::CharType* input;
32 bool expected;
35 struct BinaryTestData {
36 const FilePath::CharType* inputs[2];
37 const FilePath::CharType* expected;
40 struct BinaryBooleanTestData {
41 const FilePath::CharType* inputs[2];
42 bool expected;
45 struct BinaryIntTestData {
46 const FilePath::CharType* inputs[2];
47 int expected;
50 struct UTF8TestData {
51 const FilePath::CharType* native;
52 const char* utf8;
55 // file_util winds up using autoreleased objects on the Mac, so this needs
56 // to be a PlatformTest
57 typedef PlatformTest FilePathTest;
59 TEST_F(FilePathTest, DirName) {
60 const struct UnaryTestData cases[] = {
61 { FPL(""), FPL(".") },
62 { FPL("aa"), FPL(".") },
63 { FPL("/aa/bb"), FPL("/aa") },
64 { FPL("/aa/bb/"), FPL("/aa") },
65 { FPL("/aa/bb//"), FPL("/aa") },
66 { FPL("/aa/bb/ccc"), FPL("/aa/bb") },
67 { FPL("/aa"), FPL("/") },
68 { FPL("/aa/"), FPL("/") },
69 { FPL("/"), FPL("/") },
70 { FPL("//"), FPL("//") },
71 { FPL("///"), FPL("/") },
72 { FPL("aa/"), FPL(".") },
73 { FPL("aa/bb"), FPL("aa") },
74 { FPL("aa/bb/"), FPL("aa") },
75 { FPL("aa/bb//"), FPL("aa") },
76 { FPL("aa//bb//"), FPL("aa") },
77 { FPL("aa//bb/"), FPL("aa") },
78 { FPL("aa//bb"), FPL("aa") },
79 { FPL("//aa/bb"), FPL("//aa") },
80 { FPL("//aa/"), FPL("//") },
81 { FPL("//aa"), FPL("//") },
82 { FPL("0:"), FPL(".") },
83 { FPL("@:"), FPL(".") },
84 { FPL("[:"), FPL(".") },
85 { FPL("`:"), FPL(".") },
86 { FPL("{:"), FPL(".") },
87 { FPL("\xB3:"), 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)
93 { FPL("c:"), FPL("c:") },
94 { FPL("C:"), FPL("C:") },
95 { FPL("A:"), FPL("A:") },
96 { FPL("Z:"), FPL("Z:") },
97 { FPL("a:"), FPL("a:") },
98 { FPL("z:"), FPL("z:") },
99 { FPL("c:aa"), FPL("c:") },
100 { FPL("c:/"), FPL("c:/") },
101 { FPL("c://"), FPL("c://") },
102 { FPL("c:///"), FPL("c:/") },
103 { FPL("c:/aa"), FPL("c:/") },
104 { FPL("c:/aa/"), FPL("c:/") },
105 { FPL("c:/aa/bb"), FPL("c:/aa") },
106 { FPL("c:aa/bb"), FPL("c:aa") },
107 #endif // FILE_PATH_USES_DRIVE_LETTERS
108 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
109 { FPL("\\aa\\bb"), FPL("\\aa") },
110 { FPL("\\aa\\bb\\"), FPL("\\aa") },
111 { FPL("\\aa\\bb\\\\"), FPL("\\aa") },
112 { FPL("\\aa\\bb\\ccc"), FPL("\\aa\\bb") },
113 { FPL("\\aa"), FPL("\\") },
114 { FPL("\\aa\\"), FPL("\\") },
115 { FPL("\\"), FPL("\\") },
116 { FPL("\\\\"), FPL("\\\\") },
117 { FPL("\\\\\\"), FPL("\\") },
118 { FPL("aa\\"), FPL(".") },
119 { FPL("aa\\bb"), FPL("aa") },
120 { FPL("aa\\bb\\"), FPL("aa") },
121 { FPL("aa\\bb\\\\"), FPL("aa") },
122 { FPL("aa\\\\bb\\\\"), FPL("aa") },
123 { FPL("aa\\\\bb\\"), FPL("aa") },
124 { FPL("aa\\\\bb"), FPL("aa") },
125 { FPL("\\\\aa\\bb"), FPL("\\\\aa") },
126 { FPL("\\\\aa\\"), FPL("\\\\") },
127 { FPL("\\\\aa"), FPL("\\\\") },
128 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
129 { FPL("c:\\"), FPL("c:\\") },
130 { FPL("c:\\\\"), FPL("c:\\\\") },
131 { FPL("c:\\\\\\"), FPL("c:\\") },
132 { FPL("c:\\aa"), FPL("c:\\") },
133 { FPL("c:\\aa\\"), FPL("c:\\") },
134 { FPL("c:\\aa\\bb"), FPL("c:\\aa") },
135 { FPL("c:aa\\bb"), FPL("c:aa") },
136 #endif // FILE_PATH_USES_DRIVE_LETTERS
137 #endif // FILE_PATH_USES_WIN_SEPARATORS
140 for (size_t i = 0; i < arraysize(cases); ++i) {
141 FilePath input(cases[i].input);
142 FilePath observed = input.DirName();
143 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) <<
144 "i: " << i << ", input: " << input.value();
148 TEST_F(FilePathTest, BaseName) {
149 const struct UnaryTestData cases[] = {
150 { FPL(""), FPL("") },
151 { FPL("aa"), FPL("aa") },
152 { FPL("/aa/bb"), FPL("bb") },
153 { FPL("/aa/bb/"), FPL("bb") },
154 { FPL("/aa/bb//"), FPL("bb") },
155 { FPL("/aa/bb/ccc"), FPL("ccc") },
156 { FPL("/aa"), FPL("aa") },
157 { FPL("/"), FPL("/") },
158 { FPL("//"), FPL("//") },
159 { FPL("///"), FPL("/") },
160 { FPL("aa/"), FPL("aa") },
161 { FPL("aa/bb"), FPL("bb") },
162 { FPL("aa/bb/"), FPL("bb") },
163 { FPL("aa/bb//"), FPL("bb") },
164 { FPL("aa//bb//"), FPL("bb") },
165 { FPL("aa//bb/"), FPL("bb") },
166 { FPL("aa//bb"), FPL("bb") },
167 { FPL("//aa/bb"), FPL("bb") },
168 { FPL("//aa/"), FPL("aa") },
169 { FPL("//aa"), FPL("aa") },
170 { FPL("0:"), FPL("0:") },
171 { FPL("@:"), FPL("@:") },
172 { FPL("[:"), FPL("[:") },
173 { FPL("`:"), FPL("`:") },
174 { FPL("{:"), FPL("{:") },
175 { FPL("\xB3:"), FPL("\xB3:") },
176 { 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)
181 { FPL("c:"), FPL("") },
182 { FPL("C:"), FPL("") },
183 { FPL("A:"), FPL("") },
184 { FPL("Z:"), FPL("") },
185 { FPL("a:"), FPL("") },
186 { FPL("z:"), FPL("") },
187 { FPL("c:aa"), FPL("aa") },
188 { FPL("c:/"), FPL("/") },
189 { FPL("c://"), FPL("//") },
190 { FPL("c:///"), FPL("/") },
191 { FPL("c:/aa"), FPL("aa") },
192 { FPL("c:/aa/"), FPL("aa") },
193 { FPL("c:/aa/bb"), FPL("bb") },
194 { FPL("c:aa/bb"), FPL("bb") },
195 #endif // FILE_PATH_USES_DRIVE_LETTERS
196 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
197 { FPL("\\aa\\bb"), FPL("bb") },
198 { FPL("\\aa\\bb\\"), FPL("bb") },
199 { FPL("\\aa\\bb\\\\"), FPL("bb") },
200 { FPL("\\aa\\bb\\ccc"), FPL("ccc") },
201 { FPL("\\aa"), FPL("aa") },
202 { FPL("\\"), FPL("\\") },
203 { FPL("\\\\"), FPL("\\\\") },
204 { FPL("\\\\\\"), FPL("\\") },
205 { FPL("aa\\"), FPL("aa") },
206 { FPL("aa\\bb"), FPL("bb") },
207 { FPL("aa\\bb\\"), FPL("bb") },
208 { FPL("aa\\bb\\\\"), FPL("bb") },
209 { FPL("aa\\\\bb\\\\"), FPL("bb") },
210 { FPL("aa\\\\bb\\"), FPL("bb") },
211 { FPL("aa\\\\bb"), FPL("bb") },
212 { FPL("\\\\aa\\bb"), FPL("bb") },
213 { FPL("\\\\aa\\"), FPL("aa") },
214 { FPL("\\\\aa"), FPL("aa") },
215 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
216 { FPL("c:\\"), FPL("\\") },
217 { FPL("c:\\\\"), FPL("\\\\") },
218 { FPL("c:\\\\\\"), FPL("\\") },
219 { FPL("c:\\aa"), FPL("aa") },
220 { FPL("c:\\aa\\"), FPL("aa") },
221 { FPL("c:\\aa\\bb"), FPL("bb") },
222 { FPL("c:aa\\bb"), FPL("bb") },
223 #endif // FILE_PATH_USES_DRIVE_LETTERS
224 #endif // FILE_PATH_USES_WIN_SEPARATORS
227 for (size_t i = 0; i < arraysize(cases); ++i) {
228 FilePath input(cases[i].input);
229 FilePath observed = input.BaseName();
230 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) <<
231 "i: " << i << ", input: " << input.value();
235 TEST_F(FilePathTest, Append) {
236 const struct BinaryTestData cases[] = {
237 { { FPL(""), FPL("cc") }, FPL("cc") },
238 { { FPL("."), FPL("ff") }, FPL("ff") },
239 { { FPL("/"), FPL("cc") }, FPL("/cc") },
240 { { FPL("/aa"), FPL("") }, FPL("/aa") },
241 { { FPL("/aa/"), FPL("") }, FPL("/aa") },
242 { { FPL("//aa"), FPL("") }, FPL("//aa") },
243 { { FPL("//aa/"), FPL("") }, FPL("//aa") },
244 { { FPL("//"), FPL("aa") }, FPL("//aa") },
245 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
246 { { FPL("c:"), FPL("a") }, FPL("c:a") },
247 { { FPL("c:"), FPL("") }, FPL("c:") },
248 { { FPL("c:/"), FPL("a") }, FPL("c:/a") },
249 { { FPL("c://"), FPL("a") }, FPL("c://a") },
250 { { FPL("c:///"), FPL("a") }, FPL("c:/a") },
251 #endif // FILE_PATH_USES_DRIVE_LETTERS
252 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
253 // Append introduces the default separator character, so these test cases
254 // need to be defined with different expected results on platforms that use
255 // different default separator characters.
256 { { FPL("\\"), FPL("cc") }, FPL("\\cc") },
257 { { FPL("\\aa"), FPL("") }, FPL("\\aa") },
258 { { FPL("\\aa\\"), FPL("") }, FPL("\\aa") },
259 { { FPL("\\\\aa"), FPL("") }, FPL("\\\\aa") },
260 { { FPL("\\\\aa\\"), FPL("") }, FPL("\\\\aa") },
261 { { FPL("\\\\"), FPL("aa") }, FPL("\\\\aa") },
262 { { FPL("/aa/bb"), FPL("cc") }, FPL("/aa/bb\\cc") },
263 { { FPL("/aa/bb/"), FPL("cc") }, FPL("/aa/bb\\cc") },
264 { { FPL("aa/bb/"), FPL("cc") }, FPL("aa/bb\\cc") },
265 { { FPL("aa/bb"), FPL("cc") }, FPL("aa/bb\\cc") },
266 { { FPL("a/b"), FPL("c") }, FPL("a/b\\c") },
267 { { FPL("a/b/"), FPL("c") }, FPL("a/b\\c") },
268 { { FPL("//aa"), FPL("bb") }, FPL("//aa\\bb") },
269 { { FPL("//aa/"), FPL("bb") }, FPL("//aa\\bb") },
270 { { FPL("\\aa\\bb"), FPL("cc") }, FPL("\\aa\\bb\\cc") },
271 { { FPL("\\aa\\bb\\"), FPL("cc") }, FPL("\\aa\\bb\\cc") },
272 { { FPL("aa\\bb\\"), FPL("cc") }, FPL("aa\\bb\\cc") },
273 { { FPL("aa\\bb"), FPL("cc") }, FPL("aa\\bb\\cc") },
274 { { FPL("a\\b"), FPL("c") }, FPL("a\\b\\c") },
275 { { FPL("a\\b\\"), FPL("c") }, FPL("a\\b\\c") },
276 { { FPL("\\\\aa"), FPL("bb") }, FPL("\\\\aa\\bb") },
277 { { FPL("\\\\aa\\"), FPL("bb") }, FPL("\\\\aa\\bb") },
278 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
279 { { FPL("c:\\"), FPL("a") }, FPL("c:\\a") },
280 { { FPL("c:\\\\"), FPL("a") }, FPL("c:\\\\a") },
281 { { FPL("c:\\\\\\"), FPL("a") }, FPL("c:\\a") },
282 { { FPL("c:\\"), FPL("") }, FPL("c:\\") },
283 { { FPL("c:\\a"), FPL("b") }, FPL("c:\\a\\b") },
284 { { FPL("c:\\a\\"), FPL("b") }, FPL("c:\\a\\b") },
285 #endif // FILE_PATH_USES_DRIVE_LETTERS
286 #else // FILE_PATH_USES_WIN_SEPARATORS
287 { { FPL("/aa/bb"), FPL("cc") }, FPL("/aa/bb/cc") },
288 { { FPL("/aa/bb/"), FPL("cc") }, FPL("/aa/bb/cc") },
289 { { FPL("aa/bb/"), FPL("cc") }, FPL("aa/bb/cc") },
290 { { FPL("aa/bb"), FPL("cc") }, FPL("aa/bb/cc") },
291 { { FPL("a/b"), FPL("c") }, FPL("a/b/c") },
292 { { FPL("a/b/"), FPL("c") }, FPL("a/b/c") },
293 { { FPL("//aa"), FPL("bb") }, FPL("//aa/bb") },
294 { { FPL("//aa/"), FPL("bb") }, FPL("//aa/bb") },
295 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
296 { { FPL("c:/"), FPL("a") }, FPL("c:/a") },
297 { { FPL("c:/"), FPL("") }, FPL("c:/") },
298 { { FPL("c:/a"), FPL("b") }, FPL("c:/a/b") },
299 { { FPL("c:/a/"), FPL("b") }, FPL("c:/a/b") },
300 #endif // FILE_PATH_USES_DRIVE_LETTERS
301 #endif // FILE_PATH_USES_WIN_SEPARATORS
304 for (size_t i = 0; i < arraysize(cases); ++i) {
305 FilePath root(cases[i].inputs[0]);
306 FilePath::StringType leaf(cases[i].inputs[1]);
307 FilePath observed_str = root.Append(leaf);
308 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) <<
309 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf;
310 FilePath observed_path = root.Append(FilePath(leaf));
311 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_path.value()) <<
312 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf;
314 // TODO(erikkay): It would be nice to have a unicode test append value to
315 // 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;
320 #endif
321 observed_str = root.AppendASCII(ascii);
322 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) <<
323 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf;
327 TEST_F(FilePathTest, StripTrailingSeparators) {
328 const struct UnaryTestData cases[] = {
329 { FPL(""), FPL("") },
330 { FPL("/"), FPL("/") },
331 { FPL("//"), FPL("//") },
332 { FPL("///"), FPL("/") },
333 { FPL("////"), FPL("/") },
334 { FPL("a/"), FPL("a") },
335 { FPL("a//"), FPL("a") },
336 { FPL("a///"), FPL("a") },
337 { FPL("a////"), FPL("a") },
338 { FPL("/a"), FPL("/a") },
339 { FPL("/a/"), FPL("/a") },
340 { FPL("/a//"), FPL("/a") },
341 { FPL("/a///"), FPL("/a") },
342 { FPL("/a////"), FPL("/a") },
343 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
344 { FPL("c:"), FPL("c:") },
345 { FPL("c:/"), FPL("c:/") },
346 { FPL("c://"), FPL("c://") },
347 { FPL("c:///"), FPL("c:/") },
348 { FPL("c:////"), FPL("c:/") },
349 { FPL("c:/a"), FPL("c:/a") },
350 { FPL("c:/a/"), FPL("c:/a") },
351 { FPL("c:/a//"), FPL("c:/a") },
352 { FPL("c:/a///"), FPL("c:/a") },
353 { FPL("c:/a////"), FPL("c:/a") },
354 #endif // FILE_PATH_USES_DRIVE_LETTERS
355 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
356 { FPL("\\"), FPL("\\") },
357 { FPL("\\\\"), FPL("\\\\") },
358 { FPL("\\\\\\"), FPL("\\") },
359 { FPL("\\\\\\\\"), FPL("\\") },
360 { FPL("a\\"), FPL("a") },
361 { FPL("a\\\\"), FPL("a") },
362 { FPL("a\\\\\\"), FPL("a") },
363 { FPL("a\\\\\\\\"), FPL("a") },
364 { FPL("\\a"), FPL("\\a") },
365 { FPL("\\a\\"), FPL("\\a") },
366 { FPL("\\a\\\\"), FPL("\\a") },
367 { FPL("\\a\\\\\\"), FPL("\\a") },
368 { FPL("\\a\\\\\\\\"), FPL("\\a") },
369 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
370 { FPL("c:\\"), FPL("c:\\") },
371 { FPL("c:\\\\"), FPL("c:\\\\") },
372 { FPL("c:\\\\\\"), FPL("c:\\") },
373 { FPL("c:\\\\\\\\"), FPL("c:\\") },
374 { FPL("c:\\a"), FPL("c:\\a") },
375 { FPL("c:\\a\\"), FPL("c:\\a") },
376 { FPL("c:\\a\\\\"), FPL("c:\\a") },
377 { FPL("c:\\a\\\\\\"), FPL("c:\\a") },
378 { FPL("c:\\a\\\\\\\\"), FPL("c:\\a") },
379 #endif // FILE_PATH_USES_DRIVE_LETTERS
380 #endif // FILE_PATH_USES_WIN_SEPARATORS
383 for (size_t i = 0; i < arraysize(cases); ++i) {
384 FilePath input(cases[i].input);
385 FilePath observed = input.StripTrailingSeparators();
386 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) <<
387 "i: " << i << ", input: " << input.value();
391 TEST_F(FilePathTest, IsAbsolute) {
392 const struct UnaryBooleanTestData cases[] = {
393 { FPL(""), false },
394 { FPL("a"), false },
395 { FPL("c:"), false },
396 { FPL("c:a"), false },
397 { FPL("a/b"), false },
398 { FPL("//"), true },
399 { FPL("//a"), true },
400 { FPL("c:a/b"), false },
401 { FPL("?:/a"), false },
402 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
403 { FPL("/"), false },
404 { FPL("/a"), false },
405 { FPL("/."), false },
406 { FPL("/.."), false },
407 { FPL("c:/"), true },
408 { FPL("c:/a"), true },
409 { FPL("c:/."), true },
410 { FPL("c:/.."), true },
411 { FPL("C:/a"), true },
412 { FPL("d:/a"), true },
413 #else // FILE_PATH_USES_DRIVE_LETTERS
414 { FPL("/"), true },
415 { FPL("/a"), true },
416 { FPL("/."), true },
417 { FPL("/.."), true },
418 { FPL("c:/"), false },
419 #endif // FILE_PATH_USES_DRIVE_LETTERS
420 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
421 { FPL("a\\b"), false },
422 { FPL("\\\\"), true },
423 { FPL("\\\\a"), true },
424 { FPL("a\\b"), false },
425 { FPL("\\\\"), true },
426 { FPL("//a"), true },
427 { FPL("c:a\\b"), false },
428 { FPL("?:\\a"), false },
429 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
430 { FPL("\\"), false },
431 { FPL("\\a"), false },
432 { FPL("\\."), false },
433 { FPL("\\.."), false },
434 { FPL("c:\\"), true },
435 { FPL("c:\\"), true },
436 { FPL("c:\\a"), true },
437 { FPL("c:\\."), true },
438 { FPL("c:\\.."), true },
439 { FPL("C:\\a"), true },
440 { FPL("d:\\a"), true },
441 #else // FILE_PATH_USES_DRIVE_LETTERS
442 { FPL("\\"), true },
443 { FPL("\\a"), true },
444 { FPL("\\."), true },
445 { FPL("\\.."), true },
446 { FPL("c:\\"), false },
447 #endif // FILE_PATH_USES_DRIVE_LETTERS
448 #endif // FILE_PATH_USES_WIN_SEPARATORS
451 for (size_t i = 0; i < arraysize(cases); ++i) {
452 FilePath input(cases[i].input);
453 bool observed = input.IsAbsolute();
454 EXPECT_EQ(cases[i].expected, observed) <<
455 "i: " << i << ", input: " << input.value();
459 TEST_F(FilePathTest, PathComponentsTest) {
460 const struct UnaryTestData cases[] = {
461 { FPL("//foo/bar/baz/"), FPL("|//|foo|bar|baz")},
462 { FPL("///"), FPL("|/")},
463 { FPL("/foo//bar//baz/"), FPL("|/|foo|bar|baz")},
464 { FPL("/foo/bar/baz/"), FPL("|/|foo|bar|baz")},
465 { FPL("/foo/bar/baz//"), FPL("|/|foo|bar|baz")},
466 { FPL("/foo/bar/baz///"), FPL("|/|foo|bar|baz")},
467 { FPL("/foo/bar/baz"), FPL("|/|foo|bar|baz")},
468 { FPL("/foo/bar.bot/baz.txt"), FPL("|/|foo|bar.bot|baz.txt")},
469 { FPL("//foo//bar/baz"), FPL("|//|foo|bar|baz")},
470 { FPL("/"), FPL("|/")},
471 { FPL("foo"), FPL("|foo")},
472 { FPL(""), FPL("")},
473 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
474 { FPL("e:/foo"), FPL("|e:|/|foo")},
475 { FPL("e:/"), FPL("|e:|/")},
476 { FPL("e:"), FPL("|e:")},
477 #endif // FILE_PATH_USES_DRIVE_LETTERS
478 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
479 { FPL("../foo"), FPL("|..|foo")},
480 { FPL("./foo"), FPL("|foo")},
481 { FPL("../foo/bar/"), FPL("|..|foo|bar") },
482 { FPL("\\\\foo\\bar\\baz\\"), FPL("|\\\\|foo|bar|baz")},
483 { FPL("\\\\\\"), FPL("|\\")},
484 { FPL("\\foo\\\\bar\\\\baz\\"), FPL("|\\|foo|bar|baz")},
485 { FPL("\\foo\\bar\\baz\\"), FPL("|\\|foo|bar|baz")},
486 { FPL("\\foo\\bar\\baz\\\\"), FPL("|\\|foo|bar|baz")},
487 { FPL("\\foo\\bar\\baz\\\\\\"), FPL("|\\|foo|bar|baz")},
488 { FPL("\\foo\\bar\\baz"), FPL("|\\|foo|bar|baz")},
489 { FPL("\\foo\\bar/baz\\\\\\"), FPL("|\\|foo|bar|baz")},
490 { FPL("/foo\\bar\\baz"), FPL("|/|foo|bar|baz")},
491 { FPL("\\foo\\bar.bot\\baz.txt"), FPL("|\\|foo|bar.bot|baz.txt")},
492 { FPL("\\\\foo\\\\bar\\baz"), FPL("|\\\\|foo|bar|baz")},
493 { FPL("\\"), FPL("|\\")},
494 #endif // FILE_PATH_USES_WIN_SEPARATORS
497 for (size_t i = 0; i < arraysize(cases); ++i) {
498 FilePath input(cases[i].input);
499 std::vector<FilePath::StringType> comps;
500 input.GetComponents(&comps);
502 FilePath::StringType observed;
503 for (size_t j = 0; j < comps.size(); ++j) {
504 observed.append(FILE_PATH_LITERAL("|"), 1);
505 observed.append(comps[j]);
507 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed) <<
508 "i: " << i << ", input: " << input.value();
512 TEST_F(FilePathTest, IsParentTest) {
513 const struct BinaryBooleanTestData cases[] = {
514 { { FPL("/"), FPL("/foo/bar/baz") }, true},
515 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, true},
516 { { FPL("/foo/bar/"), FPL("/foo/bar/baz") }, true},
517 { { FPL("//foo/bar/"), FPL("//foo/bar/baz") }, true},
518 { { FPL("/foo/bar"), FPL("/foo2/bar/baz") }, false},
519 { { FPL("/foo/bar.txt"), FPL("/foo/bar/baz") }, false},
520 { { FPL("/foo/bar"), FPL("/foo/bar2/baz") }, false},
521 { { FPL("/foo/bar"), FPL("/foo/bar") }, false},
522 { { FPL("/foo/bar/baz"), FPL("/foo/bar") }, false},
523 { { FPL("foo/bar"), FPL("foo/bar/baz") }, true},
524 { { FPL("foo/bar"), FPL("foo2/bar/baz") }, false},
525 { { FPL("foo/bar"), FPL("foo/bar2/baz") }, false},
526 { { FPL(""), FPL("foo") }, false},
527 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
528 { { FPL("c:/foo/bar"), FPL("c:/foo/bar/baz") }, true},
529 { { FPL("E:/foo/bar"), FPL("e:/foo/bar/baz") }, true},
530 { { FPL("f:/foo/bar"), FPL("F:/foo/bar/baz") }, true},
531 { { FPL("E:/Foo/bar"), FPL("e:/foo/bar/baz") }, false},
532 { { FPL("f:/foo/bar"), FPL("F:/foo/Bar/baz") }, false},
533 { { FPL("c:/"), FPL("c:/foo/bar/baz") }, true},
534 { { FPL("c:"), FPL("c:/foo/bar/baz") }, true},
535 { { FPL("c:/foo/bar"), FPL("d:/foo/bar/baz") }, false},
536 { { FPL("c:/foo/bar"), FPL("D:/foo/bar/baz") }, false},
537 { { FPL("C:/foo/bar"), FPL("d:/foo/bar/baz") }, false},
538 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar/baz") }, false},
539 { { FPL("e:/foo/bar"), FPL("E:/foo2/bar/baz") }, false},
540 { { FPL("F:/foo/bar"), FPL("f:/foo2/bar/baz") }, false},
541 { { FPL("c:/foo/bar"), FPL("c:/foo/bar2/baz") }, false},
542 #endif // FILE_PATH_USES_DRIVE_LETTERS
543 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
544 { { FPL("\\foo\\bar"), FPL("\\foo\\bar\\baz") }, true},
545 { { FPL("\\foo/bar"), FPL("\\foo\\bar\\baz") }, true},
546 { { FPL("\\foo/bar"), FPL("\\foo/bar/baz") }, true},
547 { { FPL("\\"), FPL("\\foo\\bar\\baz") }, true},
548 { { FPL(""), FPL("\\foo\\bar\\baz") }, false},
549 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar\\baz") }, false},
550 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2\\baz") }, false},
551 #endif // FILE_PATH_USES_WIN_SEPARATORS
554 for (size_t i = 0; i < arraysize(cases); ++i) {
555 FilePath parent(cases[i].inputs[0]);
556 FilePath child(cases[i].inputs[1]);
558 EXPECT_EQ(parent.IsParent(child), cases[i].expected) <<
559 "i: " << i << ", parent: " << parent.value() << ", child: " <<
560 child.value();
564 TEST_F(FilePathTest, AppendRelativePathTest) {
565 const struct BinaryTestData cases[] = {
566 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
567 { { FPL("/"), FPL("/foo/bar/baz") }, FPL("foo\\bar\\baz")},
568 #else // FILE_PATH_USES_WIN_SEPARATORS
569 { { FPL("/"), FPL("/foo/bar/baz") }, FPL("foo/bar/baz")},
570 #endif // FILE_PATH_USES_WIN_SEPARATORS
571 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, FPL("baz")},
572 { { FPL("/foo/bar/"), FPL("/foo/bar/baz") }, FPL("baz")},
573 { { FPL("//foo/bar/"), FPL("//foo/bar/baz") }, FPL("baz")},
574 { { FPL("/foo/bar"), FPL("/foo2/bar/baz") }, FPL("")},
575 { { FPL("/foo/bar.txt"), FPL("/foo/bar/baz") }, FPL("")},
576 { { FPL("/foo/bar"), FPL("/foo/bar2/baz") }, FPL("")},
577 { { FPL("/foo/bar"), FPL("/foo/bar") }, FPL("")},
578 { { FPL("/foo/bar/baz"), FPL("/foo/bar") }, FPL("")},
579 { { FPL("foo/bar"), FPL("foo/bar/baz") }, FPL("baz")},
580 { { FPL("foo/bar"), FPL("foo2/bar/baz") }, FPL("")},
581 { { FPL("foo/bar"), FPL("foo/bar2/baz") }, FPL("")},
582 { { FPL(""), FPL("foo") }, FPL("")},
583 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
584 { { FPL("c:/foo/bar"), FPL("c:/foo/bar/baz") }, FPL("baz")},
585 { { FPL("E:/foo/bar"), FPL("e:/foo/bar/baz") }, FPL("baz")},
586 { { FPL("f:/foo/bar"), FPL("F:/foo/bar/baz") }, FPL("baz")},
587 { { FPL("E:/Foo/bar"), FPL("e:/foo/bar/baz") }, FPL("")},
588 { { FPL("f:/foo/bar"), FPL("F:/foo/Bar/baz") }, FPL("")},
589 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
590 { { FPL("c:/"), FPL("c:/foo/bar/baz") }, FPL("foo\\bar\\baz")},
591 // TODO(akalin): Figure out how to handle the corner case in the
592 // commented-out test case below. Appending to an empty path gives
593 // /foo\bar\baz but appending to a nonempty path "blah" gives
594 // blah\foo\bar\baz.
595 // { { FPL("c:"), FPL("c:/foo/bar/baz") }, FPL("foo\\bar\\baz")},
596 #endif // FILE_PATH_USES_WIN_SEPARATORS
597 { { FPL("c:/foo/bar"), FPL("d:/foo/bar/baz") }, FPL("")},
598 { { FPL("c:/foo/bar"), FPL("D:/foo/bar/baz") }, FPL("")},
599 { { FPL("C:/foo/bar"), FPL("d:/foo/bar/baz") }, FPL("")},
600 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar/baz") }, FPL("")},
601 { { FPL("e:/foo/bar"), FPL("E:/foo2/bar/baz") }, FPL("")},
602 { { FPL("F:/foo/bar"), FPL("f:/foo2/bar/baz") }, FPL("")},
603 { { FPL("c:/foo/bar"), FPL("c:/foo/bar2/baz") }, FPL("")},
604 #endif // FILE_PATH_USES_DRIVE_LETTERS
605 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
606 { { FPL("\\foo\\bar"), FPL("\\foo\\bar\\baz") }, FPL("baz")},
607 { { FPL("\\foo/bar"), FPL("\\foo\\bar\\baz") }, FPL("baz")},
608 { { FPL("\\foo/bar"), FPL("\\foo/bar/baz") }, FPL("baz")},
609 { { FPL("\\"), FPL("\\foo\\bar\\baz") }, FPL("foo\\bar\\baz")},
610 { { FPL(""), FPL("\\foo\\bar\\baz") }, FPL("")},
611 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar\\baz") }, FPL("")},
612 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2\\baz") }, FPL("")},
613 #endif // FILE_PATH_USES_WIN_SEPARATORS
616 const FilePath base(FPL("blah"));
618 for (size_t i = 0; i < arraysize(cases); ++i) {
619 FilePath parent(cases[i].inputs[0]);
620 FilePath child(cases[i].inputs[1]);
622 FilePath result;
623 bool success = parent.AppendRelativePath(child, &result);
624 EXPECT_EQ(cases[i].expected[0] != '\0', success) <<
625 "i: " << i << ", parent: " << parent.value() << ", child: " <<
626 child.value();
627 EXPECT_STREQ(cases[i].expected, result.value().c_str()) <<
628 "i: " << i << ", parent: " << parent.value() << ", child: " <<
629 child.value();
632 FilePath result(base);
633 bool success = parent.AppendRelativePath(child, &result);
634 EXPECT_EQ(cases[i].expected[0] != '\0', success) <<
635 "i: " << i << ", parent: " << parent.value() << ", child: " <<
636 child.value();
637 EXPECT_EQ(base.Append(cases[i].expected).value(), result.value()) <<
638 "i: " << i << ", parent: " << parent.value() << ", child: " <<
639 child.value();
644 TEST_F(FilePathTest, EqualityTest) {
645 const struct BinaryBooleanTestData cases[] = {
646 { { FPL("/foo/bar/baz"), FPL("/foo/bar/baz") }, true},
647 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, false},
648 { { FPL("/foo/bar/baz"), FPL("/foo/bar") }, false},
649 { { FPL("//foo/bar/"), FPL("//foo/bar/") }, true},
650 { { FPL("/foo/bar"), FPL("/foo2/bar") }, false},
651 { { FPL("/foo/bar.txt"), FPL("/foo/bar") }, false},
652 { { FPL("foo/bar"), FPL("foo/bar") }, true},
653 { { FPL("foo/bar"), FPL("foo/bar/baz") }, false},
654 { { FPL(""), FPL("foo") }, false},
655 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
656 { { FPL("c:/foo/bar"), FPL("c:/foo/bar") }, true},
657 { { FPL("E:/foo/bar"), FPL("e:/foo/bar") }, true},
658 { { FPL("f:/foo/bar"), FPL("F:/foo/bar") }, true},
659 { { FPL("E:/Foo/bar"), FPL("e:/foo/bar") }, false},
660 { { FPL("f:/foo/bar"), FPL("F:/foo/Bar") }, false},
661 { { FPL("c:/"), FPL("c:/") }, true},
662 { { FPL("c:"), FPL("c:") }, true},
663 { { FPL("c:/foo/bar"), FPL("d:/foo/bar") }, false},
664 { { FPL("c:/foo/bar"), FPL("D:/foo/bar") }, false},
665 { { FPL("C:/foo/bar"), FPL("d:/foo/bar") }, false},
666 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar") }, false},
667 #endif // FILE_PATH_USES_DRIVE_LETTERS
668 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
669 { { FPL("\\foo\\bar"), FPL("\\foo\\bar") }, true},
670 { { FPL("\\foo/bar"), FPL("\\foo/bar") }, true},
671 { { FPL("\\foo/bar"), FPL("\\foo\\bar") }, false},
672 { { FPL("\\"), FPL("\\") }, true},
673 { { FPL("\\"), FPL("/") }, false},
674 { { FPL(""), FPL("\\") }, false},
675 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar") }, false},
676 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2") }, false},
677 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
678 { { FPL("c:\\foo\\bar"), FPL("c:\\foo\\bar") }, true},
679 { { FPL("E:\\foo\\bar"), FPL("e:\\foo\\bar") }, true},
680 { { FPL("f:\\foo\\bar"), FPL("F:\\foo/bar") }, false},
681 #endif // FILE_PATH_USES_DRIVE_LETTERS
682 #endif // FILE_PATH_USES_WIN_SEPARATORS
685 for (size_t i = 0; i < arraysize(cases); ++i) {
686 FilePath a(cases[i].inputs[0]);
687 FilePath b(cases[i].inputs[1]);
689 EXPECT_EQ(a == b, cases[i].expected) <<
690 "equality i: " << i << ", a: " << a.value() << ", b: " <<
691 b.value();
694 for (size_t i = 0; i < arraysize(cases); ++i) {
695 FilePath a(cases[i].inputs[0]);
696 FilePath b(cases[i].inputs[1]);
698 EXPECT_EQ(a != b, !cases[i].expected) <<
699 "inequality i: " << i << ", a: " << a.value() << ", b: " <<
700 b.value();
704 TEST_F(FilePathTest, Extension) {
705 FilePath base_dir(FILE_PATH_LITERAL("base_dir"));
707 FilePath jpg = base_dir.Append(FILE_PATH_LITERAL("foo.jpg"));
708 EXPECT_EQ(FILE_PATH_LITERAL(".jpg"), jpg.Extension());
709 EXPECT_EQ(FILE_PATH_LITERAL(".jpg"), jpg.FinalExtension());
711 FilePath base = jpg.BaseName().RemoveExtension();
712 EXPECT_EQ(FILE_PATH_LITERAL("foo"), base.value());
714 FilePath path_no_ext = base_dir.Append(base);
715 EXPECT_EQ(path_no_ext.value(), jpg.RemoveExtension().value());
717 EXPECT_EQ(path_no_ext.value(), path_no_ext.RemoveExtension().value());
718 EXPECT_EQ(FILE_PATH_LITERAL(""), path_no_ext.Extension());
719 EXPECT_EQ(FILE_PATH_LITERAL(""), path_no_ext.FinalExtension());
722 TEST_F(FilePathTest, Extension2) {
723 const struct UnaryTestData cases[] = {
724 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
725 { FPL("C:\\a\\b\\c.ext"), FPL(".ext") },
726 { FPL("C:\\a\\b\\c."), FPL(".") },
727 { FPL("C:\\a\\b\\c"), FPL("") },
728 { FPL("C:\\a\\b\\"), FPL("") },
729 { FPL("C:\\a\\b.\\"), FPL(".") },
730 { FPL("C:\\a\\b\\c.ext1.ext2"), FPL(".ext2") },
731 { FPL("C:\\foo.bar\\\\\\"), FPL(".bar") },
732 { FPL("C:\\foo.bar\\.."), FPL("") },
733 { FPL("C:\\foo.bar\\..\\\\"), FPL("") },
734 #endif
735 { FPL("/foo/bar/baz.ext"), FPL(".ext") },
736 { FPL("/foo/bar/baz."), FPL(".") },
737 { FPL("/foo/bar/baz.."), FPL(".") },
738 { FPL("/foo/bar/baz"), FPL("") },
739 { FPL("/foo/bar/"), FPL("") },
740 { FPL("/foo/bar./"), FPL(".") },
741 { FPL("/foo/bar/baz.ext1.ext2"), FPL(".ext2") },
742 { FPL("/subversion-1.6.12.zip"), FPL(".zip") },
743 { FPL("/foo.12345.gz"), FPL(".gz") },
744 { FPL("/foo..gz"), FPL(".gz") },
745 { FPL("."), FPL("") },
746 { FPL(".."), FPL("") },
747 { FPL("./foo"), FPL("") },
748 { FPL("./foo.ext"), FPL(".ext") },
749 { FPL("/foo.ext1/bar.ext2"), FPL(".ext2") },
750 { FPL("/foo.bar////"), FPL(".bar") },
751 { FPL("/foo.bar/.."), FPL("") },
752 { FPL("/foo.bar/..////"), FPL("") },
753 { FPL("/foo.1234.luser.js"), FPL(".js") },
754 { FPL("/user.js"), FPL(".js") },
756 const struct UnaryTestData double_extension_cases[] = {
757 { FPL("/foo.tar.gz"), FPL(".tar.gz") },
758 { FPL("/foo.tar.Z"), FPL(".tar.Z") },
759 { FPL("/foo.tar.bz2"), FPL(".tar.bz2") },
760 { FPL("/foo.1234.gz"), FPL(".1234.gz") },
761 { FPL("/foo.1234.tar.gz"), FPL(".tar.gz") },
762 { FPL("/foo.tar.tar.gz"), FPL(".tar.gz") },
763 { FPL("/foo.tar.gz.gz"), FPL(".gz.gz") },
764 { FPL("/foo.1234.user.js"), FPL(".user.js") },
765 { FPL("foo.user.js"), FPL(".user.js") },
766 { FPL("/foo.tar.bz"), FPL(".tar.bz") },
768 for (unsigned int i = 0; i < arraysize(cases); ++i) {
769 FilePath path(cases[i].input);
770 FilePath::StringType extension = path.Extension();
771 FilePath::StringType final_extension = path.FinalExtension();
772 EXPECT_STREQ(cases[i].expected, extension.c_str())
773 << "i: " << i << ", path: " << path.value();
774 EXPECT_STREQ(cases[i].expected, final_extension.c_str())
775 << "i: " << i << ", path: " << path.value();
777 for (unsigned int i = 0; i < arraysize(double_extension_cases); ++i) {
778 FilePath path(double_extension_cases[i].input);
779 FilePath::StringType extension = path.Extension();
780 EXPECT_STREQ(double_extension_cases[i].expected, extension.c_str())
781 << "i: " << i << ", path: " << path.value();
785 TEST_F(FilePathTest, InsertBeforeExtension) {
786 const struct BinaryTestData cases[] = {
787 { { FPL(""), FPL("") }, FPL("") },
788 { { FPL(""), FPL("txt") }, FPL("") },
789 { { FPL("."), FPL("txt") }, FPL("") },
790 { { FPL(".."), FPL("txt") }, FPL("") },
791 { { FPL("foo.dll"), FPL("txt") }, FPL("footxt.dll") },
792 { { FPL("."), FPL("") }, FPL(".") },
793 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.txt.dll") },
794 { { FPL("foo"), FPL("txt") }, FPL("footxt") },
795 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
796 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baztxt.dll") },
797 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.txt.dll") },
798 { { FPL("foo.dll"), FPL("") }, FPL("foo.dll") },
799 { { FPL("foo.dll"), FPL(".") }, FPL("foo..dll") },
800 { { FPL("foo"), FPL("") }, FPL("foo") },
801 { { FPL("foo"), FPL(".") }, FPL("foo.") },
802 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz.dll") },
803 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz..dll") },
804 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
805 { { FPL("\\"), FPL("") }, FPL("\\") },
806 { { FPL("\\"), FPL("txt") }, FPL("\\txt") },
807 { { FPL("\\."), FPL("txt") }, FPL("") },
808 { { FPL("\\.."), FPL("txt") }, FPL("") },
809 { { FPL("\\."), FPL("") }, FPL("\\.") },
810 { { FPL("C:\\bar\\foo.dll"), FPL("txt") },
811 FPL("C:\\bar\\footxt.dll") },
812 { { FPL("C:\\bar.baz\\foodll"), FPL("txt") },
813 FPL("C:\\bar.baz\\foodlltxt") },
814 { { FPL("C:\\bar.baz\\foo.dll"), FPL("txt") },
815 FPL("C:\\bar.baz\\footxt.dll") },
816 { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("txt") },
817 FPL("C:\\bar.baz\\foo.dlltxt.exe") },
818 { { FPL("C:\\bar.baz\\foo"), FPL("") },
819 FPL("C:\\bar.baz\\foo") },
820 { { FPL("C:\\bar.baz\\foo.exe"), FPL("") },
821 FPL("C:\\bar.baz\\foo.exe") },
822 { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("") },
823 FPL("C:\\bar.baz\\foo.dll.exe") },
824 { { FPL("C:\\bar\\baz\\foo.exe"), FPL(" (1)") },
825 FPL("C:\\bar\\baz\\foo (1).exe") },
826 { { FPL("C:\\foo.baz\\\\"), FPL(" (1)") }, FPL("C:\\foo (1).baz") },
827 { { FPL("C:\\foo.baz\\..\\"), FPL(" (1)") }, FPL("") },
828 #endif
829 { { FPL("/"), FPL("") }, FPL("/") },
830 { { FPL("/"), FPL("txt") }, FPL("/txt") },
831 { { FPL("/."), FPL("txt") }, FPL("") },
832 { { FPL("/.."), FPL("txt") }, FPL("") },
833 { { FPL("/."), FPL("") }, FPL("/.") },
834 { { FPL("/bar/foo.dll"), FPL("txt") }, FPL("/bar/footxt.dll") },
835 { { FPL("/bar.baz/foodll"), FPL("txt") }, FPL("/bar.baz/foodlltxt") },
836 { { FPL("/bar.baz/foo.dll"), FPL("txt") }, FPL("/bar.baz/footxt.dll") },
837 { { FPL("/bar.baz/foo.dll.exe"), FPL("txt") },
838 FPL("/bar.baz/foo.dlltxt.exe") },
839 { { FPL("/bar.baz/foo"), FPL("") }, FPL("/bar.baz/foo") },
840 { { FPL("/bar.baz/foo.exe"), FPL("") }, FPL("/bar.baz/foo.exe") },
841 { { FPL("/bar.baz/foo.dll.exe"), FPL("") }, FPL("/bar.baz/foo.dll.exe") },
842 { { FPL("/bar/baz/foo.exe"), FPL(" (1)") }, FPL("/bar/baz/foo (1).exe") },
843 { { FPL("/bar/baz/..////"), FPL(" (1)") }, FPL("") },
845 for (unsigned int i = 0; i < arraysize(cases); ++i) {
846 FilePath path(cases[i].inputs[0]);
847 FilePath result = path.InsertBeforeExtension(cases[i].inputs[1]);
848 EXPECT_EQ(cases[i].expected, result.value()) << "i: " << i <<
849 ", path: " << path.value() << ", insert: " << cases[i].inputs[1];
853 TEST_F(FilePathTest, RemoveExtension) {
854 const struct UnaryTestData cases[] = {
855 { FPL(""), FPL("") },
856 { FPL("."), FPL(".") },
857 { FPL(".."), FPL("..") },
858 { FPL("foo.dll"), FPL("foo") },
859 { FPL("./foo.dll"), FPL("./foo") },
860 { FPL("foo..dll"), FPL("foo.") },
861 { FPL("foo"), FPL("foo") },
862 { FPL("foo."), FPL("foo") },
863 { FPL("foo.."), FPL("foo.") },
864 { FPL("foo.baz.dll"), FPL("foo.baz") },
865 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
866 { FPL("C:\\foo.bar\\foo"), FPL("C:\\foo.bar\\foo") },
867 { FPL("C:\\foo.bar\\..\\\\"), FPL("C:\\foo.bar\\..\\\\") },
868 #endif
869 { FPL("/foo.bar/foo"), FPL("/foo.bar/foo") },
870 { FPL("/foo.bar/..////"), FPL("/foo.bar/..////") },
872 for (unsigned int i = 0; i < arraysize(cases); ++i) {
873 FilePath path(cases[i].input);
874 FilePath removed = path.RemoveExtension();
875 FilePath removed_final = path.RemoveFinalExtension();
876 EXPECT_EQ(cases[i].expected, removed.value()) << "i: " << i <<
877 ", path: " << path.value();
878 EXPECT_EQ(cases[i].expected, removed_final.value()) << "i: " << i <<
879 ", path: " << path.value();
882 FilePath path(FPL("foo.tar.gz"));
883 FilePath removed = path.RemoveExtension();
884 FilePath removed_final = path.RemoveFinalExtension();
885 EXPECT_EQ(FPL("foo"), removed.value()) << ", path: " << path.value();
886 EXPECT_EQ(FPL("foo.tar"), removed_final.value()) << ", path: "
887 << path.value();
891 TEST_F(FilePathTest, ReplaceExtension) {
892 const struct BinaryTestData cases[] = {
893 { { FPL(""), FPL("") }, FPL("") },
894 { { FPL(""), FPL("txt") }, FPL("") },
895 { { FPL("."), FPL("txt") }, FPL("") },
896 { { FPL(".."), FPL("txt") }, FPL("") },
897 { { FPL("."), FPL("") }, FPL("") },
898 { { FPL("foo.dll"), FPL("txt") }, FPL("foo.txt") },
899 { { FPL("./foo.dll"), FPL("txt") }, FPL("./foo.txt") },
900 { { FPL("foo..dll"), FPL("txt") }, FPL("foo..txt") },
901 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.txt") },
902 { { FPL("foo"), FPL("txt") }, FPL("foo.txt") },
903 { { FPL("foo."), FPL("txt") }, FPL("foo.txt") },
904 { { FPL("foo.."), FPL("txt") }, FPL("foo..txt") },
905 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
906 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baz.txt") },
907 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.txt") },
908 { { FPL("foo.dll"), FPL("") }, FPL("foo") },
909 { { FPL("foo.dll"), FPL(".") }, FPL("foo") },
910 { { FPL("foo"), FPL("") }, FPL("foo") },
911 { { FPL("foo"), FPL(".") }, FPL("foo") },
912 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz") },
913 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz") },
914 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
915 { { FPL("C:\\foo.bar\\foo"), FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
916 { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
917 #endif
918 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") },
919 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") },
921 for (unsigned int i = 0; i < arraysize(cases); ++i) {
922 FilePath path(cases[i].inputs[0]);
923 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]);
924 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i <<
925 ", path: " << path.value() << ", replace: " << cases[i].inputs[1];
929 TEST_F(FilePathTest, AddExtension) {
930 const struct BinaryTestData cases[] = {
931 { { FPL(""), FPL("") }, FPL("") },
932 { { FPL(""), FPL("txt") }, FPL("") },
933 { { FPL("."), FPL("txt") }, FPL("") },
934 { { FPL(".."), FPL("txt") }, FPL("") },
935 { { FPL("."), FPL("") }, FPL("") },
936 { { FPL("foo.dll"), FPL("txt") }, FPL("foo.dll.txt") },
937 { { FPL("./foo.dll"), FPL("txt") }, FPL("./foo.dll.txt") },
938 { { FPL("foo..dll"), FPL("txt") }, FPL("foo..dll.txt") },
939 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.dll.txt") },
940 { { FPL("foo"), FPL("txt") }, FPL("foo.txt") },
941 { { FPL("foo."), FPL("txt") }, FPL("foo.txt") },
942 { { FPL("foo.."), FPL("txt") }, FPL("foo..txt") },
943 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
944 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baz.dll.txt") },
945 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.dll.txt") },
946 { { FPL("foo.dll"), FPL("") }, FPL("foo.dll") },
947 { { FPL("foo.dll"), FPL(".") }, FPL("foo.dll") },
948 { { FPL("foo"), FPL("") }, FPL("foo") },
949 { { FPL("foo"), FPL(".") }, FPL("foo") },
950 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz.dll") },
951 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz.dll") },
952 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
953 { { FPL("C:\\foo.bar\\foo"), FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
954 { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
955 #endif
956 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") },
957 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") },
959 for (unsigned int i = 0; i < arraysize(cases); ++i) {
960 FilePath path(cases[i].inputs[0]);
961 FilePath added = path.AddExtension(cases[i].inputs[1]);
962 EXPECT_EQ(cases[i].expected, added.value()) << "i: " << i <<
963 ", path: " << path.value() << ", add: " << cases[i].inputs[1];
967 TEST_F(FilePathTest, MatchesExtension) {
968 const struct BinaryBooleanTestData cases[] = {
969 { { FPL("foo"), FPL("") }, true},
970 { { FPL("foo"), FPL(".") }, false},
971 { { FPL("foo."), FPL("") }, false},
972 { { FPL("foo."), FPL(".") }, true},
973 { { FPL("foo.txt"), FPL(".dll") }, false},
974 { { FPL("foo.txt"), FPL(".txt") }, true},
975 { { FPL("foo.txt.dll"), FPL(".txt") }, false},
976 { { FPL("foo.txt.dll"), FPL(".dll") }, true},
977 { { FPL("foo.TXT"), FPL(".txt") }, true},
978 { { FPL("foo.txt"), FPL(".TXT") }, true},
979 { { FPL("foo.tXt"), FPL(".txt") }, true},
980 { { FPL("foo.txt"), FPL(".tXt") }, true},
981 { { FPL("foo.tXt"), FPL(".TXT") }, true},
982 { { FPL("foo.tXt"), FPL(".tXt") }, true},
983 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
984 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false},
985 { { FPL("c:/foo.txt"), FPL(".txt") }, true},
986 #endif // FILE_PATH_USES_DRIVE_LETTERS
987 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
988 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false},
989 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true},
990 #endif // FILE_PATH_USES_DRIVE_LETTERS
991 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false},
992 { { FPL("/bar/foo.txt"), FPL(".txt") }, true},
993 #if defined(OS_WIN) || defined(OS_MACOSX)
994 // Umlauts A, O, U: direct comparison, and upper case vs. lower case
995 { { FPL("foo.\u00E4\u00F6\u00FC"), FPL(".\u00E4\u00F6\u00FC") }, true},
996 { { FPL("foo.\u00C4\u00D6\u00DC"), FPL(".\u00E4\u00F6\u00FC") }, true},
997 // C with circumflex: direct comparison, and upper case vs. lower case
998 { { FPL("foo.\u0109"), FPL(".\u0109") }, true},
999 { { FPL("foo.\u0108"), FPL(".\u0109") }, true},
1000 #endif
1003 for (size_t i = 0; i < arraysize(cases); ++i) {
1004 FilePath path(cases[i].inputs[0]);
1005 FilePath::StringType ext(cases[i].inputs[1]);
1007 EXPECT_EQ(cases[i].expected, path.MatchesExtension(ext)) <<
1008 "i: " << i << ", path: " << path.value() << ", ext: " << ext;
1012 TEST_F(FilePathTest, CompareIgnoreCase) {
1013 const struct BinaryIntTestData cases[] = {
1014 { { FPL("foo"), FPL("foo") }, 0},
1015 { { FPL("FOO"), FPL("foo") }, 0},
1016 { { FPL("foo.ext"), FPL("foo.ext") }, 0},
1017 { { FPL("FOO.EXT"), FPL("foo.ext") }, 0},
1018 { { FPL("Foo.Ext"), FPL("foo.ext") }, 0},
1019 { { FPL("foO"), FPL("foo") }, 0},
1020 { { FPL("foo"), FPL("foO") }, 0},
1021 { { FPL("fOo"), FPL("foo") }, 0},
1022 { { FPL("foo"), FPL("fOo") }, 0},
1023 { { FPL("bar"), FPL("foo") }, -1},
1024 { { FPL("foo"), FPL("bar") }, 1},
1025 { { FPL("BAR"), FPL("foo") }, -1},
1026 { { FPL("FOO"), FPL("bar") }, 1},
1027 { { FPL("bar"), FPL("FOO") }, -1},
1028 { { FPL("foo"), FPL("BAR") }, 1},
1029 { { FPL("BAR"), FPL("FOO") }, -1},
1030 { { FPL("FOO"), FPL("BAR") }, 1},
1031 // German "Eszett" (lower case and the new-fangled upper case)
1032 // Note that uc(<lowercase eszett>) => "SS", NOT <uppercase eszett>!
1033 // However, neither Windows nor Mac OSX converts these.
1034 // (or even have glyphs for <uppercase eszett>)
1035 { { FPL("\u00DF"), FPL("\u00DF") }, 0},
1036 { { FPL("\u1E9E"), FPL("\u1E9E") }, 0},
1037 { { FPL("\u00DF"), FPL("\u1E9E") }, -1},
1038 { { FPL("SS"), FPL("\u00DF") }, -1},
1039 { { FPL("SS"), FPL("\u1E9E") }, -1},
1040 #if defined(OS_WIN) || defined(OS_MACOSX)
1041 // Umlauts A, O, U: direct comparison, and upper case vs. lower case
1042 { { FPL("\u00E4\u00F6\u00FC"), FPL("\u00E4\u00F6\u00FC") }, 0},
1043 { { FPL("\u00C4\u00D6\u00DC"), FPL("\u00E4\u00F6\u00FC") }, 0},
1044 // C with circumflex: direct comparison, and upper case vs. lower case
1045 { { FPL("\u0109"), FPL("\u0109") }, 0},
1046 { { FPL("\u0108"), FPL("\u0109") }, 0},
1047 // Cyrillic letter SHA: direct comparison, and upper case vs. lower case
1048 { { FPL("\u0428"), FPL("\u0428") }, 0},
1049 { { FPL("\u0428"), FPL("\u0448") }, 0},
1050 // Greek letter DELTA: direct comparison, and upper case vs. lower case
1051 { { FPL("\u0394"), FPL("\u0394") }, 0},
1052 { { FPL("\u0394"), FPL("\u03B4") }, 0},
1053 // Japanese full-width A: direct comparison, and upper case vs. lower case
1054 // Note that full-width and standard characters are considered different.
1055 { { FPL("\uFF21"), FPL("\uFF21") }, 0},
1056 { { FPL("\uFF21"), FPL("\uFF41") }, 0},
1057 { { FPL("A"), FPL("\uFF21") }, -1},
1058 { { FPL("A"), FPL("\uFF41") }, -1},
1059 { { FPL("a"), FPL("\uFF21") }, -1},
1060 { { FPL("a"), FPL("\uFF41") }, -1},
1061 #endif
1062 #if defined(OS_MACOSX)
1063 // Codepoints > 0x1000
1064 // Georgian letter DON: direct comparison, and upper case vs. lower case
1065 { { FPL("\u10A3"), FPL("\u10A3") }, 0},
1066 { { FPL("\u10A3"), FPL("\u10D3") }, 0},
1067 // Combining characters vs. pre-composed characters, upper and lower case
1068 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E31\u1E77\u1E53n") }, 0},
1069 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("kuon") }, 1},
1070 { { FPL("kuon"), FPL("k\u0301u\u032Do\u0304\u0301n") }, -1},
1071 { { FPL("K\u0301U\u032DO\u0304\u0301N"), FPL("KUON") }, 1},
1072 { { FPL("KUON"), FPL("K\u0301U\u032DO\u0304\u0301N") }, -1},
1073 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("KUON") }, 1},
1074 { { FPL("K\u0301U\u032DO\u0304\u0301N"), FPL("\u1E31\u1E77\u1E53n") }, 0},
1075 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E30\u1E76\u1E52n") }, 0},
1076 { { FPL("k\u0301u\u032Do\u0304\u0302n"), FPL("\u1E30\u1E76\u1E52n") }, 1},
1077 #endif
1080 for (size_t i = 0; i < arraysize(cases); ++i) {
1081 FilePath::StringType s1(cases[i].inputs[0]);
1082 FilePath::StringType s2(cases[i].inputs[1]);
1083 int result = FilePath::CompareIgnoreCase(s1, s2);
1084 EXPECT_EQ(cases[i].expected, result) <<
1085 "i: " << i << ", s1: " << s1 << ", s2: " << s2;
1089 TEST_F(FilePathTest, ReferencesParent) {
1090 const struct UnaryBooleanTestData cases[] = {
1091 { FPL("."), false },
1092 { FPL(".."), true },
1093 { FPL(".. "), true },
1094 { FPL(" .."), true },
1095 { FPL("..."), true },
1096 { FPL("a.."), false },
1097 { FPL("..a"), false },
1098 { FPL("../"), true },
1099 { FPL("/.."), true },
1100 { FPL("/../"), true },
1101 { FPL("/a../"), false },
1102 { FPL("/..a/"), false },
1103 { FPL("//.."), true },
1104 { FPL("..//"), true },
1105 { FPL("//..//"), true },
1106 { FPL("a//..//c"), true },
1107 { FPL("../b/c"), true },
1108 { FPL("/../b/c"), true },
1109 { FPL("a/b/.."), true },
1110 { FPL("a/b/../"), true },
1111 { FPL("a/../c"), true },
1112 { FPL("a/b/c"), false },
1115 for (size_t i = 0; i < arraysize(cases); ++i) {
1116 FilePath input(cases[i].input);
1117 bool observed = input.ReferencesParent();
1118 EXPECT_EQ(cases[i].expected, observed) <<
1119 "i: " << i << ", input: " << input.value();
1123 TEST_F(FilePathTest, FromUTF8Unsafe_And_AsUTF8Unsafe) {
1124 const struct UTF8TestData cases[] = {
1125 { FPL("foo.txt"), "foo.txt" },
1126 // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them.
1127 { FPL("\u00E0\u00E8\u00F2.txt"), "\xC3\xA0\xC3\xA8\xC3\xB2.txt" },
1128 // Full-width "ABC".
1129 { FPL("\uFF21\uFF22\uFF23.txt"),
1130 "\xEF\xBC\xA1\xEF\xBC\xA2\xEF\xBC\xA3.txt" },
1133 #if !defined(SYSTEM_NATIVE_UTF8) && defined(OS_LINUX)
1134 ScopedLocale locale("en_US.UTF-8");
1135 #endif
1137 for (size_t i = 0; i < arraysize(cases); ++i) {
1138 // Test FromUTF8Unsafe() works.
1139 FilePath from_utf8 = FilePath::FromUTF8Unsafe(cases[i].utf8);
1140 EXPECT_EQ(cases[i].native, from_utf8.value())
1141 << "i: " << i << ", input: " << cases[i].native;
1142 // Test AsUTF8Unsafe() works.
1143 FilePath from_native = FilePath(cases[i].native);
1144 EXPECT_EQ(cases[i].utf8, from_native.AsUTF8Unsafe())
1145 << "i: " << i << ", input: " << cases[i].native;
1146 // Test the two file paths are identical.
1147 EXPECT_EQ(from_utf8.value(), from_native.value());
1151 TEST_F(FilePathTest, ConstructWithNUL) {
1152 // Assert FPS() works.
1153 ASSERT_EQ(3U, FPS("a\0b").length());
1155 // Test constructor strips '\0'
1156 FilePath path(FPS("a\0b"));
1157 EXPECT_EQ(1U, path.value().length());
1158 EXPECT_EQ(FPL("a"), path.value());
1161 TEST_F(FilePathTest, AppendWithNUL) {
1162 // Assert FPS() works.
1163 ASSERT_EQ(3U, FPS("b\0b").length());
1165 // Test Append() strips '\0'
1166 FilePath path(FPL("a"));
1167 path = path.Append(FPS("b\0b"));
1168 EXPECT_EQ(3U, path.value().length());
1169 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1170 EXPECT_EQ(FPL("a\\b"), path.value());
1171 #else
1172 EXPECT_EQ(FPL("a/b"), path.value());
1173 #endif
1176 TEST_F(FilePathTest, ReferencesParentWithNUL) {
1177 // Assert FPS() works.
1178 ASSERT_EQ(3U, FPS("..\0").length());
1180 // Test ReferencesParent() doesn't break with "..\0"
1181 FilePath path(FPS("..\0"));
1182 EXPECT_TRUE(path.ReferencesParent());
1185 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1186 TEST_F(FilePathTest, NormalizePathSeparators) {
1187 const struct UnaryTestData cases[] = {
1188 { FPL("foo/bar"), FPL("foo\\bar") },
1189 { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") },
1190 { FPL("foo\\bar"), FPL("foo\\bar") },
1191 { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") },
1192 { FPL("foo"), FPL("foo") },
1193 // Trailing slashes don't automatically get stripped. That's what
1194 // StripTrailingSeparators() is for.
1195 { FPL("foo\\"), FPL("foo\\") },
1196 { FPL("foo/"), FPL("foo\\") },
1197 { FPL("foo/bar\\"), FPL("foo\\bar\\") },
1198 { FPL("foo\\bar/"), FPL("foo\\bar\\") },
1199 { FPL("foo/bar/"), FPL("foo\\bar\\") },
1200 { FPL("foo\\bar\\"), FPL("foo\\bar\\") },
1201 { FPL("\\foo/bar"), FPL("\\foo\\bar") },
1202 { FPL("/foo\\bar"), FPL("\\foo\\bar") },
1203 { FPL("c:/foo/bar/"), FPL("c:\\foo\\bar\\") },
1204 { FPL("/foo/bar/"), FPL("\\foo\\bar\\") },
1205 { FPL("\\foo\\bar\\"), FPL("\\foo\\bar\\") },
1206 { FPL("c:\\foo/bar"), FPL("c:\\foo\\bar") },
1207 { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1208 { FPL("\\\\foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1209 { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1210 // This method does not normalize the number of path separators.
1211 { FPL("foo\\\\bar"), FPL("foo\\\\bar") },
1212 { FPL("foo//bar"), FPL("foo\\\\bar") },
1213 { FPL("foo/\\bar"), FPL("foo\\\\bar") },
1214 { FPL("foo\\/bar"), FPL("foo\\\\bar") },
1215 { FPL("///foo\\\\bar"), FPL("\\\\\\foo\\\\bar") },
1216 { FPL("foo//bar///"), FPL("foo\\\\bar\\\\\\") },
1217 { FPL("foo/\\bar/\\"), FPL("foo\\\\bar\\\\") },
1218 { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") },
1220 for (size_t i = 0; i < arraysize(cases); ++i) {
1221 FilePath input(cases[i].input);
1222 FilePath observed = input.NormalizePathSeparators();
1223 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) <<
1224 "i: " << i << ", input: " << input.value();
1227 #endif
1229 TEST_F(FilePathTest, EndsWithSeparator) {
1230 const UnaryBooleanTestData cases[] = {
1231 { FPL(""), false },
1232 { FPL("/"), true },
1233 { FPL("foo/"), true },
1234 { FPL("bar"), false },
1235 { FPL("/foo/bar"), false },
1237 for (size_t i = 0; i < arraysize(cases); ++i) {
1238 FilePath input = FilePath(cases[i].input).NormalizePathSeparators();
1239 EXPECT_EQ(cases[i].expected, input.EndsWithSeparator());
1243 TEST_F(FilePathTest, AsEndingWithSeparator) {
1244 const UnaryTestData cases[] = {
1245 { FPL(""), FPL("") },
1246 { FPL("/"), FPL("/") },
1247 { FPL("foo"), FPL("foo/") },
1248 { FPL("foo/"), FPL("foo/") }
1250 for (size_t i = 0; i < arraysize(cases); ++i) {
1251 FilePath input = FilePath(cases[i].input).NormalizePathSeparators();
1252 FilePath expected = FilePath(cases[i].expected).NormalizePathSeparators();
1253 EXPECT_EQ(expected.value(), input.AsEndingWithSeparator().value());
1257 #if defined(OS_ANDROID)
1258 TEST_F(FilePathTest, ContentUriTest) {
1259 const struct UnaryBooleanTestData cases[] = {
1260 { FPL("content://foo.bar"), true },
1261 { FPL("content://foo.bar/"), true },
1262 { FPL("content://foo/bar"), true },
1263 { FPL("CoNTenT://foo.bar"), true },
1264 { FPL("content://"), true },
1265 { FPL("content:///foo.bar"), true },
1266 { FPL("content://3foo/bar"), true },
1267 { FPL("content://_foo/bar"), true },
1268 { FPL(".. "), false },
1269 { FPL("foo.bar"), false },
1270 { FPL("content:foo.bar"), false },
1271 { FPL("content:/foo.ba"), false },
1272 { FPL("content:/dir/foo.bar"), false },
1273 { FPL("content: //foo.bar"), false },
1274 { FPL("content%2a%2f%2f"), false },
1277 for (size_t i = 0; i < arraysize(cases); ++i) {
1278 FilePath input(cases[i].input);
1279 bool observed = input.IsContentUri();
1280 EXPECT_EQ(cases[i].expected, observed) <<
1281 "i: " << i << ", input: " << input.value();
1284 #endif
1286 // Test the PrintTo overload for FilePath (used when a test fails to compare two
1287 // FilePaths).
1288 TEST_F(FilePathTest, PrintTo) {
1289 std::stringstream ss;
1290 FilePath fp(FPL("foo"));
1291 base::PrintTo(fp, &ss);
1292 EXPECT_EQ("foo", ss.str());
1295 } // namespace base