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

Side by Side Diff: base/file_path_unittest.cc

Issue 18134: Add AppendASCII (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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_path.cc ('k') | no next file » | 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) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/string_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h" 10 #include "testing/platform_test.h"
11 11
12 // This macro helps avoid wrapped lines in the test structs. 12 // This macro helps avoid wrapped lines in the test structs.
13 #define FPL(x) FILE_PATH_LITERAL(x) 13 #define FPL(x) FILE_PATH_LITERAL(x)
14 14
15 struct UnaryTestData { 15 struct UnaryTestData {
16 const FilePath::CharType* input; 16 const FilePath::CharType* input;
17 const FilePath::CharType* expected; 17 const FilePath::CharType* expected;
18 }; 18 };
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 286
287 for (size_t i = 0; i < arraysize(cases); ++i) { 287 for (size_t i = 0; i < arraysize(cases); ++i) {
288 FilePath root(cases[i].inputs[0]); 288 FilePath root(cases[i].inputs[0]);
289 FilePath::StringType leaf(cases[i].inputs[1]); 289 FilePath::StringType leaf(cases[i].inputs[1]);
290 FilePath observed_str = root.Append(leaf); 290 FilePath observed_str = root.Append(leaf);
291 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) << 291 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) <<
292 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; 292 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf;
293 FilePath observed_path = root.Append(FilePath(leaf)); 293 FilePath observed_path = root.Append(FilePath(leaf));
294 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_path.value()) << 294 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_path.value()) <<
295 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf; 295 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf;
296
297 // TODO(erikkay): It would be nice to have a unicode test append value to
298 // handle the case when AppendASCII is passed UTF8
299 #if defined(OS_WIN)
300 std::string ascii = WideToASCII(leaf);
301 #elif defined(OS_POSIX)
302 std::string ascii = leaf;
303 #endif
304 observed_str = root.AppendASCII(ascii);
305 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed_str.value()) <<
306 "i: " << i << ", root: " << root.value() << ", leaf: " << leaf;
296 } 307 }
297 } 308 }
298 309
299 TEST_F(FilePathTest, IsAbsolute) { 310 TEST_F(FilePathTest, IsAbsolute) {
300 const struct UnaryBooleanTestData cases[] = { 311 const struct UnaryBooleanTestData cases[] = {
301 { FPL(""), false }, 312 { FPL(""), false },
302 { FPL("a"), false }, 313 { FPL("a"), false },
303 { FPL("c:"), false }, 314 { FPL("c:"), false },
304 { FPL("c:a"), false }, 315 { FPL("c:a"), false },
305 { FPL("a/b"), false }, 316 { FPL("a/b"), false },
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") }, 525 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") },
515 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") }, 526 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") },
516 }; 527 };
517 for (unsigned int i = 0; i < arraysize(cases); ++i) { 528 for (unsigned int i = 0; i < arraysize(cases); ++i) {
518 FilePath path(cases[i].inputs[0]); 529 FilePath path(cases[i].inputs[0]);
519 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]); 530 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]);
520 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i << 531 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i <<
521 ", path: " << path.value() << ", replace: " << cases[i].inputs[1]; 532 ", path: " << path.value() << ", replace: " << cases[i].inputs[1];
522 } 533 }
523 } 534 }
OLDNEW
« no previous file with comments | « base/file_path.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698