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

Unified Diff: base/file_path_unittest.cc

Issue 267051: Minimize dependency of user scripts.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months 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 29458)
+++ base/file_path_unittest.cc (working copy)
@@ -497,6 +497,98 @@
}
}
+TEST_F(FilePathTest, AppendAndResolveRelativeTest) {
+ const struct BinaryTestData cases[] = {
+#if defined(FILE_PATH_USES_DRIVE_LETTERS)
+ { { FPL("c:/"), FPL("foo") }, FPL("c:/foo") },
+ { { FPL("f:/foo/bar"), FPL("..") }, FPL("f:/foo") },
+ { { FPL("f:/foo.bar"), FPL("..") }, FPL("f:/") },
+ { { FPL("F:/foo/.."), FPL("./bar/.") }, FPL("F:/bar") },
+ { { FPL("E:/Foo/bar"), FPL("../..") }, FPL("E:/") },
+ { { FPL("E:/Foo/bar/."), FPL("../..") }, FPL("E:/") },
+ { { FPL("e:/foo/.."), FPL("bar/..") }, FPL("e:/") },
+ { { FPL("c:/foo/./bar/.."), FPL("../baz") }, FPL("c:/baz") },
+ { { FPL("E:/./foo/bar/.."), FPL("../baz/..") }, FPL("E:/") },
+ { { FPL("x:/foo/../bar/.."), FPL("baz/../boo") }, FPL("x:/boo") },
+ { { FPL("E:/foo.bar/.."), FPL("../baz/..") }, FPL("") },
+ { { FPL("Z:/foo"), FPL("../..") }, FPL("") },
+ { { FPL("y:/"), FPL("..") }, FPL("") },
+ { { FPL("B:/.."), FPL("bar/.") }, FPL("") },
+ { { FPL("a:/foo/.."), FPL("..") }, FPL("") },
+ { { FPL("r:/.."), FPL("..") }, FPL("") },
+ { { FPL("F:/foo/.."), FPL("../..") }, FPL("") },
+ { { FPL("O:/foo/bar/.."), FPL("../..") }, FPL("") },
+#endif // FILE_PATH_USES_DRIVE_LETTERS
+#if defined(FILE_PATH_USES_WIN_SEPARATORS)
+ { { FPL("\\\\"), FPL("foo") }, FPL("\\\\foo") },
+ { { FPL("\\\\foo"), FPL("bar") }, FPL("\\\\foo\\bar") },
+ { { FPL("\\\\foo\\bar"), FPL("..") }, FPL("\\\\foo") },
+ { { FPL("\\\\foo.bar"), FPL("..") }, FPL("\\\\") },
+ { { FPL("\\\\Foo\\bar"), FPL("..\\..") }, FPL("\\\\") },
+ { { FPL("\\\\Foo\\bar\\."), FPL("..\\..") }, FPL("\\\\") },
+ { { FPL("\\\\foo\\bar"), FPL("foo\\..\\baz") }, FPL("\\\\foo\\bar\\baz") },
+ { { FPL("\\\\foo\\.\\bar"), FPL("..\\baz\\.") }, FPL("\\\\foo\\baz") },
+ { { FPL("\\\\.\\foo\\.."), FPL("bar") }, FPL("\\\\bar") },
+ { { FPL("\\\\foo\\.."), FPL(".\\bar\\..") }, FPL("\\\\") },
+ { { FPL("\\\\foo\\bar\\.."), FPL("..\\baz") }, FPL("\\\\baz") },
+ { { FPL("\\\\foo\\bar\\.."), FPL("..\\baz\\..") }, FPL("\\\\") },
+ { { FPL("\\\\foo\\..\\bar\\.."), FPL("baz\\..\\boo") }, FPL("\\\\boo"), },
+ { { FPL("\\\\foo.bar\\.."), FPL("..\\baz\\..") }, FPL("") },
+ { { FPL("\\\\foo"), FPL("..\\..") }, FPL("") },
+ { { FPL("\\\\"), FPL("..") }, FPL("") },
+ { { FPL("\\\\.."), FPL("bar\\.") }, FPL("") },
+ { { FPL("\\\\foo\\.."), FPL("..") }, FPL("") },
+ { { FPL("\\\\.."), FPL("..") }, FPL("") },
+ { { FPL("\\\\foo\\.."), FPL("..\\..") }, FPL("") },
+ { { FPL("\\\\foo\\bar\\.."), FPL("..\\..") }, FPL("") },
+#if defined(FILE_PATH_USES_DRIVE_LETTERS)
+ { { FPL("E:/foo"), FPL("bar") }, FPL("E:/foo\\bar") },
+ { { FPL("C:/foo/bar"), FPL("foo/../baz") }, FPL("C:/foo\\bar\\baz") },
+ { { FPL("e:/foo/bar"), FPL("../baz") }, FPL("e:/foo\\baz") },
+#endif
+#else // FILE_PATH_USES_WIN_SEPARAORS
+ { { FPL("/"), FPL("foo") }, FPL("/foo") },
+ { { FPL("/foo"), FPL("bar") }, FPL("/foo/bar") },
+ { { FPL("/foo/bar/"), FPL("..") }, FPL("/foo") },
+ { { FPL("/foo.bar"), FPL("..") }, FPL("/") },
+ { { FPL("//foo"), FPL("..") }, FPL("//") },
+ { { FPL("/foo/./bar"), FPL("../..") }, FPL("/") },
+ { { FPL("/foo/bar/."), FPL("foo/../baz") }, FPL("/foo/bar/baz") },
+ { { FPL("/./foo/bar"), FPL("../baz/.") }, FPL("/foo/baz") },
+ { { FPL("/foo/.."), FPL("./bar") }, FPL("/bar") },
+ { { FPL("/foo/.."), FPL("bar/..") }, FPL("/") },
+ { { FPL("//foo/bar/.."), FPL("../baz") }, FPL("//baz") },
+ { { FPL("/foo/bar/.."), FPL("../baz/..") }, FPL("/") },
+ { { FPL("/foo/../bar/.."), FPL("baz/../boo") }, FPL("/boo") },
+ { { FPL("//foo.bar/.."), FPL("../baz") }, FPL("") },
+ { { FPL("/foo"), FPL("../..") }, FPL("") },
+ { { FPL("//"), FPL("..") }, FPL("") },
+ { { FPL("/.."), FPL("./bar") }, FPL("") },
+ { { FPL("/foo/.."), FPL("..") }, FPL("") },
+ { { FPL("/.."), FPL("..") }, FPL("") },
+ { { FPL("/foo/.."), FPL("../..") }, FPL("") },
+ { { FPL("/foo/bar/.."), FPL("../..") }, FPL("") },
+#if defined(FILE_PATH_USES_DRIVE_LETTERS)
+ { { FPL("E:/foo"), FPL("bar") }, FPL("E:/foo/bar") },
+ { { FPL("C:/foo/bar"), FPL("foo/../baz") }, FPL("C:/foo/bar/baz") },
+ { { FPL("e:/foo/bar"), FPL("../baz") }, FPL("e:/foo/baz") },
+#endif
+#endif // FILE_PATH_USES_WIN_SEPARAORS
+ };
+
+ for (size_t i = 0; i < arraysize(cases); ++i) {
+ FilePath parent(cases[i].inputs[0]);
+ FilePath child(cases[i].inputs[1]);
+
+ FilePath result;
+ EXPECT_EQ(cases[i].expected[0] != '\0',
+ parent.AppendAndResolveRelative(child, &result)) <<
+ "i: " << i << ", parent: " << parent.value() << ", child: " <<
+ child.value();
+ EXPECT_STREQ(cases[i].expected, result.value().c_str());
+ }
+}
+
TEST_F(FilePathTest, IsParentTest) {
const struct BinaryBooleanTestData cases[] = {
{ { FPL("/"), FPL("/foo/bar/baz") }, true},
@@ -544,8 +636,8 @@
FilePath child(cases[i].inputs[1]);
EXPECT_EQ(parent.IsParent(child), cases[i].expected) <<
- "i: " << i << ", parent: " << parent.value() << ", child: " <<
- child.value();
+ "i: " << i << ", parent: " << parent.value() << ", child: " <<
+ child.value();
}
}

Powered by Google App Engine
This is Rietveld 408576698