OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/scoped_temp_dir.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
11 | 13 |
12 // This macro helps avoid wrapped lines in the test structs. | 14 // This macro helps avoid wrapped lines in the test structs. |
13 #define FPL(x) FILE_PATH_LITERAL(x) | 15 #define FPL(x) FILE_PATH_LITERAL(x) |
14 | 16 |
15 struct UnaryTestData { | 17 struct UnaryTestData { |
16 const FilePath::CharType* input; | 18 const FilePath::CharType* input; |
17 const FilePath::CharType* expected; | 19 const FilePath::CharType* expected; |
18 }; | 20 }; |
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") }, | 1082 { FPL("/\\foo\\/bar"), FPL("\\\\foo\\\\bar") }, |
1081 }; | 1083 }; |
1082 for (size_t i = 0; i < arraysize(cases); ++i) { | 1084 for (size_t i = 0; i < arraysize(cases); ++i) { |
1083 FilePath input(cases[i].input); | 1085 FilePath input(cases[i].input); |
1084 FilePath observed = input.NormalizeWindowsPathSeparators(); | 1086 FilePath observed = input.NormalizeWindowsPathSeparators(); |
1085 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << | 1087 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed.value()) << |
1086 "i: " << i << ", input: " << input.value(); | 1088 "i: " << i << ", input: " << input.value(); |
1087 } | 1089 } |
1088 } | 1090 } |
1089 #endif | 1091 #endif |
| 1092 |
| 1093 #if defined(OS_WIN) |
| 1094 TEST_F(FilePathTest, TestGetLongPathHack) { |
| 1095 ScopedTempDir dir; |
| 1096 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 1097 |
| 1098 // Create long path. |
| 1099 const char kLongPathChar160[] = |
| 1100 "012345678901234567890123456789012345678901234567890123456789"; |
| 1101 "012345678901234567890123456789012345678901234567890123456789" |
| 1102 "0123456789012345678901234567890123456789"; |
| 1103 FilePath long_path1(dir.path().AppendASCII(kLongPathChar160)); |
| 1104 |
| 1105 ASSERT_TRUE(file_util::CreateDirectory(long_path1)); |
| 1106 FilePath long_path2 = long_path1.AppendASCII(kLongPathChar160); |
| 1107 ASSERT_TRUE(file_util::CreateDirectory(long_path2)); |
| 1108 |
| 1109 // Get its 8.3 name. |
| 1110 FilePath::StringType long_path2_value(long_path2.value()); |
| 1111 FilePath::StringType short_path; |
| 1112 DWORD length = ::GetShortPathName( |
| 1113 long_path2_value.c_str(), WriteInto(&short_path, MAX_PATH), MAX_PATH); |
| 1114 short_path.resize(length); |
| 1115 |
| 1116 // Test converstion from 8.3 to long path. |
| 1117 FilePath path8_3(short_path); |
| 1118 EXPECT_LT(path8_3.value().length(), long_path2.value().length()); |
| 1119 FilePath converted_long_path(path8_3.GetLongPathHack()); |
| 1120 EXPECT_TRUE(StartsWith( |
| 1121 converted_long_path.value(), FilePath::kExtendedPathPrefix, false)); |
| 1122 |
| 1123 // Should be a no-op if path starts with extended path prefix. |
| 1124 EXPECT_EQ(converted_long_path.value(), |
| 1125 converted_long_path.GetLongPathHack().value()); |
| 1126 |
| 1127 // Should be a no-op if path starts with UNC prefix. |
| 1128 FilePath starts_with_unc_prefix(FilePath::kUNCExtendedPathPrefix); |
| 1129 EXPECT_EQ(starts_with_unc_prefix.value(), |
| 1130 starts_with_unc_prefix.GetLongPathHack().value()); |
| 1131 |
| 1132 // Test for share drive prefix. |
| 1133 FilePath filer(FPL("\\\\filer\\home\\me")); |
| 1134 FilePath::StringType expected_prefix(FilePath::kUNCExtendedPathPrefix); |
| 1135 expected_prefix.append(FPL("filer\\home\\me")); |
| 1136 EXPECT_EQ(expected_prefix, filer.GetLongPathHack().value()); |
| 1137 |
| 1138 // TODO(kkanetkar): When ScopedTempDir is fixed to handle longer |
| 1139 // paths, remove this. |
| 1140 EXPECT_TRUE(file_util::Delete(long_path1, true)); |
| 1141 } |
| 1142 #endif |
OLD | NEW |