file_path_unittest.cc revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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.
4
5#include "base/basictypes.h"
6#include "base/files/file_path.h"
7#include "base/utf_string_conversions.h"
8#include "testing/gtest/include/gtest/gtest.h"
9#include "testing/platform_test.h"
10
11// This macro helps avoid wrapped lines in the test structs.
12#define FPL(x) FILE_PATH_LITERAL(x)
13
14// This macro constructs strings which can contain NULs.
15#define FPS(x) FilePath::StringType(FPL(x), arraysize(FPL(x)) - 1)
16
17namespace base {
18
19struct UnaryTestData {
20  const FilePath::CharType* input;
21  const FilePath::CharType* expected;
22};
23
24struct UnaryBooleanTestData {
25  const FilePath::CharType* input;
26  bool expected;
27};
28
29struct BinaryTestData {
30  const FilePath::CharType* inputs[2];
31  const FilePath::CharType* expected;
32};
33
34struct BinaryBooleanTestData {
35  const FilePath::CharType* inputs[2];
36  bool expected;
37};
38
39struct BinaryIntTestData {
40  const FilePath::CharType* inputs[2];
41  int expected;
42};
43
44struct UTF8TestData {
45  const FilePath::CharType* native;
46  const char* utf8;
47};
48
49// file_util winds up using autoreleased objects on the Mac, so this needs
50// to be a PlatformTest
51class FilePathTest : public PlatformTest {
52 protected:
53  virtual void SetUp() OVERRIDE {
54    PlatformTest::SetUp();
55  }
56  virtual void TearDown() OVERRIDE {
57    PlatformTest::TearDown();
58  }
59};
60
61TEST_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(".") },
91#if defined(OS_WIN)
92    { FPL("\x0143:"),       FPL(".") },
93#endif  // OS_WIN
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
140  };
141
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();
147  }
148}
149
150TEST_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:") },
179#if defined(OS_WIN)
180    { FPL("\x0143:"),       FPL("\x0143:") },
181#endif  // OS_WIN
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
227  };
228
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();
234  }
235}
236
237TEST_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
304  };
305
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;
315
316    // TODO(erikkay): It would be nice to have a unicode test append value to
317    // handle the case when AppendASCII is passed UTF8
318#if defined(OS_WIN)
319    std::string ascii = WideToUTF8(leaf);
320#elif defined(OS_POSIX)
321    std::string ascii = leaf;
322#endif
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;
326  }
327}
328
329TEST_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
383  };
384
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();
390  }
391}
392
393TEST_F(FilePathTest, IsAbsolute) {
394  const struct UnaryBooleanTestData cases[] = {
395    { FPL(""),       false },
396    { FPL("a"),      false },
397    { FPL("c:"),     false },
398    { FPL("c:a"),    false },
399    { FPL("a/b"),    false },
400    { FPL("//"),     true },
401    { FPL("//a"),    true },
402    { FPL("c:a/b"),  false },
403    { FPL("?:/a"),   false },
404#if defined(FILE_PATH_USES_DRIVE_LETTERS)
405    { FPL("/"),      false },
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
416    { FPL("/"),      true },
417    { FPL("/a"),     true },
418    { FPL("/."),     true },
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
444    { FPL("\\"),     true },
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
451  };
452
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();
458  }
459}
460
461TEST_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")},
474    { FPL(""),                        FPL("")},
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
497  };
498
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);
503
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]);
508    }
509    EXPECT_EQ(FilePath::StringType(cases[i].expected), observed) <<
510              "i: " << i << ", input: " << input.value();
511  }
512}
513
514TEST_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
554  };
555
556  for (size_t i = 0; i < arraysize(cases); ++i) {
557    FilePath parent(cases[i].inputs[0]);
558    FilePath child(cases[i].inputs[1]);
559
560    EXPECT_EQ(parent.IsParent(child), cases[i].expected) <<
561        "i: " << i << ", parent: " << parent.value() << ", child: " <<
562        child.value();
563  }
564}
565
566TEST_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
596    // blah\foo\bar\baz.
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
616  };
617
618  const FilePath base(FPL("blah"));
619
620  for (size_t i = 0; i < arraysize(cases); ++i) {
621    FilePath parent(cases[i].inputs[0]);
622    FilePath child(cases[i].inputs[1]);
623    {
624      FilePath result;
625      bool success = parent.AppendRelativePath(child, &result);
626      EXPECT_EQ(cases[i].expected[0] != '\0', success) <<
627        "i: " << i << ", parent: " << parent.value() << ", child: " <<
628        child.value();
629      EXPECT_STREQ(cases[i].expected, result.value().c_str()) <<
630        "i: " << i << ", parent: " << parent.value() << ", child: " <<
631        child.value();
632    }
633    {
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: " <<
638        child.value();
639      EXPECT_EQ(base.Append(cases[i].expected).value(), result.value()) <<
640        "i: " << i << ", parent: " << parent.value() << ", child: " <<
641        child.value();
642    }
643  }
644}
645
646TEST_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
685  };
686
687  for (size_t i = 0; i < arraysize(cases); ++i) {
688    FilePath a(cases[i].inputs[0]);
689    FilePath b(cases[i].inputs[1]);
690
691    EXPECT_EQ(a == b, cases[i].expected) <<
692      "equality i: " << i << ", a: " << a.value() << ", b: " <<
693      b.value();
694  }
695
696  for (size_t i = 0; i < arraysize(cases); ++i) {
697    FilePath a(cases[i].inputs[0]);
698    FilePath b(cases[i].inputs[1]);
699
700    EXPECT_EQ(a != b, !cases[i].expected) <<
701      "inequality i: " << i << ", a: " << a.value() << ", b: " <<
702      b.value();
703  }
704}
705
706TEST_F(FilePathTest, Extension) {
707  FilePath base_dir(FILE_PATH_LITERAL("base_dir"));
708
709  FilePath jpg = base_dir.Append(FILE_PATH_LITERAL("foo.jpg"));
710  EXPECT_EQ(FILE_PATH_LITERAL(".jpg"), jpg.Extension());
711
712  FilePath base = jpg.BaseName().RemoveExtension();
713  EXPECT_EQ(FILE_PATH_LITERAL("foo"), base.value());
714
715  FilePath path_no_ext = base_dir.Append(base);
716  EXPECT_EQ(path_no_ext.value(), jpg.RemoveExtension().value());
717
718  EXPECT_EQ(path_no_ext.value(), path_no_ext.RemoveExtension().value());
719  EXPECT_EQ(FILE_PATH_LITERAL(""), path_no_ext.Extension());
720}
721
722TEST_F(FilePathTest, Extension2) {
723  const struct UnaryTestData cases[] = {
724#if defined(FILE_PATH_USES_WIN_SEPARATORS)
725    { FPL("C:\\a\\b\\c.ext"),        FPL(".ext") },
726    { FPL("C:\\a\\b\\c."),           FPL(".") },
727    { FPL("C:\\a\\b\\c"),            FPL("") },
728    { FPL("C:\\a\\b\\"),             FPL("") },
729    { FPL("C:\\a\\b.\\"),            FPL(".") },
730    { FPL("C:\\a\\b\\c.ext1.ext2"),  FPL(".ext2") },
731    { FPL("C:\\foo.bar\\\\\\"),      FPL(".bar") },
732    { FPL("C:\\foo.bar\\.."),        FPL("") },
733    { FPL("C:\\foo.bar\\..\\\\"),    FPL("") },
734#endif
735    { FPL("/foo/bar/baz.ext"),       FPL(".ext") },
736    { FPL("/foo/bar/baz."),          FPL(".") },
737    { FPL("/foo/bar/baz.."),         FPL(".") },
738    { FPL("/foo/bar/baz"),           FPL("") },
739    { FPL("/foo/bar/"),              FPL("") },
740    { FPL("/foo/bar./"),             FPL(".") },
741    { FPL("/foo/bar/baz.ext1.ext2"), FPL(".ext2") },
742    { FPL("/foo.tar.gz"),            FPL(".tar.gz") },
743    { FPL("/foo.tar.Z"),             FPL(".tar.Z") },
744    { FPL("/foo.tar.bz2"),           FPL(".tar.bz2") },
745    { FPL("/subversion-1.6.12.zip"), FPL(".zip") },
746    { FPL("/foo.1234.gz"),           FPL(".1234.gz") },
747    { FPL("/foo.12345.gz"),          FPL(".gz") },
748    { FPL("/foo..gz"),               FPL(".gz") },
749    { FPL("/foo.1234.tar.gz"),       FPL(".tar.gz") },
750    { FPL("/foo.tar.tar.gz"),        FPL(".tar.gz") },
751    { FPL("/foo.tar.gz.gz"),         FPL(".gz.gz") },
752    { FPL("."),                      FPL("") },
753    { FPL(".."),                     FPL("") },
754    { FPL("./foo"),                  FPL("") },
755    { FPL("./foo.ext"),              FPL(".ext") },
756    { FPL("/foo.ext1/bar.ext2"),     FPL(".ext2") },
757    { FPL("/foo.bar////"),           FPL(".bar") },
758    { FPL("/foo.bar/.."),            FPL("") },
759    { FPL("/foo.bar/..////"),        FPL("") },
760    { FPL("/foo.1234.user.js"),      FPL(".user.js") },
761    { FPL("foo.user.js"),            FPL(".user.js") },
762    { FPL("/foo.1234.luser.js"),     FPL(".js") },
763    { FPL("/user.js"),               FPL(".js") },
764  };
765  for (unsigned int i = 0; i < arraysize(cases); ++i) {
766    FilePath path(cases[i].input);
767    FilePath::StringType extension = path.Extension();
768    EXPECT_STREQ(cases[i].expected, extension.c_str()) << "i: " << i <<
769        ", path: " << path.value();
770  }
771}
772
773TEST_F(FilePathTest, InsertBeforeExtension) {
774  const struct BinaryTestData cases[] = {
775    { { FPL(""),                FPL("") },        FPL("") },
776    { { FPL(""),                FPL("txt") },     FPL("") },
777    { { FPL("."),               FPL("txt") },     FPL("") },
778    { { FPL(".."),              FPL("txt") },     FPL("") },
779    { { FPL("foo.dll"),         FPL("txt") },     FPL("footxt.dll") },
780    { { FPL("."),               FPL("") },        FPL(".") },
781    { { FPL("foo.dll"),         FPL(".txt") },    FPL("foo.txt.dll") },
782    { { FPL("foo"),             FPL("txt") },     FPL("footxt") },
783    { { FPL("foo"),             FPL(".txt") },    FPL("foo.txt") },
784    { { FPL("foo.baz.dll"),     FPL("txt") },     FPL("foo.baztxt.dll") },
785    { { FPL("foo.baz.dll"),     FPL(".txt") },    FPL("foo.baz.txt.dll") },
786    { { FPL("foo.dll"),         FPL("") },        FPL("foo.dll") },
787    { { FPL("foo.dll"),         FPL(".") },       FPL("foo..dll") },
788    { { FPL("foo"),             FPL("") },        FPL("foo") },
789    { { FPL("foo"),             FPL(".") },       FPL("foo.") },
790    { { FPL("foo.baz.dll"),     FPL("") },        FPL("foo.baz.dll") },
791    { { FPL("foo.baz.dll"),     FPL(".") },       FPL("foo.baz..dll") },
792#if defined(FILE_PATH_USES_WIN_SEPARATORS)
793    { { FPL("\\"),              FPL("") },        FPL("\\") },
794    { { FPL("\\"),              FPL("txt") },     FPL("\\txt") },
795    { { FPL("\\."),             FPL("txt") },     FPL("") },
796    { { FPL("\\.."),            FPL("txt") },     FPL("") },
797    { { FPL("\\."),             FPL("") },        FPL("\\.") },
798    { { FPL("C:\\bar\\foo.dll"), FPL("txt") },
799        FPL("C:\\bar\\footxt.dll") },
800    { { FPL("C:\\bar.baz\\foodll"), FPL("txt") },
801        FPL("C:\\bar.baz\\foodlltxt") },
802    { { FPL("C:\\bar.baz\\foo.dll"), FPL("txt") },
803        FPL("C:\\bar.baz\\footxt.dll") },
804    { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("txt") },
805        FPL("C:\\bar.baz\\foo.dlltxt.exe") },
806    { { FPL("C:\\bar.baz\\foo"), FPL("") },
807        FPL("C:\\bar.baz\\foo") },
808    { { FPL("C:\\bar.baz\\foo.exe"), FPL("") },
809        FPL("C:\\bar.baz\\foo.exe") },
810    { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("") },
811        FPL("C:\\bar.baz\\foo.dll.exe") },
812    { { FPL("C:\\bar\\baz\\foo.exe"), FPL(" (1)") },
813        FPL("C:\\bar\\baz\\foo (1).exe") },
814    { { FPL("C:\\foo.baz\\\\"), FPL(" (1)") },    FPL("C:\\foo (1).baz") },
815    { { FPL("C:\\foo.baz\\..\\"), FPL(" (1)") },  FPL("") },
816#endif
817    { { FPL("/"),               FPL("") },        FPL("/") },
818    { { FPL("/"),               FPL("txt") },     FPL("/txt") },
819    { { FPL("/."),              FPL("txt") },     FPL("") },
820    { { FPL("/.."),             FPL("txt") },     FPL("") },
821    { { FPL("/."),              FPL("") },        FPL("/.") },
822    { { FPL("/bar/foo.dll"),    FPL("txt") },     FPL("/bar/footxt.dll") },
823    { { FPL("/bar.baz/foodll"), FPL("txt") },     FPL("/bar.baz/foodlltxt") },
824    { { FPL("/bar.baz/foo.dll"), FPL("txt") },    FPL("/bar.baz/footxt.dll") },
825    { { FPL("/bar.baz/foo.dll.exe"), FPL("txt") },
826        FPL("/bar.baz/foo.dlltxt.exe") },
827    { { FPL("/bar.baz/foo"),    FPL("") },        FPL("/bar.baz/foo") },
828    { { FPL("/bar.baz/foo.exe"), FPL("") },       FPL("/bar.baz/foo.exe") },
829    { { FPL("/bar.baz/foo.dll.exe"), FPL("") },   FPL("/bar.baz/foo.dll.exe") },
830    { { FPL("/bar/baz/foo.exe"), FPL(" (1)") },   FPL("/bar/baz/foo (1).exe") },
831    { { FPL("/bar/baz/..////"), FPL(" (1)") },    FPL("") },
832  };
833  for (unsigned int i = 0; i < arraysize(cases); ++i) {
834    FilePath path(cases[i].inputs[0]);
835    FilePath result = path.InsertBeforeExtension(cases[i].inputs[1]);
836    EXPECT_EQ(cases[i].expected, result.value()) << "i: " << i <<
837        ", path: " << path.value() << ", insert: " << cases[i].inputs[1];
838  }
839}
840
841TEST_F(FilePathTest, RemoveExtension) {
842  const struct UnaryTestData cases[] = {
843    { FPL(""),                    FPL("") },
844    { FPL("."),                   FPL(".") },
845    { FPL(".."),                  FPL("..") },
846    { FPL("foo.dll"),             FPL("foo") },
847    { FPL("./foo.dll"),           FPL("./foo") },
848    { FPL("foo..dll"),            FPL("foo.") },
849    { FPL("foo"),                 FPL("foo") },
850    { FPL("foo."),                FPL("foo") },
851    { FPL("foo.."),               FPL("foo.") },
852    { FPL("foo.baz.dll"),         FPL("foo.baz") },
853    { FPL("foo.tar.gz"),          FPL("foo") },
854#if defined(FILE_PATH_USES_WIN_SEPARATORS)
855    { FPL("C:\\foo.bar\\foo"),    FPL("C:\\foo.bar\\foo") },
856    { FPL("C:\\foo.bar\\..\\\\"), FPL("C:\\foo.bar\\..\\\\") },
857#endif
858    { FPL("/foo.bar/foo"),        FPL("/foo.bar/foo") },
859    { FPL("/foo.bar/..////"),     FPL("/foo.bar/..////") },
860  };
861  for (unsigned int i = 0; i < arraysize(cases); ++i) {
862    FilePath path(cases[i].input);
863    FilePath removed = path.RemoveExtension();
864    EXPECT_EQ(cases[i].expected, removed.value()) << "i: " << i <<
865        ", path: " << path.value();
866  }
867}
868
869TEST_F(FilePathTest, ReplaceExtension) {
870  const struct BinaryTestData cases[] = {
871    { { FPL(""),              FPL("") },      FPL("") },
872    { { FPL(""),              FPL("txt") },   FPL("") },
873    { { FPL("."),             FPL("txt") },   FPL("") },
874    { { FPL(".."),            FPL("txt") },   FPL("") },
875    { { FPL("."),             FPL("") },      FPL("") },
876    { { FPL("foo.dll"),       FPL("txt") },   FPL("foo.txt") },
877    { { FPL("./foo.dll"),     FPL("txt") },   FPL("./foo.txt") },
878    { { FPL("foo..dll"),      FPL("txt") },   FPL("foo..txt") },
879    { { FPL("foo.dll"),       FPL(".txt") },  FPL("foo.txt") },
880    { { FPL("foo"),           FPL("txt") },   FPL("foo.txt") },
881    { { FPL("foo."),          FPL("txt") },   FPL("foo.txt") },
882    { { FPL("foo.."),         FPL("txt") },   FPL("foo..txt") },
883    { { FPL("foo"),           FPL(".txt") },  FPL("foo.txt") },
884    { { FPL("foo.baz.dll"),   FPL("txt") },   FPL("foo.baz.txt") },
885    { { FPL("foo.baz.dll"),   FPL(".txt") },  FPL("foo.baz.txt") },
886    { { FPL("foo.dll"),       FPL("") },      FPL("foo") },
887    { { FPL("foo.dll"),       FPL(".") },     FPL("foo") },
888    { { FPL("foo"),           FPL("") },      FPL("foo") },
889    { { FPL("foo"),           FPL(".") },     FPL("foo") },
890    { { FPL("foo.baz.dll"),   FPL("") },      FPL("foo.baz") },
891    { { FPL("foo.baz.dll"),   FPL(".") },     FPL("foo.baz") },
892#if defined(FILE_PATH_USES_WIN_SEPARATORS)
893    { { FPL("C:\\foo.bar\\foo"),    FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
894    { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
895#endif
896    { { FPL("/foo.bar/foo"),        FPL("baz") }, FPL("/foo.bar/foo.baz") },
897    { { FPL("/foo.bar/..////"),     FPL("baz") }, FPL("") },
898  };
899  for (unsigned int i = 0; i < arraysize(cases); ++i) {
900    FilePath path(cases[i].inputs[0]);
901    FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]);
902    EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i <<
903        ", path: " << path.value() << ", replace: " << cases[i].inputs[1];
904  }
905}
906
907TEST_F(FilePathTest, AddExtension) {
908  const struct BinaryTestData cases[] = {
909    { { FPL(""),              FPL("") },      FPL("") },
910    { { FPL(""),              FPL("txt") },   FPL("") },
911    { { FPL("."),             FPL("txt") },   FPL("") },
912    { { FPL(".."),            FPL("txt") },   FPL("") },
913    { { FPL("."),             FPL("") },      FPL("") },
914    { { FPL("foo.dll"),       FPL("txt") },   FPL("foo.dll.txt") },
915    { { FPL("./foo.dll"),     FPL("txt") },   FPL("./foo.dll.txt") },
916    { { FPL("foo..dll"),      FPL("txt") },   FPL("foo..dll.txt") },
917    { { FPL("foo.dll"),       FPL(".txt") },  FPL("foo.dll.txt") },
918    { { FPL("foo"),           FPL("txt") },   FPL("foo.txt") },
919    { { FPL("foo."),          FPL("txt") },   FPL("foo.txt") },
920    { { FPL("foo.."),         FPL("txt") },   FPL("foo..txt") },
921    { { FPL("foo"),           FPL(".txt") },  FPL("foo.txt") },
922    { { FPL("foo.baz.dll"),   FPL("txt") },   FPL("foo.baz.dll.txt") },
923    { { FPL("foo.baz.dll"),   FPL(".txt") },  FPL("foo.baz.dll.txt") },
924    { { FPL("foo.dll"),       FPL("") },      FPL("foo.dll") },
925    { { FPL("foo.dll"),       FPL(".") },     FPL("foo.dll") },
926    { { FPL("foo"),           FPL("") },      FPL("foo") },
927    { { FPL("foo"),           FPL(".") },     FPL("foo") },
928    { { FPL("foo.baz.dll"),   FPL("") },      FPL("foo.baz.dll") },
929    { { FPL("foo.baz.dll"),   FPL(".") },     FPL("foo.baz.dll") },
930#if defined(FILE_PATH_USES_WIN_SEPARATORS)
931    { { FPL("C:\\foo.bar\\foo"),    FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
932    { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
933#endif
934    { { FPL("/foo.bar/foo"),        FPL("baz") }, FPL("/foo.bar/foo.baz") },
935    { { FPL("/foo.bar/..////"),     FPL("baz") }, FPL("") },
936  };
937  for (unsigned int i = 0; i < arraysize(cases); ++i) {
938    FilePath path(cases[i].inputs[0]);
939    FilePath added = path.AddExtension(cases[i].inputs[1]);
940    EXPECT_EQ(cases[i].expected, added.value()) << "i: " << i <<
941        ", path: " << path.value() << ", add: " << cases[i].inputs[1];
942  }
943}
944
945TEST_F(FilePathTest, MatchesExtension) {
946  const struct BinaryBooleanTestData cases[] = {
947    { { FPL("foo"),                     FPL("") },                    true},
948    { { FPL("foo"),                     FPL(".") },                   false},
949    { { FPL("foo."),                    FPL("") },                    false},
950    { { FPL("foo."),                    FPL(".") },                   true},
951    { { FPL("foo.txt"),                 FPL(".dll") },                false},
952    { { FPL("foo.txt"),                 FPL(".txt") },                true},
953    { { FPL("foo.txt.dll"),             FPL(".txt") },                false},
954    { { FPL("foo.txt.dll"),             FPL(".dll") },                true},
955    { { FPL("foo.TXT"),                 FPL(".txt") },                true},
956    { { FPL("foo.txt"),                 FPL(".TXT") },                true},
957    { { FPL("foo.tXt"),                 FPL(".txt") },                true},
958    { { FPL("foo.txt"),                 FPL(".tXt") },                true},
959    { { FPL("foo.tXt"),                 FPL(".TXT") },                true},
960    { { FPL("foo.tXt"),                 FPL(".tXt") },                true},
961#if defined(FILE_PATH_USES_DRIVE_LETTERS)
962    { { FPL("c:/foo.txt.dll"),          FPL(".txt") },                false},
963    { { FPL("c:/foo.txt"),              FPL(".txt") },                true},
964#endif  // FILE_PATH_USES_DRIVE_LETTERS
965#if defined(FILE_PATH_USES_WIN_SEPARATORS)
966    { { FPL("c:\\bar\\foo.txt.dll"),    FPL(".txt") },                false},
967    { { FPL("c:\\bar\\foo.txt"),        FPL(".txt") },                true},
968#endif  // FILE_PATH_USES_DRIVE_LETTERS
969    { { FPL("/bar/foo.txt.dll"),        FPL(".txt") },                false},
970    { { FPL("/bar/foo.txt"),            FPL(".txt") },                true},
971#if defined(OS_WIN) || defined(OS_MACOSX)
972    // Umlauts A, O, U: direct comparison, and upper case vs. lower case
973    { { FPL("foo.\u00E4\u00F6\u00FC"),  FPL(".\u00E4\u00F6\u00FC") }, true},
974    { { FPL("foo.\u00C4\u00D6\u00DC"),  FPL(".\u00E4\u00F6\u00FC") }, true},
975    // C with circumflex: direct comparison, and upper case vs. lower case
976    { { FPL("foo.\u0109"),              FPL(".\u0109") },             true},
977    { { FPL("foo.\u0108"),              FPL(".\u0109") },             true},
978#endif
979  };
980
981  for (size_t i = 0; i < arraysize(cases); ++i) {
982    FilePath path(cases[i].inputs[0]);
983    FilePath::StringType ext(cases[i].inputs[1]);
984
985    EXPECT_EQ(cases[i].expected, path.MatchesExtension(ext)) <<
986        "i: " << i << ", path: " << path.value() << ", ext: " << ext;
987  }
988}
989
990TEST_F(FilePathTest, CompareIgnoreCase) {
991  const struct BinaryIntTestData cases[] = {
992    { { FPL("foo"),                          FPL("foo") },                  0},
993    { { FPL("FOO"),                          FPL("foo") },                  0},
994    { { FPL("foo.ext"),                      FPL("foo.ext") },              0},
995    { { FPL("FOO.EXT"),                      FPL("foo.ext") },              0},
996    { { FPL("Foo.Ext"),                      FPL("foo.ext") },              0},
997    { { FPL("foO"),                          FPL("foo") },                  0},
998    { { FPL("foo"),                          FPL("foO") },                  0},
999    { { FPL("fOo"),                          FPL("foo") },                  0},
1000    { { FPL("foo"),                          FPL("fOo") },                  0},
1001    { { FPL("bar"),                          FPL("foo") },                 -1},
1002    { { FPL("foo"),                          FPL("bar") },                  1},
1003    { { FPL("BAR"),                          FPL("foo") },                 -1},
1004    { { FPL("FOO"),                          FPL("bar") },                  1},
1005    { { FPL("bar"),                          FPL("FOO") },                 -1},
1006    { { FPL("foo"),                          FPL("BAR") },                  1},
1007    { { FPL("BAR"),                          FPL("FOO") },                 -1},
1008    { { FPL("FOO"),                          FPL("BAR") },                  1},
1009    // German "Eszett" (lower case and the new-fangled upper case)
1010    // Note that uc(<lowercase eszett>) => "SS", NOT <uppercase eszett>!
1011    // However, neither Windows nor Mac OSX converts these.
1012    // (or even have glyphs for <uppercase eszett>)
1013    { { FPL("\u00DF"),                       FPL("\u00DF") },               0},
1014    { { FPL("\u1E9E"),                       FPL("\u1E9E") },               0},
1015    { { FPL("\u00DF"),                       FPL("\u1E9E") },              -1},
1016    { { FPL("SS"),                           FPL("\u00DF") },              -1},
1017    { { FPL("SS"),                           FPL("\u1E9E") },              -1},
1018#if defined(OS_WIN) || defined(OS_MACOSX)
1019    // Umlauts A, O, U: direct comparison, and upper case vs. lower case
1020    { { FPL("\u00E4\u00F6\u00FC"),           FPL("\u00E4\u00F6\u00FC") },   0},
1021    { { FPL("\u00C4\u00D6\u00DC"),           FPL("\u00E4\u00F6\u00FC") },   0},
1022    // C with circumflex: direct comparison, and upper case vs. lower case
1023    { { FPL("\u0109"),                       FPL("\u0109") },               0},
1024    { { FPL("\u0108"),                       FPL("\u0109") },               0},
1025    // Cyrillic letter SHA: direct comparison, and upper case vs. lower case
1026    { { FPL("\u0428"),                       FPL("\u0428") },               0},
1027    { { FPL("\u0428"),                       FPL("\u0448") },               0},
1028    // Greek letter DELTA: direct comparison, and upper case vs. lower case
1029    { { FPL("\u0394"),                       FPL("\u0394") },               0},
1030    { { FPL("\u0394"),                       FPL("\u03B4") },               0},
1031    // Japanese full-width A: direct comparison, and upper case vs. lower case
1032    // Note that full-width and standard characters are considered different.
1033    { { FPL("\uFF21"),                       FPL("\uFF21") },               0},
1034    { { FPL("\uFF21"),                       FPL("\uFF41") },               0},
1035    { { FPL("A"),                            FPL("\uFF21") },              -1},
1036    { { FPL("A"),                            FPL("\uFF41") },              -1},
1037    { { FPL("a"),                            FPL("\uFF21") },              -1},
1038    { { FPL("a"),                            FPL("\uFF41") },              -1},
1039#endif
1040#if defined(OS_MACOSX)
1041    // Codepoints > 0x1000
1042    // Georgian letter DON: direct comparison, and upper case vs. lower case
1043    { { FPL("\u10A3"),                       FPL("\u10A3") },               0},
1044    { { FPL("\u10A3"),                       FPL("\u10D3") },               0},
1045    // Combining characters vs. pre-composed characters, upper and lower case
1046    { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E31\u1E77\u1E53n") },  0},
1047    { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("kuon") },                 1},
1048    { { FPL("kuon"), FPL("k\u0301u\u032Do\u0304\u0301n") },                -1},
1049    { { FPL("K\u0301U\u032DO\u0304\u0301N"), FPL("KUON") },                 1},
1050    { { FPL("KUON"), FPL("K\u0301U\u032DO\u0304\u0301N") },                -1},
1051    { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("KUON") },                 1},
1052    { { FPL("K\u0301U\u032DO\u0304\u0301N"), FPL("\u1E31\u1E77\u1E53n") },  0},
1053    { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E30\u1E76\u1E52n") },  0},
1054    { { FPL("k\u0301u\u032Do\u0304\u0302n"), FPL("\u1E30\u1E76\u1E52n") },  1},
1055#endif
1056  };
1057
1058  for (size_t i = 0; i < arraysize(cases); ++i) {
1059    FilePath::StringType s1(cases[i].inputs[0]);
1060    FilePath::StringType s2(cases[i].inputs[1]);
1061    int result = FilePath::CompareIgnoreCase(s1, s2);
1062    EXPECT_EQ(cases[i].expected, result) <<
1063        "i: " << i << ", s1: " << s1 << ", s2: " << s2;
1064  }
1065}
1066
1067TEST_F(FilePathTest, ReferencesParent) {
1068  const struct UnaryBooleanTestData cases[] = {
1069    { FPL("."),        false },
1070    { FPL(".."),       true },
1071    { FPL("a.."),      false },
1072    { FPL("..a"),      false },
1073    { FPL("../"),      true },
1074    { FPL("/.."),      true },
1075    { FPL("/../"),     true },
1076    { FPL("/a../"),    false },
1077    { FPL("/..a/"),    false },
1078    { FPL("//.."),     true },
1079    { FPL("..//"),     true },
1080    { FPL("//..//"),   true },
1081    { FPL("a//..//c"), true },
1082    { FPL("../b/c"),   true },
1083    { FPL("/../b/c"),  true },
1084    { FPL("a/b/.."),   true },
1085    { FPL("a/b/../"),  true },
1086    { FPL("a/../c"),   true },
1087    { FPL("a/b/c"),    false },
1088  };
1089
1090  for (size_t i = 0; i < arraysize(cases); ++i) {
1091    FilePath input(cases[i].input);
1092    bool observed = input.ReferencesParent();
1093    EXPECT_EQ(cases[i].expected, observed) <<
1094              "i: " << i << ", input: " << input.value();
1095  }
1096}
1097
1098TEST_F(FilePathTest, FromUTF8Unsafe_And_AsUTF8Unsafe) {
1099  const struct UTF8TestData cases[] = {
1100    { FPL("foo.txt"), "foo.txt" },
1101    // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them.
1102    { FPL("\u00E0\u00E8\u00F2.txt"), "\xC3\xA0\xC3\xA8\xC3\xB2.txt" },
1103    // Full-width "ABC".
1104    { FPL("\uFF21\uFF22\uFF23.txt"),
1105      "\xEF\xBC\xA1\xEF\xBC\xA2\xEF\xBC\xA3.txt" },
1106  };
1107
1108  for (size_t i = 0; i < arraysize(cases); ++i) {
1109    // Test FromUTF8Unsafe() works.
1110    FilePath from_utf8 = FilePath::FromUTF8Unsafe(cases[i].utf8);
1111    EXPECT_EQ(cases[i].native, from_utf8.value())
1112        << "i: " << i << ", input: " << cases[i].native;
1113    // Test AsUTF8Unsafe() works.
1114    FilePath from_native = FilePath(cases[i].native);
1115    EXPECT_EQ(cases[i].utf8, from_native.AsUTF8Unsafe())
1116        << "i: " << i << ", input: " << cases[i].native;
1117    // Test the two file paths are identical.
1118    EXPECT_EQ(from_utf8.value(), from_native.value());
1119  }
1120}
1121
1122TEST_F(FilePathTest, ConstructWithNUL) {
1123  // Assert FPS() works.
1124  ASSERT_EQ(3U, FPS("a\0b").length());
1125
1126  // Test constructor strips '\0'
1127  FilePath path(FPS("a\0b"));
1128  EXPECT_EQ(1U, path.value().length());
1129  EXPECT_EQ(FPL("a"), path.value());
1130}
1131
1132TEST_F(FilePathTest, AppendWithNUL) {
1133  // Assert FPS() works.
1134  ASSERT_EQ(3U, FPS("b\0b").length());
1135
1136  // Test Append() strips '\0'
1137  FilePath path(FPL("a"));
1138  path = path.Append(FPS("b\0b"));
1139  EXPECT_EQ(3U, path.value().length());
1140#if defined(FILE_PATH_USES_WIN_SEPARATORS)
1141  EXPECT_EQ(FPL("a\\b"), path.value());
1142#else
1143  EXPECT_EQ(FPL("a/b"), path.value());
1144#endif
1145}
1146
1147TEST_F(FilePathTest, ReferencesParentWithNUL) {
1148  // Assert FPS() works.
1149  ASSERT_EQ(3U, FPS("..\0").length());
1150
1151  // Test ReferencesParent() doesn't break with "..\0"
1152  FilePath path(FPS("..\0"));
1153  EXPECT_TRUE(path.ReferencesParent());
1154}
1155
1156#if defined(FILE_PATH_USES_WIN_SEPARATORS)
1157TEST_F(FilePathTest, NormalizePathSeparators) {
1158  const struct UnaryTestData cases[] = {
1159    { FPL("foo/bar"), FPL("foo\\bar") },
1160    { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") },
1161    { FPL("foo\\bar"), FPL("foo\\bar") },
1162    { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") },
1163    { FPL("foo"), FPL("foo") },
1164    // Trailing slashes don't automatically get stripped.  That's what
1165    // StripTrailingSeparators() is for.
1166    { FPL("foo\\"), FPL("foo\\") },
1167    { FPL("foo/"), FPL("foo\\") },
1168    { FPL("foo/bar\\"), FPL("foo\\bar\\") },
1169    { FPL("foo\\bar/"), FPL("foo\\bar\\") },
1170    { FPL("foo/bar/"), FPL("foo\\bar\\") },
1171    { FPL("foo\\bar\\"), FPL("foo\\bar\\") },
1172    { FPL("\\foo/bar"), FPL("\\foo\\bar") },
1173    { FPL("/foo\\bar"), FPL("\\foo\\bar") },
1174    { FPL("c:/foo/bar/"), FPL("c:\\foo\\bar\\") },
1175    { FPL("/foo/bar/"), FPL("\\foo\\bar\\") },
1176    { FPL("\\foo\\bar\\"), FPL("\\foo\\bar\\") },
1177    { FPL("c:\\foo/bar"), FPL("c:\\foo\\bar") },
1178    { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1179    { FPL("\\\\foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1180    { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") },
1181    // This method does not normalize the number of path separators.
1182    { FPL("foo\\\\bar"), FPL("foo\\\\bar") },
1183    { FPL("foo//bar"), FPL("foo\\\\bar") },
1184    { FPL("foo/\\bar"), FPL("foo\\\\bar") },
1185    { FPL("foo\\/bar"), FPL("foo\\\\bar") },
1186    { FPL("///foo\\\\bar"), FPL("\\\\\\foo\\\\bar") },
1187    { FPL("foo//bar///"), FPL("foo\\\\bar\\\\\\") },
1188    { FPL("foo/\\bar/\\"), FPL("foo\\\\bar\\\\") },
1189    { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") },
1190  };
1191  for (size_t i = 0; i < arraysize(cases); ++i) {
1192    FilePath input(cases[i].input);
1193    FilePath observed = input.NormalizePathSeparators();
1194    EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) <<
1195              "i: " << i << ", input: " << input.value();
1196  }
1197}
1198#endif
1199
1200TEST_F(FilePathTest, EndsWithSeparator) {
1201  const UnaryBooleanTestData cases[] = {
1202    { FPL(""), false },
1203    { FPL("/"), true },
1204    { FPL("foo/"), true },
1205    { FPL("bar"), false },
1206    { FPL("/foo/bar"), false },
1207  };
1208  for (size_t i = 0; i < arraysize(cases); ++i) {
1209    FilePath input = FilePath(cases[i].input).NormalizePathSeparators();
1210    EXPECT_EQ(cases[i].expected, input.EndsWithSeparator());
1211  }
1212}
1213
1214TEST_F(FilePathTest, AsEndingWithSeparator) {
1215  const UnaryTestData cases[] = {
1216    { FPL(""), FPL("") },
1217    { FPL("/"), FPL("/") },
1218    { FPL("foo"), FPL("foo/") },
1219    { FPL("foo/"), FPL("foo/") }
1220  };
1221  for (size_t i = 0; i < arraysize(cases); ++i) {
1222    FilePath input = FilePath(cases[i].input).NormalizePathSeparators();
1223    FilePath expected = FilePath(cases[i].expected).NormalizePathSeparators();
1224    EXPECT_EQ(expected.value(), input.AsEndingWithSeparator().value());
1225  }
1226}
1227
1228}  // namespace base
1229