| 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/path_service.h" | 8 #include "base/path_service.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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 }; | 357 }; |
| 358 | 358 |
| 359 for (size_t i = 0; i < arraysize(cases); ++i) { | 359 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 360 FilePath input(cases[i].input); | 360 FilePath input(cases[i].input); |
| 361 bool observed = input.IsAbsolute(); | 361 bool observed = input.IsAbsolute(); |
| 362 EXPECT_EQ(cases[i].expected, observed) << | 362 EXPECT_EQ(cases[i].expected, observed) << |
| 363 "i: " << i << ", input: " << input.value(); | 363 "i: " << i << ", input: " << input.value(); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 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 } | |
| 409 | |
| 410 TEST_F(FilePathTest, Extension) { | 367 TEST_F(FilePathTest, Extension) { |
| 411 FilePath base_dir(FILE_PATH_LITERAL("base_dir")); | 368 FilePath base_dir(FILE_PATH_LITERAL("base_dir")); |
| 412 | 369 |
| 413 FilePath jpg = base_dir.Append(FILE_PATH_LITERAL("foo.jpg")); | 370 FilePath jpg = base_dir.Append(FILE_PATH_LITERAL("foo.jpg")); |
| 414 EXPECT_EQ(jpg.Extension(), FILE_PATH_LITERAL(".jpg")); | 371 EXPECT_EQ(jpg.Extension(), FILE_PATH_LITERAL(".jpg")); |
| 415 | 372 |
| 416 FilePath base = jpg.BaseName().RemoveExtension(); | 373 FilePath base = jpg.BaseName().RemoveExtension(); |
| 417 EXPECT_EQ(base.value(), FILE_PATH_LITERAL("foo")); | 374 EXPECT_EQ(base.value(), FILE_PATH_LITERAL("foo")); |
| 418 | 375 |
| 419 FilePath path_no_ext = base_dir.Append(base); | 376 FilePath path_no_ext = base_dir.Append(base); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") }, | 514 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") }, |
| 558 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, | 515 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, |
| 559 }; | 516 }; |
| 560 for (unsigned int i = 0; i < arraysize(cases); ++i) { | 517 for (unsigned int i = 0; i < arraysize(cases); ++i) { |
| 561 FilePath path(cases[i].inputs[0]); | 518 FilePath path(cases[i].inputs[0]); |
| 562 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); | 519 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); |
| 563 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << | 520 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << |
| 564 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; | 521 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; |
| 565 } | 522 } |
| 566 } | 523 } |
| 567 | |
| OLD | NEW |