OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.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 19 matching lines...) Expand all Loading... |
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 { | 35 struct BinaryIntTestData { |
36 const FilePath::CharType* inputs[2]; | 36 const FilePath::CharType* inputs[2]; |
37 int expected; | 37 int expected; |
38 }; | 38 }; |
39 | 39 |
| 40 struct UTF8TestData { |
| 41 const FilePath::CharType* native; |
| 42 const char* utf8; |
| 43 }; |
| 44 |
40 // file_util winds up using autoreleased objects on the Mac, so this needs | 45 // file_util winds up using autoreleased objects on the Mac, so this needs |
41 // to be a PlatformTest | 46 // to be a PlatformTest |
42 class FilePathTest : public PlatformTest { | 47 class FilePathTest : public PlatformTest { |
43 protected: | 48 protected: |
44 virtual void SetUp() { | 49 virtual void SetUp() { |
45 PlatformTest::SetUp(); | 50 PlatformTest::SetUp(); |
46 } | 51 } |
47 virtual void TearDown() { | 52 virtual void TearDown() { |
48 PlatformTest::TearDown(); | 53 PlatformTest::TearDown(); |
49 } | 54 } |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 }; | 1042 }; |
1038 | 1043 |
1039 for (size_t i = 0; i < arraysize(cases); ++i) { | 1044 for (size_t i = 0; i < arraysize(cases); ++i) { |
1040 FilePath input(cases[i].input); | 1045 FilePath input(cases[i].input); |
1041 bool observed = input.ReferencesParent(); | 1046 bool observed = input.ReferencesParent(); |
1042 EXPECT_EQ(cases[i].expected, observed) << | 1047 EXPECT_EQ(cases[i].expected, observed) << |
1043 "i: " << i << ", input: " << input.value(); | 1048 "i: " << i << ", input: " << input.value(); |
1044 } | 1049 } |
1045 } | 1050 } |
1046 | 1051 |
| 1052 TEST_F(FilePathTest, FromUTF8Unsafe_And_AsUTF8Unsafe) { |
| 1053 const struct UTF8TestData cases[] = { |
| 1054 { FPL("foo.txt"), "foo.txt" }, |
| 1055 // "aeo" with accents. Use http://0xcc.net/jsescape/ to decode them. |
| 1056 { FPL("\u00E0\u00E8\u00F2.txt"), "\xC3\xA0\xC3\xA8\xC3\xB2.txt" }, |
| 1057 // Full-width "ABC". |
| 1058 { FPL("\uFF21\uFF22\uFF23.txt"), |
| 1059 "\xEF\xBC\xA1\xEF\xBC\xA2\xEF\xBC\xA3.txt" }, |
| 1060 }; |
| 1061 |
| 1062 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 1063 // Test FromUTF8Unsafe() works. |
| 1064 FilePath from_utf8 = FilePath::FromUTF8Unsafe(cases[i].utf8); |
| 1065 EXPECT_EQ(cases[i].native, from_utf8.value()) |
| 1066 << "i: " << i << ", input: " << cases[i].native; |
| 1067 // Test AsUTF8Unsafe() works. |
| 1068 FilePath from_native = FilePath(cases[i].native); |
| 1069 EXPECT_EQ(cases[i].utf8, from_native.AsUTF8Unsafe()) |
| 1070 << "i: " << i << ", input: " << cases[i].native; |
| 1071 // Test the two file paths are identical. |
| 1072 EXPECT_EQ(from_utf8.value(), from_native.value()); |
| 1073 } |
| 1074 } |
| 1075 |
1047 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 1076 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
1048 TEST_F(FilePathTest, NormalizeWindowsPathSeparators) { | 1077 TEST_F(FilePathTest, NormalizeWindowsPathSeparators) { |
1049 const struct UnaryTestData cases[] = { | 1078 const struct UnaryTestData cases[] = { |
1050 { FPL("foo/bar"), FPL("foo\\bar") }, | 1079 { FPL("foo/bar"), FPL("foo\\bar") }, |
1051 { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") }, | 1080 { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") }, |
1052 { FPL("foo\\bar"), FPL("foo\\bar") }, | 1081 { FPL("foo\\bar"), FPL("foo\\bar") }, |
1053 { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") }, | 1082 { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") }, |
1054 { FPL("foo"), FPL("foo") }, | 1083 { FPL("foo"), FPL("foo") }, |
1055 // Trailing slashes don't automatically get stripped. That's what | 1084 // Trailing slashes don't automatically get stripped. That's what |
1056 // StripTrailingSeparators() is for. | 1085 // StripTrailingSeparators() is for. |
(...skipping 22 matching lines...) Expand all Loading... |
1079 { FPL("foo/\\bar/\\"), FPL("foo\\\\bar\\\\") }, | 1108 { FPL("foo/\\bar/\\"), FPL("foo\\\\bar\\\\") }, |
1080 { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") }, | 1109 { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") }, |
1081 }; | 1110 }; |
1082 for (size_t i = 0; i < arraysize(cases); ++i) { | 1111 for (size_t i = 0; i < arraysize(cases); ++i) { |
1083 FilePath input(cases[i].input); | 1112 FilePath input(cases[i].input); |
1084 FilePath observed = input.NormalizeWindowsPathSeparators(); | 1113 FilePath observed = input.NormalizeWindowsPathSeparators(); |
1085 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << | 1114 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << |
1086 "i: " << i << ", input: " << input.value(); | 1115 "i: " << i << ", input: " << input.value(); |
1087 } | 1116 } |
1088 } | 1117 } |
| 1118 |
1089 #endif | 1119 #endif |
OLD | NEW |