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 class FilePathTest
: public PlatformTest
{
53 virtual void SetUp() OVERRIDE
{
54 PlatformTest::SetUp();
56 virtual void TearDown() OVERRIDE
{
57 PlatformTest::TearDown();
61 TEST_F(FilePathTest
, DirName
) {
62 const struct UnaryTestData cases
[] = {
63 { FPL(""), FPL(".") },
64 { FPL("aa"), FPL(".") },
65 { FPL("/aa/bb"), FPL("/aa") },
66 { FPL("/aa/bb/"), FPL("/aa") },
67 { FPL("/aa/bb//"), FPL("/aa") },
68 { FPL("/aa/bb/ccc"), FPL("/aa/bb") },
69 { FPL("/aa"), FPL("/") },
70 { FPL("/aa/"), FPL("/") },
71 { FPL("/"), FPL("/") },
72 { FPL("//"), FPL("//") },
73 { FPL("///"), FPL("/") },
74 { FPL("aa/"), FPL(".") },
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//bb"), FPL("aa") },
81 { FPL("//aa/bb"), FPL("//aa") },
82 { FPL("//aa/"), FPL("//") },
83 { FPL("//aa"), FPL("//") },
84 { FPL("0:"), FPL(".") },
85 { FPL("@:"), FPL(".") },
86 { FPL("[:"), FPL(".") },
87 { FPL("`:"), FPL(".") },
88 { FPL("{:"), FPL(".") },
89 { FPL("\xB3:"), FPL(".") },
90 { FPL("\xC5:"), FPL(".") },
92 { FPL("\x0143:"), FPL(".") },
94 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
95 { FPL("c:"), FPL("c:") },
96 { FPL("C:"), FPL("C:") },
97 { FPL("A:"), FPL("A:") },
98 { FPL("Z:"), FPL("Z:") },
99 { FPL("a:"), FPL("a:") },
100 { FPL("z:"), FPL("z:") },
101 { FPL("c:aa"), FPL("c:") },
102 { FPL("c:/"), FPL("c:/") },
103 { FPL("c://"), FPL("c://") },
104 { FPL("c:///"), FPL("c:/") },
105 { FPL("c:/aa"), FPL("c:/") },
106 { FPL("c:/aa/"), FPL("c:/") },
107 { FPL("c:/aa/bb"), FPL("c:/aa") },
108 { FPL("c:aa/bb"), FPL("c:aa") },
109 #endif // FILE_PATH_USES_DRIVE_LETTERS
110 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
111 { FPL("\\aa\\bb"), FPL("\\aa") },
112 { FPL("\\aa\\bb\\"), FPL("\\aa") },
113 { FPL("\\aa\\bb\\\\"), FPL("\\aa") },
114 { FPL("\\aa\\bb\\ccc"), FPL("\\aa\\bb") },
115 { FPL("\\aa"), FPL("\\") },
116 { FPL("\\aa\\"), FPL("\\") },
117 { FPL("\\"), FPL("\\") },
118 { FPL("\\\\"), FPL("\\\\") },
119 { FPL("\\\\\\"), FPL("\\") },
120 { FPL("aa\\"), FPL(".") },
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\\\\bb"), FPL("aa") },
127 { FPL("\\\\aa\\bb"), FPL("\\\\aa") },
128 { FPL("\\\\aa\\"), FPL("\\\\") },
129 { FPL("\\\\aa"), FPL("\\\\") },
130 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
131 { FPL("c:\\"), FPL("c:\\") },
132 { FPL("c:\\\\"), FPL("c:\\\\") },
133 { FPL("c:\\\\\\"), FPL("c:\\") },
134 { FPL("c:\\aa"), FPL("c:\\") },
135 { FPL("c:\\aa\\"), FPL("c:\\") },
136 { FPL("c:\\aa\\bb"), FPL("c:\\aa") },
137 { FPL("c:aa\\bb"), FPL("c:aa") },
138 #endif // FILE_PATH_USES_DRIVE_LETTERS
139 #endif // FILE_PATH_USES_WIN_SEPARATORS
142 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
143 FilePath
input(cases
[i
].input
);
144 FilePath observed
= input
.DirName();
145 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
.value()) <<
146 "i: " << i
<< ", input: " << input
.value();
150 TEST_F(FilePathTest
, BaseName
) {
151 const struct UnaryTestData cases
[] = {
152 { FPL(""), FPL("") },
153 { FPL("aa"), FPL("aa") },
154 { FPL("/aa/bb"), FPL("bb") },
155 { FPL("/aa/bb/"), FPL("bb") },
156 { FPL("/aa/bb//"), FPL("bb") },
157 { FPL("/aa/bb/ccc"), FPL("ccc") },
158 { FPL("/aa"), FPL("aa") },
159 { FPL("/"), FPL("/") },
160 { FPL("//"), FPL("//") },
161 { FPL("///"), FPL("/") },
162 { FPL("aa/"), FPL("aa") },
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//bb"), FPL("bb") },
169 { FPL("//aa/bb"), FPL("bb") },
170 { FPL("//aa/"), FPL("aa") },
171 { FPL("//aa"), FPL("aa") },
172 { FPL("0:"), FPL("0:") },
173 { FPL("@:"), FPL("@:") },
174 { FPL("[:"), FPL("[:") },
175 { FPL("`:"), FPL("`:") },
176 { FPL("{:"), FPL("{:") },
177 { FPL("\xB3:"), FPL("\xB3:") },
178 { FPL("\xC5:"), FPL("\xC5:") },
180 { FPL("\x0143:"), FPL("\x0143:") },
182 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
183 { FPL("c:"), FPL("") },
184 { FPL("C:"), FPL("") },
185 { FPL("A:"), FPL("") },
186 { FPL("Z:"), FPL("") },
187 { FPL("a:"), FPL("") },
188 { FPL("z:"), FPL("") },
189 { FPL("c:aa"), FPL("aa") },
190 { FPL("c:/"), FPL("/") },
191 { FPL("c://"), FPL("//") },
192 { FPL("c:///"), FPL("/") },
193 { FPL("c:/aa"), FPL("aa") },
194 { FPL("c:/aa/"), FPL("aa") },
195 { FPL("c:/aa/bb"), FPL("bb") },
196 { FPL("c:aa/bb"), FPL("bb") },
197 #endif // FILE_PATH_USES_DRIVE_LETTERS
198 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
199 { FPL("\\aa\\bb"), FPL("bb") },
200 { FPL("\\aa\\bb\\"), FPL("bb") },
201 { FPL("\\aa\\bb\\\\"), FPL("bb") },
202 { FPL("\\aa\\bb\\ccc"), FPL("ccc") },
203 { FPL("\\aa"), FPL("aa") },
204 { FPL("\\"), FPL("\\") },
205 { FPL("\\\\"), FPL("\\\\") },
206 { FPL("\\\\\\"), FPL("\\") },
207 { FPL("aa\\"), FPL("aa") },
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\\\\bb"), FPL("bb") },
214 { FPL("\\\\aa\\bb"), FPL("bb") },
215 { FPL("\\\\aa\\"), FPL("aa") },
216 { FPL("\\\\aa"), FPL("aa") },
217 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
218 { FPL("c:\\"), FPL("\\") },
219 { FPL("c:\\\\"), FPL("\\\\") },
220 { FPL("c:\\\\\\"), FPL("\\") },
221 { FPL("c:\\aa"), FPL("aa") },
222 { FPL("c:\\aa\\"), FPL("aa") },
223 { FPL("c:\\aa\\bb"), FPL("bb") },
224 { FPL("c:aa\\bb"), FPL("bb") },
225 #endif // FILE_PATH_USES_DRIVE_LETTERS
226 #endif // FILE_PATH_USES_WIN_SEPARATORS
229 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
230 FilePath
input(cases
[i
].input
);
231 FilePath observed
= input
.BaseName();
232 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
.value()) <<
233 "i: " << i
<< ", input: " << input
.value();
237 TEST_F(FilePathTest
, Append
) {
238 const struct BinaryTestData cases
[] = {
239 { { FPL(""), FPL("cc") }, FPL("cc") },
240 { { FPL("."), FPL("ff") }, FPL("ff") },
241 { { FPL("/"), FPL("cc") }, FPL("/cc") },
242 { { FPL("/aa"), FPL("") }, FPL("/aa") },
243 { { FPL("/aa/"), FPL("") }, FPL("/aa") },
244 { { FPL("//aa"), FPL("") }, FPL("//aa") },
245 { { FPL("//aa/"), FPL("") }, FPL("//aa") },
246 { { FPL("//"), FPL("aa") }, FPL("//aa") },
247 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
248 { { FPL("c:"), FPL("a") }, FPL("c:a") },
249 { { FPL("c:"), FPL("") }, FPL("c:") },
250 { { FPL("c:/"), FPL("a") }, FPL("c:/a") },
251 { { FPL("c://"), FPL("a") }, FPL("c://a") },
252 { { FPL("c:///"), FPL("a") }, FPL("c:/a") },
253 #endif // FILE_PATH_USES_DRIVE_LETTERS
254 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
255 // Append introduces the default separator character, so these test cases
256 // need to be defined with different expected results on platforms that use
257 // different default separator characters.
258 { { FPL("\\"), FPL("cc") }, FPL("\\cc") },
259 { { FPL("\\aa"), FPL("") }, FPL("\\aa") },
260 { { FPL("\\aa\\"), FPL("") }, FPL("\\aa") },
261 { { FPL("\\\\aa"), FPL("") }, FPL("\\\\aa") },
262 { { FPL("\\\\aa\\"), FPL("") }, FPL("\\\\aa") },
263 { { FPL("\\\\"), FPL("aa") }, FPL("\\\\aa") },
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 { { FPL("\\aa\\bb"), FPL("cc") }, FPL("\\aa\\bb\\cc") },
273 { { FPL("\\aa\\bb\\"), FPL("cc") }, FPL("\\aa\\bb\\cc") },
274 { { FPL("aa\\bb\\"), FPL("cc") }, FPL("aa\\bb\\cc") },
275 { { FPL("aa\\bb"), FPL("cc") }, FPL("aa\\bb\\cc") },
276 { { FPL("a\\b"), FPL("c") }, FPL("a\\b\\c") },
277 { { FPL("a\\b\\"), FPL("c") }, FPL("a\\b\\c") },
278 { { FPL("\\\\aa"), FPL("bb") }, FPL("\\\\aa\\bb") },
279 { { FPL("\\\\aa\\"), FPL("bb") }, FPL("\\\\aa\\bb") },
280 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
281 { { FPL("c:\\"), FPL("a") }, FPL("c:\\a") },
282 { { FPL("c:\\\\"), FPL("a") }, FPL("c:\\\\a") },
283 { { FPL("c:\\\\\\"), FPL("a") }, FPL("c:\\a") },
284 { { FPL("c:\\"), FPL("") }, FPL("c:\\") },
285 { { FPL("c:\\a"), FPL("b") }, FPL("c:\\a\\b") },
286 { { FPL("c:\\a\\"), FPL("b") }, FPL("c:\\a\\b") },
287 #endif // FILE_PATH_USES_DRIVE_LETTERS
288 #else // FILE_PATH_USES_WIN_SEPARATORS
289 { { FPL("/aa/bb"), FPL("cc") }, FPL("/aa/bb/cc") },
290 { { FPL("/aa/bb/"), FPL("cc") }, FPL("/aa/bb/cc") },
291 { { FPL("aa/bb/"), FPL("cc") }, FPL("aa/bb/cc") },
292 { { FPL("aa/bb"), FPL("cc") }, FPL("aa/bb/cc") },
293 { { FPL("a/b"), FPL("c") }, FPL("a/b/c") },
294 { { FPL("a/b/"), FPL("c") }, FPL("a/b/c") },
295 { { FPL("//aa"), FPL("bb") }, FPL("//aa/bb") },
296 { { FPL("//aa/"), FPL("bb") }, FPL("//aa/bb") },
297 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
298 { { FPL("c:/"), FPL("a") }, FPL("c:/a") },
299 { { FPL("c:/"), FPL("") }, FPL("c:/") },
300 { { FPL("c:/a"), FPL("b") }, FPL("c:/a/b") },
301 { { FPL("c:/a/"), FPL("b") }, FPL("c:/a/b") },
302 #endif // FILE_PATH_USES_DRIVE_LETTERS
303 #endif // FILE_PATH_USES_WIN_SEPARATORS
306 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
307 FilePath
root(cases
[i
].inputs
[0]);
308 FilePath::StringType
leaf(cases
[i
].inputs
[1]);
309 FilePath observed_str
= root
.Append(leaf
);
310 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed_str
.value()) <<
311 "i: " << i
<< ", root: " << root
.value() << ", leaf: " << leaf
;
312 FilePath observed_path
= root
.Append(FilePath(leaf
));
313 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed_path
.value()) <<
314 "i: " << i
<< ", root: " << root
.value() << ", leaf: " << leaf
;
316 // TODO(erikkay): It would be nice to have a unicode test append value to
317 // handle the case when AppendASCII is passed UTF8
319 std::string ascii
= WideToUTF8(leaf
);
320 #elif defined(OS_POSIX)
321 std::string ascii
= leaf
;
323 observed_str
= root
.AppendASCII(ascii
);
324 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed_str
.value()) <<
325 "i: " << i
<< ", root: " << root
.value() << ", leaf: " << leaf
;
329 TEST_F(FilePathTest
, StripTrailingSeparators
) {
330 const struct UnaryTestData cases
[] = {
331 { FPL(""), FPL("") },
332 { FPL("/"), FPL("/") },
333 { FPL("//"), FPL("//") },
334 { FPL("///"), FPL("/") },
335 { FPL("////"), FPL("/") },
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 { FPL("/a///"), FPL("/a") },
344 { FPL("/a////"), FPL("/a") },
345 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
346 { FPL("c:"), FPL("c:") },
347 { FPL("c:/"), FPL("c:/") },
348 { FPL("c://"), FPL("c://") },
349 { FPL("c:///"), FPL("c:/") },
350 { FPL("c:////"), FPL("c:/") },
351 { FPL("c:/a"), FPL("c:/a") },
352 { FPL("c:/a/"), FPL("c:/a") },
353 { FPL("c:/a//"), FPL("c:/a") },
354 { FPL("c:/a///"), FPL("c:/a") },
355 { FPL("c:/a////"), FPL("c:/a") },
356 #endif // FILE_PATH_USES_DRIVE_LETTERS
357 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
358 { FPL("\\"), FPL("\\") },
359 { FPL("\\\\"), FPL("\\\\") },
360 { FPL("\\\\\\"), FPL("\\") },
361 { FPL("\\\\\\\\"), FPL("\\") },
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 { FPL("\\a\\\\\\"), FPL("\\a") },
370 { FPL("\\a\\\\\\\\"), FPL("\\a") },
371 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
372 { FPL("c:\\"), FPL("c:\\") },
373 { FPL("c:\\\\"), FPL("c:\\\\") },
374 { FPL("c:\\\\\\"), FPL("c:\\") },
375 { FPL("c:\\\\\\\\"), FPL("c:\\") },
376 { FPL("c:\\a"), FPL("c:\\a") },
377 { FPL("c:\\a\\"), FPL("c:\\a") },
378 { FPL("c:\\a\\\\"), FPL("c:\\a") },
379 { FPL("c:\\a\\\\\\"), FPL("c:\\a") },
380 { FPL("c:\\a\\\\\\\\"), FPL("c:\\a") },
381 #endif // FILE_PATH_USES_DRIVE_LETTERS
382 #endif // FILE_PATH_USES_WIN_SEPARATORS
385 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
386 FilePath
input(cases
[i
].input
);
387 FilePath observed
= input
.StripTrailingSeparators();
388 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
.value()) <<
389 "i: " << i
<< ", input: " << input
.value();
393 TEST_F(FilePathTest
, IsAbsolute
) {
394 const struct UnaryBooleanTestData cases
[] = {
397 { FPL("c:"), false },
398 { FPL("c:a"), false },
399 { FPL("a/b"), false },
401 { FPL("//a"), true },
402 { FPL("c:a/b"), false },
403 { FPL("?:/a"), false },
404 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
406 { FPL("/a"), false },
407 { FPL("/."), false },
408 { FPL("/.."), false },
409 { FPL("c:/"), true },
410 { FPL("c:/a"), true },
411 { FPL("c:/."), true },
412 { FPL("c:/.."), true },
413 { FPL("C:/a"), true },
414 { FPL("d:/a"), true },
415 #else // FILE_PATH_USES_DRIVE_LETTERS
419 { FPL("/.."), true },
420 { FPL("c:/"), false },
421 #endif // FILE_PATH_USES_DRIVE_LETTERS
422 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
423 { FPL("a\\b"), false },
424 { FPL("\\\\"), true },
425 { FPL("\\\\a"), true },
426 { FPL("a\\b"), false },
427 { FPL("\\\\"), true },
428 { FPL("//a"), true },
429 { FPL("c:a\\b"), false },
430 { FPL("?:\\a"), false },
431 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
432 { FPL("\\"), false },
433 { FPL("\\a"), false },
434 { FPL("\\."), false },
435 { FPL("\\.."), false },
436 { FPL("c:\\"), true },
437 { FPL("c:\\"), true },
438 { FPL("c:\\a"), true },
439 { FPL("c:\\."), true },
440 { FPL("c:\\.."), true },
441 { FPL("C:\\a"), true },
442 { FPL("d:\\a"), true },
443 #else // FILE_PATH_USES_DRIVE_LETTERS
445 { FPL("\\a"), true },
446 { FPL("\\."), true },
447 { FPL("\\.."), true },
448 { FPL("c:\\"), false },
449 #endif // FILE_PATH_USES_DRIVE_LETTERS
450 #endif // FILE_PATH_USES_WIN_SEPARATORS
453 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
454 FilePath
input(cases
[i
].input
);
455 bool observed
= input
.IsAbsolute();
456 EXPECT_EQ(cases
[i
].expected
, observed
) <<
457 "i: " << i
<< ", input: " << input
.value();
461 TEST_F(FilePathTest
, PathComponentsTest
) {
462 const struct UnaryTestData cases
[] = {
463 { FPL("//foo/bar/baz/"), FPL("|//|foo|bar|baz")},
464 { FPL("///"), FPL("|/")},
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/baz///"), FPL("|/|foo|bar|baz")},
469 { FPL("/foo/bar/baz"), FPL("|/|foo|bar|baz")},
470 { FPL("/foo/bar.bot/baz.txt"), FPL("|/|foo|bar.bot|baz.txt")},
471 { FPL("//foo//bar/baz"), FPL("|//|foo|bar|baz")},
472 { FPL("/"), FPL("|/")},
473 { FPL("foo"), FPL("|foo")},
475 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
476 { FPL("e:/foo"), FPL("|e:|/|foo")},
477 { FPL("e:/"), FPL("|e:|/")},
478 { FPL("e:"), FPL("|e:")},
479 #endif // FILE_PATH_USES_DRIVE_LETTERS
480 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
481 { FPL("../foo"), FPL("|..|foo")},
482 { FPL("./foo"), FPL("|foo")},
483 { FPL("../foo/bar/"), FPL("|..|foo|bar") },
484 { FPL("\\\\foo\\bar\\baz\\"), FPL("|\\\\|foo|bar|baz")},
485 { FPL("\\\\\\"), FPL("|\\")},
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/baz\\\\\\"), FPL("|\\|foo|bar|baz")},
492 { FPL("/foo\\bar\\baz"), FPL("|/|foo|bar|baz")},
493 { FPL("\\foo\\bar.bot\\baz.txt"), FPL("|\\|foo|bar.bot|baz.txt")},
494 { FPL("\\\\foo\\\\bar\\baz"), FPL("|\\\\|foo|bar|baz")},
495 { FPL("\\"), FPL("|\\")},
496 #endif // FILE_PATH_USES_WIN_SEPARATORS
499 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
500 FilePath
input(cases
[i
].input
);
501 std::vector
<FilePath::StringType
> comps
;
502 input
.GetComponents(&comps
);
504 FilePath::StringType observed
;
505 for (size_t j
= 0; j
< comps
.size(); ++j
) {
506 observed
.append(FILE_PATH_LITERAL("|"), 1);
507 observed
.append(comps
[j
]);
509 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
) <<
510 "i: " << i
<< ", input: " << input
.value();
514 TEST_F(FilePathTest
, IsParentTest
) {
515 const struct BinaryBooleanTestData cases
[] = {
516 { { FPL("/"), FPL("/foo/bar/baz") }, true},
517 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, true},
518 { { FPL("/foo/bar/"), FPL("/foo/bar/baz") }, true},
519 { { FPL("//foo/bar/"), FPL("//foo/bar/baz") }, true},
520 { { FPL("/foo/bar"), FPL("/foo2/bar/baz") }, false},
521 { { FPL("/foo/bar.txt"), FPL("/foo/bar/baz") }, false},
522 { { FPL("/foo/bar"), FPL("/foo/bar2/baz") }, false},
523 { { FPL("/foo/bar"), FPL("/foo/bar") }, false},
524 { { FPL("/foo/bar/baz"), FPL("/foo/bar") }, false},
525 { { FPL("foo/bar"), FPL("foo/bar/baz") }, true},
526 { { FPL("foo/bar"), FPL("foo2/bar/baz") }, false},
527 { { FPL("foo/bar"), FPL("foo/bar2/baz") }, false},
528 { { FPL(""), FPL("foo") }, false},
529 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
530 { { FPL("c:/foo/bar"), FPL("c:/foo/bar/baz") }, true},
531 { { FPL("E:/foo/bar"), FPL("e:/foo/bar/baz") }, true},
532 { { FPL("f:/foo/bar"), FPL("F:/foo/bar/baz") }, true},
533 { { FPL("E:/Foo/bar"), FPL("e:/foo/bar/baz") }, false},
534 { { FPL("f:/foo/bar"), FPL("F:/foo/Bar/baz") }, false},
535 { { FPL("c:/"), FPL("c:/foo/bar/baz") }, true},
536 { { FPL("c:"), FPL("c:/foo/bar/baz") }, true},
537 { { FPL("c:/foo/bar"), FPL("d:/foo/bar/baz") }, false},
538 { { FPL("c:/foo/bar"), FPL("D:/foo/bar/baz") }, false},
539 { { FPL("C:/foo/bar"), FPL("d:/foo/bar/baz") }, false},
540 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar/baz") }, false},
541 { { FPL("e:/foo/bar"), FPL("E:/foo2/bar/baz") }, false},
542 { { FPL("F:/foo/bar"), FPL("f:/foo2/bar/baz") }, false},
543 { { FPL("c:/foo/bar"), FPL("c:/foo/bar2/baz") }, false},
544 #endif // FILE_PATH_USES_DRIVE_LETTERS
545 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
546 { { FPL("\\foo\\bar"), FPL("\\foo\\bar\\baz") }, true},
547 { { FPL("\\foo/bar"), FPL("\\foo\\bar\\baz") }, true},
548 { { FPL("\\foo/bar"), FPL("\\foo/bar/baz") }, true},
549 { { FPL("\\"), FPL("\\foo\\bar\\baz") }, true},
550 { { FPL(""), FPL("\\foo\\bar\\baz") }, false},
551 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar\\baz") }, false},
552 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2\\baz") }, false},
553 #endif // FILE_PATH_USES_WIN_SEPARATORS
556 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
557 FilePath
parent(cases
[i
].inputs
[0]);
558 FilePath
child(cases
[i
].inputs
[1]);
560 EXPECT_EQ(parent
.IsParent(child
), cases
[i
].expected
) <<
561 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
566 TEST_F(FilePathTest
, AppendRelativePathTest
) {
567 const struct BinaryTestData cases
[] = {
568 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
569 { { FPL("/"), FPL("/foo/bar/baz") }, FPL("foo\\bar\\baz")},
570 #else // FILE_PATH_USES_WIN_SEPARATORS
571 { { FPL("/"), FPL("/foo/bar/baz") }, FPL("foo/bar/baz")},
572 #endif // FILE_PATH_USES_WIN_SEPARATORS
573 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, FPL("baz")},
574 { { FPL("/foo/bar/"), FPL("/foo/bar/baz") }, FPL("baz")},
575 { { FPL("//foo/bar/"), FPL("//foo/bar/baz") }, FPL("baz")},
576 { { FPL("/foo/bar"), FPL("/foo2/bar/baz") }, FPL("")},
577 { { FPL("/foo/bar.txt"), FPL("/foo/bar/baz") }, FPL("")},
578 { { FPL("/foo/bar"), FPL("/foo/bar2/baz") }, FPL("")},
579 { { FPL("/foo/bar"), FPL("/foo/bar") }, FPL("")},
580 { { FPL("/foo/bar/baz"), FPL("/foo/bar") }, FPL("")},
581 { { FPL("foo/bar"), FPL("foo/bar/baz") }, FPL("baz")},
582 { { FPL("foo/bar"), FPL("foo2/bar/baz") }, FPL("")},
583 { { FPL("foo/bar"), FPL("foo/bar2/baz") }, FPL("")},
584 { { FPL(""), FPL("foo") }, FPL("")},
585 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
586 { { FPL("c:/foo/bar"), FPL("c:/foo/bar/baz") }, FPL("baz")},
587 { { FPL("E:/foo/bar"), FPL("e:/foo/bar/baz") }, FPL("baz")},
588 { { FPL("f:/foo/bar"), FPL("F:/foo/bar/baz") }, FPL("baz")},
589 { { FPL("E:/Foo/bar"), FPL("e:/foo/bar/baz") }, FPL("")},
590 { { FPL("f:/foo/bar"), FPL("F:/foo/Bar/baz") }, FPL("")},
591 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
592 { { FPL("c:/"), FPL("c:/foo/bar/baz") }, FPL("foo\\bar\\baz")},
593 // TODO(akalin): Figure out how to handle the corner case in the
594 // commented-out test case below. Appending to an empty path gives
595 // /foo\bar\baz but appending to a nonempty path "blah" gives
597 // { { FPL("c:"), FPL("c:/foo/bar/baz") }, FPL("foo\\bar\\baz")},
598 #endif // FILE_PATH_USES_WIN_SEPARATORS
599 { { FPL("c:/foo/bar"), FPL("d:/foo/bar/baz") }, FPL("")},
600 { { FPL("c:/foo/bar"), FPL("D:/foo/bar/baz") }, FPL("")},
601 { { FPL("C:/foo/bar"), FPL("d:/foo/bar/baz") }, FPL("")},
602 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar/baz") }, FPL("")},
603 { { FPL("e:/foo/bar"), FPL("E:/foo2/bar/baz") }, FPL("")},
604 { { FPL("F:/foo/bar"), FPL("f:/foo2/bar/baz") }, FPL("")},
605 { { FPL("c:/foo/bar"), FPL("c:/foo/bar2/baz") }, FPL("")},
606 #endif // FILE_PATH_USES_DRIVE_LETTERS
607 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
608 { { FPL("\\foo\\bar"), FPL("\\foo\\bar\\baz") }, FPL("baz")},
609 { { FPL("\\foo/bar"), FPL("\\foo\\bar\\baz") }, FPL("baz")},
610 { { FPL("\\foo/bar"), FPL("\\foo/bar/baz") }, FPL("baz")},
611 { { FPL("\\"), FPL("\\foo\\bar\\baz") }, FPL("foo\\bar\\baz")},
612 { { FPL(""), FPL("\\foo\\bar\\baz") }, FPL("")},
613 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar\\baz") }, FPL("")},
614 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2\\baz") }, FPL("")},
615 #endif // FILE_PATH_USES_WIN_SEPARATORS
618 const FilePath
base(FPL("blah"));
620 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
621 FilePath
parent(cases
[i
].inputs
[0]);
622 FilePath
child(cases
[i
].inputs
[1]);
625 bool success
= parent
.AppendRelativePath(child
, &result
);
626 EXPECT_EQ(cases
[i
].expected
[0] != '\0', success
) <<
627 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
629 EXPECT_STREQ(cases
[i
].expected
, result
.value().c_str()) <<
630 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
634 FilePath
result(base
);
635 bool success
= parent
.AppendRelativePath(child
, &result
);
636 EXPECT_EQ(cases
[i
].expected
[0] != '\0', success
) <<
637 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
639 EXPECT_EQ(base
.Append(cases
[i
].expected
).value(), result
.value()) <<
640 "i: " << i
<< ", parent: " << parent
.value() << ", child: " <<
646 TEST_F(FilePathTest
, EqualityTest
) {
647 const struct BinaryBooleanTestData cases
[] = {
648 { { FPL("/foo/bar/baz"), FPL("/foo/bar/baz") }, true},
649 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, false},
650 { { FPL("/foo/bar/baz"), FPL("/foo/bar") }, false},
651 { { FPL("//foo/bar/"), FPL("//foo/bar/") }, true},
652 { { FPL("/foo/bar"), FPL("/foo2/bar") }, false},
653 { { FPL("/foo/bar.txt"), FPL("/foo/bar") }, false},
654 { { FPL("foo/bar"), FPL("foo/bar") }, true},
655 { { FPL("foo/bar"), FPL("foo/bar/baz") }, false},
656 { { FPL(""), FPL("foo") }, false},
657 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
658 { { FPL("c:/foo/bar"), FPL("c:/foo/bar") }, true},
659 { { FPL("E:/foo/bar"), FPL("e:/foo/bar") }, true},
660 { { FPL("f:/foo/bar"), FPL("F:/foo/bar") }, true},
661 { { FPL("E:/Foo/bar"), FPL("e:/foo/bar") }, false},
662 { { FPL("f:/foo/bar"), FPL("F:/foo/Bar") }, false},
663 { { FPL("c:/"), FPL("c:/") }, true},
664 { { FPL("c:"), FPL("c:") }, true},
665 { { FPL("c:/foo/bar"), FPL("d:/foo/bar") }, false},
666 { { FPL("c:/foo/bar"), FPL("D:/foo/bar") }, false},
667 { { FPL("C:/foo/bar"), FPL("d:/foo/bar") }, false},
668 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar") }, false},
669 #endif // FILE_PATH_USES_DRIVE_LETTERS
670 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
671 { { FPL("\\foo\\bar"), FPL("\\foo\\bar") }, true},
672 { { FPL("\\foo/bar"), FPL("\\foo/bar") }, true},
673 { { FPL("\\foo/bar"), FPL("\\foo\\bar") }, false},
674 { { FPL("\\"), FPL("\\") }, true},
675 { { FPL("\\"), FPL("/") }, false},
676 { { FPL(""), FPL("\\") }, false},
677 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar") }, false},
678 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2") }, false},
679 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
680 { { FPL("c:\\foo\\bar"), FPL("c:\\foo\\bar") }, true},
681 { { FPL("E:\\foo\\bar"), FPL("e:\\foo\\bar") }, true},
682 { { FPL("f:\\foo\\bar"), FPL("F:\\foo/bar") }, false},
683 #endif // FILE_PATH_USES_DRIVE_LETTERS
684 #endif // FILE_PATH_USES_WIN_SEPARATORS
687 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
688 FilePath
a(cases
[i
].inputs
[0]);
689 FilePath
b(cases
[i
].inputs
[1]);
691 EXPECT_EQ(a
== b
, cases
[i
].expected
) <<
692 "equality i: " << i
<< ", a: " << a
.value() << ", b: " <<
696 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
697 FilePath
a(cases
[i
].inputs
[0]);
698 FilePath
b(cases
[i
].inputs
[1]);
700 EXPECT_EQ(a
!= b
, !cases
[i
].expected
) <<
701 "inequality i: " << i
<< ", a: " << a
.value() << ", b: " <<
706 TEST_F(FilePathTest
, Extension
) {
707 FilePath
base_dir(FILE_PATH_LITERAL("base_dir"));
709 FilePath jpg
= base_dir
.Append(FILE_PATH_LITERAL("foo.jpg"));
710 EXPECT_EQ(FILE_PATH_LITERAL(".jpg"), jpg
.Extension());
711 EXPECT_EQ(FILE_PATH_LITERAL(".jpg"), jpg
.FinalExtension());
713 FilePath base
= jpg
.BaseName().RemoveExtension();
714 EXPECT_EQ(FILE_PATH_LITERAL("foo"), base
.value());
716 FilePath path_no_ext
= base_dir
.Append(base
);
717 EXPECT_EQ(path_no_ext
.value(), jpg
.RemoveExtension().value());
719 EXPECT_EQ(path_no_ext
.value(), path_no_ext
.RemoveExtension().value());
720 EXPECT_EQ(FILE_PATH_LITERAL(""), path_no_ext
.Extension());
721 EXPECT_EQ(FILE_PATH_LITERAL(""), path_no_ext
.FinalExtension());
724 TEST_F(FilePathTest
, Extension2
) {
725 const struct UnaryTestData cases
[] = {
726 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
727 { FPL("C:\\a\\b\\c.ext"), FPL(".ext") },
728 { FPL("C:\\a\\b\\c."), FPL(".") },
729 { FPL("C:\\a\\b\\c"), FPL("") },
730 { FPL("C:\\a\\b\\"), FPL("") },
731 { FPL("C:\\a\\b.\\"), FPL(".") },
732 { FPL("C:\\a\\b\\c.ext1.ext2"), FPL(".ext2") },
733 { FPL("C:\\foo.bar\\\\\\"), FPL(".bar") },
734 { FPL("C:\\foo.bar\\.."), FPL("") },
735 { FPL("C:\\foo.bar\\..\\\\"), FPL("") },
737 { FPL("/foo/bar/baz.ext"), FPL(".ext") },
738 { FPL("/foo/bar/baz."), FPL(".") },
739 { FPL("/foo/bar/baz.."), FPL(".") },
740 { FPL("/foo/bar/baz"), FPL("") },
741 { FPL("/foo/bar/"), FPL("") },
742 { FPL("/foo/bar./"), FPL(".") },
743 { FPL("/foo/bar/baz.ext1.ext2"), FPL(".ext2") },
744 { FPL("/subversion-1.6.12.zip"), FPL(".zip") },
745 { FPL("/foo.12345.gz"), FPL(".gz") },
746 { FPL("/foo..gz"), FPL(".gz") },
747 { FPL("."), FPL("") },
748 { FPL(".."), FPL("") },
749 { FPL("./foo"), FPL("") },
750 { FPL("./foo.ext"), FPL(".ext") },
751 { FPL("/foo.ext1/bar.ext2"), FPL(".ext2") },
752 { FPL("/foo.bar////"), FPL(".bar") },
753 { FPL("/foo.bar/.."), FPL("") },
754 { FPL("/foo.bar/..////"), FPL("") },
755 { FPL("/foo.1234.luser.js"), FPL(".js") },
756 { FPL("/user.js"), FPL(".js") },
758 const struct UnaryTestData double_extension_cases
[] = {
759 { FPL("/foo.tar.gz"), FPL(".tar.gz") },
760 { FPL("/foo.tar.Z"), FPL(".tar.Z") },
761 { FPL("/foo.tar.bz2"), FPL(".tar.bz2") },
762 { FPL("/foo.1234.gz"), FPL(".1234.gz") },
763 { FPL("/foo.1234.tar.gz"), FPL(".tar.gz") },
764 { FPL("/foo.tar.tar.gz"), FPL(".tar.gz") },
765 { FPL("/foo.tar.gz.gz"), FPL(".gz.gz") },
766 { FPL("/foo.1234.user.js"), FPL(".user.js") },
767 { FPL("foo.user.js"), FPL(".user.js") },
769 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
770 FilePath
path(cases
[i
].input
);
771 FilePath::StringType extension
= path
.Extension();
772 FilePath::StringType final_extension
= path
.FinalExtension();
773 EXPECT_STREQ(cases
[i
].expected
, extension
.c_str()) << "i: " << i
<<
774 ", path: " << path
.value();
775 EXPECT_STREQ(cases
[i
].expected
, final_extension
.c_str()) << "i: " << i
<<
776 ", path: " << path
.value();
778 for (unsigned int i
= 0; i
< arraysize(double_extension_cases
); ++i
) {
779 FilePath
path(cases
[i
].input
);
780 FilePath::StringType extension
= path
.Extension();
781 EXPECT_STREQ(cases
[i
].expected
, extension
.c_str()) << "i: " << i
<<
782 ", path: " << path
.value();
786 TEST_F(FilePathTest
, InsertBeforeExtension
) {
787 const struct BinaryTestData cases
[] = {
788 { { FPL(""), FPL("") }, FPL("") },
789 { { FPL(""), FPL("txt") }, FPL("") },
790 { { FPL("."), FPL("txt") }, FPL("") },
791 { { FPL(".."), FPL("txt") }, FPL("") },
792 { { FPL("foo.dll"), FPL("txt") }, FPL("footxt.dll") },
793 { { FPL("."), FPL("") }, FPL(".") },
794 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.txt.dll") },
795 { { FPL("foo"), FPL("txt") }, FPL("footxt") },
796 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
797 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baztxt.dll") },
798 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.txt.dll") },
799 { { FPL("foo.dll"), FPL("") }, FPL("foo.dll") },
800 { { FPL("foo.dll"), FPL(".") }, FPL("foo..dll") },
801 { { FPL("foo"), FPL("") }, FPL("foo") },
802 { { FPL("foo"), FPL(".") }, FPL("foo.") },
803 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz.dll") },
804 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz..dll") },
805 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
806 { { FPL("\\"), FPL("") }, FPL("\\") },
807 { { FPL("\\"), FPL("txt") }, FPL("\\txt") },
808 { { FPL("\\."), FPL("txt") }, FPL("") },
809 { { FPL("\\.."), FPL("txt") }, FPL("") },
810 { { FPL("\\."), FPL("") }, FPL("\\.") },
811 { { FPL("C:\\bar\\foo.dll"), FPL("txt") },
812 FPL("C:\\bar\\footxt.dll") },
813 { { FPL("C:\\bar.baz\\foodll"), FPL("txt") },
814 FPL("C:\\bar.baz\\foodlltxt") },
815 { { FPL("C:\\bar.baz\\foo.dll"), FPL("txt") },
816 FPL("C:\\bar.baz\\footxt.dll") },
817 { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("txt") },
818 FPL("C:\\bar.baz\\foo.dlltxt.exe") },
819 { { FPL("C:\\bar.baz\\foo"), FPL("") },
820 FPL("C:\\bar.baz\\foo") },
821 { { FPL("C:\\bar.baz\\foo.exe"), FPL("") },
822 FPL("C:\\bar.baz\\foo.exe") },
823 { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("") },
824 FPL("C:\\bar.baz\\foo.dll.exe") },
825 { { FPL("C:\\bar\\baz\\foo.exe"), FPL(" (1)") },
826 FPL("C:\\bar\\baz\\foo (1).exe") },
827 { { FPL("C:\\foo.baz\\\\"), FPL(" (1)") }, FPL("C:\\foo (1).baz") },
828 { { FPL("C:\\foo.baz\\..\\"), FPL(" (1)") }, FPL("") },
830 { { FPL("/"), FPL("") }, FPL("/") },
831 { { FPL("/"), FPL("txt") }, FPL("/txt") },
832 { { FPL("/."), FPL("txt") }, FPL("") },
833 { { FPL("/.."), FPL("txt") }, FPL("") },
834 { { FPL("/."), FPL("") }, FPL("/.") },
835 { { FPL("/bar/foo.dll"), FPL("txt") }, FPL("/bar/footxt.dll") },
836 { { FPL("/bar.baz/foodll"), FPL("txt") }, FPL("/bar.baz/foodlltxt") },
837 { { FPL("/bar.baz/foo.dll"), FPL("txt") }, FPL("/bar.baz/footxt.dll") },
838 { { FPL("/bar.baz/foo.dll.exe"), FPL("txt") },
839 FPL("/bar.baz/foo.dlltxt.exe") },
840 { { FPL("/bar.baz/foo"), FPL("") }, FPL("/bar.baz/foo") },
841 { { FPL("/bar.baz/foo.exe"), FPL("") }, FPL("/bar.baz/foo.exe") },
842 { { FPL("/bar.baz/foo.dll.exe"), FPL("") }, FPL("/bar.baz/foo.dll.exe") },
843 { { FPL("/bar/baz/foo.exe"), FPL(" (1)") }, FPL("/bar/baz/foo (1).exe") },
844 { { FPL("/bar/baz/..////"), FPL(" (1)") }, FPL("") },
846 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
847 FilePath
path(cases
[i
].inputs
[0]);
848 FilePath result
= path
.InsertBeforeExtension(cases
[i
].inputs
[1]);
849 EXPECT_EQ(cases
[i
].expected
, result
.value()) << "i: " << i
<<
850 ", path: " << path
.value() << ", insert: " << cases
[i
].inputs
[1];
854 TEST_F(FilePathTest
, RemoveExtension
) {
855 const struct UnaryTestData cases
[] = {
856 { FPL(""), FPL("") },
857 { FPL("."), FPL(".") },
858 { FPL(".."), FPL("..") },
859 { FPL("foo.dll"), FPL("foo") },
860 { FPL("./foo.dll"), FPL("./foo") },
861 { FPL("foo..dll"), FPL("foo.") },
862 { FPL("foo"), FPL("foo") },
863 { FPL("foo."), FPL("foo") },
864 { FPL("foo.."), FPL("foo.") },
865 { FPL("foo.baz.dll"), FPL("foo.baz") },
866 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
867 { FPL("C:\\foo.bar\\foo"), FPL("C:\\foo.bar\\foo") },
868 { FPL("C:\\foo.bar\\..\\\\"), FPL("C:\\foo.bar\\..\\\\") },
870 { FPL("/foo.bar/foo"), FPL("/foo.bar/foo") },
871 { FPL("/foo.bar/..////"), FPL("/foo.bar/..////") },
873 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
874 FilePath
path(cases
[i
].input
);
875 FilePath removed
= path
.RemoveExtension();
876 FilePath removed_final
= path
.RemoveFinalExtension();
877 EXPECT_EQ(cases
[i
].expected
, removed
.value()) << "i: " << i
<<
878 ", path: " << path
.value();
879 EXPECT_EQ(cases
[i
].expected
, removed_final
.value()) << "i: " << i
<<
880 ", path: " << path
.value();
883 FilePath
path(FPL("foo.tar.gz"));
884 FilePath removed
= path
.RemoveExtension();
885 FilePath removed_final
= path
.RemoveFinalExtension();
886 EXPECT_EQ(FPL("foo"), removed
.value()) << ", path: " << path
.value();
887 EXPECT_EQ(FPL("foo.tar"), removed_final
.value()) << ", path: "
892 TEST_F(FilePathTest
, ReplaceExtension
) {
893 const struct BinaryTestData cases
[] = {
894 { { FPL(""), FPL("") }, FPL("") },
895 { { FPL(""), FPL("txt") }, FPL("") },
896 { { FPL("."), FPL("txt") }, FPL("") },
897 { { FPL(".."), FPL("txt") }, FPL("") },
898 { { FPL("."), FPL("") }, FPL("") },
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.dll"), 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"), FPL(".txt") }, FPL("foo.txt") },
907 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baz.txt") },
908 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.txt") },
909 { { FPL("foo.dll"), FPL("") }, FPL("foo") },
910 { { FPL("foo.dll"), FPL(".") }, FPL("foo") },
911 { { FPL("foo"), FPL("") }, FPL("foo") },
912 { { FPL("foo"), FPL(".") }, FPL("foo") },
913 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz") },
914 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz") },
915 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
916 { { FPL("C:\\foo.bar\\foo"), FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
917 { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
919 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") },
920 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") },
922 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
923 FilePath
path(cases
[i
].inputs
[0]);
924 FilePath replaced
= path
.ReplaceExtension(cases
[i
].inputs
[1]);
925 EXPECT_EQ(cases
[i
].expected
, replaced
.value()) << "i: " << i
<<
926 ", path: " << path
.value() << ", replace: " << cases
[i
].inputs
[1];
930 TEST_F(FilePathTest
, AddExtension
) {
931 const struct BinaryTestData cases
[] = {
932 { { FPL(""), FPL("") }, FPL("") },
933 { { FPL(""), FPL("txt") }, FPL("") },
934 { { FPL("."), FPL("txt") }, FPL("") },
935 { { FPL(".."), FPL("txt") }, FPL("") },
936 { { FPL("."), FPL("") }, FPL("") },
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.dll"), FPL(".txt") }, FPL("foo.dll.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"), FPL(".txt") }, FPL("foo.txt") },
945 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baz.dll.txt") },
946 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.dll.txt") },
947 { { FPL("foo.dll"), FPL("") }, FPL("foo.dll") },
948 { { FPL("foo.dll"), FPL(".") }, FPL("foo.dll") },
949 { { FPL("foo"), FPL("") }, FPL("foo") },
950 { { FPL("foo"), FPL(".") }, FPL("foo") },
951 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz.dll") },
952 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz.dll") },
953 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
954 { { FPL("C:\\foo.bar\\foo"), FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
955 { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
957 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") },
958 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") },
960 for (unsigned int i
= 0; i
< arraysize(cases
); ++i
) {
961 FilePath
path(cases
[i
].inputs
[0]);
962 FilePath added
= path
.AddExtension(cases
[i
].inputs
[1]);
963 EXPECT_EQ(cases
[i
].expected
, added
.value()) << "i: " << i
<<
964 ", path: " << path
.value() << ", add: " << cases
[i
].inputs
[1];
968 TEST_F(FilePathTest
, MatchesExtension
) {
969 const struct BinaryBooleanTestData cases
[] = {
970 { { FPL("foo"), FPL("") }, true},
971 { { FPL("foo"), FPL(".") }, false},
972 { { FPL("foo."), FPL("") }, false},
973 { { FPL("foo."), FPL(".") }, true},
974 { { FPL("foo.txt"), FPL(".dll") }, false},
975 { { FPL("foo.txt"), FPL(".txt") }, true},
976 { { FPL("foo.txt.dll"), FPL(".txt") }, false},
977 { { FPL("foo.txt.dll"), FPL(".dll") }, 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 { { FPL("foo.tXt"), FPL(".tXt") }, true},
984 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
985 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false},
986 { { FPL("c:/foo.txt"), FPL(".txt") }, true},
987 #endif // FILE_PATH_USES_DRIVE_LETTERS
988 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
989 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false},
990 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true},
991 #endif // FILE_PATH_USES_DRIVE_LETTERS
992 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false},
993 { { FPL("/bar/foo.txt"), FPL(".txt") }, true},
994 #if defined(OS_WIN) || defined(OS_MACOSX)
995 // Umlauts A, O, U: direct comparison, and upper case vs. lower case
996 { { FPL("foo.\u00E4\u00F6\u00FC"), FPL(".\u00E4\u00F6\u00FC") }, true},
997 { { FPL("foo.\u00C4\u00D6\u00DC"), FPL(".\u00E4\u00F6\u00FC") }, true},
998 // C with circumflex: direct comparison, and upper case vs. lower case
999 { { FPL("foo.\u0109"), FPL(".\u0109") }, true},
1000 { { FPL("foo.\u0108"), FPL(".\u0109") }, true},
1004 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1005 FilePath
path(cases
[i
].inputs
[0]);
1006 FilePath::StringType
ext(cases
[i
].inputs
[1]);
1008 EXPECT_EQ(cases
[i
].expected
, path
.MatchesExtension(ext
)) <<
1009 "i: " << i
<< ", path: " << path
.value() << ", ext: " << ext
;
1013 TEST_F(FilePathTest
, CompareIgnoreCase
) {
1014 const struct BinaryIntTestData cases
[] = {
1015 { { FPL("foo"), FPL("foo") }, 0},
1016 { { FPL("FOO"), FPL("foo") }, 0},
1017 { { FPL("foo.ext"), FPL("foo.ext") }, 0},
1018 { { FPL("FOO.EXT"), FPL("foo.ext") }, 0},
1019 { { FPL("Foo.Ext"), FPL("foo.ext") }, 0},
1020 { { FPL("foO"), FPL("foo") }, 0},
1021 { { FPL("foo"), FPL("foO") }, 0},
1022 { { FPL("fOo"), FPL("foo") }, 0},
1023 { { FPL("foo"), FPL("fOo") }, 0},
1024 { { FPL("bar"), FPL("foo") }, -1},
1025 { { FPL("foo"), FPL("bar") }, 1},
1026 { { FPL("BAR"), FPL("foo") }, -1},
1027 { { FPL("FOO"), FPL("bar") }, 1},
1028 { { FPL("bar"), FPL("FOO") }, -1},
1029 { { FPL("foo"), FPL("BAR") }, 1},
1030 { { FPL("BAR"), FPL("FOO") }, -1},
1031 { { FPL("FOO"), FPL("BAR") }, 1},
1032 // German "Eszett" (lower case and the new-fangled upper case)
1033 // Note that uc(<lowercase eszett>) => "SS", NOT <uppercase eszett>!
1034 // However, neither Windows nor Mac OSX converts these.
1035 // (or even have glyphs for <uppercase eszett>)
1036 { { FPL("\u00DF"), FPL("\u00DF") }, 0},
1037 { { FPL("\u1E9E"), FPL("\u1E9E") }, 0},
1038 { { FPL("\u00DF"), FPL("\u1E9E") }, -1},
1039 { { FPL("SS"), FPL("\u00DF") }, -1},
1040 { { FPL("SS"), FPL("\u1E9E") }, -1},
1041 #if defined(OS_WIN) || defined(OS_MACOSX)
1042 // Umlauts A, O, U: direct comparison, and upper case vs. lower case
1043 { { FPL("\u00E4\u00F6\u00FC"), FPL("\u00E4\u00F6\u00FC") }, 0},
1044 { { FPL("\u00C4\u00D6\u00DC"), FPL("\u00E4\u00F6\u00FC") }, 0},
1045 // C with circumflex: direct comparison, and upper case vs. lower case
1046 { { FPL("\u0109"), FPL("\u0109") }, 0},
1047 { { FPL("\u0108"), FPL("\u0109") }, 0},
1048 // Cyrillic letter SHA: direct comparison, and upper case vs. lower case
1049 { { FPL("\u0428"), FPL("\u0428") }, 0},
1050 { { FPL("\u0428"), FPL("\u0448") }, 0},
1051 // Greek letter DELTA: direct comparison, and upper case vs. lower case
1052 { { FPL("\u0394"), FPL("\u0394") }, 0},
1053 { { FPL("\u0394"), FPL("\u03B4") }, 0},
1054 // Japanese full-width A: direct comparison, and upper case vs. lower case
1055 // Note that full-width and standard characters are considered different.
1056 { { FPL("\uFF21"), FPL("\uFF21") }, 0},
1057 { { FPL("\uFF21"), FPL("\uFF41") }, 0},
1058 { { FPL("A"), FPL("\uFF21") }, -1},
1059 { { FPL("A"), FPL("\uFF41") }, -1},
1060 { { FPL("a"), FPL("\uFF21") }, -1},
1061 { { FPL("a"), FPL("\uFF41") }, -1},
1063 #if defined(OS_MACOSX)
1064 // Codepoints > 0x1000
1065 // Georgian letter DON: direct comparison, and upper case vs. lower case
1066 { { FPL("\u10A3"), FPL("\u10A3") }, 0},
1067 { { FPL("\u10A3"), FPL("\u10D3") }, 0},
1068 // Combining characters vs. pre-composed characters, upper and lower case
1069 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E31\u1E77\u1E53n") }, 0},
1070 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("kuon") }, 1},
1071 { { FPL("kuon"), FPL("k\u0301u\u032Do\u0304\u0301n") }, -1},
1072 { { FPL("K\u0301U\u032DO\u0304\u0301N"), FPL("KUON") }, 1},
1073 { { FPL("KUON"), FPL("K\u0301U\u032DO\u0304\u0301N") }, -1},
1074 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("KUON") }, 1},
1075 { { FPL("K\u0301U\u032DO\u0304\u0301N"), FPL("\u1E31\u1E77\u1E53n") }, 0},
1076 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E30\u1E76\u1E52n") }, 0},
1077 { { FPL("k\u0301u\u032Do\u0304\u0302n"), FPL("\u1E30\u1E76\u1E52n") }, 1},
1081 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1082 FilePath::StringType
s1(cases
[i
].inputs
[0]);
1083 FilePath::StringType
s2(cases
[i
].inputs
[1]);
1084 int result
= FilePath::CompareIgnoreCase(s1
, s2
);
1085 EXPECT_EQ(cases
[i
].expected
, result
) <<
1086 "i: " << i
<< ", s1: " << s1
<< ", s2: " << s2
;
1090 TEST_F(FilePathTest
, ReferencesParent
) {
1091 const struct UnaryBooleanTestData cases
[] = {
1092 { FPL("."), false },
1093 { FPL(".."), true },
1094 { FPL(".. "), true },
1095 { FPL(" .."), true },
1096 { FPL("..."), true },
1097 { FPL("a.."), false },
1098 { FPL("..a"), false },
1099 { FPL("../"), true },
1100 { FPL("/.."), true },
1101 { FPL("/../"), true },
1102 { FPL("/a../"), false },
1103 { FPL("/..a/"), false },
1104 { FPL("//.."), true },
1105 { FPL("..//"), true },
1106 { FPL("//..//"), true },
1107 { FPL("a//..//c"), true },
1108 { FPL("../b/c"), true },
1109 { FPL("/../b/c"), true },
1110 { FPL("a/b/.."), true },
1111 { FPL("a/b/../"), true },
1112 { FPL("a/../c"), true },
1113 { FPL("a/b/c"), false },
1116 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1117 FilePath
input(cases
[i
].input
);
1118 bool observed
= input
.ReferencesParent();
1119 EXPECT_EQ(cases
[i
].expected
, observed
) <<
1120 "i: " << i
<< ", input: " << input
.value();
1124 TEST_F(FilePathTest
, FromUTF8Unsafe_And_AsUTF8Unsafe
) {
1125 const struct UTF8TestData cases
[] = {
1126 { FPL("foo.txt"), "foo.txt" },
1127 // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them.
1128 { FPL("\u00E0\u00E8\u00F2.txt"), "\xC3\xA0\xC3\xA8\xC3\xB2.txt" },
1129 // Full-width "ABC".
1130 { FPL("\uFF21\uFF22\uFF23.txt"),
1131 "\xEF\xBC\xA1\xEF\xBC\xA2\xEF\xBC\xA3.txt" },
1134 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1135 // Test FromUTF8Unsafe() works.
1136 FilePath from_utf8
= FilePath::FromUTF8Unsafe(cases
[i
].utf8
);
1137 EXPECT_EQ(cases
[i
].native
, from_utf8
.value())
1138 << "i: " << i
<< ", input: " << cases
[i
].native
;
1139 // Test AsUTF8Unsafe() works.
1140 FilePath from_native
= FilePath(cases
[i
].native
);
1141 EXPECT_EQ(cases
[i
].utf8
, from_native
.AsUTF8Unsafe())
1142 << "i: " << i
<< ", input: " << cases
[i
].native
;
1143 // Test the two file paths are identical.
1144 EXPECT_EQ(from_utf8
.value(), from_native
.value());
1148 TEST_F(FilePathTest
, ConstructWithNUL
) {
1149 // Assert FPS() works.
1150 ASSERT_EQ(3U, FPS("a\0b").length());
1152 // Test constructor strips '\0'
1153 FilePath
path(FPS("a\0b"));
1154 EXPECT_EQ(1U, path
.value().length());
1155 EXPECT_EQ(FPL("a"), path
.value());
1158 TEST_F(FilePathTest
, AppendWithNUL
) {
1159 // Assert FPS() works.
1160 ASSERT_EQ(3U, FPS("b\0b").length());
1162 // Test Append() strips '\0'
1163 FilePath
path(FPL("a"));
1164 path
= path
.Append(FPS("b\0b"));
1165 EXPECT_EQ(3U, path
.value().length());
1166 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1167 EXPECT_EQ(FPL("a\\b"), path
.value());
1169 EXPECT_EQ(FPL("a/b"), path
.value());
1173 TEST_F(FilePathTest
, ReferencesParentWithNUL
) {
1174 // Assert FPS() works.
1175 ASSERT_EQ(3U, FPS("..\0").length());
1177 // Test ReferencesParent() doesn't break with "..\0"
1178 FilePath
path(FPS("..\0"));
1179 EXPECT_TRUE(path
.ReferencesParent());
1182 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1183 TEST_F(FilePathTest
, NormalizePathSeparators
) {
1184 const struct UnaryTestData cases
[] = {
1185 { FPL("foo/bar"), FPL("foo\\bar") },
1186 { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") },
1187 { FPL("foo\\bar"), FPL("foo\\bar") },
1188 { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") },
1189 { FPL("foo"), FPL("foo") },
1190 // Trailing slashes don't automatically get stripped. That's what
1191 // StripTrailingSeparators() is for.
1192 { FPL("foo\\"), FPL("foo\\") },
1193 { FPL("foo/"), FPL("foo\\") },
1194 { FPL("foo/bar\\"), FPL("foo\\bar\\") },
1195 { FPL("foo\\bar/"), FPL("foo\\bar\\") },
1196 { FPL("foo/bar/"), FPL("foo\\bar\\") },
1197 { FPL("foo\\bar\\"), FPL("foo\\bar\\") },
1198 { FPL("\\foo/bar"), FPL("\\foo\\bar") },
1199 { FPL("/foo\\bar"), FPL("\\foo\\bar") },
1200 { FPL("c:/foo/bar/"), FPL("c:\\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("//foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1207 // This method does not normalize the number of path separators.
1208 { FPL("foo\\\\bar"), FPL("foo\\\\bar") },
1209 { FPL("foo//bar"), FPL("foo\\\\bar") },
1210 { FPL("foo/\\bar"), FPL("foo\\\\bar") },
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") },
1217 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1218 FilePath
input(cases
[i
].input
);
1219 FilePath observed
= input
.NormalizePathSeparators();
1220 EXPECT_EQ(FilePath::StringType(cases
[i
].expected
), observed
.value()) <<
1221 "i: " << i
<< ", input: " << input
.value();
1226 TEST_F(FilePathTest
, EndsWithSeparator
) {
1227 const UnaryBooleanTestData cases
[] = {
1230 { FPL("foo/"), true },
1231 { FPL("bar"), false },
1232 { FPL("/foo/bar"), false },
1234 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1235 FilePath input
= FilePath(cases
[i
].input
).NormalizePathSeparators();
1236 EXPECT_EQ(cases
[i
].expected
, input
.EndsWithSeparator());
1240 TEST_F(FilePathTest
, AsEndingWithSeparator
) {
1241 const UnaryTestData cases
[] = {
1242 { FPL(""), FPL("") },
1243 { FPL("/"), FPL("/") },
1244 { FPL("foo"), FPL("foo/") },
1245 { FPL("foo/"), FPL("foo/") }
1247 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1248 FilePath input
= FilePath(cases
[i
].input
).NormalizePathSeparators();
1249 FilePath expected
= FilePath(cases
[i
].expected
).NormalizePathSeparators();
1250 EXPECT_EQ(expected
.value(), input
.AsEndingWithSeparator().value());
1254 #if defined(OS_ANDROID)
1255 TEST_F(FilePathTest
, ContentUriTest
) {
1256 const struct UnaryBooleanTestData cases
[] = {
1257 { FPL("content://foo.bar"), true },
1258 { FPL("content://foo.bar/"), true },
1259 { FPL("content://foo/bar"), true },
1260 { FPL("CoNTenT://foo.bar"), true },
1261 { FPL("content://"), true },
1262 { FPL("content:///foo.bar"), true },
1263 { FPL("content://3foo/bar"), true },
1264 { FPL("content://_foo/bar"), true },
1265 { FPL(".. "), false },
1266 { FPL("foo.bar"), false },
1267 { FPL("content:foo.bar"), false },
1268 { FPL("content:/foo.ba"), false },
1269 { FPL("content:/dir/foo.bar"), false },
1270 { FPL("content: //foo.bar"), false },
1271 { FPL("content%2a%2f%2f"), false },
1274 for (size_t i
= 0; i
< arraysize(cases
); ++i
) {
1275 FilePath
input(cases
[i
].input
);
1276 bool observed
= input
.IsContentUri();
1277 EXPECT_EQ(cases
[i
].expected
, observed
) <<
1278 "i: " << i
<< ", input: " << input
.value();