Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: base/file_path_unittest.cc

Issue 5754002: Moving away from shell api to support long path names on windows for filesystem. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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) {
Erik does not do reviews 2010/12/23 17:57:27 we may need to test some really long paths as well
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 short_path;
1111 DWORD length = ::GetShortPathName(
1112 long_path2.value().c_str(), WriteInto(&short_path, MAX_PATH), MAX_PATH);
1113 short_path.resize(length);
1114
1115 // Test converstion from 8.3 to long path.
1116 EXPECT_LT(short_path.length(), long_path2.value().length());
1117 FilePath converted_long_path(FilePath(short_path).GetLongPathHack());
1118 EXPECT_TRUE(StartsWith(
1119 converted_long_path.value(), FilePath::kExtendedPathPrefix, false));
1120
1121 // Should be a no-op if path already starts with extended path prefix.
1122 EXPECT_EQ(converted_long_path.value(),
1123 converted_long_path.GetLongPathHack().value());
1124
1125 // Should be a no-op if path already starts with UNC prefix.
1126 FilePath starts_with_unc_prefix(FilePath::kUNCExtendedPathPrefix);
1127 EXPECT_EQ(starts_with_unc_prefix.value(),
1128 starts_with_unc_prefix.GetLongPathHack().value());
1129
1130 // Test for share drive prefix.
1131 FilePath unc_path(FPL("\\\\filer\\home\\me"));
1132 FilePath::StringType prefixed_unc_path(FilePath::kUNCExtendedPathPrefix);
1133 prefixed_unc_path.append(FPL("filer\\home\\me"));
1134 EXPECT_EQ(prefixed_unc_path, unc_path.GetLongPathHack().value());
1135
1136 // TODO(kkanetkar): When ScopedTempDir is fixed to handle longer
1137 // paths, remove this.
1138 EXPECT_TRUE(file_util::Delete(long_path1, true));
1139 }
1140 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698