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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: base/file_path_unittest.cc
===================================================================
--- base/file_path_unittest.cc (revision 69859)
+++ base/file_path_unittest.cc (working copy)
@@ -5,7 +5,9 @@
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "base/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -1087,3 +1089,54 @@
}
}
#endif
+
+#if defined(OS_WIN)
+TEST_F(FilePathTest, TestGetLongPathHack) {
+ ScopedTempDir dir;
+ ASSERT_TRUE(dir.CreateUniqueTempDir());
+
+ // Create long path.
+ const char kLongPathChar160[] =
+ "012345678901234567890123456789012345678901234567890123456789";
+ "012345678901234567890123456789012345678901234567890123456789"
+ "0123456789012345678901234567890123456789";
+ FilePath long_path1(dir.path().AppendASCII(kLongPathChar160));
+
+ ASSERT_TRUE(file_util::CreateDirectory(long_path1));
+ FilePath long_path2 = long_path1.AppendASCII(kLongPathChar160);
+ ASSERT_TRUE(file_util::CreateDirectory(long_path2));
+
+ // Get its 8.3 name.
+ FilePath::StringType long_path2_value(long_path2.value());
+ FilePath::StringType short_path;
+ DWORD length = ::GetShortPathName(
+ long_path2_value.c_str(), WriteInto(&short_path, MAX_PATH), MAX_PATH);
kinuko 2010/12/22 23:20:49 I think we can just use long_path2.value().c_str()
Kavita Kanetkar 2010/12/23 03:14:28 Done.
+ short_path.resize(length);
+
+ // Test converstion from 8.3 to long path.
+ FilePath path8_3(short_path);
kinuko 2010/12/22 23:20:49 Do we need path8_3? Using short_path looks fine t
Kavita Kanetkar 2010/12/23 03:14:28 Sorry. That was before I changed the GetLongPathHa
+ EXPECT_LT(path8_3.value().length(), long_path2.value().length());
+ FilePath converted_long_path(path8_3.GetLongPathHack());
+ EXPECT_TRUE(StartsWith(
+ converted_long_path.value(), FilePath::kExtendedPathPrefix, false));
+
+ // Should be a no-op if path starts with extended path prefix.
kinuko 2010/12/22 23:20:49 nit: if path starts ... -> if path already starts
Kavita Kanetkar 2010/12/23 03:14:28 Done.
+ EXPECT_EQ(converted_long_path.value(),
+ converted_long_path.GetLongPathHack().value());
+
+ // Should be a no-op if path starts with UNC prefix.
kinuko 2010/12/22 23:20:49 ditto.
Kavita Kanetkar 2010/12/23 03:14:28 Done.
+ FilePath starts_with_unc_prefix(FilePath::kUNCExtendedPathPrefix);
+ EXPECT_EQ(starts_with_unc_prefix.value(),
+ starts_with_unc_prefix.GetLongPathHack().value());
+
+ // Test for share drive prefix.
+ FilePath filer(FPL("\\\\filer\\home\\me"));
+ FilePath::StringType expected_prefix(FilePath::kUNCExtendedPathPrefix);
+ expected_prefix.append(FPL("filer\\home\\me"));
kinuko 2010/12/22 23:20:49 nit: s/filer/unc_path/ and s/expected_prefix/prefi
Kavita Kanetkar 2010/12/23 03:14:28 Done.
+ EXPECT_EQ(expected_prefix, filer.GetLongPathHack().value());
+
+ // TODO(kkanetkar): When ScopedTempDir is fixed to handle longer
+ // paths, remove this.
+ EXPECT_TRUE(file_util::Delete(long_path1, true));
+}
+#endif
« base/file_path.cc ('K') | « base/file_path.cc ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698