mark@chromium.org | 6380e26 | 2008-10-04 03:21:47 +0900 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
mark@chromium.org | 6380e26 | 2008-10-04 03:21:47 +0900 | [diff] [blame] | 5 | #include "base/basictypes.h" |
aa@chromium.org | 76e5c63 | 2008-12-18 17:38:16 +0900 | [diff] [blame] | 6 | #include "base/file_path.h" |
| 7 | #include "base/file_util.h" |
| 8 | #include "base/path_service.h" |
mark@chromium.org | e3e1ce7 | 2008-10-04 04:05:46 +0900 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
aa@chromium.org | 76e5c63 | 2008-12-18 17:38:16 +0900 | [diff] [blame] | 10 | #include "testing/platform_test.h" |
mark@chromium.org | 6380e26 | 2008-10-04 03:21:47 +0900 | [diff] [blame] | 11 | |
| 12 | // This macro helps avoid wrapped lines in the test structs. |
| 13 | #define FPL(x) FILE_PATH_LITERAL(x) |
| 14 | |
| 15 | struct UnaryTestData { |
| 16 | const FilePath::CharType* input; |
| 17 | const FilePath::CharType* expected; |
| 18 | }; |
| 19 | |
| 20 | struct UnaryBooleanTestData { |
| 21 | const FilePath::CharType* input; |
| 22 | bool expected; |
| 23 | }; |
| 24 | |
| 25 | struct BinaryTestData { |
| 26 | const FilePath::CharType* inputs[2]; |
| 27 | const FilePath::CharType* expected; |
| 28 | }; |
| 29 | |
aa@chromium.org | 76e5c63 | 2008-12-18 17:38:16 +0900 | [diff] [blame] | 30 | // file_util winds up using autoreleased objects on the Mac, so this needs |
| 31 | // to be a PlatformTest |
| 32 | class FilePathTest : public PlatformTest { |
| 33 | protected: |
| 34 | virtual void SetUp() { |
| 35 | PlatformTest::SetUp(); |
| 36 | } |
| 37 | virtual void TearDown() { |
| 38 | PlatformTest::TearDown(); |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | TEST_F(FilePathTest, DirName) { |
mark@chromium.org | 6380e26 | 2008-10-04 03:21:47 +0900 | [diff] [blame] | 43 | const struct UnaryTestData cases[] = { |
| 44 | { FPL(""), FPL(".") }, |
| 45 | { FPL("aa"), FPL(".") }, |
| 46 | { FPL("/aa/bb"), FPL("/aa") }, |
| 47 | { FPL("/aa/bb/"), FPL("/aa") }, |
| 48 | { FPL("/aa/bb//"), FPL("/aa") }, |
| 49 | { FPL("/aa/bb/ccc"), FPL("/aa/bb") }, |
| 50 | { FPL("/aa"), FPL("/") }, |
| 51 | { FPL("/aa/"), FPL("/") }, |
| 52 | { FPL("/"), FPL("/") }, |
| 53 | { FPL("//"), FPL("//") }, |
| 54 | { FPL("///"), FPL("/") }, |
| 55 | { FPL("aa/"), FPL(".") }, |
| 56 | { FPL("aa/bb"), FPL("aa") }, |
| 57 | { FPL("aa/bb/"), FPL("aa") }, |
| 58 | { FPL("aa/bb//"), FPL("aa") }, |
| 59 | { FPL("aa//bb//"), FPL("aa") }, |
| 60 | { FPL("aa//bb/"), FPL("aa") }, |
| 61 | { FPL("aa//bb"), FPL("aa") }, |
| 62 | { FPL("//aa/bb"), FPL("//aa") }, |
| 63 | { FPL("//aa/"), FPL("//") }, |
| 64 | { FPL("//aa"), FPL("//") }, |
| 65 | { FPL("0:"), FPL(".") }, |
| 66 | { FPL("@:"), FPL(".") }, |
| 67 | { FPL("[:"), FPL(".") }, |
| 68 | { FPL("`:"), FPL(".") }, |
| 69 | { FPL("{:"), FPL(".") }, |
| 70 | { FPL("\xB3:"), FPL(".") }, |
| 71 | { FPL("\xC5:"), FPL(".") }, |
| 72 | #if defined(OS_WIN) |
| 73 | { FPL("\x0143:"), FPL(".") }, |
| 74 | #endif // OS_WIN |
| 75 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 76 | { FPL("c:"), FPL("c:") }, |
| 77 | { FPL("C:"), FPL("C:") }, |
| 78 | { FPL("A:"), FPL("A:") }, |
| 79 | { FPL("Z:"), FPL("Z:") }, |
| 80 | { FPL("a:"), FPL("a:") }, |
| 81 | { FPL("z:"), FPL("z:") }, |
| 82 | { FPL("c:aa"), FPL("c:") }, |
| 83 | { FPL("c:/"), FPL("c:/") }, |
| 84 | { FPL("c://"), FPL("c://") }, |
| 85 | { FPL("c:///"), FPL("c:/") }, |
| 86 | { FPL("c:/aa"), FPL("c:/") }, |
| 87 | { FPL("c:/aa/"), FPL("c:/") }, |
| 88 | { FPL("c:/aa/bb"), FPL("c:/aa") }, |
| 89 | { FPL("c:aa/bb"), FPL("c:aa") }, |
| 90 | #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 91 | #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 92 | { FPL("\\aa\\bb"), FPL("\\aa") }, |
| 93 | { FPL("\\aa\\bb\\"), FPL("\\aa") }, |
| 94 | { FPL("\\aa\\bb\\\\"), FPL("\\aa") }, |
| 95 | { FPL("\\aa\\bb\\ccc"), FPL("\\aa\\bb") }, |
| 96 | { FPL("\\aa"), FPL("\\") }, |
| 97 | { FPL("\\aa\\"), FPL("\\") }, |
| 98 | { FPL("\\"), FPL("\\") }, |
| 99 | { FPL("\\\\"), FPL("\\\\") }, |
| 100 | { FPL("\\\\\\"), FPL("\\") }, |
| 101 | { FPL("aa\\"), FPL(".") }, |
| 102 | { FPL("aa\\bb"), FPL("aa") }, |
| 103 | { FPL("aa\\bb\\"), FPL("aa") }, |
| 104 | { FPL("aa\\bb\\\\"), FPL("aa") }, |
| 105 | { FPL("aa\\\\bb\\\\"), FPL("aa") }, |
| 106 | { FPL("aa\\\\bb\\"), FPL("aa") }, |
| 107 | { FPL("aa\\\\bb"), FPL("aa") }, |
| 108 | { FPL("\\\\aa\\bb"), FPL("\\\\aa") }, |
| 109 | { FPL("\\\\aa\\"), FPL("\\\\") }, |
| 110 | { FPL("\\\\aa"), FPL("\\\\") }, |
| 111 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 112 | { FPL("c:\\"), FPL("c:\\") }, |
| 113 | { FPL("c:\\\\"), FPL("c:\\\\") }, |
| 114 | { FPL("c:\\\\\\"), FPL("c:\\") }, |
| 115 | { FPL("c:\\aa"), FPL("c:\\") }, |
| 116 | { FPL("c:\\aa\\"), FPL("c:\\") }, |
| 117 | { FPL("c:\\aa\\bb"), FPL("c:\\aa") }, |
| 118 | { FPL("c:aa\\bb"), FPL("c:aa") }, |
| 119 | #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 120 | #endif // FILE_PATH_USES_WIN_SEPARATORS |
| 121 | }; |
| 122 | |
| 123 | for (size_t i = 0; i < arraysize(cases); ++i) { |
| 124 | FilePath input(cases[i].input); |
| 125 | FilePath observed = input.DirName(); |
| 126 | EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << |
| 127 | "i: " << i << ", input: " << input.value(); |
| 128 | } |
| 129 | } |
| 130 | |
aa@chromium.org | 76e5c63 | 2008-12-18 17:38:16 +0900 | [diff] [blame] | 131 | TEST_F(FilePathTest, BaseName) { |
mark@chromium.org | 6380e26 | 2008-10-04 03:21:47 +0900 | [diff] [blame] | 132 | const struct UnaryTestData cases[] = { |
| 133 | { FPL(""), FPL("") }, |
| 134 | { FPL("aa"), FPL("aa") }, |
| 135 | { FPL("/aa/bb"), FPL("bb") }, |
| 136 | { FPL("/aa/bb/"), FPL("bb") }, |
| 137 | { FPL("/aa/bb//"), FPL("bb") }, |
| 138 | { FPL("/aa/bb/ccc"), FPL("ccc") }, |
| 139 | { FPL("/aa"), FPL("aa") }, |
| 140 | { FPL("/"), FPL("/") }, |
| 141 | { FPL("//"), FPL("//") }, |
| 142 | { FPL("///"), FPL("/") }, |
| 143 | { FPL("aa/"), FPL("aa") }, |
| 144 | { FPL("aa/bb"), FPL("bb") }, |
| 145 | { FPL("aa/bb/"), FPL("bb") }, |
| 146 | { FPL("aa/bb//"), FPL("bb") }, |
| 147 | { FPL("aa//bb//"), FPL("bb") }, |
| 148 | { FPL("aa//bb/"), FPL("bb") }, |
| 149 | { FPL("aa//bb"), FPL("bb") }, |
| 150 | { FPL("//aa/bb"), FPL("bb") }, |
| 151 | { FPL("//aa/"), FPL("aa") }, |
| 152 | { FPL("//aa"), FPL("aa") }, |
| 153 | { FPL("0:"), FPL("0:") }, |
| 154 | { FPL("@:"), FPL("@:") }, |
| 155 | { FPL("[:"), FPL("[:") }, |
| 156 | { FPL("`:"), FPL("`:") }, |
| 157 | { FPL("{:"), FPL("{:") }, |
| 158 | { FPL("\xB3:"), FPL("\xB3:") }, |
| 159 | { FPL("\xC5:"), FPL("\xC5:") }, |
| 160 | #if defined(OS_WIN) |
| 161 | { FPL("\x0143:"), FPL("\x0143:") }, |
| 162 | #endif // OS_WIN |
| 163 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 164 | { FPL("c:"), FPL("") }, |
| 165 | { FPL("C:"), FPL("") }, |
| 166 | { FPL("A:"), FPL("") }, |
| 167 | { FPL("Z:"), FPL("") }, |
| 168 | { FPL("a:"), FPL("") }, |
| 169 | { FPL("z:"), FPL("") }, |
| 170 | { FPL("c:aa"), FPL("aa") }, |
| 171 | { FPL("c:/"), FPL("/") }, |
| 172 | { FPL("c://"), FPL("//") }, |
| 173 | { FPL("c:///"), FPL("/") }, |
| 174 | { FPL("c:/aa"), FPL("aa") }, |
| 175 | { FPL("c:/aa/"), FPL("aa") }, |
| 176 | { FPL("c:/aa/bb"), FPL("bb") }, |
| 177 | { FPL("c:aa/bb"), FPL("bb") }, |
| 178 | #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 179 | #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 180 | { FPL("\\aa\\bb"), FPL("bb") }, |
| 181 | { FPL("\\aa\\bb\\"), FPL("bb") }, |
| 182 | { FPL("\\aa\\bb\\\\"), FPL("bb") }, |
| 183 | { FPL("\\aa\\bb\\ccc"), FPL("ccc") }, |
| 184 | { FPL("\\aa"), FPL("aa") }, |
| 185 | { FPL("\\"), FPL("\\") }, |
| 186 | { FPL("\\\\"), FPL("\\\\") }, |
| 187 | { FPL("\\\\\\"), FPL("\\") }, |
| 188 | { FPL("aa\\"), FPL("aa") }, |
| 189 | { FPL("aa\\bb"), FPL("bb") }, |
| 190 | { FPL("aa\\bb\\"), FPL("bb") }, |
| 191 | { FPL("aa\\bb\\\\"), FPL("bb") }, |
| 192 | { FPL("aa\\\\bb\\\\"), FPL("bb") }, |
| 193 | { FPL("aa\\\\bb\\"), FPL("bb") }, |
| 194 | { FPL("aa\\\\bb"), FPL("bb") }, |
| 195 | { FPL("\\\\aa\\bb"), FPL("bb") }, |
| 196 | { FPL("\\\\aa\\"), FPL("aa") }, |
| 197 | { FPL("\\\\aa"), FPL("aa") }, |
| 198 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 199 | { FPL("c:\\"), FPL("\\") }, |
| 200 | { FPL("c:\\\\"), FPL("\\\\") }, |
| 201 | { FPL("c:\\\\\\"), FPL("\\") }, |
| 202 | { FPL("c:\\aa"), FPL("aa") }, |
| 203 | { FPL("c:\\aa\\"), FPL("aa") }, |
| 204 | { FPL("c:\\aa\\bb"), FPL("bb") }, |
| 205 | { FPL("c:aa\\bb"), FPL("bb") }, |
| 206 | #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 207 | #endif // FILE_PATH_USES_WIN_SEPARATORS |
| 208 | }; |
| 209 | |
| 210 | for (size_t i = 0; i < arraysize(cases); ++i) { |
| 211 | FilePath input(cases[i].input); |
estade@chromium.org | d872d68 | 2009-01-06 08:59:36 +0900 | [diff] [blame] | 212 | FilePath observed = input.BaseName(); |
| 213 | EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << |
mark@chromium.org | 6380e26 | 2008-10-04 03:21:47 +0900 | [diff] [blame] | 214 | "i: " << i << ", input: " << input.value(); |
| 215 | } |
| 216 | } |
| 217 | |
aa@chromium.org | 76e5c63 | 2008-12-18 17:38:16 +0900 | [diff] [blame] | 218 | TEST_F(FilePathTest, Append) { |
mark@chromium.org | 6380e26 | 2008-10-04 03:21:47 +0900 | [diff] [blame] | 219 | const struct BinaryTestData cases[] = { |
| 220 | { { FPL(""), FPL("cc") }, FPL("cc") }, |
| 221 | { { FPL("."), FPL("ff") }, FPL("ff") }, |
| 222 | { { FPL("/"), FPL("cc") }, FPL("/cc") }, |
| 223 | { { FPL("/aa"), FPL("") }, FPL("/aa") }, |
| 224 | { { FPL("/aa/"), FPL("") }, FPL("/aa") }, |
| 225 | { { FPL("//aa"), FPL("") }, FPL("//aa") }, |
| 226 | { { FPL("//aa/"), FPL("") }, FPL("//aa") }, |
| 227 | { { FPL("//"), FPL("aa") }, FPL("//aa") }, |
| 228 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 229 | { { FPL("c:"), FPL("a") }, FPL("c:a") }, |
| 230 | { { FPL("c:"), FPL("") }, FPL("c:") }, |
| 231 | { { FPL("c:/"), FPL("a") }, FPL("c:/a") }, |
| 232 | { { FPL("c://"), FPL("a") }, FPL("c://a") }, |
| 233 | { { FPL("c:///"), FPL("a") }, FPL("c:/a") }, |
| 234 | #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 235 | #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 236 | // Append introduces the default separator character, so these test cases |
| 237 | // need to be defined with different expected results on platforms that use |
| 238 | // different default separator characters. |
| 239 | { { FPL("\\"), FPL("cc") }, FPL("\\cc") }, |
| 240 | { { FPL("\\aa"), FPL("") }, FPL("\\aa") }, |
| 241 | { { FPL("\\aa\\"), FPL("") }, FPL("\\aa") }, |
| 242 | { { FPL("\\\\aa"), FPL("") }, FPL("\\\\aa") }, |
| 243 | { { FPL("\\\\aa\\"), FPL("") }, FPL("\\\\aa") }, |
| 244 | { { FPL("\\\\"), FPL("aa") }, FPL("\\\\aa") }, |
| 245 | { { FPL("/aa/bb"), FPL("cc") }, FPL("/aa/bb\\cc") }, |
| 246 | { { FPL("/aa/bb/"), FPL("cc") }, FPL("/aa/bb\\cc") }, |
| 247 | { { FPL("aa/bb/"), FPL("cc") }, FPL("aa/bb\\cc") }, |
| 248 | { { FPL("aa/bb"), FPL("cc") }, FPL("aa/bb\\cc") }, |
| 249 | { { FPL("a/b"), FPL("c") }, FPL("a/b\\c") }, |
| 250 | { { FPL("a/b/"), FPL("c") }, FPL("a/b\\c") }, |
| 251 | { { FPL("//aa"), FPL("bb") }, FPL("//aa\\bb") }, |
| 252 | { { FPL("//aa/"), FPL("bb") }, FPL("//aa\\bb") }, |
| 253 | { { FPL("\\aa\\bb"), FPL("cc") }, FPL("\\aa\\bb\\cc") }, |
| 254 | { { FPL("\\aa\\bb\\"), FPL("cc") }, FPL("\\aa\\bb\\cc") }, |
| 255 | { { FPL("aa\\bb\\"), FPL("cc") }, FPL("aa\\bb\\cc") }, |
| 256 | { { FPL("aa\\bb"), FPL("cc") }, FPL("aa\\bb\\cc") }, |
| 257 | { { FPL("a\\b"), FPL("c") }, FPL("a\\b\\c") }, |
| 258 | { { FPL("a\\b\\"), FPL("c") }, FPL("a\\b\\c") }, |
| 259 | { { FPL("\\\\aa"), FPL("bb") }, FPL("\\\\aa\\bb") }, |
| 260 | { { FPL("\\\\aa\\"), FPL("bb") }, FPL("\\\\aa\\bb") }, |
| 261 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 262 | { { FPL("c:\\"), FPL("a") }, FPL("c:\\a") }, |
| 263 | { { FPL("c:\\\\"), FPL("a") }, FPL("c:\\\\a") }, |
| 264 | { { FPL("c:\\\\\\"), FPL("a") }, FPL("c:\\a") }, |
| 265 | { { FPL("c:\\"), FPL("") }, FPL("c:\\") }, |
| 266 | { { FPL("c:\\a"), FPL("b") }, FPL("c:\\a\\b") }, |
| 267 | { { FPL("c:\\a\\"), FPL("b") }, FPL("c:\\a\\b") }, |
| 268 | #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 269 | #else // FILE_PATH_USES_WIN_SEPARATORS |
| 270 | { { FPL("/aa/bb"), FPL("cc") }, FPL("/aa/bb/cc") }, |
| 271 | { { FPL("/aa/bb/"), FPL("cc") }, FPL("/aa/bb/cc") }, |
| 272 | { { FPL("aa/bb/"), FPL("cc") }, FPL("aa/bb/cc") }, |
| 273 | { { FPL("aa/bb"), FPL("cc") }, FPL("aa/bb/cc") }, |
| 274 | { { FPL("a/b"), FPL("c") }, FPL("a/b/c") }, |
| 275 | { { FPL("a/b/"), FPL("c") }, FPL("a/b/c") }, |
| 276 | { { FPL("//aa"), FPL("bb") }, FPL("//aa/bb") }, |
| 277 | { { FPL("//aa/"), FPL("bb") }, FPL("//aa/bb") }, |
| 278 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 279 | { { FPL("c:/"), FPL("a") }, FPL("c:/a") }, |
| 280 | { { FPL("c:/"), FPL("") }, FPL("c:/") }, |
| 281 | { { FPL("c:/a"), FPL("b") }, FPL("c:/a/b") }, |
| 282 | { { FPL("c:/a/"), FPL("b") }, FPL("c:/a/b") }, |
| 283 | #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 284 | #endif // FILE_PATH_USES_WIN_SEPARATORS |
| 285 | }; |
| 286 | |
| 287 | for (size_t i = 0; i < arraysize(cases); ++i) { |
| 288 | FilePath root(cases[i].inputs[0]); |
| 289 | FilePath::StringType leaf(cases[i].inputs[1]); |
mark@chromium.org | fac7b26 | 2008-12-09 01:49:08 +0900 | [diff] [blame] | 290 | FilePath observed_str = root.Append(leaf); |
| 291 | EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) << |
| 292 | "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; |
| 293 | FilePath observed_path = root.Append(FilePath(leaf)); |
| 294 | EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_path.value()) << |
mark@chromium.org | 6380e26 | 2008-10-04 03:21:47 +0900 | [diff] [blame] | 295 | "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; |
| 296 | } |
| 297 | } |
| 298 | |
aa@chromium.org | 76e5c63 | 2008-12-18 17:38:16 +0900 | [diff] [blame] | 299 | TEST_F(FilePathTest, IsAbsolute) { |
mark@chromium.org | 6380e26 | 2008-10-04 03:21:47 +0900 | [diff] [blame] | 300 | const struct UnaryBooleanTestData cases[] = { |
| 301 | { FPL(""), false }, |
| 302 | { FPL("a"), false }, |
| 303 | { FPL("c:"), false }, |
| 304 | { FPL("c:a"), false }, |
| 305 | { FPL("a/b"), false }, |
| 306 | { FPL("//"), true }, |
| 307 | { FPL("//a"), true }, |
| 308 | { FPL("c:a/b"), false }, |
| 309 | { FPL("?:/a"), false }, |
| 310 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 311 | { FPL("/"), false }, |
| 312 | { FPL("/a"), false }, |
| 313 | { FPL("/."), false }, |
| 314 | { FPL("/.."), false }, |
| 315 | { FPL("c:/"), true }, |
| 316 | { FPL("c:/a"), true }, |
| 317 | { FPL("c:/."), true }, |
| 318 | { FPL("c:/.."), true }, |
| 319 | { FPL("C:/a"), true }, |
| 320 | { FPL("d:/a"), true }, |
| 321 | #else // FILE_PATH_USES_DRIVE_LETTERS |
| 322 | { FPL("/"), true }, |
| 323 | { FPL("/a"), true }, |
| 324 | { FPL("/."), true }, |
| 325 | { FPL("/.."), true }, |
| 326 | { FPL("c:/"), false }, |
| 327 | #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 328 | #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 329 | { FPL("a\\b"), false }, |
| 330 | { FPL("\\\\"), true }, |
| 331 | { FPL("\\\\a"), true }, |
| 332 | { FPL("a\\b"), false }, |
| 333 | { FPL("\\\\"), true }, |
| 334 | { FPL("//a"), true }, |
| 335 | { FPL("c:a\\b"), false }, |
| 336 | { FPL("?:\\a"), false }, |
| 337 | #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 338 | { FPL("\\"), false }, |
| 339 | { FPL("\\a"), false }, |
| 340 | { FPL("\\."), false }, |
| 341 | { FPL("\\.."), false }, |
| 342 | { FPL("c:\\"), true }, |
| 343 | { FPL("c:\\"), true }, |
| 344 | { FPL("c:\\a"), true }, |
| 345 | { FPL("c:\\."), true }, |
| 346 | { FPL("c:\\.."), true }, |
| 347 | { FPL("C:\\a"), true }, |
| 348 | { FPL("d:\\a"), true }, |
| 349 | #else // FILE_PATH_USES_DRIVE_LETTERS |
| 350 | { FPL("\\"), true }, |
| 351 | { FPL("\\a"), true }, |
| 352 | { FPL("\\."), true }, |
| 353 | { FPL("\\.."), true }, |
| 354 | { FPL("c:\\"), false }, |
| 355 | #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 356 | #endif // FILE_PATH_USES_WIN_SEPARATORS |
| 357 | }; |
| 358 | |
| 359 | for (size_t i = 0; i < arraysize(cases); ++i) { |
| 360 | FilePath input(cases[i].input); |
| 361 | bool observed = input.IsAbsolute(); |
| 362 | EXPECT_EQ(cases[i].expected, observed) << |
| 363 | "i: " << i << ", input: " << input.value(); |
| 364 | } |
| 365 | } |
aa@chromium.org | 76e5c63 | 2008-12-18 17:38:16 +0900 | [diff] [blame] | 366 | |
| 367 | TEST_F(FilePathTest, Contains) { |
| 368 | FilePath data_dir; |
| 369 | ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &data_dir)); |
| 370 | data_dir = data_dir.Append(FILE_PATH_LITERAL("FilePathTest")); |
| 371 | |
| 372 | // Create a fresh, empty copy of this directory. |
| 373 | file_util::Delete(data_dir, true); |
| 374 | file_util::CreateDirectory(data_dir); |
| 375 | |
| 376 | FilePath foo(data_dir.Append(FILE_PATH_LITERAL("foo"))); |
| 377 | FilePath bar(foo.Append(FILE_PATH_LITERAL("bar.txt"))); |
| 378 | FilePath baz(data_dir.Append(FILE_PATH_LITERAL("baz.txt"))); |
| 379 | FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
| 380 | |
| 381 | // Annoyingly, the directories must actually exist in order for realpath(), |
| 382 | // which Contains() relies on in posix, to work. |
| 383 | file_util::CreateDirectory(foo); |
| 384 | std::string data("hello"); |
| 385 | file_util::WriteFile(bar.ToWStringHack(), data.c_str(), data.length()); |
| 386 | file_util::WriteFile(baz.ToWStringHack(), data.c_str(), data.length()); |
| 387 | file_util::WriteFile(foobar.ToWStringHack(), data.c_str(), data.length()); |
| 388 | |
| 389 | EXPECT_TRUE(foo.Contains(bar)); |
| 390 | EXPECT_FALSE(foo.Contains(baz)); |
| 391 | EXPECT_FALSE(foo.Contains(foobar)); |
| 392 | EXPECT_FALSE(foo.Contains(foo)); |
| 393 | |
| 394 | // Platform-specific concerns |
| 395 | FilePath foo_caps(data_dir.Append(FILE_PATH_LITERAL("FOO"))); |
| 396 | #if defined(OS_WIN) |
| 397 | EXPECT_TRUE(foo.Contains(foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); |
| 398 | EXPECT_TRUE(foo.Contains( |
| 399 | FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt")))); |
| 400 | #elif defined(OS_LINUX) |
| 401 | EXPECT_FALSE(foo.Contains(foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); |
| 402 | #else |
| 403 | // We can't really do this test on osx since the case-sensitivity of the |
| 404 | // filesystem is configurable. |
| 405 | #endif |
| 406 | |
| 407 | // Note: whether |
| 408 | } |