| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 402 |
| 403 EXPECT_TRUE(file_util::Move(dir_name_from, dir_name_to)); | 403 EXPECT_TRUE(file_util::Move(dir_name_from, dir_name_to)); |
| 404 | 404 |
| 405 // Check everything has been moved. | 405 // Check everything has been moved. |
| 406 EXPECT_FALSE(file_util::PathExists(dir_name_from)); | 406 EXPECT_FALSE(file_util::PathExists(dir_name_from)); |
| 407 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 407 EXPECT_FALSE(file_util::PathExists(file_name_from)); |
| 408 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 408 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 409 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 409 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 410 } | 410 } |
| 411 | 411 |
| 412 TEST_F(FileUtilTest, CopyDirectoryRecursively) { | 412 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { |
| 413 // Create a directory. | 413 // Create a directory. |
| 414 FilePath dir_name_from = | 414 FilePath dir_name_from = |
| 415 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 415 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 416 file_util::CreateDirectory(dir_name_from); | 416 file_util::CreateDirectory(dir_name_from); |
| 417 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 417 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 418 | 418 |
| 419 // Create a file under the directory. | 419 // Create a file under the directory. |
| 420 FilePath file_name_from = | 420 FilePath file_name_from = |
| 421 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 421 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 422 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 422 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 452 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 452 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
| 453 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 453 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
| 454 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 454 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
| 455 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 455 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
| 456 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 456 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 457 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 457 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 458 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); | 458 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); |
| 459 EXPECT_TRUE(file_util::PathExists(file_name2_to)); | 459 EXPECT_TRUE(file_util::PathExists(file_name2_to)); |
| 460 } | 460 } |
| 461 | 461 |
| 462 TEST_F(FileUtilTest, CopyDirectory) { | 462 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { |
| 463 // Create a directory. | 463 // Create a directory. |
| 464 FilePath dir_name_from = | 464 FilePath dir_name_from = |
| 465 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 465 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 466 file_util::CreateDirectory(dir_name_from); | 466 file_util::CreateDirectory(dir_name_from); |
| 467 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 467 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 468 | 468 |
| 469 // Create a file under the directory. | 469 // Create a file under the directory. |
| 470 FilePath file_name_from = | 470 FilePath file_name_from = |
| 471 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 471 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 472 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 472 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 473 ASSERT_TRUE(file_util::PathExists(file_name_from)); | 473 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 474 | 474 |
| 475 // Create a subdirectory. | 475 // Create a subdirectory. |
| 476 FilePath subdir_name_from = | 476 FilePath subdir_name_from = |
| 477 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 477 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 478 file_util::CreateDirectory(subdir_name_from); | 478 file_util::CreateDirectory(subdir_name_from); |
| 479 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); | 479 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); |
| 480 | 480 |
| 481 // Create a file under the subdirectory. | 481 // Create a file under the subdirectory. |
| 482 FilePath file_name2_from = | 482 FilePath file_name2_from = |
| 483 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 483 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 484 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 484 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 485 ASSERT_TRUE(file_util::PathExists(file_name2_from)); | 485 ASSERT_TRUE(file_util::PathExists(file_name2_from)); |
| 486 | 486 |
| 487 // Copy the directory recursively. |
| 488 FilePath dir_name_exists = |
| 489 test_dir_.Append(FILE_PATH_LITERAL("Destination")); |
| 490 |
| 491 FilePath dir_name_to = |
| 492 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 493 FilePath file_name_to = |
| 494 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 495 FilePath subdir_name_to = |
| 496 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 497 FilePath file_name2_to = |
| 498 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 499 |
| 500 // Create the destination directory. |
| 501 file_util::CreateDirectory(dir_name_exists); |
| 502 ASSERT_TRUE(file_util::PathExists(dir_name_exists)); |
| 503 |
| 504 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_exists, true)); |
| 505 |
| 506 // Check everything has been copied. |
| 507 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
| 508 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
| 509 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
| 510 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
| 511 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 512 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 513 EXPECT_TRUE(file_util::PathExists(subdir_name_to)); |
| 514 EXPECT_TRUE(file_util::PathExists(file_name2_to)); |
| 515 } |
| 516 |
| 517 TEST_F(FileUtilTest, CopyDirectoryNew) { |
| 518 // Create a directory. |
| 519 FilePath dir_name_from = |
| 520 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 521 file_util::CreateDirectory(dir_name_from); |
| 522 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 523 |
| 524 // Create a file under the directory. |
| 525 FilePath file_name_from = |
| 526 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 527 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 528 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 529 |
| 530 // Create a subdirectory. |
| 531 FilePath subdir_name_from = |
| 532 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 533 file_util::CreateDirectory(subdir_name_from); |
| 534 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); |
| 535 |
| 536 // Create a file under the subdirectory. |
| 537 FilePath file_name2_from = |
| 538 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 539 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 540 ASSERT_TRUE(file_util::PathExists(file_name2_from)); |
| 541 |
| 487 // Copy the directory not recursively. | 542 // Copy the directory not recursively. |
| 488 FilePath dir_name_to = | 543 FilePath dir_name_to = |
| 489 test_dir_.Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 544 test_dir_.Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 490 FilePath file_name_to = | 545 FilePath file_name_to = |
| 491 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 546 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 492 FilePath subdir_name_to = | 547 FilePath subdir_name_to = |
| 493 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 548 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 494 | 549 |
| 495 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 550 ASSERT_FALSE(file_util::PathExists(dir_name_to)); |
| 496 | 551 |
| 497 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_to, false)); | 552 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_to, false)); |
| 498 | 553 |
| 499 // Check everything has been copied. | 554 // Check everything has been copied. |
| 500 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 555 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
| 501 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 556 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
| 502 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 557 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
| 503 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 558 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
| 504 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 559 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 505 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 560 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 506 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); | 561 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); |
| 507 } | 562 } |
| 508 | 563 |
| 564 TEST_F(FileUtilTest, CopyDirectoryExists) { |
| 565 // Create a directory. |
| 566 FilePath dir_name_from = |
| 567 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 568 file_util::CreateDirectory(dir_name_from); |
| 569 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 570 |
| 571 // Create a file under the directory. |
| 572 FilePath file_name_from = |
| 573 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 574 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 575 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 576 |
| 577 // Create a subdirectory. |
| 578 FilePath subdir_name_from = |
| 579 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 580 file_util::CreateDirectory(subdir_name_from); |
| 581 ASSERT_TRUE(file_util::PathExists(subdir_name_from)); |
| 582 |
| 583 // Create a file under the subdirectory. |
| 584 FilePath file_name2_from = |
| 585 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 586 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 587 ASSERT_TRUE(file_util::PathExists(file_name2_from)); |
| 588 |
| 589 // Copy the directory not recursively. |
| 590 FilePath dir_name_to = |
| 591 test_dir_.Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 592 FilePath file_name_to = |
| 593 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 594 FilePath subdir_name_to = |
| 595 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 596 |
| 597 // Create the destination directory. |
| 598 file_util::CreateDirectory(dir_name_to); |
| 599 ASSERT_TRUE(file_util::PathExists(dir_name_to)); |
| 600 |
| 601 EXPECT_TRUE(file_util::CopyDirectory(dir_name_from, dir_name_to, false)); |
| 602 |
| 603 // Check everything has been copied. |
| 604 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
| 605 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
| 606 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
| 607 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
| 608 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
| 609 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 610 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); |
| 611 } |
| 612 |
| 509 TEST_F(FileUtilTest, CopyFile) { | 613 TEST_F(FileUtilTest, CopyFile) { |
| 510 // Create a directory | 614 // Create a directory |
| 511 FilePath dir_name_from = | 615 FilePath dir_name_from = |
| 512 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 616 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 513 file_util::CreateDirectory(dir_name_from); | 617 file_util::CreateDirectory(dir_name_from); |
| 514 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 618 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
| 515 | 619 |
| 516 // Create a file under the directory | 620 // Create a file under the directory |
| 517 FilePath file_name_from = | 621 FilePath file_name_from = |
| 518 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 622 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 #elif defined(OS_LINUX) | 1204 #elif defined(OS_LINUX) |
| 1101 EXPECT_FALSE(file_util::ContainsPath(foo, | 1205 EXPECT_FALSE(file_util::ContainsPath(foo, |
| 1102 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | 1206 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); |
| 1103 #else | 1207 #else |
| 1104 // We can't really do this test on osx since the case-sensitivity of the | 1208 // We can't really do this test on osx since the case-sensitivity of the |
| 1105 // filesystem is configurable. | 1209 // filesystem is configurable. |
| 1106 #endif | 1210 #endif |
| 1107 } | 1211 } |
| 1108 | 1212 |
| 1109 } // namespace | 1213 } // namespace |
| OLD | NEW |