OLD | NEW |
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/string_util.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" |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 FilePath::StringType observed; | 490 FilePath::StringType observed; |
491 for (size_t j = 0; j < comps.size(); ++j) { | 491 for (size_t j = 0; j < comps.size(); ++j) { |
492 observed.append(FILE_PATH_LITERAL("|"), 1); | 492 observed.append(FILE_PATH_LITERAL("|"), 1); |
493 observed.append(comps[j]); | 493 observed.append(comps[j]); |
494 } | 494 } |
495 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed) << | 495 EXPECT_EQ(FilePath::StringType(cases[i].expected), observed) << |
496 "i: " << i << ", input: " << input.value(); | 496 "i: " << i << ", input: " << input.value(); |
497 } | 497 } |
498 } | 498 } |
499 | 499 |
| 500 TEST_F(FilePathTest, AppendAndResolveRelativeTest) { |
| 501 const struct BinaryTestData cases[] = { |
| 502 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 503 { { FPL("c:/"), FPL("foo") }, FPL("c:/foo") }, |
| 504 { { FPL("f:/foo/bar"), FPL("..") }, FPL("f:/foo") }, |
| 505 { { FPL("f:/foo.bar"), FPL("..") }, FPL("f:/") }, |
| 506 { { FPL("F:/foo/.."), FPL("./bar/.") }, FPL("F:/bar") }, |
| 507 { { FPL("E:/Foo/bar"), FPL("../..") }, FPL("E:/") }, |
| 508 { { FPL("E:/Foo/bar/."), FPL("../..") }, FPL("E:/") }, |
| 509 { { FPL("e:/foo/.."), FPL("bar/..") }, FPL("e:/") }, |
| 510 { { FPL("c:/foo/./bar/.."), FPL("../baz") }, FPL("c:/baz") }, |
| 511 { { FPL("E:/./foo/bar/.."), FPL("../baz/..") }, FPL("E:/") }, |
| 512 { { FPL("x:/foo/../bar/.."), FPL("baz/../boo") }, FPL("x:/boo") }, |
| 513 { { FPL("E:/foo.bar/.."), FPL("../baz/..") }, FPL("") }, |
| 514 { { FPL("Z:/foo"), FPL("../..") }, FPL("") }, |
| 515 { { FPL("y:/"), FPL("..") }, FPL("") }, |
| 516 { { FPL("B:/.."), FPL("bar/.") }, FPL("") }, |
| 517 { { FPL("a:/foo/.."), FPL("..") }, FPL("") }, |
| 518 { { FPL("r:/.."), FPL("..") }, FPL("") }, |
| 519 { { FPL("F:/foo/.."), FPL("../..") }, FPL("") }, |
| 520 { { FPL("O:/foo/bar/.."), FPL("../..") }, FPL("") }, |
| 521 #endif // FILE_PATH_USES_DRIVE_LETTERS |
| 522 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
| 523 { { FPL("\\\\"), FPL("foo") }, FPL("\\\\foo") }, |
| 524 { { FPL("\\\\foo"), FPL("bar") }, FPL("\\\\foo\\bar") }, |
| 525 { { FPL("\\\\foo\\bar"), FPL("..") }, FPL("\\\\foo") }, |
| 526 { { FPL("\\\\foo.bar"), FPL("..") }, FPL("\\\\") }, |
| 527 { { FPL("\\\\Foo\\bar"), FPL("..\\..") }, FPL("\\\\") }, |
| 528 { { FPL("\\\\Foo\\bar\\."), FPL("..\\..") }, FPL("\\\\") }, |
| 529 { { FPL("\\\\foo\\bar"), FPL("foo\\..\\baz") }, FPL("\\\\foo\\bar\\baz") }, |
| 530 { { FPL("\\\\foo\\.\\bar"), FPL("..\\baz\\.") }, FPL("\\\\foo\\baz") }, |
| 531 { { FPL("\\\\.\\foo\\.."), FPL("bar") }, FPL("\\\\bar") }, |
| 532 { { FPL("\\\\foo\\.."), FPL(".\\bar\\..") }, FPL("\\\\") }, |
| 533 { { FPL("\\\\foo\\bar\\.."), FPL("..\\baz") }, FPL("\\\\baz") }, |
| 534 { { FPL("\\\\foo\\bar\\.."), FPL("..\\baz\\..") }, FPL("\\\\") }, |
| 535 { { FPL("\\\\foo\\..\\bar\\.."), FPL("baz\\..\\boo") }, FPL("\\\\boo"), }, |
| 536 { { FPL("\\\\foo.bar\\.."), FPL("..\\baz\\..") }, FPL("") }, |
| 537 { { FPL("\\\\foo"), FPL("..\\..") }, FPL("") }, |
| 538 { { FPL("\\\\"), FPL("..") }, FPL("") }, |
| 539 { { FPL("\\\\.."), FPL("bar\\.") }, FPL("") }, |
| 540 { { FPL("\\\\foo\\.."), FPL("..") }, FPL("") }, |
| 541 { { FPL("\\\\.."), FPL("..") }, FPL("") }, |
| 542 { { FPL("\\\\foo\\.."), FPL("..\\..") }, FPL("") }, |
| 543 { { FPL("\\\\foo\\bar\\.."), FPL("..\\..") }, FPL("") }, |
| 544 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 545 { { FPL("E:/foo"), FPL("bar") }, FPL("E:/foo\\bar") }, |
| 546 { { FPL("C:/foo/bar"), FPL("foo/../baz") }, FPL("C:/foo\\bar\\baz") }, |
| 547 { { FPL("e:/foo/bar"), FPL("../baz") }, FPL("e:/foo\\baz") }, |
| 548 #endif |
| 549 #else // FILE_PATH_USES_WIN_SEPARAORS |
| 550 { { FPL("/"), FPL("foo") }, FPL("/foo") }, |
| 551 { { FPL("/foo"), FPL("bar") }, FPL("/foo/bar") }, |
| 552 { { FPL("/foo/bar/"), FPL("..") }, FPL("/foo") }, |
| 553 { { FPL("/foo.bar"), FPL("..") }, FPL("/") }, |
| 554 { { FPL("//foo"), FPL("..") }, FPL("//") }, |
| 555 { { FPL("/foo/./bar"), FPL("../..") }, FPL("/") }, |
| 556 { { FPL("/foo/bar/."), FPL("foo/../baz") }, FPL("/foo/bar/baz") }, |
| 557 { { FPL("/./foo/bar"), FPL("../baz/.") }, FPL("/foo/baz") }, |
| 558 { { FPL("/foo/.."), FPL("./bar") }, FPL("/bar") }, |
| 559 { { FPL("/foo/.."), FPL("bar/..") }, FPL("/") }, |
| 560 { { FPL("//foo/bar/.."), FPL("../baz") }, FPL("//baz") }, |
| 561 { { FPL("/foo/bar/.."), FPL("../baz/..") }, FPL("/") }, |
| 562 { { FPL("/foo/../bar/.."), FPL("baz/../boo") }, FPL("/boo") }, |
| 563 { { FPL("//foo.bar/.."), FPL("../baz") }, FPL("") }, |
| 564 { { FPL("/foo"), FPL("../..") }, FPL("") }, |
| 565 { { FPL("//"), FPL("..") }, FPL("") }, |
| 566 { { FPL("/.."), FPL("./bar") }, FPL("") }, |
| 567 { { FPL("/foo/.."), FPL("..") }, FPL("") }, |
| 568 { { FPL("/.."), FPL("..") }, FPL("") }, |
| 569 { { FPL("/foo/.."), FPL("../..") }, FPL("") }, |
| 570 { { FPL("/foo/bar/.."), FPL("../..") }, FPL("") }, |
| 571 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 572 { { FPL("E:/foo"), FPL("bar") }, FPL("E:/foo/bar") }, |
| 573 { { FPL("C:/foo/bar"), FPL("foo/../baz") }, FPL("C:/foo/bar/baz") }, |
| 574 { { FPL("e:/foo/bar"), FPL("../baz") }, FPL("e:/foo/baz") }, |
| 575 #endif |
| 576 #endif // FILE_PATH_USES_WIN_SEPARAORS |
| 577 }; |
| 578 |
| 579 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 580 FilePath parent(cases[i].inputs[0]); |
| 581 FilePath child(cases[i].inputs[1]); |
| 582 |
| 583 FilePath result; |
| 584 EXPECT_EQ(cases[i].expected[0] != '\0', |
| 585 parent.AppendAndResolveRelative(child, &result)) << |
| 586 "i: " << i << ", parent: " << parent.value() << ", child: " << |
| 587 child.value(); |
| 588 EXPECT_STREQ(cases[i].expected, result.value().c_str()); |
| 589 } |
| 590 } |
| 591 |
500 TEST_F(FilePathTest, IsParentTest) { | 592 TEST_F(FilePathTest, IsParentTest) { |
501 const struct BinaryBooleanTestData cases[] = { | 593 const struct BinaryBooleanTestData cases[] = { |
502 { { FPL("/"), FPL("/foo/bar/baz") }, true}, | 594 { { FPL("/"), FPL("/foo/bar/baz") }, true}, |
503 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, true}, | 595 { { FPL("/foo/bar"), FPL("/foo/bar/baz") }, true}, |
504 { { FPL("/foo/bar/"), FPL("/foo/bar/baz") }, true}, | 596 { { FPL("/foo/bar/"), FPL("/foo/bar/baz") }, true}, |
505 { { FPL("//foo/bar/"), FPL("//foo/bar/baz") }, true}, | 597 { { FPL("//foo/bar/"), FPL("//foo/bar/baz") }, true}, |
506 { { FPL("/foo/bar"), FPL("/foo2/bar/baz") }, false}, | 598 { { FPL("/foo/bar"), FPL("/foo2/bar/baz") }, false}, |
507 { { FPL("/foo/bar.txt"), FPL("/foo/bar/baz") }, false}, | 599 { { FPL("/foo/bar.txt"), FPL("/foo/bar/baz") }, false}, |
508 { { FPL("/foo/bar"), FPL("/foo/bar2/baz") }, false}, | 600 { { FPL("/foo/bar"), FPL("/foo/bar2/baz") }, false}, |
509 { { FPL("/foo/bar"), FPL("/foo/bar") }, false}, | 601 { { FPL("/foo/bar"), FPL("/foo/bar") }, false}, |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 { FPL("a/b/c"), false }, | 993 { FPL("a/b/c"), false }, |
902 }; | 994 }; |
903 | 995 |
904 for (size_t i = 0; i < arraysize(cases); ++i) { | 996 for (size_t i = 0; i < arraysize(cases); ++i) { |
905 FilePath input(cases[i].input); | 997 FilePath input(cases[i].input); |
906 bool observed = input.ReferencesParent(); | 998 bool observed = input.ReferencesParent(); |
907 EXPECT_EQ(cases[i].expected, observed) << | 999 EXPECT_EQ(cases[i].expected, observed) << |
908 "i: " << i << ", input: " << input.value(); | 1000 "i: " << i << ", input: " << input.value(); |
909 } | 1001 } |
910 } | 1002 } |
OLD | NEW |