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

Side by Side Diff: base/file_path_unittest.cc

Issue 17243: Add implementations of various extension related methods (derived from file_u... (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') | base/file_util.h » ('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) 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/path_service.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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt")))); 399 FilePath(foo.value() + FILE_PATH_LITERAL("/bar.txt"))));
400 #elif defined(OS_LINUX) 400 #elif defined(OS_LINUX)
401 EXPECT_FALSE(foo.Contains(foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); 401 EXPECT_FALSE(foo.Contains(foo_caps.Append(FILE_PATH_LITERAL("bar.txt"))));
402 #else 402 #else
403 // We can't really do this test on osx since the case-sensitivity of the 403 // We can't really do this test on osx since the case-sensitivity of the
404 // filesystem is configurable. 404 // filesystem is configurable.
405 #endif 405 #endif
406 406
407 // Note: whether 407 // Note: whether
408 } 408 }
409
410 TEST_F(FilePathTest, Extension) {
411 FilePath base_dir(FILE_PATH_LITERAL("base_dir"));
412
413 FilePath jpg = base_dir.Append(FILE_PATH_LITERAL("foo.jpg"));
414 EXPECT_EQ(jpg.Extension(), FILE_PATH_LITERAL(".jpg"));
415
416 FilePath base = jpg.BaseName().RemoveExtension();
417 EXPECT_EQ(base.value(), FILE_PATH_LITERAL("foo"));
418
419 FilePath path_no_ext = base_dir.Append(base);
420 EXPECT_EQ(jpg.RemoveExtension().value(), path_no_ext.value());
421
422 EXPECT_EQ(path_no_ext.value(), path_no_ext.RemoveExtension().value());
423 EXPECT_EQ(path_no_ext.Extension(), FILE_PATH_LITERAL(""));
424 }
425
426 TEST_F(FilePathTest, Extension2) {
427 const struct UnaryTestData cases[] = {
428 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
429 { FPL("C:\\a\\b\\c.ext"), FPL(".ext") },
430 { FPL("C:\\a\\b\\c."), FPL(".") },
431 { FPL("C:\\a\\b\\c"), FPL("") },
432 { FPL("C:\\a\\b\\"), FPL("") },
433 { FPL("C:\\a\\b.\\"), FPL(".") },
434 { FPL("C:\\a\\b\\c.ext1.ext2"), FPL(".ext2") },
435 { FPL("C:\\foo.bar\\\\\\"), FPL(".bar") },
436 { FPL("C:\\foo.bar\\.."), FPL("") },
437 { FPL("C:\\foo.bar\\..\\\\"), FPL("") },
438 #endif
439 { FPL("/foo/bar/baz.ext"), FPL(".ext") },
440 { FPL("/foo/bar/baz."), FPL(".") },
441 { FPL("/foo/bar/baz.."), FPL(".") },
442 { FPL("/foo/bar/baz"), FPL("") },
443 { FPL("/foo/bar/"), FPL("") },
444 { FPL("/foo/bar./"), FPL(".") },
445 { FPL("/foo/bar/baz.ext1.ext2"), FPL(".ext2") },
446 { FPL("."), FPL("") },
447 { FPL(".."), FPL("") },
448 { FPL("./foo"), FPL("") },
449 { FPL("./foo.ext"), FPL(".ext") },
450 { FPL("/foo.ext1/bar.ext2"), FPL(".ext2") },
451 { FPL("/foo.bar////"), FPL(".bar") },
452 { FPL("/foo.bar/.."), FPL("") },
453 { FPL("/foo.bar/..////"), FPL("") },
454 };
455 for (unsigned int i = 0; i < arraysize(cases); ++i) {
456 FilePath path(cases[i].input);
457 FilePath::StringType extension = path.Extension();
458 EXPECT_STREQ(cases[i].expected, extension.c_str()) << "i: " << i <<
459 ", path: " << path.value();
460 }
461 }
462
463 TEST_F(FilePathTest, InsertBeforeExtension) {
464 const struct BinaryTestData cases[] = {
465 { { FPL(""), FPL("") }, FPL("") },
466 { { FPL(""), FPL("txt") }, FPL("") },
467 { { FPL("."), FPL("txt") }, FPL("") },
468 { { FPL(".."), FPL("txt") }, FPL("") },
469 { { FPL("foo.dll"), FPL("txt") }, FPL("footxt.dll") },
470 { { FPL("."), FPL("") }, FPL(".") },
471 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.txt.dll") },
472 { { FPL("foo"), FPL("txt") }, FPL("footxt") },
473 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
474 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baztxt.dll") },
475 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.txt.dll") },
476 { { FPL("foo.dll"), FPL("") }, FPL("foo.dll") },
477 { { FPL("foo.dll"), FPL(".") }, FPL("foo..dll") },
478 { { FPL("foo"), FPL("") }, FPL("foo") },
479 { { FPL("foo"), FPL(".") }, FPL("foo.") },
480 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz.dll") },
481 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz..dll") },
482 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
483 { { FPL("\\"), FPL("") }, FPL("\\") },
484 { { FPL("\\"), FPL("txt") }, FPL("\\txt") },
485 { { FPL("\\."), FPL("txt") }, FPL("") },
486 { { FPL("\\.."), FPL("txt") }, FPL("") },
487 { { FPL("\\."), FPL("") }, FPL("\\.") },
488 { { FPL("C:\\bar\\foo.dll"), FPL("txt") },
489 FPL("C:\\bar\\footxt.dll") },
490 { { FPL("C:\\bar.baz\\foodll"), FPL("txt") },
491 FPL("C:\\bar.baz\\foodlltxt") },
492 { { FPL("C:\\bar.baz\\foo.dll"), FPL("txt") },
493 FPL("C:\\bar.baz\\footxt.dll") },
494 { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("txt") },
495 FPL("C:\\bar.baz\\foo.dlltxt.exe") },
496 { { FPL("C:\\bar.baz\\foo"), FPL("") },
497 FPL("C:\\bar.baz\\foo") },
498 { { FPL("C:\\bar.baz\\foo.exe"), FPL("") },
499 FPL("C:\\bar.baz\\foo.exe") },
500 { { FPL("C:\\bar.baz\\foo.dll.exe"), FPL("") },
501 FPL("C:\\bar.baz\\foo.dll.exe") },
502 { { FPL("C:\\bar\\baz\\foo.exe"), FPL(" (1)") },
503 FPL("C:\\bar\\baz\\foo (1).exe") },
504 { { FPL("C:\\foo.baz\\\\"), FPL(" (1)") }, FPL("C:\\foo (1).baz") },
505 { { FPL("C:\\foo.baz\\..\\"), FPL(" (1)") }, FPL("") },
506 #endif
507 { { FPL("/"), FPL("") }, FPL("/") },
508 { { FPL("/"), FPL("txt") }, FPL("/txt") },
509 { { FPL("/."), FPL("txt") }, FPL("") },
510 { { FPL("/.."), FPL("txt") }, FPL("") },
511 { { FPL("/."), FPL("") }, FPL("/.") },
512 { { FPL("/bar/foo.dll"), FPL("txt") }, FPL("/bar/footxt.dll") },
513 { { FPL("/bar.baz/foodll"), FPL("txt") }, FPL("/bar.baz/foodlltxt") },
514 { { FPL("/bar.baz/foo.dll"), FPL("txt") }, FPL("/bar.baz/footxt.dll") },
515 { { FPL("/bar.baz/foo.dll.exe"), FPL("txt") },
516 FPL("/bar.baz/foo.dlltxt.exe") },
517 { { FPL("/bar.baz/foo"), FPL("") }, FPL("/bar.baz/foo") },
518 { { FPL("/bar.baz/foo.exe"), FPL("") }, FPL("/bar.baz/foo.exe") },
519 { { FPL("/bar.baz/foo.dll.exe"), FPL("") }, FPL("/bar.baz/foo.dll.exe") },
520 { { FPL("/bar/baz/foo.exe"), FPL(" (1)") }, FPL("/bar/baz/foo (1).exe") },
521 { { FPL("/bar/baz/..////"), FPL(" (1)") }, FPL("") },
522 };
523 for (unsigned int i = 0; i < arraysize(cases); ++i) {
524 FilePath path(cases[i].inputs[0]);
525 FilePath result = path.InsertBeforeExtension(cases[i].inputs[1]);
526 EXPECT_EQ(cases[i].expected, result.value()) << "i: " << i <<
527 ", path: " << path.value() << ", insert: " << cases[i].inputs[1];
528 }
529 }
530
531 TEST_F(FilePathTest, ReplaceExtension) {
532 const struct BinaryTestData cases[] = {
533 { { FPL(""), FPL("") }, FPL("") },
534 { { FPL(""), FPL("txt") }, FPL("") },
535 { { FPL("."), FPL("txt") }, FPL("") },
536 { { FPL(".."), FPL("txt") }, FPL("") },
537 { { FPL("."), FPL("") }, FPL("") },
538 { { FPL("foo.dll"), FPL("txt") }, FPL("foo.txt") },
539 { { FPL("foo..dll"), FPL("txt") }, FPL("foo..txt") },
540 { { FPL("foo.dll"), FPL(".txt") }, FPL("foo.txt") },
541 { { FPL("foo"), FPL("txt") }, FPL("foo.txt") },
542 { { FPL("foo."), FPL("txt") }, FPL("foo.txt") },
543 { { FPL("foo.."), FPL("txt") }, FPL("foo..txt") },
544 { { FPL("foo"), FPL(".txt") }, FPL("foo.txt") },
545 { { FPL("foo.baz.dll"), FPL("txt") }, FPL("foo.baz.txt") },
546 { { FPL("foo.baz.dll"), FPL(".txt") }, FPL("foo.baz.txt") },
547 { { FPL("foo.dll"), FPL("") }, FPL("foo") },
548 { { FPL("foo.dll"), FPL(".") }, FPL("foo") },
549 { { FPL("foo"), FPL("") }, FPL("foo") },
550 { { FPL("foo"), FPL(".") }, FPL("foo") },
551 { { FPL("foo.baz.dll"), FPL("") }, FPL("foo.baz") },
552 { { FPL("foo.baz.dll"), FPL(".") }, FPL("foo.baz") },
553 #if defined(FILE_PATH_USES_WIN_SEPARATORS)
554 { { FPL("C:\\foo.bar\\foo"), FPL("baz") }, FPL("C:\\foo.bar\\foo.baz") },
555 { { FPL("C:\\foo.bar\\..\\\\"), FPL("baz") }, FPL("") },
556 #endif
557 { { FPL("/foo.bar/foo"), FPL("baz") }, FPL("/foo.bar/foo.baz") },
558 { { FPL("/foo.bar/..////"), FPL("baz") }, FPL("") },
559 };
560 for (unsigned int i = 0; i < arraysize(cases); ++i) {
561 FilePath path(cases[i].inputs[0]);
562 FilePath replaced = path.ReplaceExtension(cases[i].inputs[1]);
563 EXPECT_EQ(cases[i].expected, replaced.value()) << "i: " << i <<
564 ", path: " << path.value() << ", replace: " << cases[i].inputs[1];
565 }
566 }
567
OLDNEW
« no previous file with comments | « base/file_path.cc ('k') | base/file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698