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 "base/basictypes.h"
6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/platform_test.h"
11 // This macro helps avoid wrapped lines in the test structs.
12 #define FPL(x) FILE_PATH_LITERAL(x)
14 // This macro constructs strings which can contain NULs.
15 #define FPS(x) FilePath::StringType(FPL(x), arraysize(FPL(x)) - 1)
19 struct UnaryTestData
{
20 const FilePath::CharType
* input
;
21 const FilePath::CharType
* expected
;
24 struct UnaryBooleanTestData
{
25 const FilePath::CharType
* input
;
29 struct BinaryTestData
{
30 const FilePath::CharType
* inputs
[2];
31 const FilePath::CharType
* expected
;
34 struct BinaryBooleanTestData
{
35 const FilePath::CharType
* inputs
[2];
39 struct BinaryIntTestData
{
40 const FilePath::CharType
* inputs
[2];
45 const FilePath::CharType
* native
;
49 // file_util winds up using autoreleased objects on the Mac, so this needs
50 // to be a PlatformTest
51 typedef PlatformTest FilePathTest
;
53 TEST_F(FilePathTest
, DirName
) {
54 const struct UnaryTestData cases
[] = {
55 { FPL(""), FPL(".") },
56 { FPL("aa"), FPL(".") },
57 { FPL("/aa/bb"), FPL("/aa") },
58 { FPL("/aa/bb/"), FPL("/aa") },
59 { FPL("/aa/bb//"), FPL("/aa") },
60 { FPL("/aa/bb/ccc"), FPL("/aa/bb") },
61 { FPL("/aa"), FPL("/") },
62 { FPL("/aa/"), FPL("/") },
63 { FPL("/"), FPL("/") },
64 { FPL("//"), FPL("//") },
65 { FPL("///"), FPL("/") },
66 { FPL("aa/"), FPL(".") },
67 { FPL("aa/bb"), FPL("aa") },
68 { FPL("aa/bb/"), FPL("aa") },
69 { FPL("aa/bb//"), FPL("aa") },
70 { FPL("aa//bb//"), FPL("aa") },
71 { FPL("aa//bb/"), FPL("aa") },
72 { FPL("aa//bb"), FPL("aa") },
73 { FPL("//aa/bb"), FPL("//aa") },
74 { FPL("//aa/"), FPL("//") },
75 { FPL("//aa"), FPL("//") },
76 { FPL("0:"), FPL(".") },
77 { FPL("@:"), FPL(".") },
78 { FPL("[:"), FPL(".") },
79 { FPL("`:"), FPL(".") },
80 { FPL("{:"), FPL(".") },
81 { FPL("\xB3:"), FPL(".") },
82 { FPL("\xC5:"), FPL(".") },
84 { FPL("\x0143:"), FPL(".") },
86 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
87 { FPL("c:"), FPL("c:") },
88 { FPL("C:"), FPL("C:") },
89 { FPL("A:"), FPL("A:") },
90 { FPL("Z:"), FPL("Z:") },
91 { FPL("a:"), FPL("a:") },
92 { FPL("z:"), FPL("z:") },
93 { FPL("c:aa"), FPL("c:") },
94 { FPL("c:/"), FPL("c:/") },
95 { FPL("c://"), FPL("c://") },
96 { FPL("c:///"), FPL("c:/") },
97 { FPL("c:/aa"), FPL("c:/") },
98 { FPL("c:/aa/"), FPL("c:/") },
99 { FPL("c:/aa/bb"), FPL("c:/aa") },
100 { FPL("c:aa/bb"), FPL("c:aa") },
101 #endif // FILE_PATH_USES_DRIVE_LETTERS
102 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
103 { FPL("\\aa\\bb"), FPL("\\aa") },
104 { FPL("\\aa\\bb\\"), FPL("\\aa") },
105 { FPL("\\aa\\bb\\\\"), FPL("\\aa") },
106 { FPL("\\aa\\bb\\ccc"), FPL("\\aa\\bb") },
107 { FPL("\\aa"), FPL("\\") },
108 { FPL("\\aa\\"), FPL("\\") },
109 { FPL("\\"), FPL("\\") },
110 { FPL("\\\\"), FPL("\\\\") },
111 { FPL("\\\\\\"), FPL("\\") },
112 { FPL("aa\\"), FPL(".") },
113 { FPL("aa\\bb"), FPL("aa") },
114 { FPL("aa\\bb\\"), FPL("aa") },
115 { FPL("aa\\bb\\\\"), FPL("aa") },
116 { FPL("aa\\\\bb\\\\"), FPL("aa") },
117 { FPL("aa\\\\bb\\"), FPL("aa") },
118 { FPL("aa\\\\bb"), FPL("aa") },
119 { FPL("\\\\aa\\bb"), FPL("\\\\aa") },
120 { FPL("\\\\aa\\"), FPL("\\\\") },
121 { FPL("\\\\aa"), FPL("\\\\") },
122 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
123 { FPL("c:\\"), FPL("c:\\") },
124 { FPL("c:\\\\"), FPL("c:\\\\") },
125 { FPL("c:\\\\\\"), FPL("c:\\") },
126 { FPL("c:\\aa"), FPL("c:\\") },
127 { FPL("c:\\aa\\"), FPL("c:\\") },
128 { FPL("c:\\aa\\bb"), FPL("c:\\aa") },
129 { FPL("c:aa\\bb"), FPL("c:aa") },
130 #endif // FILE_PATH_USES_DRIVE_LETTERS
131 #endif // FILE_PATH_USES_WIN_SEPARATORS
134 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
135 FilePath
input(cases
[i
].input
);
136 FilePath observed
= input
.DirName();
137 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
.value()) <<
138 "i: " << i
<< ", input: " << input
.value();
142 TEST_F(FilePathTest
, BaseName
) {
143 const struct UnaryTestData cases
[] = {
144 { FPL(""), FPL("") },
145 { FPL("aa"), FPL("aa") },
146 { FPL("/aa/bb"), FPL("bb") },
147 { FPL("/aa/bb/"), FPL("bb") },
148 { FPL("/aa/bb//"), FPL("bb") },
149 { FPL("/aa/bb/ccc"), FPL("ccc") },
150 { FPL("/aa"), FPL("aa") },
151 { FPL("/"), FPL("/") },
152 { FPL("//"), FPL("//") },
153 { FPL("///"), FPL("/") },
154 { FPL("aa/"), FPL("aa") },
155 { FPL("aa/bb"), FPL("bb") },
156 { FPL("aa/bb/"), FPL("bb") },
157 { FPL("aa/bb//"), FPL("bb") },
158 { FPL("aa//bb//"), FPL("bb") },
159 { FPL("aa//bb/"), FPL("bb") },
160 { FPL("aa//bb"), FPL("bb") },
161 { FPL("//aa/bb"), FPL("bb") },
162 { FPL("//aa/"), FPL("aa") },
163 { FPL("//aa"), FPL("aa") },
164 { FPL("0:"), FPL("0:") },
165 { FPL("@:"), FPL("@:") },
166 { FPL("[:"), FPL("[:") },
167 { FPL("`:"), FPL("`:") },
168 { FPL("{:"), FPL("{:") },
169 { FPL("\xB3:"), FPL("\xB3:") },
170 { FPL("\xC5:"), FPL("\xC5:") },
172 { FPL("\x0143:"), FPL("\x0143:") },
174 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
175 { FPL("c:"), FPL("") },
176 { FPL("C:"), FPL("") },
177 { FPL("A:"), FPL("") },
178 { FPL("Z:"), FPL("") },
179 { FPL("a:"), FPL("") },
180 { FPL("z:"), FPL("") },
181 { FPL("c:aa"), FPL("aa") },
182 { FPL("c:/"), FPL("/") },
183 { FPL("c://"), FPL("//") },
184 { FPL("c:///"), FPL("/") },
185 { FPL("c:/aa"), FPL("aa") },
186 { FPL("c:/aa/"), FPL("aa") },
187 { FPL("c:/aa/bb"), FPL("bb") },
188 { FPL("c:aa/bb"), FPL("bb") },
189 #endif // FILE_PATH_USES_DRIVE_LETTERS
190 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
191 { FPL("\\aa\\bb"), FPL("bb") },
192 { FPL("\\aa\\bb\\"), FPL("bb") },
193 { FPL("\\aa\\bb\\\\"), FPL("bb") },
194 { FPL("\\aa\\bb\\ccc"), FPL("ccc") },
195 { FPL("\\aa"), FPL("aa") },
196 { FPL("\\"), FPL("\\") },
197 { FPL("\\\\"), FPL("\\\\") },
198 { FPL("\\\\\\"), FPL("\\") },
199 { FPL("aa\\"), FPL("aa") },
200 { FPL("aa\\bb"), FPL("bb") },
201 { FPL("aa\\bb\\"), FPL("bb") },
202 { FPL("aa\\bb\\\\"), FPL("bb") },
203 { FPL("aa\\\\bb\\\\"), FPL("bb") },
204 { FPL("aa\\\\bb\\"), FPL("bb") },
205 { FPL("aa\\\\bb"), FPL("bb") },
206 { FPL("\\\\aa\\bb"), FPL("bb") },
207 { FPL("\\\\aa\\"), FPL("aa") },
208 { FPL("\\\\aa"), FPL("aa") },
209 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
210 { FPL("c:\\"), FPL("\\") },
211 { FPL("c:\\\\"), FPL("\\\\") },
212 { FPL("c:\\\\\\"), FPL("\\") },
213 { FPL("c:\\aa"), FPL("aa") },
214 { FPL("c:\\aa\\"), FPL("aa") },
215 { FPL("c:\\aa\\bb"), FPL("bb") },
216 { FPL("c:aa\\bb"), FPL("bb") },
217 #endif // FILE_PATH_USES_DRIVE_LETTERS
218 #endif // FILE_PATH_USES_WIN_SEPARATORS
221 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
222 FilePath
input(cases
[i
].input
);
223 FilePath observed
= input
.BaseName();
224 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
.value()) <<
225 "i: " << i
<< ", input: " << input
.value();
229 TEST_F(FilePathTest
, Append
) {
230 const struct BinaryTestData cases
[] = {
231 { { FPL(""), FPL("cc") }, FPL("cc") },
232 { { FPL("."), FPL("ff") }, FPL("ff") },
233 { { FPL("/"), FPL("cc") }, FPL("/cc") },
234 { { FPL("/aa"), FPL("") }, FPL("/aa") },
235 { { FPL("/aa/"), FPL("") }, FPL("/aa") },
236 { { FPL("//aa"), FPL("") }, FPL("//aa") },
237 { { FPL("//aa/"), FPL("") }, FPL("//aa") },
238 { { FPL("//"), FPL("aa") }, FPL("//aa") },
239 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
240 { { FPL("c:"), FPL("a") }, FPL("c:a") },
241 { { FPL("c:"), FPL("") }, FPL("c:") },
242 { { FPL("c:/"), FPL("a") }, FPL("c:/a") },
243 { { FPL("c://"), FPL("a") }, FPL("c://a") },
244 { { FPL("c:///"), FPL("a") }, FPL("c:/a") },
245 #endif // FILE_PATH_USES_DRIVE_LETTERS
246 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
247 // Append introduces the default separator character, so these test cases
248 // need to be defined with different expected results on platforms that use
249 // different default separator characters.
250 { { FPL("\\"), FPL("cc") }, FPL("\\cc") },
251 { { FPL("\\aa"), FPL("") }, FPL("\\aa") },
252 { { FPL("\\aa\\"), FPL("") }, FPL("\\aa") },
253 { { FPL("\\\\aa"), FPL("") }, FPL("\\\\aa") },
254 { { FPL("\\\\aa\\"), FPL("") }, FPL("\\\\aa") },
255 { { FPL("\\\\"), FPL("aa") }, FPL("\\\\aa") },
256 { { FPL("/aa/bb"), FPL("cc") }, FPL("/aa/bb\\cc") },
257 { { FPL("/aa/bb/"), FPL("cc") }, FPL("/aa/bb\\cc") },
258 { { FPL("aa/bb/"), FPL("cc") }, FPL("aa/bb\\cc") },
259 { { FPL("aa/bb"), FPL("cc") }, FPL("aa/bb\\cc") },
260 { { FPL("a/b"), FPL("c") }, FPL("a/b\\c") },
261 { { FPL("a/b/"), FPL("c") }, FPL("a/b\\c") },
262 { { FPL("//aa"), FPL("bb") }, FPL("//aa\\bb") },
263 { { FPL("//aa/"), FPL("bb") }, FPL("//aa\\bb") },
264 { { FPL("\\aa\\bb"), FPL("cc") }, FPL("\\aa\\bb\\cc") },
265 { { FPL("\\aa\\bb\\"), FPL("cc") }, FPL("\\aa\\bb\\cc") },
266 { { FPL("aa\\bb\\"), FPL("cc") }, FPL("aa\\bb\\cc") },
267 { { FPL("aa\\bb"), FPL("cc") }, FPL("aa\\bb\\cc") },
268 { { FPL("a\\b"), FPL("c") }, FPL("a\\b\\c") },
269 { { FPL("a\\b\\"), FPL("c") }, FPL("a\\b\\c") },
270 { { FPL("\\\\aa"), FPL("bb") }, FPL("\\\\aa\\bb") },
271 { { FPL("\\\\aa\\"), FPL("bb") }, FPL("\\\\aa\\bb") },
272 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
273 { { FPL("c:\\"), FPL("a") }, FPL("c:\\a") },
274 { { FPL("c:\\\\"), FPL("a") }, FPL("c:\\\\a") },
275 { { FPL("c:\\\\\\"), FPL("a") }, FPL("c:\\a") },
276 { { FPL("c:\\"), FPL("") }, FPL("c:\\") },
277 { { FPL("c:\\a"), FPL("b") }, FPL("c:\\a\\b") },
278 { { FPL("c:\\a\\"), FPL("b") }, FPL("c:\\a\\b") },
279 #endif // FILE_PATH_USES_DRIVE_LETTERS
280 #else // FILE_PATH_USES_WIN_SEPARATORS
281 { { FPL("/aa/bb"), FPL("cc") }, FPL("/aa/bb/cc") },
282 { { FPL("/aa/bb/"), FPL("cc") }, FPL("/aa/bb/cc") },
283 { { FPL("aa/bb/"), FPL("cc") }, FPL("aa/bb/cc") },
284 { { FPL("aa/bb"), FPL("cc") }, FPL("aa/bb/cc") },
285 { { FPL("a/b"), FPL("c") }, FPL("a/b/c") },
286 { { FPL("a/b/"), FPL("c") }, FPL("a/b/c") },
287 { { FPL("//aa"), FPL("bb") }, FPL("//aa/bb") },
288 { { FPL("//aa/"), FPL("bb") }, FPL("//aa/bb") },
289 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
290 { { FPL("c:/"), FPL("a") }, FPL("c:/a") },
291 { { FPL("c:/"), FPL("") }, FPL("c:/") },
292 { { FPL("c:/a"), FPL("b") }, FPL("c:/a/b") },
293 { { FPL("c:/a/"), FPL("b") }, FPL("c:/a/b") },
294 #endif // FILE_PATH_USES_DRIVE_LETTERS
295 #endif // FILE_PATH_USES_WIN_SEPARATORS
298 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
299 FilePath
root(cases
[i
].inputs
[0]);
300 FilePath::StringType
leaf(cases
[i
].inputs
[1]);
301 FilePath observed_str
= root
.Append(leaf
);
302 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed_str
.value()) <<
303 "i: " << i
<< ", root: " << root
.value() << ", leaf: " << leaf
;
304 FilePath observed_path
= root
.Append(FilePath(leaf
));
305 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed_path
.value()) <<
306 "i: " << i
<< ", root: " << root
.value() << ", leaf: " << leaf
;
308 // TODO(erikkay): It would be nice to have a unicode test append value to
309 // handle the case when AppendASCII is passed UTF8
311 std::string ascii
= WideToUTF8(leaf
);
312 #elif defined(OS_POSIX)
313 std::string ascii
= leaf
;
315 observed_str
= root
.AppendASCII(ascii
);
316 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed_str
.value()) <<
317 "i: " << i
<< ", root: " << root
.value() << ", leaf: " << leaf
;
321 TEST_F(FilePathTest
, StripTrailingSeparators
) {
322 const struct UnaryTestData cases
[] = {
323 { FPL(""), FPL("") },
324 { FPL("/"), FPL("/") },
325 { FPL("//"), FPL("//") },
326 { FPL("///"), FPL("/") },
327 { FPL("////"), FPL("/") },
328 { FPL("a/"), FPL("a") },
329 { FPL("a//"), FPL("a") },
330 { FPL("a///"), FPL("a") },
331 { FPL("a////"), FPL("a") },
332 { FPL("/a"), FPL("/a") },
333 { FPL("/a/"), FPL("/a") },
334 { FPL("/a//"), FPL("/a") },
335 { FPL("/a///"), FPL("/a") },
336 { FPL("/a////"), FPL("/a") },
337 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
338 { FPL("c:"), FPL("c:") },
339 { FPL("c:/"), FPL("c:/") },
340 { FPL("c://"), FPL("c://") },
341 { FPL("c:///"), FPL("c:/") },
342 { FPL("c:////"), FPL("c:/") },
343 { FPL("c:/a"), FPL("c:/a") },
344 { FPL("c:/a/"), FPL("c:/a") },
345 { FPL("c:/a//"), FPL("c:/a") },
346 { FPL("c:/a///"), FPL("c:/a") },
347 { FPL("c:/a////"), FPL("c:/a") },
348 #endif // FILE_PATH_USES_DRIVE_LETTERS
349 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
350 { FPL("\\"), FPL("\\") },
351 { FPL("\\\\"), FPL("\\\\") },
352 { FPL("\\\\\\"), FPL("\\") },
353 { FPL("\\\\\\\\"), FPL("\\") },
354 { FPL("a\\"), FPL("a") },
355 { FPL("a\\\\"), FPL("a") },
356 { FPL("a\\\\\\"), FPL("a") },
357 { FPL("a\\\\\\\\"), FPL("a") },
358 { FPL("\\a"), FPL("\\a") },
359 { FPL("\\a\\"), FPL("\\a") },
360 { FPL("\\a\\\\"), FPL("\\a") },
361 { FPL("\\a\\\\\\"), FPL("\\a") },
362 { FPL("\\a\\\\\\\\"), FPL("\\a") },
363 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
364 { FPL("c:\\"), FPL("c:\\") },
365 { FPL("c:\\\\"), FPL("c:\\\\") },
366 { FPL("c:\\\\\\"), FPL("c:\\") },
367 { FPL("c:\\\\\\\\"), FPL("c:\\") },
368 { FPL("c:\\a"), FPL("c:\\a") },
369 { FPL("c:\\a\\"), FPL("c:\\a") },
370 { FPL("c:\\a\\\\"), FPL("c:\\a") },
371 { FPL("c:\\a\\\\\\"), FPL("c:\\a") },
372 { FPL("c:\\a\\\\\\\\"), FPL("c:\\a") },
373 #endif // FILE_PATH_USES_DRIVE_LETTERS
374 #endif // FILE_PATH_USES_WIN_SEPARATORS
377 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
378 FilePath
input(cases
[i
].input
);
379 FilePath observed
= input
.StripTrailingSeparators();
380 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
.value()) <<
381 "i: " << i
<< ", input: " << input
.value();
385 TEST_F(FilePathTest
, IsAbsolute
) {
386 const struct UnaryBooleanTestData cases
[] = {
389 { FPL("c:"), false },
390 { FPL("c:a"), false },
391 { FPL("a/b"), false },
393 { FPL("//a"), true },
394 { FPL("c:a/b"), false },
395 { FPL("?:/a"), false },
396 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
398 { FPL("/a"), false },
399 { FPL("/."), false },
400 { FPL("/.."), false },
401 { FPL("c:/"), true },
402 { FPL("c:/a"), true },
403 { FPL("c:/."), true },
404 { FPL("c:/.."), true },
405 { FPL("C:/a"), true },
406 { FPL("d:/a"), true },
407 #else // FILE_PATH_USES_DRIVE_LETTERS
411 { FPL("/.."), true },
412 { FPL("c:/"), false },
413 #endif // FILE_PATH_USES_DRIVE_LETTERS
414 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
415 { FPL("a\\b"), false },
416 { FPL("\\\\"), true },
417 { FPL("\\\\a"), true },
418 { FPL("a\\b"), false },
419 { FPL("\\\\"), true },
420 { FPL("//a"), true },
421 { FPL("c:a\\b"), false },
422 { FPL("?:\\a"), false },
423 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
424 { FPL("\\"), false },
425 { FPL("\\a"), false },
426 { FPL("\\."), false },
427 { FPL("\\.."), false },
428 { FPL("c:\\"), true },
429 { FPL("c:\\"), true },
430 { FPL("c:\\a"), true },
431 { FPL("c:\\."), true },
432 { FPL("c:\\.."), true },
433 { FPL("C:\\a"), true },
434 { FPL("d:\\a"), true },
435 #else // FILE_PATH_USES_DRIVE_LETTERS
437 { FPL("\\a"), true },
438 { FPL("\\."), true },
439 { FPL("\\.."), true },
440 { FPL("c:\\"), false },
441 #endif // FILE_PATH_USES_DRIVE_LETTERS
442 #endif // FILE_PATH_USES_WIN_SEPARATORS
445 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
446 FilePath
input(cases
[i
].input
);
447 bool observed
= input
.IsAbsolute();
448 EXPECT_EQ(cases
[i
].expected
, observed
) <<
449 "i: " << i
<< ", input: " << input
.value();
453 TEST_F(FilePathTest
, PathComponentsTest
) {
454 const struct UnaryTestData cases
[] = {
455 { FPL("//foo/bar/baz/"), FPL("|//|foo|bar|baz")},
456 { FPL("///"), FPL("|/")},
457 { FPL("/foo//bar//baz/"), FPL("|/|foo|bar|baz")},
458 { FPL("/foo/bar/baz/"), FPL("|/|foo|bar|baz")},
459 { FPL("/foo/bar/baz//"), FPL("|/|foo|bar|baz")},
460 { FPL("/foo/bar/baz///"), FPL("|/|foo|bar|baz")},
461 { FPL("/foo/bar/baz"), FPL("|/|foo|bar|baz")},
462 { FPL("/foo/bar.bot/baz.txt"), FPL("|/|foo|bar.bot|baz.txt")},
463 { FPL("//foo//bar/baz"), FPL("|//|foo|bar|baz")},
464 { FPL("/"), FPL("|/")},
465 { FPL("foo"), FPL("|foo")},
467 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
468 { FPL("e:/foo"), FPL("|e:|/|foo")},
469 { FPL("e:/"), FPL("|e:|/")},
470 { FPL("e:"), FPL("|e:")},
471 #endif // FILE_PATH_USES_DRIVE_LETTERS
472 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
473 { FPL("../foo"), FPL("|..|foo")},
474 { FPL("./foo"), FPL("|foo")},
475 { FPL("../foo/bar/"), FPL("|..|foo|bar") },
476 { FPL("\\\\foo\\bar\\baz\\"), FPL("|\\\\|foo|bar|baz")},
477 { FPL("\\\\\\"), FPL("|\\")},
478 { FPL("\\foo\\\\bar\\\\baz\\"), FPL("|\\|foo|bar|baz")},
479 { FPL("\\foo\\bar\\baz\\"), FPL("|\\|foo|bar|baz")},
480 { FPL("\\foo\\bar\\baz\\\\"), FPL("|\\|foo|bar|baz")},
481 { FPL("\\foo\\bar\\baz\\\\\\"), FPL("|\\|foo|bar|baz")},
482 { FPL("\\foo\\bar\\baz"), FPL("|\\|foo|bar|baz")},
483 { FPL("\\foo\\bar/baz\\\\\\"), FPL("|\\|foo|bar|baz")},
484 { FPL("/foo\\bar\\baz"), FPL("|/|foo|bar|baz")},
485 { FPL("\\foo\\bar.bot\\baz.txt"), FPL("|\\|foo|bar.bot|baz.txt")},
486 { FPL("\\\\foo\\\\bar\\baz"), FPL("|\\\\|foo|bar|baz")},
487 { FPL("\\"), FPL("|\\")},
488 #endif // FILE_PATH_USES_WIN_SEPARATORS
491 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
492 FilePath
input(cases
[i
].input
);
493 std::vector
<FilePath::StringType
> comps
;
494 input
.GetComponents(&comps
);
496 FilePath::StringType observed
;
497 for (size_t j
= 0; j
< comps
.size(); ++j
) {
498 observed
.append(FILE_PATH_LITERAL("|"), 1);
499 observed
.append(comps
[j
]);
501 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
) <<
502 "i: " << i
<< ", input: " << input
.value();
506 TEST_F(FilePathTest
, IsParentTest
) {
507 const struct BinaryBooleanTestData cases
[] = {
508 { { FPL("/"), FPL("/foo/bar/baz") }, true},
509 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, true},
510 { { FPL("/foo/bar/"), FPL("/foo/bar/baz") }, true},
511 { { FPL("//foo/bar/"), FPL("//foo/bar/baz") }, true},
512 { { FPL("/foo/bar"), FPL("/foo2/bar/baz") }, false},
513 { { FPL("/foo/bar.txt"), FPL("/foo/bar/baz") }, false},
514 { { FPL("/foo/bar"), FPL("/foo/bar2/baz") }, false},
515 { { FPL("/foo/bar"), FPL("/foo/bar") }, false},
516 { { FPL("/foo/bar/baz"), FPL("/foo/bar") }, false},
517 { { FPL("foo/bar"), FPL("foo/bar/baz") }, true},
518 { { FPL("foo/bar"), FPL("foo2/bar/baz") }, false},
519 { { FPL("foo/bar"), FPL("foo/bar2/baz") }, false},
520 { { FPL(""), FPL("foo") }, false},
521 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
522 { { FPL("c:/foo/bar"), FPL("c:/foo/bar/baz") }, true},
523 { { FPL("E:/foo/bar"), FPL("e:/foo/bar/baz") }, true},
524 { { FPL("f:/foo/bar"), FPL("F:/foo/bar/baz") }, true},
525 { { FPL("E:/Foo/bar"), FPL("e:/foo/bar/baz") }, false},
526 { { FPL("f:/foo/bar"), FPL("F:/foo/Bar/baz") }, false},
527 { { FPL("c:/"), FPL("c:/foo/bar/baz") }, true},
528 { { FPL("c:"), FPL("c:/foo/bar/baz") }, true},
529 { { FPL("c:/foo/bar"), FPL("d:/foo/bar/baz") }, false},
530 { { FPL("c:/foo/bar"), FPL("D:/foo/bar/baz") }, false},
531 { { FPL("C:/foo/bar"), FPL("d:/foo/bar/baz") }, false},
532 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar/baz") }, false},
533 { { FPL("e:/foo/bar"), FPL("E:/foo2/bar/baz") }, false},
534 { { FPL("F:/foo/bar"), FPL("f:/foo2/bar/baz") }, false},
535 { { FPL("c:/foo/bar"), FPL("c:/foo/bar2/baz") }, false},
536 #endif // FILE_PATH_USES_DRIVE_LETTERS
537 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
538 { { FPL("\\foo\\bar"), FPL("\\foo\\bar\\baz") }, true},
539 { { FPL("\\foo/bar"), FPL("\\foo\\bar\\baz") }, true},
540 { { FPL("\\foo/bar"), FPL("\\foo/bar/baz") }, true},
541 { { FPL("\\"), FPL("\\foo\\bar\\baz") }, true},
542 { { FPL(""), FPL("\\foo\\bar\\baz") }, false},
543 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar\\baz") }, false},
544 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2\\baz") }, false},
545 #endif // FILE_PATH_USES_WIN_SEPARATORS
548 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
549 FilePath
parent(cases
[i
].inputs
[0]);
550 FilePath
child(cases
[i
].inputs
[1]);
552 EXPECT_EQ(parent
.IsParent(child
), cases
[i
].expected
) <<
553 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
558 TEST_F(FilePathTest
, AppendRelativePathTest
) {
559 const struct BinaryTestData cases
[] = {
560 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
561 { { FPL("/"), FPL("/foo/bar/baz") }, FPL("foo\\bar\\baz")},
562 #else // FILE_PATH_USES_WIN_SEPARATORS
563 { { FPL("/"), FPL("/foo/bar/baz") }, FPL("foo/bar/baz")},
564 #endif // FILE_PATH_USES_WIN_SEPARATORS
565 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, FPL("baz")},
566 { { FPL("/foo/bar/"), FPL("/foo/bar/baz") }, FPL("baz")},
567 { { FPL("//foo/bar/"), FPL("//foo/bar/baz") }, FPL("baz")},
568 { { FPL("/foo/bar"), FPL("/foo2/bar/baz") }, FPL("")},
569 { { FPL("/foo/bar.txt"), FPL("/foo/bar/baz") }, FPL("")},
570 { { FPL("/foo/bar"), FPL("/foo/bar2/baz") }, FPL("")},
571 { { FPL("/foo/bar"), FPL("/foo/bar") }, FPL("")},
572 { { FPL("/foo/bar/baz"), FPL("/foo/bar") }, FPL("")},
573 { { FPL("foo/bar"), FPL("foo/bar/baz") }, FPL("baz")},
574 { { FPL("foo/bar"), FPL("foo2/bar/baz") }, FPL("")},
575 { { FPL("foo/bar"), FPL("foo/bar2/baz") }, FPL("")},
576 { { FPL(""), FPL("foo") }, FPL("")},
577 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
578 { { FPL("c:/foo/bar"), FPL("c:/foo/bar/baz") }, FPL("baz")},
579 { { FPL("E:/foo/bar"), FPL("e:/foo/bar/baz") }, FPL("baz")},
580 { { FPL("f:/foo/bar"), FPL("F:/foo/bar/baz") }, FPL("baz")},
581 { { FPL("E:/Foo/bar"), FPL("e:/foo/bar/baz") }, FPL("")},
582 { { FPL("f:/foo/bar"), FPL("F:/foo/Bar/baz") }, FPL("")},
583 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
584 { { FPL("c:/"), FPL("c:/foo/bar/baz") }, FPL("foo\\bar\\baz")},
585 // TODO(akalin): Figure out how to handle the corner case in the
586 // commented-out test case below. Appending to an empty path gives
587 // /foo\bar\baz but appending to a nonempty path "blah" gives
589 // { { FPL("c:"), FPL("c:/foo/bar/baz") }, FPL("foo\\bar\\baz")},
590 #endif // FILE_PATH_USES_WIN_SEPARATORS
591 { { FPL("c:/foo/bar"), FPL("d:/foo/bar/baz") }, FPL("")},
592 { { FPL("c:/foo/bar"), FPL("D:/foo/bar/baz") }, FPL("")},
593 { { FPL("C:/foo/bar"), FPL("d:/foo/bar/baz") }, FPL("")},
594 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar/baz") }, FPL("")},
595 { { FPL("e:/foo/bar"), FPL("E:/foo2/bar/baz") }, FPL("")},
596 { { FPL("F:/foo/bar"), FPL("f:/foo2/bar/baz") }, FPL("")},
597 { { FPL("c:/foo/bar"), FPL("c:/foo/bar2/baz") }, FPL("")},
598 #endif // FILE_PATH_USES_DRIVE_LETTERS
599 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
600 { { FPL("\\foo\\bar"), FPL("\\foo\\bar\\baz") }, FPL("baz")},
601 { { FPL("\\foo/bar"), FPL("\\foo\\bar\\baz") }, FPL("baz")},
602 { { FPL("\\foo/bar"), FPL("\\foo/bar/baz") }, FPL("baz")},
603 { { FPL("\\"), FPL("\\foo\\bar\\baz") }, FPL("foo\\bar\\baz")},
604 { { FPL(""), FPL("\\foo\\bar\\baz") }, FPL("")},
605 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar\\baz") }, FPL("")},
606 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2\\baz") }, FPL("")},
607 #endif // FILE_PATH_USES_WIN_SEPARATORS
610 const FilePath
base(FPL("blah"));
612 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
613 FilePath
parent(cases
[i
].inputs
[0]);
614 FilePath
child(cases
[i
].inputs
[1]);
617 bool success
= parent
.AppendRelativePath(child
, &result
);
618 EXPECT_EQ(cases
[i
].expected
[0] != '\0', success
) <<
619 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
621 EXPECT_STREQ(cases
[i
].expected
, result
.value().c_str()) <<
622 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
626 FilePath
result(base
);
627 bool success
= parent
.AppendRelativePath(child
, &result
);
628 EXPECT_EQ(cases
[i
].expected
[0] != '\0', success
) <<
629 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
631 EXPECT_EQ(base
.Append(cases
[i
].expected
).value(), result
.value()) <<
632 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
638 TEST_F(FilePathTest
, EqualityTest
) {
639 const struct BinaryBooleanTestData cases
[] = {
640 { { FPL("/foo/bar/baz"), FPL("/foo/bar/baz") }, true},
641 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, false},
642 { { FPL("/foo/bar/baz"), FPL("/foo/bar") }, false},
643 { { FPL("//foo/bar/"), FPL("//foo/bar/") }, true},
644 { { FPL("/foo/bar"), FPL("/foo2/bar") }, false},
645 { { FPL("/foo/bar.txt"), FPL("/foo/bar") }, false},
646 { { FPL("foo/bar"), FPL("foo/bar") }, true},
647 { { FPL("foo/bar"), FPL("foo/bar/baz") }, false},
648 { { FPL(""), FPL("foo") }, false},
649 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
650 { { FPL("c:/foo/bar"), FPL("c:/foo/bar") }, true},
651 { { FPL("E:/foo/bar"), FPL("e:/foo/bar") }, true},
652 { { FPL("f:/foo/bar"), FPL("F:/foo/bar") }, true},
653 { { FPL("E:/Foo/bar"), FPL("e:/foo/bar") }, false},
654 { { FPL("f:/foo/bar"), FPL("F:/foo/Bar") }, false},
655 { { FPL("c:/"), FPL("c:/") }, true},
656 { { FPL("c:"), FPL("c:") }, true},
657 { { FPL("c:/foo/bar"), FPL("d:/foo/bar") }, false},
658 { { FPL("c:/foo/bar"), FPL("D:/foo/bar") }, false},
659 { { FPL("C:/foo/bar"), FPL("d:/foo/bar") }, false},
660 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar") }, false},
661 #endif // FILE_PATH_USES_DRIVE_LETTERS
662 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
663 { { FPL("\\foo\\bar"), FPL("\\foo\\bar") }, true},
664 { { FPL("\\foo/bar"), FPL("\\foo/bar") }, true},
665 { { FPL("\\foo/bar"), FPL("\\foo\\bar") }, false},
666 { { FPL("\\"), FPL("\\") }, true},
667 { { FPL("\\"), FPL("/") }, false},
668 { { FPL(""), FPL("\\") }, false},
669 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar") }, false},
670 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2") }, false},
671 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
672 { { FPL("c:\\foo\\bar"), FPL("c:\\foo\\bar") }, true},
673 { { FPL("E:\\foo\\bar"), FPL("e:\\foo\\bar") }, true},
674 { { FPL("f:\\foo\\bar"), FPL("F:\\foo/bar") }, false},
675 #endif // FILE_PATH_USES_DRIVE_LETTERS
676 #endif // FILE_PATH_USES_WIN_SEPARATORS
679 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
680 FilePath
a(cases
[i
].inputs
[0]);
681 FilePath
b(cases
[i
].inputs
[1]);
683 EXPECT_EQ(a
== b
, cases
[i
].expected
) <<
684 "equality i: " << i
<< ", a: " << a
.value() << ", b: " <<
688 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
689 FilePath
a(cases
[i
].inputs
[0]);
690 FilePath
b(cases
[i
].inputs
[1]);
692 EXPECT_EQ(a
!= b
, !cases
[i
].expected
) <<
693 "inequality i: " << i
<< ", a: " << a
.value() << ", b: " <<
698 TEST_F(FilePathTest
, Extension
) {
699 FilePath
base_dir(FILE_PATH_LITERAL("base_dir"));
701 FilePath jpg
= base_dir
.Append(FILE_PATH_LITERAL("foo.jpg"));
702 EXPECT_EQ(FILE_PATH_LITERAL(".jpg"), jpg
.Extension());
703 EXPECT_EQ(FILE_PATH_LITERAL(".jpg"), jpg
.FinalExtension());
705 FilePath base
= jpg
.BaseName().RemoveExtension();
706 EXPECT_EQ(FILE_PATH_LITERAL("foo"), base
.value());
708 FilePath path_no_ext
= base_dir
.Append(base
);
709 EXPECT_EQ(path_no_ext
.value(), jpg
.RemoveExtension().value());
711 EXPECT_EQ(path_no_ext
.value(), path_no_ext
.RemoveExtension().value());
712 EXPECT_EQ(FILE_PATH_LITERAL(""), path_no_ext
.Extension());
713 EXPECT_EQ(FILE_PATH_LITERAL(""), path_no_ext
.FinalExtension());
716 TEST_F(FilePathTest
, Extension2
) {
717 const struct UnaryTestData cases
[] = {
718 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
719 { FPL("C:\\a\\b\\c.ext"), FPL(".ext") },
720 { FPL("C:\\a\\b\\c."), FPL(".") },
721 { FPL("C:\\a\\b\\c"), FPL("") },
722 { FPL("C:\\a\\b\\"), FPL("") },
723 { FPL("C:\\a\\b.\\"), FPL(".") },
724 { FPL("C:\\a\\b\\c.ext1.ext2"), FPL(".ext2") },
725 { FPL("C:\\foo.bar\\\\\\"), FPL(".bar") },
726 { FPL("C:\\foo.bar\\.."), FPL("") },
727 { FPL("C:\\foo.bar\\..\\\\"), FPL("") },
729 { FPL("/foo/bar/baz.ext"), FPL(".ext") },
730 { FPL("/foo/bar/baz."), FPL(".") },
731 { FPL("/foo/bar/baz.."), FPL(".") },
732 { FPL("/foo/bar/baz"), FPL("") },
733 { FPL("/foo/bar/"), FPL("") },
734 { FPL("/foo/bar./"), FPL(".") },
735 { FPL("/foo/bar/baz.ext1.ext2"), FPL(".ext2") },
736 { FPL("/subversion-1.6.12.zip"), FPL(".zip") },
737 { FPL("/foo.12345.gz"), FPL(".gz") },
738 { FPL("/foo..gz"), FPL(".gz") },
739 { FPL("."), FPL("") },
740 { FPL(".."), FPL("") },
741 { FPL("./foo"), FPL("") },
742 { FPL("./foo.ext"), FPL(".ext") },
743 { FPL("/foo.ext1/bar.ext2"), FPL(".ext2") },
744 { FPL("/foo.bar////"), FPL(".bar") },
745 { FPL("/foo.bar/.."), FPL("") },
746 { FPL("/foo.bar/..////"), FPL("") },
747 { FPL("/foo.1234.luser.js"), FPL(".js") },
748 { FPL("/user.js"), FPL(".js") },
750 const struct UnaryTestData double_extension_cases
[] = {
751 { FPL("/foo.tar.gz"), FPL(".tar.gz") },
752 { FPL("/foo.tar.Z"), FPL(".tar.Z") },
753 { FPL("/foo.tar.bz2"), FPL(".tar.bz2") },
754 { FPL("/foo.1234.gz"), FPL(".1234.gz") },
755 { FPL("/foo.1234.tar.gz"), FPL(".tar.gz") },
756 { FPL("/foo.tar.tar.gz"), FPL(".tar.gz") },
757 { FPL("/foo.tar.gz.gz"), FPL(".gz.gz") },
758 { FPL("/foo.1234.user.js"), FPL(".user.js") },
759 { FPL("foo.user.js"), FPL(".user.js") },
760 { FPL("/foo.tar.bz"), FPL(".tar.bz") },
762 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
763 FilePath
path(cases
[i
].input
);
764 FilePath::StringType extension
= path
.Extension();
765 FilePath::StringType final_extension
= path
.FinalExtension();
766 EXPECT_STREQ(cases
[i
].expected
, extension
.c_str())
767 << "i: " << i
<< ", path: " << path
.value();
768 EXPECT_STREQ(cases
[i
].expected
, final_extension
.c_str())
769 << "i: " << i
<< ", path: " << path
.value();
771 for (unsigned int i
= 0; i
< arraysize(double_extension_cases
); ++i
) {
772 FilePath
path(double_extension_cases
[i
].input
);
773 FilePath::StringType extension
= path
.Extension();
774 EXPECT_STREQ(double_extension_cases
[i
].expected
, extension
.c_str())
775 << "i: " << i
<< ", path: " << path
.value();
779 TEST_F(FilePathTest
, InsertBeforeExtension
) {
780 const struct BinaryTestData cases
[] = {
781 { { FPL(""), FPL("") }, FPL("") },
782 { { FPL(""), FPL("txt") }, FPL("") },
783 { { FPL("."), FPL("txt") }, FPL("") },
784 { { FPL(".."), FPL("txt") }, FPL("") },
785 { { FPL("foo.dll"), FPL("txt") }, FPL("footxt.dll") },
786 { { FPL("."), FPL("") }, FPL(".") },
787 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.txt.dll") },
788 { { FPL("foo"), FPL("txt") }, FPL("footxt") },
789 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
790 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baztxt.dll") },
791 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.txt.dll") },
792 { { FPL("foo.dll"), FPL("") }, FPL("foo.dll") },
793 { { FPL("foo.dll"), FPL(".") }, FPL("foo..dll") },
794 { { FPL("foo"), FPL("") }, FPL("foo") },
795 { { FPL("foo"), FPL(".") }, FPL("foo.") },
796 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz.dll") },
797 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz..dll") },
798 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
799 { { FPL("\\"), FPL("") }, FPL("\\") },
800 { { FPL("\\"), FPL("txt") }, FPL("\\txt") },
801 { { FPL("\\."), FPL("txt") }, FPL("") },
802 { { FPL("\\.."), FPL("txt") }, FPL("") },
803 { { FPL("\\."), FPL("") }, FPL("\\.") },
804 { { FPL("C:\\bar\\foo.dll"), FPL("txt") },
805 FPL("C:\\bar\\footxt.dll") },
806 { { FPL("C:\\bar.baz\\foodll"), FPL("txt") },
807 FPL("C:\\bar.baz\\foodlltxt") },
808 { { FPL("C:\\bar.baz\\foo.dll"), FPL("txt") },
809 FPL("C:\\bar.baz\\footxt.dll") },
810 { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("txt") },
811 FPL("C:\\bar.baz\\foo.dlltxt.exe") },
812 { { FPL("C:\\bar.baz\\foo"), FPL("") },
813 FPL("C:\\bar.baz\\foo") },
814 { { FPL("C:\\bar.baz\\foo.exe"), FPL("") },
815 FPL("C:\\bar.baz\\foo.exe") },
816 { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("") },
817 FPL("C:\\bar.baz\\foo.dll.exe") },
818 { { FPL("C:\\bar\\baz\\foo.exe"), FPL(" (1)") },
819 FPL("C:\\bar\\baz\\foo (1).exe") },
820 { { FPL("C:\\foo.baz\\\\"), FPL(" (1)") }, FPL("C:\\foo (1).baz") },
821 { { FPL("C:\\foo.baz\\..\\"), FPL(" (1)") }, FPL("") },
823 { { FPL("/"), FPL("") }, FPL("/") },
824 { { FPL("/"), FPL("txt") }, FPL("/txt") },
825 { { FPL("/."), FPL("txt") }, FPL("") },
826 { { FPL("/.."), FPL("txt") }, FPL("") },
827 { { FPL("/."), FPL("") }, FPL("/.") },
828 { { FPL("/bar/foo.dll"), FPL("txt") }, FPL("/bar/footxt.dll") },
829 { { FPL("/bar.baz/foodll"), FPL("txt") }, FPL("/bar.baz/foodlltxt") },
830 { { FPL("/bar.baz/foo.dll"), FPL("txt") }, FPL("/bar.baz/footxt.dll") },
831 { { FPL("/bar.baz/foo.dll.exe"), FPL("txt") },
832 FPL("/bar.baz/foo.dlltxt.exe") },
833 { { FPL("/bar.baz/foo"), FPL("") }, FPL("/bar.baz/foo") },
834 { { FPL("/bar.baz/foo.exe"), FPL("") }, FPL("/bar.baz/foo.exe") },
835 { { FPL("/bar.baz/foo.dll.exe"), FPL("") }, FPL("/bar.baz/foo.dll.exe") },
836 { { FPL("/bar/baz/foo.exe"), FPL(" (1)") }, FPL("/bar/baz/foo (1).exe") },
837 { { FPL("/bar/baz/..////"), FPL(" (1)") }, FPL("") },
839 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
840 FilePath
path(cases
[i
].inputs
[0]);
841 FilePath result
= path
.InsertBeforeExtension(cases
[i
].inputs
[1]);
842 EXPECT_EQ(cases
[i
].expected
, result
.value()) << "i: " << i
<<
843 ", path: " << path
.value() << ", insert: " << cases
[i
].inputs
[1];
847 TEST_F(FilePathTest
, RemoveExtension
) {
848 const struct UnaryTestData cases
[] = {
849 { FPL(""), FPL("") },
850 { FPL("."), FPL(".") },
851 { FPL(".."), FPL("..") },
852 { FPL("foo.dll"), FPL("foo") },
853 { FPL("./foo.dll"), FPL("./foo") },
854 { FPL("foo..dll"), FPL("foo.") },
855 { FPL("foo"), FPL("foo") },
856 { FPL("foo."), FPL("foo") },
857 { FPL("foo.."), FPL("foo.") },
858 { FPL("foo.baz.dll"), FPL("foo.baz") },
859 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
860 { FPL("C:\\foo.bar\\foo"), FPL("C:\\foo.bar\\foo") },
861 { FPL("C:\\foo.bar\\..\\\\"), FPL("C:\\foo.bar\\..\\\\") },
863 { FPL("/foo.bar/foo"), FPL("/foo.bar/foo") },
864 { FPL("/foo.bar/..////"), FPL("/foo.bar/..////") },
866 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
867 FilePath
path(cases
[i
].input
);
868 FilePath removed
= path
.RemoveExtension();
869 FilePath removed_final
= path
.RemoveFinalExtension();
870 EXPECT_EQ(cases
[i
].expected
, removed
.value()) << "i: " << i
<<
871 ", path: " << path
.value();
872 EXPECT_EQ(cases
[i
].expected
, removed_final
.value()) << "i: " << i
<<
873 ", path: " << path
.value();
876 FilePath
path(FPL("foo.tar.gz"));
877 FilePath removed
= path
.RemoveExtension();
878 FilePath removed_final
= path
.RemoveFinalExtension();
879 EXPECT_EQ(FPL("foo"), removed
.value()) << ", path: " << path
.value();
880 EXPECT_EQ(FPL("foo.tar"), removed_final
.value()) << ", path: "
885 TEST_F(FilePathTest
, ReplaceExtension
) {
886 const struct BinaryTestData cases
[] = {
887 { { FPL(""), FPL("") }, FPL("") },
888 { { FPL(""), FPL("txt") }, FPL("") },
889 { { FPL("."), FPL("txt") }, FPL("") },
890 { { FPL(".."), FPL("txt") }, FPL("") },
891 { { FPL("."), FPL("") }, FPL("") },
892 { { FPL("foo.dll"), FPL("txt") }, FPL("foo.txt") },
893 { { FPL("./foo.dll"), FPL("txt") }, FPL("./foo.txt") },
894 { { FPL("foo..dll"), FPL("txt") }, FPL("foo..txt") },
895 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.txt") },
896 { { FPL("foo"), FPL("txt") }, FPL("foo.txt") },
897 { { FPL("foo."), FPL("txt") }, FPL("foo.txt") },
898 { { FPL("foo.."), FPL("txt") }, FPL("foo..txt") },
899 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
900 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baz.txt") },
901 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.txt") },
902 { { FPL("foo.dll"), FPL("") }, FPL("foo") },
903 { { FPL("foo.dll"), FPL(".") }, FPL("foo") },
904 { { FPL("foo"), FPL("") }, FPL("foo") },
905 { { FPL("foo"), FPL(".") }, FPL("foo") },
906 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz") },
907 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz") },
908 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
909 { { FPL("C:\\foo.bar\\foo"), FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
910 { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
912 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") },
913 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") },
915 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
916 FilePath
path(cases
[i
].inputs
[0]);
917 FilePath replaced
= path
.ReplaceExtension(cases
[i
].inputs
[1]);
918 EXPECT_EQ(cases
[i
].expected
, replaced
.value()) << "i: " << i
<<
919 ", path: " << path
.value() << ", replace: " << cases
[i
].inputs
[1];
923 TEST_F(FilePathTest
, AddExtension
) {
924 const struct BinaryTestData cases
[] = {
925 { { FPL(""), FPL("") }, FPL("") },
926 { { FPL(""), FPL("txt") }, FPL("") },
927 { { FPL("."), FPL("txt") }, FPL("") },
928 { { FPL(".."), FPL("txt") }, FPL("") },
929 { { FPL("."), FPL("") }, FPL("") },
930 { { FPL("foo.dll"), FPL("txt") }, FPL("foo.dll.txt") },
931 { { FPL("./foo.dll"), FPL("txt") }, FPL("./foo.dll.txt") },
932 { { FPL("foo..dll"), FPL("txt") }, FPL("foo..dll.txt") },
933 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.dll.txt") },
934 { { FPL("foo"), FPL("txt") }, FPL("foo.txt") },
935 { { FPL("foo."), FPL("txt") }, FPL("foo.txt") },
936 { { FPL("foo.."), FPL("txt") }, FPL("foo..txt") },
937 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
938 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baz.dll.txt") },
939 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.dll.txt") },
940 { { FPL("foo.dll"), FPL("") }, FPL("foo.dll") },
941 { { FPL("foo.dll"), FPL(".") }, FPL("foo.dll") },
942 { { FPL("foo"), FPL("") }, FPL("foo") },
943 { { FPL("foo"), FPL(".") }, FPL("foo") },
944 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz.dll") },
945 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz.dll") },
946 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
947 { { FPL("C:\\foo.bar\\foo"), FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
948 { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
950 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") },
951 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") },
953 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
954 FilePath
path(cases
[i
].inputs
[0]);
955 FilePath added
= path
.AddExtension(cases
[i
].inputs
[1]);
956 EXPECT_EQ(cases
[i
].expected
, added
.value()) << "i: " << i
<<
957 ", path: " << path
.value() << ", add: " << cases
[i
].inputs
[1];
961 TEST_F(FilePathTest
, MatchesExtension
) {
962 const struct BinaryBooleanTestData cases
[] = {
963 { { FPL("foo"), FPL("") }, true},
964 { { FPL("foo"), FPL(".") }, false},
965 { { FPL("foo."), FPL("") }, false},
966 { { FPL("foo."), FPL(".") }, true},
967 { { FPL("foo.txt"), FPL(".dll") }, false},
968 { { FPL("foo.txt"), FPL(".txt") }, true},
969 { { FPL("foo.txt.dll"), FPL(".txt") }, false},
970 { { FPL("foo.txt.dll"), FPL(".dll") }, true},
971 { { FPL("foo.TXT"), FPL(".txt") }, true},
972 { { FPL("foo.txt"), FPL(".TXT") }, true},
973 { { FPL("foo.tXt"), FPL(".txt") }, true},
974 { { FPL("foo.txt"), FPL(".tXt") }, true},
975 { { FPL("foo.tXt"), FPL(".TXT") }, true},
976 { { FPL("foo.tXt"), FPL(".tXt") }, true},
977 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
978 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false},
979 { { FPL("c:/foo.txt"), FPL(".txt") }, true},
980 #endif // FILE_PATH_USES_DRIVE_LETTERS
981 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
982 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false},
983 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true},
984 #endif // FILE_PATH_USES_DRIVE_LETTERS
985 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false},
986 { { FPL("/bar/foo.txt"), FPL(".txt") }, true},
987 #if defined(OS_WIN) || defined(OS_MACOSX)
988 // Umlauts A, O, U: direct comparison, and upper case vs. lower case
989 { { FPL("foo.\u00E4\u00F6\u00FC"), FPL(".\u00E4\u00F6\u00FC") }, true},
990 { { FPL("foo.\u00C4\u00D6\u00DC"), FPL(".\u00E4\u00F6\u00FC") }, true},
991 // C with circumflex: direct comparison, and upper case vs. lower case
992 { { FPL("foo.\u0109"), FPL(".\u0109") }, true},
993 { { FPL("foo.\u0108"), FPL(".\u0109") }, true},
997 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
998 FilePath
path(cases
[i
].inputs
[0]);
999 FilePath::StringType
ext(cases
[i
].inputs
[1]);
1001 EXPECT_EQ(cases
[i
].expected
, path
.MatchesExtension(ext
)) <<
1002 "i: " << i
<< ", path: " << path
.value() << ", ext: " << ext
;
1006 TEST_F(FilePathTest
, CompareIgnoreCase
) {
1007 const struct BinaryIntTestData cases
[] = {
1008 { { FPL("foo"), FPL("foo") }, 0},
1009 { { FPL("FOO"), FPL("foo") }, 0},
1010 { { FPL("foo.ext"), FPL("foo.ext") }, 0},
1011 { { FPL("FOO.EXT"), FPL("foo.ext") }, 0},
1012 { { FPL("Foo.Ext"), FPL("foo.ext") }, 0},
1013 { { FPL("foO"), FPL("foo") }, 0},
1014 { { FPL("foo"), FPL("foO") }, 0},
1015 { { FPL("fOo"), FPL("foo") }, 0},
1016 { { FPL("foo"), FPL("fOo") }, 0},
1017 { { FPL("bar"), FPL("foo") }, -1},
1018 { { FPL("foo"), FPL("bar") }, 1},
1019 { { FPL("BAR"), FPL("foo") }, -1},
1020 { { FPL("FOO"), FPL("bar") }, 1},
1021 { { FPL("bar"), FPL("FOO") }, -1},
1022 { { FPL("foo"), FPL("BAR") }, 1},
1023 { { FPL("BAR"), FPL("FOO") }, -1},
1024 { { FPL("FOO"), FPL("BAR") }, 1},
1025 // German "Eszett" (lower case and the new-fangled upper case)
1026 // Note that uc(<lowercase eszett>) => "SS", NOT <uppercase eszett>!
1027 // However, neither Windows nor Mac OSX converts these.
1028 // (or even have glyphs for <uppercase eszett>)
1029 { { FPL("\u00DF"), FPL("\u00DF") }, 0},
1030 { { FPL("\u1E9E"), FPL("\u1E9E") }, 0},
1031 { { FPL("\u00DF"), FPL("\u1E9E") }, -1},
1032 { { FPL("SS"), FPL("\u00DF") }, -1},
1033 { { FPL("SS"), FPL("\u1E9E") }, -1},
1034 #if defined(OS_WIN) || defined(OS_MACOSX)
1035 // Umlauts A, O, U: direct comparison, and upper case vs. lower case
1036 { { FPL("\u00E4\u00F6\u00FC"), FPL("\u00E4\u00F6\u00FC") }, 0},
1037 { { FPL("\u00C4\u00D6\u00DC"), FPL("\u00E4\u00F6\u00FC") }, 0},
1038 // C with circumflex: direct comparison, and upper case vs. lower case
1039 { { FPL("\u0109"), FPL("\u0109") }, 0},
1040 { { FPL("\u0108"), FPL("\u0109") }, 0},
1041 // Cyrillic letter SHA: direct comparison, and upper case vs. lower case
1042 { { FPL("\u0428"), FPL("\u0428") }, 0},
1043 { { FPL("\u0428"), FPL("\u0448") }, 0},
1044 // Greek letter DELTA: direct comparison, and upper case vs. lower case
1045 { { FPL("\u0394"), FPL("\u0394") }, 0},
1046 { { FPL("\u0394"), FPL("\u03B4") }, 0},
1047 // Japanese full-width A: direct comparison, and upper case vs. lower case
1048 // Note that full-width and standard characters are considered different.
1049 { { FPL("\uFF21"), FPL("\uFF21") }, 0},
1050 { { FPL("\uFF21"), FPL("\uFF41") }, 0},
1051 { { FPL("A"), FPL("\uFF21") }, -1},
1052 { { FPL("A"), FPL("\uFF41") }, -1},
1053 { { FPL("a"), FPL("\uFF21") }, -1},
1054 { { FPL("a"), FPL("\uFF41") }, -1},
1056 #if defined(OS_MACOSX)
1057 // Codepoints > 0x1000
1058 // Georgian letter DON: direct comparison, and upper case vs. lower case
1059 { { FPL("\u10A3"), FPL("\u10A3") }, 0},
1060 { { FPL("\u10A3"), FPL("\u10D3") }, 0},
1061 // Combining characters vs. pre-composed characters, upper and lower case
1062 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E31\u1E77\u1E53n") }, 0},
1063 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("kuon") }, 1},
1064 { { FPL("kuon"), FPL("k\u0301u\u032Do\u0304\u0301n") }, -1},
1065 { { FPL("K\u0301U\u032DO\u0304\u0301N"), FPL("KUON") }, 1},
1066 { { FPL("KUON"), FPL("K\u0301U\u032DO\u0304\u0301N") }, -1},
1067 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("KUON") }, 1},
1068 { { FPL("K\u0301U\u032DO\u0304\u0301N"), FPL("\u1E31\u1E77\u1E53n") }, 0},
1069 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E30\u1E76\u1E52n") }, 0},
1070 { { FPL("k\u0301u\u032Do\u0304\u0302n"), FPL("\u1E30\u1E76\u1E52n") }, 1},
1074 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1075 FilePath::StringType
s1(cases
[i
].inputs
[0]);
1076 FilePath::StringType
s2(cases
[i
].inputs
[1]);
1077 int result
= FilePath::CompareIgnoreCase(s1
, s2
);
1078 EXPECT_EQ(cases
[i
].expected
, result
) <<
1079 "i: " << i
<< ", s1: " << s1
<< ", s2: " << s2
;
1083 TEST_F(FilePathTest
, ReferencesParent
) {
1084 const struct UnaryBooleanTestData cases
[] = {
1085 { FPL("."), false },
1086 { FPL(".."), true },
1087 { FPL(".. "), true },
1088 { FPL(" .."), true },
1089 { FPL("..."), true },
1090 { FPL("a.."), false },
1091 { FPL("..a"), false },
1092 { FPL("../"), true },
1093 { FPL("/.."), true },
1094 { FPL("/../"), true },
1095 { FPL("/a../"), false },
1096 { FPL("/..a/"), false },
1097 { FPL("//.."), true },
1098 { FPL("..//"), true },
1099 { FPL("//..//"), true },
1100 { FPL("a//..//c"), true },
1101 { FPL("../b/c"), true },
1102 { FPL("/../b/c"), true },
1103 { FPL("a/b/.."), true },
1104 { FPL("a/b/../"), true },
1105 { FPL("a/../c"), true },
1106 { FPL("a/b/c"), false },
1109 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1110 FilePath
input(cases
[i
].input
);
1111 bool observed
= input
.ReferencesParent();
1112 EXPECT_EQ(cases
[i
].expected
, observed
) <<
1113 "i: " << i
<< ", input: " << input
.value();
1117 TEST_F(FilePathTest
, FromUTF8Unsafe_And_AsUTF8Unsafe
) {
1118 const struct UTF8TestData cases
[] = {
1119 { FPL("foo.txt"), "foo.txt" },
1120 // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them.
1121 { FPL("\u00E0\u00E8\u00F2.txt"), "\xC3\xA0\xC3\xA8\xC3\xB2.txt" },
1122 // Full-width "ABC".
1123 { FPL("\uFF21\uFF22\uFF23.txt"),
1124 "\xEF\xBC\xA1\xEF\xBC\xA2\xEF\xBC\xA3.txt" },
1127 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1128 // Test FromUTF8Unsafe() works.
1129 FilePath from_utf8
= FilePath::FromUTF8Unsafe(cases
[i
].utf8
);
1130 EXPECT_EQ(cases
[i
].native
, from_utf8
.value())
1131 << "i: " << i
<< ", input: " << cases
[i
].native
;
1132 // Test AsUTF8Unsafe() works.
1133 FilePath from_native
= FilePath(cases
[i
].native
);
1134 EXPECT_EQ(cases
[i
].utf8
, from_native
.AsUTF8Unsafe())
1135 << "i: " << i
<< ", input: " << cases
[i
].native
;
1136 // Test the two file paths are identical.
1137 EXPECT_EQ(from_utf8
.value(), from_native
.value());
1141 TEST_F(FilePathTest
, ConstructWithNUL
) {
1142 // Assert FPS() works.
1143 ASSERT_EQ(3U, FPS("a\0b").length());
1145 // Test constructor strips '\0'
1146 FilePath
path(FPS("a\0b"));
1147 EXPECT_EQ(1U, path
.value().length());
1148 EXPECT_EQ(FPL("a"), path
.value());
1151 TEST_F(FilePathTest
, AppendWithNUL
) {
1152 // Assert FPS() works.
1153 ASSERT_EQ(3U, FPS("b\0b").length());
1155 // Test Append() strips '\0'
1156 FilePath
path(FPL("a"));
1157 path
= path
.Append(FPS("b\0b"));
1158 EXPECT_EQ(3U, path
.value().length());
1159 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1160 EXPECT_EQ(FPL("a\\b"), path
.value());
1162 EXPECT_EQ(FPL("a/b"), path
.value());
1166 TEST_F(FilePathTest
, ReferencesParentWithNUL
) {
1167 // Assert FPS() works.
1168 ASSERT_EQ(3U, FPS("..\0").length());
1170 // Test ReferencesParent() doesn't break with "..\0"
1171 FilePath
path(FPS("..\0"));
1172 EXPECT_TRUE(path
.ReferencesParent());
1175 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1176 TEST_F(FilePathTest
, NormalizePathSeparators
) {
1177 const struct UnaryTestData cases
[] = {
1178 { FPL("foo/bar"), FPL("foo\\bar") },
1179 { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") },
1180 { FPL("foo\\bar"), FPL("foo\\bar") },
1181 { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") },
1182 { FPL("foo"), FPL("foo") },
1183 // Trailing slashes don't automatically get stripped. That's what
1184 // StripTrailingSeparators() is for.
1185 { FPL("foo\\"), FPL("foo\\") },
1186 { FPL("foo/"), FPL("foo\\") },
1187 { FPL("foo/bar\\"), FPL("foo\\bar\\") },
1188 { FPL("foo\\bar/"), FPL("foo\\bar\\") },
1189 { FPL("foo/bar/"), FPL("foo\\bar\\") },
1190 { FPL("foo\\bar\\"), FPL("foo\\bar\\") },
1191 { FPL("\\foo/bar"), FPL("\\foo\\bar") },
1192 { FPL("/foo\\bar"), FPL("\\foo\\bar") },
1193 { FPL("c:/foo/bar/"), FPL("c:\\foo\\bar\\") },
1194 { FPL("/foo/bar/"), FPL("\\foo\\bar\\") },
1195 { FPL("\\foo\\bar\\"), FPL("\\foo\\bar\\") },
1196 { FPL("c:\\foo/bar"), FPL("c:\\foo\\bar") },
1197 { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1198 { FPL("\\\\foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1199 { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1200 // This method does not normalize the number of path separators.
1201 { FPL("foo\\\\bar"), FPL("foo\\\\bar") },
1202 { FPL("foo//bar"), FPL("foo\\\\bar") },
1203 { FPL("foo/\\bar"), FPL("foo\\\\bar") },
1204 { FPL("foo\\/bar"), FPL("foo\\\\bar") },
1205 { FPL("///foo\\\\bar"), FPL("\\\\\\foo\\\\bar") },
1206 { FPL("foo//bar///"), FPL("foo\\\\bar\\\\\\") },
1207 { FPL("foo/\\bar/\\"), FPL("foo\\\\bar\\\\") },
1208 { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") },
1210 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1211 FilePath
input(cases
[i
].input
);
1212 FilePath observed
= input
.NormalizePathSeparators();
1213 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
.value()) <<
1214 "i: " << i
<< ", input: " << input
.value();
1219 TEST_F(FilePathTest
, EndsWithSeparator
) {
1220 const UnaryBooleanTestData cases
[] = {
1223 { FPL("foo/"), true },
1224 { FPL("bar"), false },
1225 { FPL("/foo/bar"), false },
1227 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1228 FilePath input
= FilePath(cases
[i
].input
).NormalizePathSeparators();
1229 EXPECT_EQ(cases
[i
].expected
, input
.EndsWithSeparator());
1233 TEST_F(FilePathTest
, AsEndingWithSeparator
) {
1234 const UnaryTestData cases
[] = {
1235 { FPL(""), FPL("") },
1236 { FPL("/"), FPL("/") },
1237 { FPL("foo"), FPL("foo/") },
1238 { FPL("foo/"), FPL("foo/") }
1240 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1241 FilePath input
= FilePath(cases
[i
].input
).NormalizePathSeparators();
1242 FilePath expected
= FilePath(cases
[i
].expected
).NormalizePathSeparators();
1243 EXPECT_EQ(expected
.value(), input
.AsEndingWithSeparator().value());
1247 #if defined(OS_ANDROID)
1248 TEST_F(FilePathTest
, ContentUriTest
) {
1249 const struct UnaryBooleanTestData cases
[] = {
1250 { FPL("content://foo.bar"), true },
1251 { FPL("content://foo.bar/"), true },
1252 { FPL("content://foo/bar"), true },
1253 { FPL("CoNTenT://foo.bar"), true },
1254 { FPL("content://"), true },
1255 { FPL("content:///foo.bar"), true },
1256 { FPL("content://3foo/bar"), true },
1257 { FPL("content://_foo/bar"), true },
1258 { FPL(".. "), false },
1259 { FPL("foo.bar"), false },
1260 { FPL("content:foo.bar"), false },
1261 { FPL("content:/foo.ba"), false },
1262 { FPL("content:/dir/foo.bar"), false },
1263 { FPL("content: //foo.bar"), false },
1264 { FPL("content%2a%2f%2f"), false },
1267 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1268 FilePath
input(cases
[i
].input
);
1269 bool observed
= input
.IsContentUri();
1270 EXPECT_EQ(cases
[i
].expected
, observed
) <<
1271 "i: " << i
<< ", input: " << input
.value();