Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: base/file_path_unittest.cc

Issue 337042: Revert 30168 - Commit patch set from http://codereview.chromium.org/149796... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_path.cc ('k') | chrome/browser/download/download_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
40 // file_util winds up using autoreleased objects on the Mac, so this needs 35 // file_util winds up using autoreleased objects on the Mac, so this needs
41 // to be a PlatformTest 36 // to be a PlatformTest
42 class FilePathTest : public PlatformTest { 37 class FilePathTest : public PlatformTest {
43 protected: 38 protected:
44 virtual void SetUp() { 39 virtual void SetUp() {
45 PlatformTest::SetUp(); 40 PlatformTest::SetUp();
46 } 41 }
47 virtual void TearDown() { 42 virtual void TearDown() {
48 PlatformTest::TearDown(); 43 PlatformTest::TearDown();
49 } 44 }
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 for (unsigned int i = 0; i < arraysize(cases); ++i) { 934 for (unsigned int i = 0; i < arraysize(cases); ++i) {
940 FilePath path(cases[i].inputs[0]); 935 FilePath path(cases[i].inputs[0]);
941 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); 936 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]);
942 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << 937 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i <<
943 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; 938 ", path: " << path.value() << ", replace: " << cases[i].inputs[1];
944 } 939 }
945 } 940 }
946 941
947 TEST_F(FilePathTest, MatchesExtension) { 942 TEST_F(FilePathTest, MatchesExtension) {
948 const struct BinaryBooleanTestData cases[] = { 943 const struct BinaryBooleanTestData cases[] = {
949 { { FPL("foo"), FPL("") }, true}, 944 { { FPL("foo"), FPL("") }, true},
950 { { FPL("foo"), FPL(".") }, false}, 945 { { FPL("foo"), FPL(".") }, false},
951 { { FPL("foo."), FPL("") }, false}, 946 { { FPL("foo."), FPL("") }, false},
952 { { FPL("foo."), FPL(".") }, true}, 947 { { FPL("foo."), FPL(".") }, true},
953 { { FPL("foo.txt"), FPL(".dll") }, false}, 948 { { FPL("foo.txt"), FPL(".dll") }, false},
954 { { FPL("foo.txt"), FPL(".txt") }, true}, 949 { { FPL("foo.txt"), FPL(".txt") }, true},
955 { { FPL("foo.txt.dll"), FPL(".txt") }, false}, 950 { { FPL("foo.txt.dll"), FPL(".txt") }, false},
956 { { FPL("foo.txt.dll"), FPL(".dll") }, true}, 951 { { 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},
963 #if defined(FILE_PATH_USES_DRIVE_LETTERS) 952 #if defined(FILE_PATH_USES_DRIVE_LETTERS)
964 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false}, 953 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false},
965 { { FPL("c:/foo.txt"), FPL(".txt") }, true}, 954 { { FPL("c:/foo.txt"), FPL(".txt") }, true},
966 #endif // FILE_PATH_USES_DRIVE_LETTERS 955 #endif // FILE_PATH_USES_DRIVE_LETTERS
967 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 956 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
968 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false}, 957 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false},
969 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true}, 958 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true},
970 #endif // FILE_PATH_USES_DRIVE_LETTERS 959 #endif // FILE_PATH_USES_DRIVE_LETTERS
971 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false}, 960 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false},
972 { { FPL("/bar/foo.txt"), FPL(".txt") }, true}, 961 { { 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
981 }; 962 };
982 963
983 for (size_t i = 0; i < arraysize(cases); ++i) { 964 for (size_t i = 0; i < arraysize(cases); ++i) {
984 FilePath path(cases[i].inputs[0]); 965 FilePath path(cases[i].inputs[0]);
985 FilePath::StringType ext(cases[i].inputs[1]); 966 FilePath::StringType ext(cases[i].inputs[1]);
986 967
987 EXPECT_EQ(cases[i].expected, path.MatchesExtension(ext)) << 968 EXPECT_EQ(cases[i].expected, path.MatchesExtension(ext)) <<
988 "i: " << i << ", path: " << path.value() << ", ext: " << ext; 969 "i: " << i << ", path: " << path.value() << ", ext: " << ext;
989 } 970 }
990 } 971 }
991 972
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
1069 TEST_F(FilePathTest, ReferencesParent) { 973 TEST_F(FilePathTest, ReferencesParent) {
1070 const struct UnaryBooleanTestData cases[] = { 974 const struct UnaryBooleanTestData cases[] = {
1071 { FPL("."), false }, 975 { FPL("."), false },
1072 { FPL(".."), true }, 976 { FPL(".."), true },
1073 { FPL("a.."), false }, 977 { FPL("a.."), false },
1074 { FPL("..a"), false }, 978 { FPL("..a"), false },
1075 { FPL("../"), true }, 979 { FPL("../"), true },
1076 { FPL("/.."), true }, 980 { FPL("/.."), true },
1077 { FPL("/../"), true }, 981 { FPL("/../"), true },
1078 { FPL("/a../"), false }, 982 { FPL("/a../"), false },
(...skipping 10 matching lines...) Expand all
1089 { FPL("a/b/c"), false }, 993 { FPL("a/b/c"), false },
1090 }; 994 };
1091 995
1092 for (size_t i = 0; i < arraysize(cases); ++i) { 996 for (size_t i = 0; i < arraysize(cases); ++i) {
1093 FilePath input(cases[i].input); 997 FilePath input(cases[i].input);
1094 bool observed = input.ReferencesParent(); 998 bool observed = input.ReferencesParent();
1095 EXPECT_EQ(cases[i].expected, observed) << 999 EXPECT_EQ(cases[i].expected, observed) <<
1096 "i: " << i << ", input: " << input.value(); 1000 "i: " << i << ", input: " << input.value();
1097 } 1001 }
1098 } 1002 }
1099
OLDNEW
« no previous file with comments | « base/file_path.cc ('k') | chrome/browser/download/download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698