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" |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, | 889 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, |
890 }; | 890 }; |
891 for (unsigned int i = 0; i < arraysize(cases); ++i) { | 891 for (unsigned int i = 0; i < arraysize(cases); ++i) { |
892 FilePath path(cases[i].inputs[0]); | 892 FilePath path(cases[i].inputs[0]); |
893 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); | 893 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); |
894 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << | 894 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << |
895 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; | 895 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; |
896 } | 896 } |
897 } | 897 } |
898 | 898 |
| 899 TEST_F(FilePathTest, AddExtension) { |
| 900 const struct BinaryTestData cases[] = { |
| 901 { { FPL(""), FPL("") }, FPL("") }, |
| 902 { { FPL(""), FPL("txt") }, FPL("") }, |
| 903 { { FPL("."), FPL("txt") }, FPL("") }, |
| 904 { { FPL(".."), FPL("txt") }, FPL("") }, |
| 905 { { FPL("."), FPL("") }, FPL("") }, |
| 906 { { FPL("foo.dll"), FPL("txt") }, FPL("foo.dll.txt") }, |
| 907 { { FPL("./foo.dll"), FPL("txt") }, FPL("./foo.dll.txt") }, |
| 908 { { FPL("foo..dll"), FPL("txt") }, FPL("foo..dll.txt") }, |
| 909 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.dll.txt") }, |
| 910 { { FPL("foo"), FPL("txt") }, FPL("foo.txt") }, |
| 911 { { FPL("foo."), FPL("txt") }, FPL("foo.txt") }, |
| 912 { { FPL("foo.."), FPL("txt") }, FPL("foo..txt") }, |
| 913 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") }, |
| 914 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baz.dll.txt") }, |
| 915 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.dll.txt") }, |
| 916 { { FPL("foo.dll"), FPL("") }, FPL("foo.dll") }, |
| 917 { { FPL("foo.dll"), FPL(".") }, FPL("foo.dll") }, |
| 918 { { FPL("foo"), FPL("") }, FPL("foo") }, |
| 919 { { FPL("foo"), FPL(".") }, FPL("foo") }, |
| 920 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz.dll") }, |
| 921 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz.dll") }, |
| 922 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 923 { { FPL("C:\\foo.bar\\foo"), FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") }, |
| 924 { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") }, |
| 925 #endif |
| 926 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") }, |
| 927 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, |
| 928 }; |
| 929 for (unsigned int i = 0; i < arraysize(cases); ++i) { |
| 930 FilePath path(cases[i].inputs[0]); |
| 931 FilePath added = path.AddExtension(cases[i].inputs[1]); |
| 932 EXPECT_EQ(cases[i].expected, added.value()) << "i: " << i << |
| 933 ", path: " << path.value() << ", add: " << cases[i].inputs[1]; |
| 934 } |
| 935 } |
| 936 |
899 TEST_F(FilePathTest, MatchesExtension) { | 937 TEST_F(FilePathTest, MatchesExtension) { |
900 const struct BinaryBooleanTestData cases[] = { | 938 const struct BinaryBooleanTestData cases[] = { |
901 { { FPL("foo"), FPL("") }, true}, | 939 { { FPL("foo"), FPL("") }, true}, |
902 { { FPL("foo"), FPL(".") }, false}, | 940 { { FPL("foo"), FPL(".") }, false}, |
903 { { FPL("foo."), FPL("") }, false}, | 941 { { FPL("foo."), FPL("") }, false}, |
904 { { FPL("foo."), FPL(".") }, true}, | 942 { { FPL("foo."), FPL(".") }, true}, |
905 { { FPL("foo.txt"), FPL(".dll") }, false}, | 943 { { FPL("foo.txt"), FPL(".dll") }, false}, |
906 { { FPL("foo.txt"), FPL(".txt") }, true}, | 944 { { FPL("foo.txt"), FPL(".txt") }, true}, |
907 { { FPL("foo.txt.dll"), FPL(".txt") }, false}, | 945 { { FPL("foo.txt.dll"), FPL(".txt") }, false}, |
908 { { FPL("foo.txt.dll"), FPL(".dll") }, true}, | 946 { { FPL("foo.txt.dll"), FPL(".dll") }, true}, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 }; | 1148 }; |
1111 for (size_t i = 0; i < arraysize(cases); ++i) { | 1149 for (size_t i = 0; i < arraysize(cases); ++i) { |
1112 FilePath input(cases[i].input); | 1150 FilePath input(cases[i].input); |
1113 FilePath observed = input.NormalizePathSeparators(); | 1151 FilePath observed = input.NormalizePathSeparators(); |
1114 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << | 1152 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << |
1115 "i: " << i << ", input: " << input.value(); | 1153 "i: " << i << ", input: " << input.value(); |
1116 } | 1154 } |
1117 } | 1155 } |
1118 | 1156 |
1119 #endif | 1157 #endif |
OLD | NEW |