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

Side by Side Diff: base/files/file_path_unittest.cc

Issue 15078003: Cleanup: Remove unneeded base/file_util.h includes in base. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: rebase Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « base/file_version_info_unittest.cc ('k') | base/files/file_path_watcher_kqueue.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/file_util.h"
7 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
8 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h" 9 #include "testing/platform_test.h"
11 10
12 // This macro helps avoid wrapped lines in the test structs. 11 // This macro helps avoid wrapped lines in the test structs.
13 #define FPL(x) FILE_PATH_LITERAL(x) 12 #define FPL(x) FILE_PATH_LITERAL(x)
14 13
15 // This macro constructs strings which can contain NULs. 14 // This macro constructs strings which can contain NULs.
16 #define FPS(x) FilePath::StringType(FPL(x), arraysize(FPL(x)) - 1) 15 #define FPS(x) FilePath::StringType(FPL(x), arraysize(FPL(x)) - 1)
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 FilePath from_native = FilePath(cases[i].native); 1114 FilePath from_native = FilePath(cases[i].native);
1116 EXPECT_EQ(cases[i].utf8, from_native.AsUTF8Unsafe()) 1115 EXPECT_EQ(cases[i].utf8, from_native.AsUTF8Unsafe())
1117 << "i: " << i << ", input: " << cases[i].native; 1116 << "i: " << i << ", input: " << cases[i].native;
1118 // Test the two file paths are identical. 1117 // Test the two file paths are identical.
1119 EXPECT_EQ(from_utf8.value(), from_native.value()); 1118 EXPECT_EQ(from_utf8.value(), from_native.value());
1120 } 1119 }
1121 } 1120 }
1122 1121
1123 TEST_F(FilePathTest, ConstructWithNUL) { 1122 TEST_F(FilePathTest, ConstructWithNUL) {
1124 // Assert FPS() works. 1123 // Assert FPS() works.
1125 ASSERT_TRUE(FPS("a\0b").length() == 3); 1124 ASSERT_EQ(3U, FPS("a\0b").length());
1126 1125
1127 // Test constructor strips '\0' 1126 // Test constructor strips '\0'
1128 FilePath path(FPS("a\0b")); 1127 FilePath path(FPS("a\0b"));
1129 EXPECT_TRUE(path.value().length() == 1); 1128 EXPECT_EQ(1U, path.value().length());
1130 EXPECT_EQ(path.value(), FPL("a")); 1129 EXPECT_EQ(FPL("a"), path.value());
1131 } 1130 }
1132 1131
1133 TEST_F(FilePathTest, AppendWithNUL) { 1132 TEST_F(FilePathTest, AppendWithNUL) {
1134 // Assert FPS() works. 1133 // Assert FPS() works.
1135 ASSERT_TRUE(FPS("b\0b").length() == 3); 1134 ASSERT_EQ(3U, FPS("b\0b").length());
1136 1135
1137 // Test Append() strips '\0' 1136 // Test Append() strips '\0'
1138 FilePath path(FPL("a")); 1137 FilePath path(FPL("a"));
1139 path = path.Append(FPS("b\0b")); 1138 path = path.Append(FPS("b\0b"));
1140 EXPECT_TRUE(path.value().length() == 3); 1139 EXPECT_EQ(3U, path.value().length());
1141 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 1140 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1142 EXPECT_EQ(path.value(), FPL("a\\b")); 1141 EXPECT_EQ(FPL("a\\b"), path.value());
1143 #else 1142 #else
1144 EXPECT_EQ(path.value(), FPL("a/b")); 1143 EXPECT_EQ(FPL("a/b"), path.value());
1145 #endif 1144 #endif
1146 } 1145 }
1147 1146
1148 TEST_F(FilePathTest, ReferencesParentWithNUL) { 1147 TEST_F(FilePathTest, ReferencesParentWithNUL) {
1149 // Assert FPS() works. 1148 // Assert FPS() works.
1150 ASSERT_TRUE(FPS("..\0").length() == 3); 1149 ASSERT_EQ(3U, FPS("..\0").length());
1151 1150
1152 // Test ReferencesParent() doesn't break with "..\0" 1151 // Test ReferencesParent() doesn't break with "..\0"
1153 FilePath path(FPS("..\0")); 1152 FilePath path(FPS("..\0"));
1154 EXPECT_TRUE(path.ReferencesParent()); 1153 EXPECT_TRUE(path.ReferencesParent());
1155 } 1154 }
1156 1155
1157 #if defined(FILE_PATH_USES_WIN_SEPARATORS) 1156 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
1158 TEST_F(FilePathTest, NormalizePathSeparators) { 1157 TEST_F(FilePathTest, NormalizePathSeparators) {
1159 const struct UnaryTestData cases[] = { 1158 const struct UnaryTestData cases[] = {
1160 { FPL("foo/bar"), FPL("foo\\bar") }, 1159 { FPL("foo/bar"), FPL("foo\\bar") },
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 { FPL("foo/"), FPL("foo/") } 1219 { FPL("foo/"), FPL("foo/") }
1221 }; 1220 };
1222 for (size_t i = 0; i < arraysize(cases); ++i) { 1221 for (size_t i = 0; i < arraysize(cases); ++i) {
1223 FilePath input = FilePath(cases[i].input).NormalizePathSeparators(); 1222 FilePath input = FilePath(cases[i].input).NormalizePathSeparators();
1224 FilePath expected = FilePath(cases[i].expected).NormalizePathSeparators(); 1223 FilePath expected = FilePath(cases[i].expected).NormalizePathSeparators();
1225 EXPECT_EQ(expected.value(), input.AsEndingWithSeparator().value()); 1224 EXPECT_EQ(expected.value(), input.AsEndingWithSeparator().value());
1226 } 1225 }
1227 } 1226 }
1228 1227
1229 } // namespace base 1228 } // namespace base
OLDNEW
« no previous file with comments | « base/file_version_info_unittest.cc ('k') | base/files/file_path_watcher_kqueue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698