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

Side by Side Diff: base/file_util_unittest.cc

Issue 145026: Move PathComponents from file_util to FilePath, add FilePath::IsParent() (Closed)
Patch Set: noop Created 11 years, 6 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 unified diff | Download patch
« no previous file with comments | « base/file_util.cc ('k') | chrome/browser/importer/ie_importer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 cur_file = enumerator.Next(); 1065 cur_file = enumerator.Next();
1066 EXPECT_EQ(fileB.value(), cur_file.value()); 1066 EXPECT_EQ(fileB.value(), cur_file.value());
1067 cur_file = enumerator.Next(); 1067 cur_file = enumerator.Next();
1068 EXPECT_EQ(fileF.value(), cur_file.value()); 1068 EXPECT_EQ(fileF.value(), cur_file.value());
1069 cur_file = enumerator.Next(); 1069 cur_file = enumerator.Next();
1070 #endif 1070 #endif
1071 1071
1072 EXPECT_EQ(FILE_PATH_LITERAL(""), cur_file.value()); 1072 EXPECT_EQ(FILE_PATH_LITERAL(""), cur_file.value());
1073 } 1073 }
1074 1074
1075 void PathComponents(const std::wstring& path,
1076 std::vector<std::wstring>* components) {
1077 DCHECK(components != NULL);
1078 if (components == NULL)
1079 return;
1080 std::wstring::size_type start = 0;
1081 std::wstring::size_type end = path.find('/', start);
1082
1083 // Special case the "/" or "\" directory. On Windows with a drive letter,
1084 // this code path won't hit, but the right thing should still happen.
1085 // "E:\foo" will turn into "E:","foo".
1086 if (end == start) {
1087 components->push_back(std::wstring(path, 0, 1));
1088 start = end + 1;
1089 end = path.find('/', start);
1090 }
1091 while (end != std::wstring::npos) {
1092 std::wstring component = std::wstring(path, start, end - start);
1093 components->push_back(component);
1094 start = end + 1;
1095 end = path.find('/', start);
1096 }
1097 std::wstring component = std::wstring(path, start);
1098 components->push_back(component);
1099 }
1100
1101 static const struct PathComponentsCase {
1102 const FilePath::CharType* path;
1103 const FilePath::CharType* result;
1104 } kPathComponents[] = {
1105 {FILE_PATH_LITERAL("/foo/bar/baz/"), FILE_PATH_LITERAL("/|foo|bar|baz|")},
1106 {FILE_PATH_LITERAL("/foo/bar/baz"), FILE_PATH_LITERAL("/|foo|bar|baz")},
1107 {FILE_PATH_LITERAL("e:/foo"), FILE_PATH_LITERAL("e:|foo")},
1108 };
1109
1110 TEST_F(FileUtilTest, PathComponentsTest) {
1111 for (size_t i = 0; i < arraysize(kPathComponents); ++i) {
1112 FilePath path(kPathComponents[i].path);
1113 std::vector<FilePath::StringType> comps;
1114 file_util::PathComponents(path, &comps);
1115
1116 FilePath::StringType result;
1117 for (size_t j = 0; j < comps.size(); ++j) {
1118 result.append(comps[j]);
1119 if (j < comps.size() - 1)
1120 result.append(FILE_PATH_LITERAL("|"), 1);
1121 }
1122 EXPECT_EQ(kPathComponents[i].result, result);
1123 }
1124 }
1125
1126 TEST_F(FileUtilTest, Contains) { 1075 TEST_F(FileUtilTest, Contains) {
1127 FilePath data_dir = test_dir_.Append(FILE_PATH_LITERAL("FilePathTest")); 1076 FilePath data_dir = test_dir_.Append(FILE_PATH_LITERAL("FilePathTest"));
1128 1077
1129 // Create a fresh, empty copy of this directory. 1078 // Create a fresh, empty copy of this directory.
1130 if (file_util::PathExists(data_dir)) { 1079 if (file_util::PathExists(data_dir)) {
1131 ASSERT_TRUE(file_util::Delete(data_dir, true)); 1080 ASSERT_TRUE(file_util::Delete(data_dir, true));
1132 } 1081 }
1133 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); 1082 ASSERT_TRUE(file_util::CreateDirectory(data_dir));
1134 1083
1135 FilePath foo(data_dir.Append(FILE_PATH_LITERAL("foo"))); 1084 FilePath foo(data_dir.Append(FILE_PATH_LITERAL("foo")));
(...skipping 24 matching lines...) Expand all
1160 #elif defined(OS_LINUX) 1109 #elif defined(OS_LINUX)
1161 EXPECT_FALSE(file_util::ContainsPath(foo, 1110 EXPECT_FALSE(file_util::ContainsPath(foo,
1162 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); 1111 foo_caps.Append(FILE_PATH_LITERAL("bar.txt"))));
1163 #else 1112 #else
1164 // We can't really do this test on osx since the case-sensitivity of the 1113 // We can't really do this test on osx since the case-sensitivity of the
1165 // filesystem is configurable. 1114 // filesystem is configurable.
1166 #endif 1115 #endif
1167 } 1116 }
1168 1117
1169 } // namespace 1118 } // namespace
OLDNEW
« no previous file with comments | « base/file_util.cc ('k') | chrome/browser/importer/ie_importer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698