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 14 matching lines...) Expand all Loading... |
25 struct BinaryTestData { | 25 struct BinaryTestData { |
26 const FilePath::CharType* inputs[2]; | 26 const FilePath::CharType* inputs[2]; |
27 const FilePath::CharType* expected; | 27 const FilePath::CharType* expected; |
28 }; | 28 }; |
29 | 29 |
30 struct BinaryBooleanTestData { | 30 struct BinaryBooleanTestData { |
31 const FilePath::CharType* inputs[2]; | 31 const FilePath::CharType* inputs[2]; |
32 bool expected; | 32 bool expected; |
33 }; | 33 }; |
34 | 34 |
| 35 struct BinaryIntTestData { |
| 36 const FilePath::CharType* inputs[2]; |
| 37 int expected; |
| 38 }; |
| 39 |
35 // file_util winds up using autoreleased objects on the Mac, so this needs | 40 // file_util winds up using autoreleased objects on the Mac, so this needs |
36 // to be a PlatformTest | 41 // to be a PlatformTest |
37 class FilePathTest : public PlatformTest { | 42 class FilePathTest : public PlatformTest { |
38 protected: | 43 protected: |
39 virtual void SetUp() { | 44 virtual void SetUp() { |
40 PlatformTest::SetUp(); | 45 PlatformTest::SetUp(); |
41 } | 46 } |
42 virtual void TearDown() { | 47 virtual void TearDown() { |
43 PlatformTest::TearDown(); | 48 PlatformTest::TearDown(); |
44 } | 49 } |
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 for (unsigned int i = 0; i < arraysize(cases); ++i) { | 939 for (unsigned int i = 0; i < arraysize(cases); ++i) { |
935 FilePath path(cases[i].inputs[0]); | 940 FilePath path(cases[i].inputs[0]); |
936 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); | 941 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); |
937 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << | 942 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << |
938 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; | 943 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; |
939 } | 944 } |
940 } | 945 } |
941 | 946 |
942 TEST_F(FilePathTest, MatchesExtension) { | 947 TEST_F(FilePathTest, MatchesExtension) { |
943 const struct BinaryBooleanTestData cases[] = { | 948 const struct BinaryBooleanTestData cases[] = { |
944 { { FPL("foo"), FPL("") }, true}, | 949 { { FPL("foo"), FPL("") }, true}, |
945 { { FPL("foo"), FPL(".") }, false}, | 950 { { FPL("foo"), FPL(".") }, false}, |
946 { { FPL("foo."), FPL("") }, false}, | 951 { { FPL("foo."), FPL("") }, false}, |
947 { { FPL("foo."), FPL(".") }, true}, | 952 { { FPL("foo."), FPL(".") }, true}, |
948 { { FPL("foo.txt"), FPL(".dll") }, false}, | 953 { { FPL("foo.txt"), FPL(".dll") }, false}, |
949 { { FPL("foo.txt"), FPL(".txt") }, true}, | 954 { { FPL("foo.txt"), FPL(".txt") }, true}, |
950 { { FPL("foo.txt.dll"), FPL(".txt") }, false}, | 955 { { FPL("foo.txt.dll"), FPL(".txt") }, false}, |
951 { { FPL("foo.txt.dll"), FPL(".dll") }, true}, | 956 { { FPL("foo.txt.dll"), FPL(".dll") }, 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 { { FPL("foo.tXt"), FPL(".TXT") }, true}, |
| 962 { { FPL("foo.tXt"), FPL(".tXt") }, true}, |
952 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 963 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
953 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false}, | 964 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false}, |
954 { { FPL("c:/foo.txt"), FPL(".txt") }, true}, | 965 { { FPL("c:/foo.txt"), FPL(".txt") }, true}, |
955 #endif // FILE_PATH_USES_DRIVE_LETTERS | 966 #endif // FILE_PATH_USES_DRIVE_LETTERS |
956 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 967 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
957 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false}, | 968 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false}, |
958 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true}, | 969 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true}, |
959 #endif // FILE_PATH_USES_DRIVE_LETTERS | 970 #endif // FILE_PATH_USES_DRIVE_LETTERS |
960 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false}, | 971 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false}, |
961 { { FPL("/bar/foo.txt"), FPL(".txt") }, true}, | 972 { { FPL("/bar/foo.txt"), FPL(".txt") }, true}, |
| 973 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 974 // Umlauts A, O, U: direct comparison, and upper case vs. lower case |
| 975 { { FPL("foo.\u00E4\u00F6\u00FC"), FPL(".\u00E4\u00F6\u00FC") }, true}, |
| 976 { { FPL("foo.\u00C4\u00D6\u00DC"), FPL(".\u00E4\u00F6\u00FC") }, true}, |
| 977 // C with circumflex: direct comparison, and upper case vs. lower case |
| 978 { { FPL("foo.\u0109"), FPL(".\u0109") }, true}, |
| 979 { { FPL("foo.\u0108"), FPL(".\u0109") }, true}, |
| 980 #endif |
962 }; | 981 }; |
963 | 982 |
964 for (size_t i = 0; i < arraysize(cases); ++i) { | 983 for (size_t i = 0; i < arraysize(cases); ++i) { |
965 FilePath path(cases[i].inputs[0]); | 984 FilePath path(cases[i].inputs[0]); |
966 FilePath::StringType ext(cases[i].inputs[1]); | 985 FilePath::StringType ext(cases[i].inputs[1]); |
967 | 986 |
968 EXPECT_EQ(cases[i].expected, path.MatchesExtension(ext)) << | 987 EXPECT_EQ(cases[i].expected, path.MatchesExtension(ext)) << |
969 "i: " << i << ", path: " << path.value() << ", ext: " << ext; | 988 "i: " << i << ", path: " << path.value() << ", ext: " << ext; |
970 } | 989 } |
971 } | 990 } |
972 | 991 |
| 992 TEST_F(FilePathTest, CompareIgnoreCase) { |
| 993 const struct BinaryIntTestData cases[] = { |
| 994 { { FPL("foo"), FPL("foo") }, 0}, |
| 995 { { FPL("FOO"), FPL("foo") }, 0}, |
| 996 { { FPL("foo.ext"), FPL("foo.ext") }, 0}, |
| 997 { { FPL("FOO.EXT"), FPL("foo.ext") }, 0}, |
| 998 { { FPL("Foo.Ext"), FPL("foo.ext") }, 0}, |
| 999 { { FPL("foO"), FPL("foo") }, 0}, |
| 1000 { { FPL("foo"), FPL("foO") }, 0}, |
| 1001 { { FPL("fOo"), FPL("foo") }, 0}, |
| 1002 { { FPL("foo"), FPL("fOo") }, 0}, |
| 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 { { FPL("BAR"), FPL("FOO") }, -1}, |
| 1010 { { FPL("FOO"), FPL("BAR") }, 1}, |
| 1011 // German "Eszett" (lower case and the new-fangled upper case) |
| 1012 // Note that uc(<lowercase eszett>) => "SS", NOT <uppercase eszett>! |
| 1013 // However, neither Windows nor Mac OSX converts these. |
| 1014 // (or even have glyphs for <uppercase eszett>) |
| 1015 { { FPL("\u00DF"), FPL("\u00DF") }, 0}, |
| 1016 { { FPL("\u1E9E"), FPL("\u1E9E") }, 0}, |
| 1017 { { FPL("\u00DF"), FPL("\u1E9E") }, -1}, |
| 1018 { { FPL("SS"), FPL("\u00DF") }, -1}, |
| 1019 { { FPL("SS"), FPL("\u1E9E") }, -1}, |
| 1020 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 1021 // Umlauts A, O, U: direct comparison, and upper case vs. lower case |
| 1022 { { FPL("\u00E4\u00F6\u00FC"), FPL("\u00E4\u00F6\u00FC") }, 0}, |
| 1023 { { FPL("\u00C4\u00D6\u00DC"), FPL("\u00E4\u00F6\u00FC") }, 0}, |
| 1024 // C with circumflex: direct comparison, and upper case vs. lower case |
| 1025 { { FPL("\u0109"), FPL("\u0109") }, 0}, |
| 1026 { { FPL("\u0108"), FPL("\u0109") }, 0}, |
| 1027 // Cyrillic letter SHA: direct comparison, and upper case vs. lower case |
| 1028 { { FPL("\u0428"), FPL("\u0428") }, 0}, |
| 1029 { { FPL("\u0428"), FPL("\u0448") }, 0}, |
| 1030 // Greek letter DELTA: direct comparison, and upper case vs. lower case |
| 1031 { { FPL("\u0394"), FPL("\u0394") }, 0}, |
| 1032 { { FPL("\u0394"), FPL("\u03B4") }, 0}, |
| 1033 // Japanese full-width A: direct comparison, and upper case vs. lower case |
| 1034 // Note that full-width and standard characters are considered different. |
| 1035 { { FPL("\uFF21"), FPL("\uFF21") }, 0}, |
| 1036 { { FPL("\uFF21"), FPL("\uFF41") }, 0}, |
| 1037 { { FPL("A"), FPL("\uFF21") }, -1}, |
| 1038 { { FPL("A"), FPL("\uFF41") }, -1}, |
| 1039 { { FPL("a"), FPL("\uFF21") }, -1}, |
| 1040 { { FPL("a"), FPL("\uFF41") }, -1}, |
| 1041 #endif |
| 1042 #if defined(OS_MACOSX) |
| 1043 // Codepoints > 0x1000 |
| 1044 // Georgian letter DON: direct comparison, and upper case vs. lower case |
| 1045 { { FPL("\u10A3"), FPL("\u10A3") }, 0}, |
| 1046 { { FPL("\u10A3"), FPL("\u10D3") }, 0}, |
| 1047 // Combining characters vs. pre-composed characters, upper and lower case |
| 1048 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E31\u1E77\u1E53n") }, 0}, |
| 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("KUON"), FPL("K\u0301U\u032DO\u0304\u0301N") }, -1}, |
| 1053 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("KUON") }, 1}, |
| 1054 { { FPL("K\u0301U\u032DO\u0304\u0301N"), FPL("\u1E31\u1E77\u1E53n") }, 0}, |
| 1055 { { FPL("k\u0301u\u032Do\u0304\u0301n"), FPL("\u1E30\u1E76\u1E52n") }, 0}, |
| 1056 { { FPL("k\u0301u\u032Do\u0304\u0302n"), FPL("\u1E30\u1E76\u1E52n") }, 1}, |
| 1057 #endif |
| 1058 }; |
| 1059 |
| 1060 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 1061 FilePath::StringType s1(cases[i].inputs[0]); |
| 1062 FilePath::StringType s2(cases[i].inputs[1]); |
| 1063 int result = FilePath::CompareIgnoreCase(s1, s2); |
| 1064 EXPECT_EQ(cases[i].expected, result) << |
| 1065 "i: " << i << ", s1: " << s1 << ", s2: " << s2; |
| 1066 } |
| 1067 } |
| 1068 |
973 TEST_F(FilePathTest, ReferencesParent) { | 1069 TEST_F(FilePathTest, ReferencesParent) { |
974 const struct UnaryBooleanTestData cases[] = { | 1070 const struct UnaryBooleanTestData cases[] = { |
975 { FPL("."), false }, | 1071 { FPL("."), false }, |
976 { FPL(".."), true }, | 1072 { FPL(".."), true }, |
977 { FPL("a.."), false }, | 1073 { FPL("a.."), false }, |
978 { FPL("..a"), false }, | 1074 { FPL("..a"), false }, |
979 { FPL("../"), true }, | 1075 { FPL("../"), true }, |
980 { FPL("/.."), true }, | 1076 { FPL("/.."), true }, |
981 { FPL("/../"), true }, | 1077 { FPL("/../"), true }, |
982 { FPL("/a../"), false }, | 1078 { FPL("/a../"), false }, |
(...skipping 10 matching lines...) Expand all Loading... |
993 { FPL("a/b/c"), false }, | 1089 { FPL("a/b/c"), false }, |
994 }; | 1090 }; |
995 | 1091 |
996 for (size_t i = 0; i < arraysize(cases); ++i) { | 1092 for (size_t i = 0; i < arraysize(cases); ++i) { |
997 FilePath input(cases[i].input); | 1093 FilePath input(cases[i].input); |
998 bool observed = input.ReferencesParent(); | 1094 bool observed = input.ReferencesParent(); |
999 EXPECT_EQ(cases[i].expected, observed) << | 1095 EXPECT_EQ(cases[i].expected, observed) << |
1000 "i: " << i << ", input: " << input.value(); | 1096 "i: " << i << ", input: " << input.value(); |
1001 } | 1097 } |
1002 } | 1098 } |
OLD | NEW |