OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 { { FPL("c:/"), FPL("c:/") }, true}, | 654 { { FPL("c:/"), FPL("c:/") }, true}, |
655 { { FPL("c:"), FPL("c:") }, true}, | 655 { { FPL("c:"), FPL("c:") }, true}, |
656 { { FPL("c:/foo/bar"), FPL("d:/foo/bar") }, false}, | 656 { { FPL("c:/foo/bar"), FPL("d:/foo/bar") }, false}, |
657 { { FPL("c:/foo/bar"), FPL("D:/foo/bar") }, false}, | 657 { { FPL("c:/foo/bar"), FPL("D:/foo/bar") }, false}, |
658 { { FPL("C:/foo/bar"), FPL("d:/foo/bar") }, false}, | 658 { { FPL("C:/foo/bar"), FPL("d:/foo/bar") }, false}, |
659 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar") }, false}, | 659 { { FPL("c:/foo/bar"), FPL("c:/foo2/bar") }, false}, |
660 #endif // FILE_PATH_USES_DRIVE_LETTERS | 660 #endif // FILE_PATH_USES_DRIVE_LETTERS |
661 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 661 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
662 { { FPL("\\foo\\bar"), FPL("\\foo\\bar") }, true}, | 662 { { FPL("\\foo\\bar"), FPL("\\foo\\bar") }, true}, |
663 { { FPL("\\foo/bar"), FPL("\\foo/bar") }, true}, | 663 { { FPL("\\foo/bar"), FPL("\\foo/bar") }, true}, |
664 { { FPL("\\foo/bar"), FPL("\\foo\bar") }, false}, | 664 { { FPL("\\foo/bar"), FPL("\\foo\\bar") }, false}, |
665 { { FPL("\\"), FPL("\\") }, true}, | 665 { { FPL("\\"), FPL("\\") }, true}, |
666 { { FPL("\\"), FPL("/") }, false}, | 666 { { FPL("\\"), FPL("/") }, false}, |
667 { { FPL(""), FPL("\\") }, false}, | 667 { { FPL(""), FPL("\\") }, false}, |
668 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar") }, false}, | 668 { { FPL("\\foo\\bar"), FPL("\\foo2\\bar") }, false}, |
669 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2") }, false}, | 669 { { FPL("\\foo\\bar"), FPL("\\foo\\bar2") }, false}, |
670 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 670 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
671 { { FPL("c:\\foo\\bar"), FPL("c:\\foo\\bar") }, true}, | 671 { { FPL("c:\\foo\\bar"), FPL("c:\\foo\\bar") }, true}, |
672 { { FPL("E:\\foo\\bar"), FPL("e:\\foo\\bar") }, true}, | 672 { { FPL("E:\\foo\\bar"), FPL("e:\\foo\\bar") }, true}, |
673 { { FPL("f:\\foo\\bar"), FPL("F:\\foo/bar") }, false}, | 673 { { FPL("f:\\foo\\bar"), FPL("F:\\foo/bar") }, false}, |
674 #endif // FILE_PATH_USES_DRIVE_LETTERS | 674 #endif // FILE_PATH_USES_DRIVE_LETTERS |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 { FPL("a/b/c"), false }, | 997 { FPL("a/b/c"), false }, |
998 }; | 998 }; |
999 | 999 |
1000 for (size_t i = 0; i < arraysize(cases); ++i) { | 1000 for (size_t i = 0; i < arraysize(cases); ++i) { |
1001 FilePath input(cases[i].input); | 1001 FilePath input(cases[i].input); |
1002 bool observed = input.ReferencesParent(); | 1002 bool observed = input.ReferencesParent(); |
1003 EXPECT_EQ(cases[i].expected, observed) << | 1003 EXPECT_EQ(cases[i].expected, observed) << |
1004 "i: " << i << ", input: " << input.value(); | 1004 "i: " << i << ", input: " << input.value(); |
1005 } | 1005 } |
1006 } | 1006 } |
| 1007 |
| 1008 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 1009 TEST_F(FilePathTest, NormalizeWindowsPathSeparators) { |
| 1010 const struct UnaryTestData cases[] = { |
| 1011 { FPL("foo/bar"), FPL("foo\\bar") }, |
| 1012 { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") }, |
| 1013 { FPL("foo\\bar"), FPL("foo\\bar") }, |
| 1014 { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") }, |
| 1015 { FPL("foo"), FPL("foo") }, |
| 1016 // Trailing slashes don't automatically get stripped. That's what |
| 1017 // StripTrailingSeparators() is for. |
| 1018 { FPL("foo\\"), FPL("foo\\") }, |
| 1019 { FPL("foo/"), FPL("foo\\") }, |
| 1020 { FPL("foo/bar\\"), FPL("foo\\bar\\") }, |
| 1021 { FPL("foo\\bar/"), FPL("foo\\bar\\") }, |
| 1022 { FPL("foo/bar/"), FPL("foo\\bar\\") }, |
| 1023 { FPL("foo\\bar\\"), FPL("foo\\bar\\") }, |
| 1024 { FPL("\\foo/bar"), FPL("\\foo\\bar") }, |
| 1025 { FPL("/foo\\bar"), FPL("\\foo\\bar") }, |
| 1026 { FPL("c:/foo/bar/"), FPL("c:\\foo\\bar\\") }, |
| 1027 { FPL("/foo/bar/"), FPL("\\foo\\bar\\") }, |
| 1028 { FPL("\\foo\\bar\\"), FPL("\\foo\\bar\\") }, |
| 1029 { FPL("c:\\foo/bar"), FPL("c:\\foo\\bar") }, |
| 1030 { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") }, |
| 1031 { FPL("\\\\foo\\bar\\"), FPL("\\\\foo\\bar\\") }, |
| 1032 { FPL("//foo\\bar\\"), FPL("\\\\foo\\bar\\") }, |
| 1033 // This method does not normalize the number of path separators. |
| 1034 { FPL("foo\\\\bar"), FPL("foo\\\\bar") }, |
| 1035 { FPL("foo//bar"), FPL("foo\\\\bar") }, |
| 1036 { FPL("foo/\\bar"), FPL("foo\\\\bar") }, |
| 1037 { FPL("foo\\/bar"), FPL("foo\\\\bar") }, |
| 1038 { FPL("///foo\\\\bar"), FPL("\\\\\\foo\\\\bar") }, |
| 1039 { FPL("foo//bar///"), FPL("foo\\\\bar\\\\\\") }, |
| 1040 { FPL("foo/\\bar/\\"), FPL("foo\\\\bar\\\\") }, |
| 1041 { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") }, |
| 1042 }; |
| 1043 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 1044 FilePath input(cases[i].input); |
| 1045 FilePath observed = input.NormalizeWindowsPathSeparators(); |
| 1046 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << |
| 1047 "i: " << i << ", input: " << input.value(); |
| 1048 } |
| 1049 } |
| 1050 #endif |
OLD | NEW |