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,52 @@ |
} |
} |
#endif |
+ |
+#if defined(OS_WIN) |
+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
|
+ 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 short_path; |
+ DWORD length = ::GetShortPathName( |
+ long_path2.value().c_str(), WriteInto(&short_path, MAX_PATH), MAX_PATH); |
+ short_path.resize(length); |
+ |
+ // Test converstion from 8.3 to long path. |
+ EXPECT_LT(short_path.length(), long_path2.value().length()); |
+ FilePath converted_long_path(FilePath(short_path).GetLongPathHack()); |
+ EXPECT_TRUE(StartsWith( |
+ converted_long_path.value(), FilePath::kExtendedPathPrefix, false)); |
+ |
+ // Should be a no-op if path already starts with extended path prefix. |
+ EXPECT_EQ(converted_long_path.value(), |
+ converted_long_path.GetLongPathHack().value()); |
+ |
+ // Should be a no-op if path already starts with UNC prefix. |
+ 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 unc_path(FPL("\\\\filer\\home\\me")); |
+ FilePath::StringType prefixed_unc_path(FilePath::kUNCExtendedPathPrefix); |
+ prefixed_unc_path.append(FPL("filer\\home\\me")); |
+ EXPECT_EQ(prefixed_unc_path, unc_path.GetLongPathHack().value()); |
+ |
+ // TODO(kkanetkar): When ScopedTempDir is fixed to handle longer |
+ // paths, remove this. |
+ EXPECT_TRUE(file_util::Delete(long_path1, true)); |
+} |
+#endif |