| 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);
|
| + short_path.resize(length);
|
| +
|
| + // Test converstion from 8.3 to long path.
|
| + FilePath path8_3(short_path);
|
| + 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.
|
| + EXPECT_EQ(converted_long_path.value(),
|
| + converted_long_path.GetLongPathHack().value());
|
| +
|
| + // Should be a no-op if path 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 filer(FPL("\\\\filer\\home\\me"));
|
| + FilePath::StringType expected_prefix(FilePath::kUNCExtendedPathPrefix);
|
| + expected_prefix.append(FPL("filer\\home\\me"));
|
| + 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
|
|
|