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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 EXPECT_FALSE(file_util::PathExists(file_name)); | 373 EXPECT_FALSE(file_util::PathExists(file_name)); |
374 EXPECT_TRUE(file_util::PathExists(subdir_path)); | 374 EXPECT_TRUE(file_util::PathExists(subdir_path)); |
375 #endif | 375 #endif |
376 | 376 |
377 // Delete recursively and make sure all contents are deleted | 377 // Delete recursively and make sure all contents are deleted |
378 ASSERT_TRUE(file_util::Delete(directory_contents, true)); | 378 ASSERT_TRUE(file_util::Delete(directory_contents, true)); |
379 EXPECT_FALSE(file_util::PathExists(file_name)); | 379 EXPECT_FALSE(file_util::PathExists(file_name)); |
380 EXPECT_FALSE(file_util::PathExists(subdir_path)); | 380 EXPECT_FALSE(file_util::PathExists(subdir_path)); |
381 } | 381 } |
382 | 382 |
| 383 TEST_F(FileUtilTest, MoveFileNew) { |
| 384 // Create a file |
| 385 FilePath file_name_from = |
| 386 test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 387 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 388 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 389 |
| 390 // The destination |
| 391 FilePath file_name_to = |
| 392 test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); |
| 393 ASSERT_FALSE(file_util::PathExists(file_name_to)); |
| 394 |
| 395 EXPECT_TRUE(file_util::Move(file_name_from, file_name_to)); |
| 396 |
| 397 // Check everything has been moved. |
| 398 EXPECT_FALSE(file_util::PathExists(file_name_from)); |
| 399 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 400 } |
| 401 |
| 402 TEST_F(FileUtilTest, MoveFileExists) { |
| 403 // Create a file |
| 404 FilePath file_name_from = |
| 405 test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 406 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 407 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 408 |
| 409 // The destination name |
| 410 FilePath file_name_to = |
| 411 test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); |
| 412 CreateTextFile(file_name_to, L"Old file content"); |
| 413 ASSERT_TRUE(file_util::PathExists(file_name_to)); |
| 414 |
| 415 EXPECT_TRUE(file_util::Move(file_name_from, file_name_to)); |
| 416 |
| 417 // Check everything has been moved. |
| 418 EXPECT_FALSE(file_util::PathExists(file_name_from)); |
| 419 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 420 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); |
| 421 } |
| 422 |
| 423 TEST_F(FileUtilTest, MoveFileDirExists) { |
| 424 // Create a file |
| 425 FilePath file_name_from = |
| 426 test_dir_.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 427 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 428 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 429 |
| 430 // The destination directory |
| 431 FilePath dir_name_to = |
| 432 test_dir_.Append(FILE_PATH_LITERAL("Destination")); |
| 433 file_util::CreateDirectory(dir_name_to); |
| 434 ASSERT_TRUE(file_util::PathExists(dir_name_to)); |
| 435 |
| 436 EXPECT_FALSE(file_util::Move(file_name_from, dir_name_to)); |
| 437 } |
| 438 |
| 439 |
383 TEST_F(FileUtilTest, MoveNew) { | 440 TEST_F(FileUtilTest, MoveNew) { |
384 // Create a directory | 441 // Create a directory |
385 FilePath dir_name_from = | 442 FilePath dir_name_from = |
386 test_dir_.Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 443 test_dir_.Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
387 file_util::CreateDirectory(dir_name_from); | 444 file_util::CreateDirectory(dir_name_from); |
388 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 445 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
389 | 446 |
390 // Create a file under the directory | 447 // Create a file under the directory |
391 FilePath file_name_from = | 448 FilePath file_name_from = |
392 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 449 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 // Check everything has been copied. | 695 // Check everything has been copied. |
639 EXPECT_TRUE(file_util::PathExists(dir_name_from)); | 696 EXPECT_TRUE(file_util::PathExists(dir_name_from)); |
640 EXPECT_TRUE(file_util::PathExists(file_name_from)); | 697 EXPECT_TRUE(file_util::PathExists(file_name_from)); |
641 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); | 698 EXPECT_TRUE(file_util::PathExists(subdir_name_from)); |
642 EXPECT_TRUE(file_util::PathExists(file_name2_from)); | 699 EXPECT_TRUE(file_util::PathExists(file_name2_from)); |
643 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 700 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
644 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 701 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
645 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); | 702 EXPECT_FALSE(file_util::PathExists(subdir_name_to)); |
646 } | 703 } |
647 | 704 |
| 705 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { |
| 706 // Create a file |
| 707 FilePath file_name_from = |
| 708 test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 709 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 710 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 711 |
| 712 // The destination name |
| 713 FilePath file_name_to = |
| 714 test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
| 715 ASSERT_FALSE(file_util::PathExists(file_name_to)); |
| 716 |
| 717 EXPECT_TRUE(file_util::CopyDirectory(file_name_from, file_name_to, true)); |
| 718 |
| 719 // Check the has been copied |
| 720 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 721 } |
| 722 |
| 723 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { |
| 724 // Create a file |
| 725 FilePath file_name_from = |
| 726 test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 727 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 728 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 729 |
| 730 // The destination name |
| 731 FilePath file_name_to = |
| 732 test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
| 733 CreateTextFile(file_name_to, L"Old file content"); |
| 734 ASSERT_TRUE(file_util::PathExists(file_name_to)); |
| 735 |
| 736 EXPECT_TRUE(file_util::CopyDirectory(file_name_from, file_name_to, true)); |
| 737 |
| 738 // Check the has been copied |
| 739 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 740 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); |
| 741 } |
| 742 |
| 743 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { |
| 744 // Create a file |
| 745 FilePath file_name_from = |
| 746 test_dir_.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 747 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 748 ASSERT_TRUE(file_util::PathExists(file_name_from)); |
| 749 |
| 750 // The destination |
| 751 FilePath dir_name_to = |
| 752 test_dir_.Append(FILE_PATH_LITERAL("Destination")); |
| 753 file_util::CreateDirectory(dir_name_to); |
| 754 ASSERT_TRUE(file_util::PathExists(dir_name_to)); |
| 755 FilePath file_name_to = |
| 756 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 757 |
| 758 EXPECT_TRUE(file_util::CopyDirectory(file_name_from, dir_name_to, true)); |
| 759 |
| 760 // Check the has been copied |
| 761 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
| 762 } |
| 763 |
648 TEST_F(FileUtilTest, CopyFile) { | 764 TEST_F(FileUtilTest, CopyFile) { |
649 // Create a directory | 765 // Create a directory |
650 FilePath dir_name_from = | 766 FilePath dir_name_from = |
651 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 767 test_dir_.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
652 file_util::CreateDirectory(dir_name_from); | 768 file_util::CreateDirectory(dir_name_from); |
653 ASSERT_TRUE(file_util::PathExists(dir_name_from)); | 769 ASSERT_TRUE(file_util::PathExists(dir_name_from)); |
654 | 770 |
655 // Create a file under the directory | 771 // Create a file under the directory |
656 FilePath file_name_from = | 772 FilePath file_name_from = |
657 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 773 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 #elif defined(OS_LINUX) | 1355 #elif defined(OS_LINUX) |
1240 EXPECT_FALSE(file_util::ContainsPath(foo, | 1356 EXPECT_FALSE(file_util::ContainsPath(foo, |
1241 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | 1357 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); |
1242 #else | 1358 #else |
1243 // We can't really do this test on osx since the case-sensitivity of the | 1359 // We can't really do this test on osx since the case-sensitivity of the |
1244 // filesystem is configurable. | 1360 // filesystem is configurable. |
1245 #endif | 1361 #endif |
1246 } | 1362 } |
1247 | 1363 |
1248 } // namespace | 1364 } // namespace |
OLD | NEW |