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

Unified Diff: base/file_util_unittest.cc

Issue 12489: Remove file_util::kPathSeparator from posix. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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
« no previous file with comments | « base/file_util_mac.mm ('k') | base/file_util_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_unittest.cc
===================================================================
--- base/file_util_unittest.cc (revision 6039)
+++ base/file_util_unittest.cc (working copy)
@@ -147,6 +147,8 @@
#endif
}
+// TODO(port): enable this test for non-Windows.
+#if defined(OS_WIN)
static const struct InsertBeforeExtensionCase {
std::wstring path;
std::wstring suffix;
@@ -204,6 +206,7 @@
EXPECT_EQ(path, kInsertBeforeExtension[i].result);
}
}
+#endif // defined(OS_WIN)
static const struct filename_case {
const wchar_t* path;
@@ -785,6 +788,8 @@
}
}
+// TODO(port): enable this test for non-windows.
+#if defined(OS_WIN)
static const struct ReplaceExtensionCase {
std::wstring file_name;
std::wstring extension;
@@ -827,6 +832,7 @@
file_util::ReplaceExtension(&result_path, L".baz");
EXPECT_EQ(path + L".baz", result_path);
}
+#endif // defined(OS_WIN)
TEST_F(FileUtilTest, FileEnumeratorTest) {
// Test an empty directory.
@@ -925,4 +931,56 @@
// (we don't care what).
}
+
+void PathComponents(const std::wstring& path,
+ std::vector<std::wstring>* components) {
+ DCHECK(components != NULL);
+ if (components == NULL)
+ return;
+ std::wstring::size_type start = 0;
+ std::wstring::size_type end = path.find('/', start);
+
+ // Special case the "/" or "\" directory. On Windows with a drive letter,
+ // this code path won't hit, but the right thing should still happen.
+ // "E:\foo" will turn into "E:","foo".
+ if (end == start) {
+ components->push_back(std::wstring(path, 0, 1));
+ start = end + 1;
+ end = path.find('/', start);
+ }
+ while (end != std::wstring::npos) {
+ std::wstring component = std::wstring(path, start, end - start);
+ components->push_back(component);
+ start = end + 1;
+ end = path.find('/', start);
+ }
+ std::wstring component = std::wstring(path, start);
+ components->push_back(component);
+}
+
+static const struct PathComponentsCase {
+ std::wstring path;
+ FilePath::StringType result;
+} kPathComponents[] = {
+ {L"/foo/bar/baz/", FILE_PATH_LITERAL("/|foo|bar|baz|")},
+ {L"/foo/bar/baz", FILE_PATH_LITERAL("/|foo|bar|baz")},
+ {L"e:/foo", FILE_PATH_LITERAL("e:|foo")},
+};
+
+TEST_F(FileUtilTest, PathComponentsTest) {
+ for (size_t i = 0; i < arraysize(kPathComponents); ++i) {
+ FilePath path = FilePath::FromWStringHack(kPathComponents[i].path);
+ std::vector<FilePath::StringType> comps;
+ file_util::PathComponents(path, &comps);
+
+ FilePath::StringType result;
+ for (size_t j = 0; j < comps.size(); ++j) {
+ result.append(comps[j]);
+ if (j < comps.size() - 1)
+ result.append(FILE_PATH_LITERAL("|"), 1);
+ }
+ EXPECT_EQ(kPathComponents[i].result, result);
+ }
+}
+
} // namespace
« no previous file with comments | « base/file_util_mac.mm ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698