OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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" |
11 | 11 |
12 // This macro helps avoid wrapped lines in the test structs. | 12 // This macro helps avoid wrapped lines in the test structs. |
13 #define FPL(x) FILE_PATH_LITERAL(x) | 13 #define FPL(x) FILE_PATH_LITERAL(x) |
14 | 14 |
15 // This macro constructs strings which can contain NULs. | |
16 #define FPS(x) FilePath::StringType(FPL(x), arraysize(FPL(x)) - 1) | |
17 | |
15 struct UnaryTestData { | 18 struct UnaryTestData { |
16 const FilePath::CharType* input; | 19 const FilePath::CharType* input; |
17 const FilePath::CharType* expected; | 20 const FilePath::CharType* expected; |
18 }; | 21 }; |
19 | 22 |
20 struct UnaryBooleanTestData { | 23 struct UnaryBooleanTestData { |
21 const FilePath::CharType* input; | 24 const FilePath::CharType* input; |
22 bool expected; | 25 bool expected; |
23 }; | 26 }; |
24 | 27 |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1108 << "i: " << i << ", input: " << cases[i].native; | 1111 << "i: " << i << ", input: " << cases[i].native; |
1109 // Test AsUTF8Unsafe() works. | 1112 // Test AsUTF8Unsafe() works. |
1110 FilePath from_native = FilePath(cases[i].native); | 1113 FilePath from_native = FilePath(cases[i].native); |
1111 EXPECT_EQ(cases[i].utf8, from_native.AsUTF8Unsafe()) | 1114 EXPECT_EQ(cases[i].utf8, from_native.AsUTF8Unsafe()) |
1112 << "i: " << i << ", input: " << cases[i].native; | 1115 << "i: " << i << ", input: " << cases[i].native; |
1113 // Test the two file paths are identical. | 1116 // Test the two file paths are identical. |
1114 EXPECT_EQ(from_utf8.value(), from_native.value()); | 1117 EXPECT_EQ(from_utf8.value(), from_native.value()); |
1115 } | 1118 } |
1116 } | 1119 } |
1117 | 1120 |
1121 // Test constructor strips '\0' | |
1122 TEST_F(FilePathTest, ConstructWithNUL) { | |
1123 FilePath path(FPS("a\0b")); | |
1124 EXPECT_EQ(path.value(), FPL("a")); | |
Chris Evans
2013/01/08 09:41:01
I'm not 100% sure how std::string equality works.
| |
1125 } | |
1126 | |
1127 // Test Append() strips '\0' | |
1128 TEST_F(FilePathTest, AppendWithNUL) { | |
1129 FilePath path(FPL("a")); | |
1130 path = path.Append(FPS("b\0b")); | |
1131 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | |
1132 EXPECT_EQ(path.value(), "a\\b"); | |
1133 #else | |
1134 EXPECT_EQ(path.value(), "a/b"); | |
Chris Evans
2013/01/08 09:41:01
Again, maybe check length() to be sure.
| |
1135 #endif | |
1136 } | |
1137 | |
1138 // Test ReferencesParent() doesn't break with "..\0" | |
1139 TEST_F(FilePathTest, ReferencesParentWithNUL) { | |
1140 FilePath path(FPS("..\0")); | |
1141 ASSERT_TRUE(path.ReferencesParent()); | |
1142 } | |
1143 | |
1118 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 1144 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
1119 TEST_F(FilePathTest, NormalizePathSeparators) { | 1145 TEST_F(FilePathTest, NormalizePathSeparators) { |
1120 const struct UnaryTestData cases[] = { | 1146 const struct UnaryTestData cases[] = { |
1121 { FPL("foo/bar"), FPL("foo\\bar") }, | 1147 { FPL("foo/bar"), FPL("foo\\bar") }, |
1122 { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") }, | 1148 { FPL("foo/bar\\betz"), FPL("foo\\bar\\betz") }, |
1123 { FPL("foo\\bar"), FPL("foo\\bar") }, | 1149 { FPL("foo\\bar"), FPL("foo\\bar") }, |
1124 { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") }, | 1150 { FPL("foo\\bar/betz"), FPL("foo\\bar\\betz") }, |
1125 { FPL("foo"), FPL("foo") }, | 1151 { FPL("foo"), FPL("foo") }, |
1126 // Trailing slashes don't automatically get stripped. That's what | 1152 // Trailing slashes don't automatically get stripped. That's what |
1127 // StripTrailingSeparators() is for. | 1153 // StripTrailingSeparators() is for. |
(...skipping 24 matching lines...) Expand all Loading... | |
1152 }; | 1178 }; |
1153 for (size_t i = 0; i < arraysize(cases); ++i) { | 1179 for (size_t i = 0; i < arraysize(cases); ++i) { |
1154 FilePath input(cases[i].input); | 1180 FilePath input(cases[i].input); |
1155 FilePath observed = input.NormalizePathSeparators(); | 1181 FilePath observed = input.NormalizePathSeparators(); |
1156 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << | 1182 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << |
1157 "i: " << i << ", input: " << input.value(); | 1183 "i: " << i << ", input: " << input.value(); |
1158 } | 1184 } |
1159 } | 1185 } |
1160 | 1186 |
1161 #endif | 1187 #endif |
OLD | NEW |