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/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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") }, | 627 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") }, |
628 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, | 628 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, |
629 }; | 629 }; |
630 for (unsigned int i = 0; i < arraysize(cases); ++i) { | 630 for (unsigned int i = 0; i < arraysize(cases); ++i) { |
631 FilePath path(cases[i].inputs[0]); | 631 FilePath path(cases[i].inputs[0]); |
632 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); | 632 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); |
633 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << | 633 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << |
634 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; | 634 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; |
635 } | 635 } |
636 } | 636 } |
| 637 |
| 638 TEST_F(FilePathTest, MatchesExtension) { |
| 639 const struct BinaryBooleanTestData cases[] = { |
| 640 { { FPL("foo"), FPL("") }, true}, |
| 641 { { FPL("foo"), FPL(".") }, false}, |
| 642 { { FPL("foo."), FPL("") }, false}, |
| 643 { { FPL("foo."), FPL(".") }, true}, |
| 644 { { FPL("foo.txt"), FPL(".dll") }, false}, |
| 645 { { FPL("foo.txt"), FPL(".txt") }, true}, |
| 646 { { FPL("foo.txt.dll"), FPL(".txt") }, false}, |
| 647 { { FPL("foo.txt.dll"), FPL(".dll") }, true}, |
| 648 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 649 { { FPL("c:/foo.txt.dll"), FPL(".txt") }, false}, |
| 650 { { FPL("c:/foo.txt"), FPL(".txt") }, true}, |
| 651 #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 652 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 653 { { FPL("c:\\bar\\foo.txt.dll"), FPL(".txt") }, false}, |
| 654 { { FPL("c:\\bar\\foo.txt"), FPL(".txt") }, true}, |
| 655 #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 656 { { FPL("/bar/foo.txt.dll"), FPL(".txt") }, false}, |
| 657 { { FPL("/bar/foo.txt"), FPL(".txt") }, true}, |
| 658 }; |
| 659 |
| 660 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 661 FilePath path(cases[i].inputs[0]); |
| 662 FilePath::StringType ext(cases[i].inputs[1]); |
| 663 |
| 664 EXPECT_EQ(cases[i].expected, path.MatchesExtension(ext)) << |
| 665 "i: " << i << ", path: " << path.value() << ", ext: " << ext; |
| 666 } |
| 667 } |
OLD | NEW |