| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <fstream> | 9 #include <fstream> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 file.open(filename.value().c_str()); | 242 file.open(filename.value().c_str()); |
| 243 EXPECT_TRUE(file.is_open()); | 243 EXPECT_TRUE(file.is_open()); |
| 244 file.getline(contents, arraysize(contents)); | 244 file.getline(contents, arraysize(contents)); |
| 245 file.close(); | 245 file.close(); |
| 246 return std::wstring(contents); | 246 return std::wstring(contents); |
| 247 } | 247 } |
| 248 | 248 |
| 249 TEST_F(FileUtilTest, FileAndDirectorySize) { | 249 TEST_F(FileUtilTest, FileAndDirectorySize) { |
| 250 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize | 250 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize |
| 251 // should return 53 bytes. | 251 // should return 53 bytes. |
| 252 FilePath file_01 = temp_dir_.path().Append(FPL("The file 01.txt")); | 252 FilePath file_01 = temp_dir_.GetPath().Append(FPL("The file 01.txt")); |
| 253 CreateTextFile(file_01, L"12345678901234567890"); | 253 CreateTextFile(file_01, L"12345678901234567890"); |
| 254 int64_t size_f1 = 0; | 254 int64_t size_f1 = 0; |
| 255 ASSERT_TRUE(GetFileSize(file_01, &size_f1)); | 255 ASSERT_TRUE(GetFileSize(file_01, &size_f1)); |
| 256 EXPECT_EQ(20ll, size_f1); | 256 EXPECT_EQ(20ll, size_f1); |
| 257 | 257 |
| 258 FilePath subdir_path = temp_dir_.path().Append(FPL("Level2")); | 258 FilePath subdir_path = temp_dir_.GetPath().Append(FPL("Level2")); |
| 259 CreateDirectory(subdir_path); | 259 CreateDirectory(subdir_path); |
| 260 | 260 |
| 261 FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); | 261 FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); |
| 262 CreateTextFile(file_02, L"123456789012345678901234567890"); | 262 CreateTextFile(file_02, L"123456789012345678901234567890"); |
| 263 int64_t size_f2 = 0; | 263 int64_t size_f2 = 0; |
| 264 ASSERT_TRUE(GetFileSize(file_02, &size_f2)); | 264 ASSERT_TRUE(GetFileSize(file_02, &size_f2)); |
| 265 EXPECT_EQ(30ll, size_f2); | 265 EXPECT_EQ(30ll, size_f2); |
| 266 | 266 |
| 267 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); | 267 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); |
| 268 CreateDirectory(subsubdir_path); | 268 CreateDirectory(subsubdir_path); |
| 269 | 269 |
| 270 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); | 270 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); |
| 271 CreateTextFile(file_03, L"123"); | 271 CreateTextFile(file_03, L"123"); |
| 272 | 272 |
| 273 int64_t computed_size = ComputeDirectorySize(temp_dir_.path()); | 273 int64_t computed_size = ComputeDirectorySize(temp_dir_.GetPath()); |
| 274 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); | 274 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); |
| 275 } | 275 } |
| 276 | 276 |
| 277 TEST_F(FileUtilTest, NormalizeFilePathBasic) { | 277 TEST_F(FileUtilTest, NormalizeFilePathBasic) { |
| 278 // Create a directory under the test dir. Because we create it, | 278 // Create a directory under the test dir. Because we create it, |
| 279 // we know it is not a link. | 279 // we know it is not a link. |
| 280 FilePath file_a_path = temp_dir_.path().Append(FPL("file_a")); | 280 FilePath file_a_path = temp_dir_.GetPath().Append(FPL("file_a")); |
| 281 FilePath dir_path = temp_dir_.path().Append(FPL("dir")); | 281 FilePath dir_path = temp_dir_.GetPath().Append(FPL("dir")); |
| 282 FilePath file_b_path = dir_path.Append(FPL("file_b")); | 282 FilePath file_b_path = dir_path.Append(FPL("file_b")); |
| 283 CreateDirectory(dir_path); | 283 CreateDirectory(dir_path); |
| 284 | 284 |
| 285 FilePath normalized_file_a_path, normalized_file_b_path; | 285 FilePath normalized_file_a_path, normalized_file_b_path; |
| 286 ASSERT_FALSE(PathExists(file_a_path)); | 286 ASSERT_FALSE(PathExists(file_a_path)); |
| 287 ASSERT_FALSE(NormalizeFilePath(file_a_path, &normalized_file_a_path)) | 287 ASSERT_FALSE(NormalizeFilePath(file_a_path, &normalized_file_a_path)) |
| 288 << "NormalizeFilePath() should fail on nonexistent paths."; | 288 << "NormalizeFilePath() should fail on nonexistent paths."; |
| 289 | 289 |
| 290 CreateTextFile(file_a_path, bogus_content); | 290 CreateTextFile(file_a_path, bogus_content); |
| 291 ASSERT_TRUE(PathExists(file_a_path)); | 291 ASSERT_TRUE(PathExists(file_a_path)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 312 // | |-> sub_a | 312 // | |-> sub_a |
| 313 // | |-> file.txt | 313 // | |-> file.txt |
| 314 // | |-> long_name___... (Very long name.) | 314 // | |-> long_name___... (Very long name.) |
| 315 // | |-> sub_long | 315 // | |-> sub_long |
| 316 // | |-> deep.txt | 316 // | |-> deep.txt |
| 317 // |-> base_b | 317 // |-> base_b |
| 318 // |-> to_sub_a (reparse point to temp_dir\base_a\sub_a) | 318 // |-> to_sub_a (reparse point to temp_dir\base_a\sub_a) |
| 319 // |-> to_base_b (reparse point to temp_dir\base_b) | 319 // |-> to_base_b (reparse point to temp_dir\base_b) |
| 320 // |-> to_sub_long (reparse point to temp_dir\sub_a\long_name_\sub_long) | 320 // |-> to_sub_long (reparse point to temp_dir\sub_a\long_name_\sub_long) |
| 321 | 321 |
| 322 FilePath base_a = temp_dir_.path().Append(FPL("base_a")); | 322 FilePath base_a = temp_dir_.GetPath().Append(FPL("base_a")); |
| 323 #if defined(OS_WIN) | 323 #if defined(OS_WIN) |
| 324 // TEMP can have a lower case drive letter. | 324 // TEMP can have a lower case drive letter. |
| 325 string16 temp_base_a = base_a.value(); | 325 string16 temp_base_a = base_a.value(); |
| 326 ASSERT_FALSE(temp_base_a.empty()); | 326 ASSERT_FALSE(temp_base_a.empty()); |
| 327 *temp_base_a.begin() = ToUpperASCII(*temp_base_a.begin()); | 327 *temp_base_a.begin() = ToUpperASCII(*temp_base_a.begin()); |
| 328 base_a = FilePath(temp_base_a); | 328 base_a = FilePath(temp_base_a); |
| 329 #endif | 329 #endif |
| 330 ASSERT_TRUE(CreateDirectory(base_a)); | 330 ASSERT_TRUE(CreateDirectory(base_a)); |
| 331 | 331 |
| 332 FilePath sub_a = base_a.Append(FPL("sub_a")); | 332 FilePath sub_a = base_a.Append(FPL("sub_a")); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 355 | 355 |
| 356 FilePath long_name = sub_a.Append(FilePath(long_name_str)); | 356 FilePath long_name = sub_a.Append(FilePath(long_name_str)); |
| 357 FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt); | 357 FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt); |
| 358 ASSERT_EQ(static_cast<size_t>(MAX_PATH - kCreateDirLimit), | 358 ASSERT_EQ(static_cast<size_t>(MAX_PATH - kCreateDirLimit), |
| 359 deep_file.value().length()); | 359 deep_file.value().length()); |
| 360 | 360 |
| 361 FilePath sub_long = deep_file.DirName(); | 361 FilePath sub_long = deep_file.DirName(); |
| 362 ASSERT_TRUE(CreateDirectory(sub_long)); | 362 ASSERT_TRUE(CreateDirectory(sub_long)); |
| 363 CreateTextFile(deep_file, bogus_content); | 363 CreateTextFile(deep_file, bogus_content); |
| 364 | 364 |
| 365 FilePath base_b = temp_dir_.path().Append(FPL("base_b")); | 365 FilePath base_b = temp_dir_.GetPath().Append(FPL("base_b")); |
| 366 ASSERT_TRUE(CreateDirectory(base_b)); | 366 ASSERT_TRUE(CreateDirectory(base_b)); |
| 367 | 367 |
| 368 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); | 368 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); |
| 369 ASSERT_TRUE(CreateDirectory(to_sub_a)); | 369 ASSERT_TRUE(CreateDirectory(to_sub_a)); |
| 370 FilePath normalized_path; | 370 FilePath normalized_path; |
| 371 { | 371 { |
| 372 ReparsePoint reparse_to_sub_a(to_sub_a, sub_a); | 372 ReparsePoint reparse_to_sub_a(to_sub_a, sub_a); |
| 373 ASSERT_TRUE(reparse_to_sub_a.IsValid()); | 373 ASSERT_TRUE(reparse_to_sub_a.IsValid()); |
| 374 | 374 |
| 375 FilePath to_base_b = base_b.Append(FPL("to_base_b")); | 375 FilePath to_base_b = base_b.Append(FPL("to_base_b")); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // to traverse them. | 423 // to traverse them. |
| 424 } | 424 } |
| 425 | 425 |
| 426 ASSERT_FALSE(NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), | 426 ASSERT_FALSE(NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), |
| 427 &normalized_path)); | 427 &normalized_path)); |
| 428 } | 428 } |
| 429 | 429 |
| 430 TEST_F(FileUtilTest, DevicePathToDriveLetter) { | 430 TEST_F(FileUtilTest, DevicePathToDriveLetter) { |
| 431 // Get a drive letter. | 431 // Get a drive letter. |
| 432 string16 real_drive_letter = | 432 string16 real_drive_letter = |
| 433 ToUpperASCII(temp_dir_.path().value().substr(0, 2)); | 433 ToUpperASCII(temp_dir_.GetPath().value().substr(0, 2)); |
| 434 if (!isalpha(real_drive_letter[0]) || ':' != real_drive_letter[1]) { | 434 if (!isalpha(real_drive_letter[0]) || ':' != real_drive_letter[1]) { |
| 435 LOG(ERROR) << "Can't get a drive letter to test with."; | 435 LOG(ERROR) << "Can't get a drive letter to test with."; |
| 436 return; | 436 return; |
| 437 } | 437 } |
| 438 | 438 |
| 439 // Get the NT style path to that drive. | 439 // Get the NT style path to that drive. |
| 440 wchar_t device_path[MAX_PATH] = {'\0'}; | 440 wchar_t device_path[MAX_PATH] = {'\0'}; |
| 441 ASSERT_TRUE( | 441 ASSERT_TRUE( |
| 442 ::QueryDosDevice(real_drive_letter.c_str(), device_path, MAX_PATH)); | 442 ::QueryDosDevice(real_drive_letter.c_str(), device_path, MAX_PATH)); |
| 443 FilePath actual_device_path(device_path); | 443 FilePath actual_device_path(device_path); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 } | 497 } |
| 498 | 498 |
| 499 TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { | 499 TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { |
| 500 // Test that CreateTemporaryFileInDir() creates a path and returns a long path | 500 // Test that CreateTemporaryFileInDir() creates a path and returns a long path |
| 501 // if it is available. This test requires that: | 501 // if it is available. This test requires that: |
| 502 // - the filesystem at |temp_dir_| supports long filenames. | 502 // - the filesystem at |temp_dir_| supports long filenames. |
| 503 // - the account has FILE_LIST_DIRECTORY permission for all ancestor | 503 // - the account has FILE_LIST_DIRECTORY permission for all ancestor |
| 504 // directories of |temp_dir_|. | 504 // directories of |temp_dir_|. |
| 505 const FilePath::CharType kLongDirName[] = FPL("A long path"); | 505 const FilePath::CharType kLongDirName[] = FPL("A long path"); |
| 506 const FilePath::CharType kTestSubDirName[] = FPL("test"); | 506 const FilePath::CharType kTestSubDirName[] = FPL("test"); |
| 507 FilePath long_test_dir = temp_dir_.path().Append(kLongDirName); | 507 FilePath long_test_dir = temp_dir_.GetPath().Append(kLongDirName); |
| 508 ASSERT_TRUE(CreateDirectory(long_test_dir)); | 508 ASSERT_TRUE(CreateDirectory(long_test_dir)); |
| 509 | 509 |
| 510 // kLongDirName is not a 8.3 component. So GetShortName() should give us a | 510 // kLongDirName is not a 8.3 component. So GetShortName() should give us a |
| 511 // different short name. | 511 // different short name. |
| 512 WCHAR path_buffer[MAX_PATH]; | 512 WCHAR path_buffer[MAX_PATH]; |
| 513 DWORD path_buffer_length = GetShortPathName(long_test_dir.value().c_str(), | 513 DWORD path_buffer_length = GetShortPathName(long_test_dir.value().c_str(), |
| 514 path_buffer, MAX_PATH); | 514 path_buffer, MAX_PATH); |
| 515 ASSERT_LT(path_buffer_length, DWORD(MAX_PATH)); | 515 ASSERT_LT(path_buffer_length, DWORD(MAX_PATH)); |
| 516 ASSERT_NE(DWORD(0), path_buffer_length); | 516 ASSERT_NE(DWORD(0), path_buffer_length); |
| 517 FilePath short_test_dir(path_buffer); | 517 FilePath short_test_dir(path_buffer); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 544 path_buffer_length = GetLongPathName(temp_file.value().c_str(), | 544 path_buffer_length = GetLongPathName(temp_file.value().c_str(), |
| 545 path_buffer, MAX_PATH); | 545 path_buffer, MAX_PATH); |
| 546 EXPECT_EQ(DWORD(0), path_buffer_length); | 546 EXPECT_EQ(DWORD(0), path_buffer_length); |
| 547 } | 547 } |
| 548 | 548 |
| 549 #endif // defined(OS_WIN) | 549 #endif // defined(OS_WIN) |
| 550 | 550 |
| 551 #if defined(OS_POSIX) | 551 #if defined(OS_POSIX) |
| 552 | 552 |
| 553 TEST_F(FileUtilTest, CreateAndReadSymlinks) { | 553 TEST_F(FileUtilTest, CreateAndReadSymlinks) { |
| 554 FilePath link_from = temp_dir_.path().Append(FPL("from_file")); | 554 FilePath link_from = temp_dir_.GetPath().Append(FPL("from_file")); |
| 555 FilePath link_to = temp_dir_.path().Append(FPL("to_file")); | 555 FilePath link_to = temp_dir_.GetPath().Append(FPL("to_file")); |
| 556 CreateTextFile(link_to, bogus_content); | 556 CreateTextFile(link_to, bogus_content); |
| 557 | 557 |
| 558 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 558 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| 559 << "Failed to create file symlink."; | 559 << "Failed to create file symlink."; |
| 560 | 560 |
| 561 // If we created the link properly, we should be able to read the contents | 561 // If we created the link properly, we should be able to read the contents |
| 562 // through it. | 562 // through it. |
| 563 std::wstring contents = ReadTextFile(link_from); | 563 std::wstring contents = ReadTextFile(link_from); |
| 564 EXPECT_EQ(bogus_content, contents); | 564 EXPECT_EQ(bogus_content, contents); |
| 565 | 565 |
| 566 FilePath result; | 566 FilePath result; |
| 567 ASSERT_TRUE(ReadSymbolicLink(link_from, &result)); | 567 ASSERT_TRUE(ReadSymbolicLink(link_from, &result)); |
| 568 EXPECT_EQ(link_to.value(), result.value()); | 568 EXPECT_EQ(link_to.value(), result.value()); |
| 569 | 569 |
| 570 // Link to a directory. | 570 // Link to a directory. |
| 571 link_from = temp_dir_.path().Append(FPL("from_dir")); | 571 link_from = temp_dir_.GetPath().Append(FPL("from_dir")); |
| 572 link_to = temp_dir_.path().Append(FPL("to_dir")); | 572 link_to = temp_dir_.GetPath().Append(FPL("to_dir")); |
| 573 ASSERT_TRUE(CreateDirectory(link_to)); | 573 ASSERT_TRUE(CreateDirectory(link_to)); |
| 574 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 574 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| 575 << "Failed to create directory symlink."; | 575 << "Failed to create directory symlink."; |
| 576 | 576 |
| 577 // Test failures. | 577 // Test failures. |
| 578 EXPECT_FALSE(CreateSymbolicLink(link_to, link_to)); | 578 EXPECT_FALSE(CreateSymbolicLink(link_to, link_to)); |
| 579 EXPECT_FALSE(ReadSymbolicLink(link_to, &result)); | 579 EXPECT_FALSE(ReadSymbolicLink(link_to, &result)); |
| 580 FilePath missing = temp_dir_.path().Append(FPL("missing")); | 580 FilePath missing = temp_dir_.GetPath().Append(FPL("missing")); |
| 581 EXPECT_FALSE(ReadSymbolicLink(missing, &result)); | 581 EXPECT_FALSE(ReadSymbolicLink(missing, &result)); |
| 582 } | 582 } |
| 583 | 583 |
| 584 // The following test of NormalizeFilePath() require that we create a symlink. | 584 // The following test of NormalizeFilePath() require that we create a symlink. |
| 585 // This can not be done on Windows before Vista. On Vista, creating a symlink | 585 // This can not be done on Windows before Vista. On Vista, creating a symlink |
| 586 // requires privilege "SeCreateSymbolicLinkPrivilege". | 586 // requires privilege "SeCreateSymbolicLinkPrivilege". |
| 587 // TODO(skerner): Investigate the possibility of giving base_unittests the | 587 // TODO(skerner): Investigate the possibility of giving base_unittests the |
| 588 // privileges required to create a symlink. | 588 // privileges required to create a symlink. |
| 589 TEST_F(FileUtilTest, NormalizeFilePathSymlinks) { | 589 TEST_F(FileUtilTest, NormalizeFilePathSymlinks) { |
| 590 // Link one file to another. | 590 // Link one file to another. |
| 591 FilePath link_from = temp_dir_.path().Append(FPL("from_file")); | 591 FilePath link_from = temp_dir_.GetPath().Append(FPL("from_file")); |
| 592 FilePath link_to = temp_dir_.path().Append(FPL("to_file")); | 592 FilePath link_to = temp_dir_.GetPath().Append(FPL("to_file")); |
| 593 CreateTextFile(link_to, bogus_content); | 593 CreateTextFile(link_to, bogus_content); |
| 594 | 594 |
| 595 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 595 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| 596 << "Failed to create file symlink."; | 596 << "Failed to create file symlink."; |
| 597 | 597 |
| 598 // Check that NormalizeFilePath sees the link. | 598 // Check that NormalizeFilePath sees the link. |
| 599 FilePath normalized_path; | 599 FilePath normalized_path; |
| 600 ASSERT_TRUE(NormalizeFilePath(link_from, &normalized_path)); | 600 ASSERT_TRUE(NormalizeFilePath(link_from, &normalized_path)); |
| 601 EXPECT_NE(link_from, link_to); | 601 EXPECT_NE(link_from, link_to); |
| 602 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); | 602 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); |
| 603 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); | 603 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); |
| 604 | 604 |
| 605 // Link to a directory. | 605 // Link to a directory. |
| 606 link_from = temp_dir_.path().Append(FPL("from_dir")); | 606 link_from = temp_dir_.GetPath().Append(FPL("from_dir")); |
| 607 link_to = temp_dir_.path().Append(FPL("to_dir")); | 607 link_to = temp_dir_.GetPath().Append(FPL("to_dir")); |
| 608 ASSERT_TRUE(CreateDirectory(link_to)); | 608 ASSERT_TRUE(CreateDirectory(link_to)); |
| 609 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 609 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| 610 << "Failed to create directory symlink."; | 610 << "Failed to create directory symlink."; |
| 611 | 611 |
| 612 EXPECT_FALSE(NormalizeFilePath(link_from, &normalized_path)) | 612 EXPECT_FALSE(NormalizeFilePath(link_from, &normalized_path)) |
| 613 << "Links to directories should return false."; | 613 << "Links to directories should return false."; |
| 614 | 614 |
| 615 // Test that a loop in the links causes NormalizeFilePath() to return false. | 615 // Test that a loop in the links causes NormalizeFilePath() to return false. |
| 616 link_from = temp_dir_.path().Append(FPL("link_a")); | 616 link_from = temp_dir_.GetPath().Append(FPL("link_a")); |
| 617 link_to = temp_dir_.path().Append(FPL("link_b")); | 617 link_to = temp_dir_.GetPath().Append(FPL("link_b")); |
| 618 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 618 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| 619 << "Failed to create loop symlink a."; | 619 << "Failed to create loop symlink a."; |
| 620 ASSERT_TRUE(CreateSymbolicLink(link_from, link_to)) | 620 ASSERT_TRUE(CreateSymbolicLink(link_from, link_to)) |
| 621 << "Failed to create loop symlink b."; | 621 << "Failed to create loop symlink b."; |
| 622 | 622 |
| 623 // Infinite loop! | 623 // Infinite loop! |
| 624 EXPECT_FALSE(NormalizeFilePath(link_from, &normalized_path)); | 624 EXPECT_FALSE(NormalizeFilePath(link_from, &normalized_path)); |
| 625 } | 625 } |
| 626 #endif // defined(OS_POSIX) | 626 #endif // defined(OS_POSIX) |
| 627 | 627 |
| 628 TEST_F(FileUtilTest, DeleteNonExistent) { | 628 TEST_F(FileUtilTest, DeleteNonExistent) { |
| 629 FilePath non_existent = temp_dir_.path().AppendASCII("bogus_file_dne.foobar"); | 629 FilePath non_existent = |
| 630 temp_dir_.GetPath().AppendASCII("bogus_file_dne.foobar"); |
| 630 ASSERT_FALSE(PathExists(non_existent)); | 631 ASSERT_FALSE(PathExists(non_existent)); |
| 631 | 632 |
| 632 EXPECT_TRUE(DeleteFile(non_existent, false)); | 633 EXPECT_TRUE(DeleteFile(non_existent, false)); |
| 633 ASSERT_FALSE(PathExists(non_existent)); | 634 ASSERT_FALSE(PathExists(non_existent)); |
| 634 EXPECT_TRUE(DeleteFile(non_existent, true)); | 635 EXPECT_TRUE(DeleteFile(non_existent, true)); |
| 635 ASSERT_FALSE(PathExists(non_existent)); | 636 ASSERT_FALSE(PathExists(non_existent)); |
| 636 } | 637 } |
| 637 | 638 |
| 638 TEST_F(FileUtilTest, DeleteNonExistentWithNonExistentParent) { | 639 TEST_F(FileUtilTest, DeleteNonExistentWithNonExistentParent) { |
| 639 FilePath non_existent = temp_dir_.path().AppendASCII("bogus_topdir"); | 640 FilePath non_existent = temp_dir_.GetPath().AppendASCII("bogus_topdir"); |
| 640 non_existent = non_existent.AppendASCII("bogus_subdir"); | 641 non_existent = non_existent.AppendASCII("bogus_subdir"); |
| 641 ASSERT_FALSE(PathExists(non_existent)); | 642 ASSERT_FALSE(PathExists(non_existent)); |
| 642 | 643 |
| 643 EXPECT_TRUE(DeleteFile(non_existent, false)); | 644 EXPECT_TRUE(DeleteFile(non_existent, false)); |
| 644 ASSERT_FALSE(PathExists(non_existent)); | 645 ASSERT_FALSE(PathExists(non_existent)); |
| 645 EXPECT_TRUE(DeleteFile(non_existent, true)); | 646 EXPECT_TRUE(DeleteFile(non_existent, true)); |
| 646 ASSERT_FALSE(PathExists(non_existent)); | 647 ASSERT_FALSE(PathExists(non_existent)); |
| 647 } | 648 } |
| 648 | 649 |
| 649 TEST_F(FileUtilTest, DeleteFile) { | 650 TEST_F(FileUtilTest, DeleteFile) { |
| 650 // Create a file | 651 // Create a file |
| 651 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 1.txt")); | 652 FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 1.txt")); |
| 652 CreateTextFile(file_name, bogus_content); | 653 CreateTextFile(file_name, bogus_content); |
| 653 ASSERT_TRUE(PathExists(file_name)); | 654 ASSERT_TRUE(PathExists(file_name)); |
| 654 | 655 |
| 655 // Make sure it's deleted | 656 // Make sure it's deleted |
| 656 EXPECT_TRUE(DeleteFile(file_name, false)); | 657 EXPECT_TRUE(DeleteFile(file_name, false)); |
| 657 EXPECT_FALSE(PathExists(file_name)); | 658 EXPECT_FALSE(PathExists(file_name)); |
| 658 | 659 |
| 659 // Test recursive case, create a new file | 660 // Test recursive case, create a new file |
| 660 file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); | 661 file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); |
| 661 CreateTextFile(file_name, bogus_content); | 662 CreateTextFile(file_name, bogus_content); |
| 662 ASSERT_TRUE(PathExists(file_name)); | 663 ASSERT_TRUE(PathExists(file_name)); |
| 663 | 664 |
| 664 // Make sure it's deleted | 665 // Make sure it's deleted |
| 665 EXPECT_TRUE(DeleteFile(file_name, true)); | 666 EXPECT_TRUE(DeleteFile(file_name, true)); |
| 666 EXPECT_FALSE(PathExists(file_name)); | 667 EXPECT_FALSE(PathExists(file_name)); |
| 667 } | 668 } |
| 668 | 669 |
| 669 #if defined(OS_POSIX) | 670 #if defined(OS_POSIX) |
| 670 TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) { | 671 TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) { |
| 671 // Create a file. | 672 // Create a file. |
| 672 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteFile 2.txt")); | 673 FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); |
| 673 CreateTextFile(file_name, bogus_content); | 674 CreateTextFile(file_name, bogus_content); |
| 674 ASSERT_TRUE(PathExists(file_name)); | 675 ASSERT_TRUE(PathExists(file_name)); |
| 675 | 676 |
| 676 // Create a symlink to the file. | 677 // Create a symlink to the file. |
| 677 FilePath file_link = temp_dir_.path().Append("file_link_2"); | 678 FilePath file_link = temp_dir_.GetPath().Append("file_link_2"); |
| 678 ASSERT_TRUE(CreateSymbolicLink(file_name, file_link)) | 679 ASSERT_TRUE(CreateSymbolicLink(file_name, file_link)) |
| 679 << "Failed to create symlink."; | 680 << "Failed to create symlink."; |
| 680 | 681 |
| 681 // Delete the symbolic link. | 682 // Delete the symbolic link. |
| 682 EXPECT_TRUE(DeleteFile(file_link, false)); | 683 EXPECT_TRUE(DeleteFile(file_link, false)); |
| 683 | 684 |
| 684 // Make sure original file is not deleted. | 685 // Make sure original file is not deleted. |
| 685 EXPECT_FALSE(PathExists(file_link)); | 686 EXPECT_FALSE(PathExists(file_link)); |
| 686 EXPECT_TRUE(PathExists(file_name)); | 687 EXPECT_TRUE(PathExists(file_name)); |
| 687 } | 688 } |
| 688 | 689 |
| 689 TEST_F(FileUtilTest, DeleteSymlinkToNonExistentFile) { | 690 TEST_F(FileUtilTest, DeleteSymlinkToNonExistentFile) { |
| 690 // Create a non-existent file path. | 691 // Create a non-existent file path. |
| 691 FilePath non_existent = temp_dir_.path().Append(FPL("Test DeleteFile 3.txt")); | 692 FilePath non_existent = |
| 693 temp_dir_.GetPath().Append(FPL("Test DeleteFile 3.txt")); |
| 692 EXPECT_FALSE(PathExists(non_existent)); | 694 EXPECT_FALSE(PathExists(non_existent)); |
| 693 | 695 |
| 694 // Create a symlink to the non-existent file. | 696 // Create a symlink to the non-existent file. |
| 695 FilePath file_link = temp_dir_.path().Append("file_link_3"); | 697 FilePath file_link = temp_dir_.GetPath().Append("file_link_3"); |
| 696 ASSERT_TRUE(CreateSymbolicLink(non_existent, file_link)) | 698 ASSERT_TRUE(CreateSymbolicLink(non_existent, file_link)) |
| 697 << "Failed to create symlink."; | 699 << "Failed to create symlink."; |
| 698 | 700 |
| 699 // Make sure the symbolic link is exist. | 701 // Make sure the symbolic link is exist. |
| 700 EXPECT_TRUE(IsLink(file_link)); | 702 EXPECT_TRUE(IsLink(file_link)); |
| 701 EXPECT_FALSE(PathExists(file_link)); | 703 EXPECT_FALSE(PathExists(file_link)); |
| 702 | 704 |
| 703 // Delete the symbolic link. | 705 // Delete the symbolic link. |
| 704 EXPECT_TRUE(DeleteFile(file_link, false)); | 706 EXPECT_TRUE(DeleteFile(file_link, false)); |
| 705 | 707 |
| 706 // Make sure the symbolic link is deleted. | 708 // Make sure the symbolic link is deleted. |
| 707 EXPECT_FALSE(IsLink(file_link)); | 709 EXPECT_FALSE(IsLink(file_link)); |
| 708 } | 710 } |
| 709 | 711 |
| 710 TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) { | 712 TEST_F(FileUtilTest, ChangeFilePermissionsAndRead) { |
| 711 // Create a file path. | 713 // Create a file path. |
| 712 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); | 714 FilePath file_name = |
| 715 temp_dir_.GetPath().Append(FPL("Test Readable File.txt")); |
| 713 EXPECT_FALSE(PathExists(file_name)); | 716 EXPECT_FALSE(PathExists(file_name)); |
| 714 | 717 |
| 715 const std::string kData("hello"); | 718 const std::string kData("hello"); |
| 716 | 719 |
| 717 int buffer_size = kData.length(); | 720 int buffer_size = kData.length(); |
| 718 char* buffer = new char[buffer_size]; | 721 char* buffer = new char[buffer_size]; |
| 719 | 722 |
| 720 // Write file. | 723 // Write file. |
| 721 EXPECT_EQ(static_cast<int>(kData.length()), | 724 EXPECT_EQ(static_cast<int>(kData.length()), |
| 722 WriteFile(file_name, kData.data(), kData.length())); | 725 WriteFile(file_name, kData.data(), kData.length())); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 744 | 747 |
| 745 // Delete the file. | 748 // Delete the file. |
| 746 EXPECT_TRUE(DeleteFile(file_name, false)); | 749 EXPECT_TRUE(DeleteFile(file_name, false)); |
| 747 EXPECT_FALSE(PathExists(file_name)); | 750 EXPECT_FALSE(PathExists(file_name)); |
| 748 | 751 |
| 749 delete[] buffer; | 752 delete[] buffer; |
| 750 } | 753 } |
| 751 | 754 |
| 752 TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) { | 755 TEST_F(FileUtilTest, ChangeFilePermissionsAndWrite) { |
| 753 // Create a file path. | 756 // Create a file path. |
| 754 FilePath file_name = temp_dir_.path().Append(FPL("Test Readable File.txt")); | 757 FilePath file_name = |
| 758 temp_dir_.GetPath().Append(FPL("Test Readable File.txt")); |
| 755 EXPECT_FALSE(PathExists(file_name)); | 759 EXPECT_FALSE(PathExists(file_name)); |
| 756 | 760 |
| 757 const std::string kData("hello"); | 761 const std::string kData("hello"); |
| 758 | 762 |
| 759 // Write file. | 763 // Write file. |
| 760 EXPECT_EQ(static_cast<int>(kData.length()), | 764 EXPECT_EQ(static_cast<int>(kData.length()), |
| 761 WriteFile(file_name, kData.data(), kData.length())); | 765 WriteFile(file_name, kData.data(), kData.length())); |
| 762 EXPECT_TRUE(PathExists(file_name)); | 766 EXPECT_TRUE(PathExists(file_name)); |
| 763 | 767 |
| 764 // Make sure the file is writable. | 768 // Make sure the file is writable. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 785 WriteFile(file_name, kData.data(), kData.length())); | 789 WriteFile(file_name, kData.data(), kData.length())); |
| 786 EXPECT_TRUE(PathIsWritable(file_name)); | 790 EXPECT_TRUE(PathIsWritable(file_name)); |
| 787 | 791 |
| 788 // Delete the file. | 792 // Delete the file. |
| 789 EXPECT_TRUE(DeleteFile(file_name, false)); | 793 EXPECT_TRUE(DeleteFile(file_name, false)); |
| 790 EXPECT_FALSE(PathExists(file_name)); | 794 EXPECT_FALSE(PathExists(file_name)); |
| 791 } | 795 } |
| 792 | 796 |
| 793 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { | 797 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { |
| 794 // Create a directory path. | 798 // Create a directory path. |
| 795 FilePath subdir_path = | 799 FilePath subdir_path = temp_dir_.GetPath().Append(FPL("PermissionTest1")); |
| 796 temp_dir_.path().Append(FPL("PermissionTest1")); | |
| 797 CreateDirectory(subdir_path); | 800 CreateDirectory(subdir_path); |
| 798 ASSERT_TRUE(PathExists(subdir_path)); | 801 ASSERT_TRUE(PathExists(subdir_path)); |
| 799 | 802 |
| 800 // Create a dummy file to enumerate. | 803 // Create a dummy file to enumerate. |
| 801 FilePath file_name = subdir_path.Append(FPL("Test Readable File.txt")); | 804 FilePath file_name = subdir_path.Append(FPL("Test Readable File.txt")); |
| 802 EXPECT_FALSE(PathExists(file_name)); | 805 EXPECT_FALSE(PathExists(file_name)); |
| 803 const std::string kData("hello"); | 806 const std::string kData("hello"); |
| 804 EXPECT_EQ(static_cast<int>(kData.length()), | 807 EXPECT_EQ(static_cast<int>(kData.length()), |
| 805 WriteFile(file_name, kData.data(), kData.length())); | 808 WriteFile(file_name, kData.data(), kData.length())); |
| 806 EXPECT_TRUE(PathExists(file_name)); | 809 EXPECT_TRUE(PathExists(file_name)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 837 EXPECT_TRUE(DeleteFile(subdir_path, true)); | 840 EXPECT_TRUE(DeleteFile(subdir_path, true)); |
| 838 EXPECT_FALSE(PathExists(subdir_path)); | 841 EXPECT_FALSE(PathExists(subdir_path)); |
| 839 } | 842 } |
| 840 | 843 |
| 841 TEST_F(FileUtilTest, ExecutableExistsInPath) { | 844 TEST_F(FileUtilTest, ExecutableExistsInPath) { |
| 842 // Create two directories that we will put in our PATH | 845 // Create two directories that we will put in our PATH |
| 843 const char kPath[] = "PATH"; | 846 const char kPath[] = "PATH"; |
| 844 const FilePath::CharType kDir1[] = FPL("dir1"); | 847 const FilePath::CharType kDir1[] = FPL("dir1"); |
| 845 const FilePath::CharType kDir2[] = FPL("dir2"); | 848 const FilePath::CharType kDir2[] = FPL("dir2"); |
| 846 | 849 |
| 847 FilePath dir1 = temp_dir_.path().Append(kDir1); | 850 FilePath dir1 = temp_dir_.GetPath().Append(kDir1); |
| 848 FilePath dir2 = temp_dir_.path().Append(kDir2); | 851 FilePath dir2 = temp_dir_.GetPath().Append(kDir2); |
| 849 ASSERT_TRUE(CreateDirectory(dir1)); | 852 ASSERT_TRUE(CreateDirectory(dir1)); |
| 850 ASSERT_TRUE(CreateDirectory(dir2)); | 853 ASSERT_TRUE(CreateDirectory(dir2)); |
| 851 | 854 |
| 852 std::unique_ptr<Environment> env(base::Environment::Create()); | 855 std::unique_ptr<Environment> env(base::Environment::Create()); |
| 853 | 856 |
| 854 ASSERT_TRUE(env->SetVar(kPath, dir1.value() + ":" + dir2.value())); | 857 ASSERT_TRUE(env->SetVar(kPath, dir1.value() + ":" + dir2.value())); |
| 855 | 858 |
| 856 const FilePath::CharType kRegularFileName[] = FPL("regular_file"); | 859 const FilePath::CharType kRegularFileName[] = FPL("regular_file"); |
| 857 const FilePath::CharType kExeFileName[] = FPL("exe"); | 860 const FilePath::CharType kExeFileName[] = FPL("exe"); |
| 858 const FilePath::CharType kDneFileName[] = FPL("does_not_exist"); | 861 const FilePath::CharType kDneFileName[] = FPL("does_not_exist"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 878 } | 881 } |
| 879 | 882 |
| 880 #endif // defined(OS_POSIX) | 883 #endif // defined(OS_POSIX) |
| 881 | 884 |
| 882 #if defined(OS_WIN) | 885 #if defined(OS_WIN) |
| 883 // Tests that the Delete function works for wild cards, especially | 886 // Tests that the Delete function works for wild cards, especially |
| 884 // with the recursion flag. Also coincidentally tests PathExists. | 887 // with the recursion flag. Also coincidentally tests PathExists. |
| 885 // TODO(erikkay): see if anyone's actually using this feature of the API | 888 // TODO(erikkay): see if anyone's actually using this feature of the API |
| 886 TEST_F(FileUtilTest, DeleteWildCard) { | 889 TEST_F(FileUtilTest, DeleteWildCard) { |
| 887 // Create a file and a directory | 890 // Create a file and a directory |
| 888 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); | 891 FilePath file_name = |
| 892 temp_dir_.GetPath().Append(FPL("Test DeleteWildCard.txt")); |
| 889 CreateTextFile(file_name, bogus_content); | 893 CreateTextFile(file_name, bogus_content); |
| 890 ASSERT_TRUE(PathExists(file_name)); | 894 ASSERT_TRUE(PathExists(file_name)); |
| 891 | 895 |
| 892 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); | 896 FilePath subdir_path = temp_dir_.GetPath().Append(FPL("DeleteWildCardDir")); |
| 893 CreateDirectory(subdir_path); | 897 CreateDirectory(subdir_path); |
| 894 ASSERT_TRUE(PathExists(subdir_path)); | 898 ASSERT_TRUE(PathExists(subdir_path)); |
| 895 | 899 |
| 896 // Create the wildcard path | 900 // Create the wildcard path |
| 897 FilePath directory_contents = temp_dir_.path(); | 901 FilePath directory_contents = temp_dir_.GetPath(); |
| 898 directory_contents = directory_contents.Append(FPL("*")); | 902 directory_contents = directory_contents.Append(FPL("*")); |
| 899 | 903 |
| 900 // Delete non-recursively and check that only the file is deleted | 904 // Delete non-recursively and check that only the file is deleted |
| 901 EXPECT_TRUE(DeleteFile(directory_contents, false)); | 905 EXPECT_TRUE(DeleteFile(directory_contents, false)); |
| 902 EXPECT_FALSE(PathExists(file_name)); | 906 EXPECT_FALSE(PathExists(file_name)); |
| 903 EXPECT_TRUE(PathExists(subdir_path)); | 907 EXPECT_TRUE(PathExists(subdir_path)); |
| 904 | 908 |
| 905 // Delete recursively and make sure all contents are deleted | 909 // Delete recursively and make sure all contents are deleted |
| 906 EXPECT_TRUE(DeleteFile(directory_contents, true)); | 910 EXPECT_TRUE(DeleteFile(directory_contents, true)); |
| 907 EXPECT_FALSE(PathExists(file_name)); | 911 EXPECT_FALSE(PathExists(file_name)); |
| 908 EXPECT_FALSE(PathExists(subdir_path)); | 912 EXPECT_FALSE(PathExists(subdir_path)); |
| 909 } | 913 } |
| 910 | 914 |
| 911 // TODO(erikkay): see if anyone's actually using this feature of the API | 915 // TODO(erikkay): see if anyone's actually using this feature of the API |
| 912 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { | 916 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { |
| 913 // Create a file and a directory | 917 // Create a file and a directory |
| 914 FilePath subdir_path = | 918 FilePath subdir_path = |
| 915 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); | 919 temp_dir_.GetPath().Append(FPL("DeleteNonExistantWildCard")); |
| 916 CreateDirectory(subdir_path); | 920 CreateDirectory(subdir_path); |
| 917 ASSERT_TRUE(PathExists(subdir_path)); | 921 ASSERT_TRUE(PathExists(subdir_path)); |
| 918 | 922 |
| 919 // Create the wildcard path | 923 // Create the wildcard path |
| 920 FilePath directory_contents = subdir_path; | 924 FilePath directory_contents = subdir_path; |
| 921 directory_contents = directory_contents.Append(FPL("*")); | 925 directory_contents = directory_contents.Append(FPL("*")); |
| 922 | 926 |
| 923 // Delete non-recursively and check nothing got deleted | 927 // Delete non-recursively and check nothing got deleted |
| 924 EXPECT_TRUE(DeleteFile(directory_contents, false)); | 928 EXPECT_TRUE(DeleteFile(directory_contents, false)); |
| 925 EXPECT_TRUE(PathExists(subdir_path)); | 929 EXPECT_TRUE(PathExists(subdir_path)); |
| 926 | 930 |
| 927 // Delete recursively and check nothing got deleted | 931 // Delete recursively and check nothing got deleted |
| 928 EXPECT_TRUE(DeleteFile(directory_contents, true)); | 932 EXPECT_TRUE(DeleteFile(directory_contents, true)); |
| 929 EXPECT_TRUE(PathExists(subdir_path)); | 933 EXPECT_TRUE(PathExists(subdir_path)); |
| 930 } | 934 } |
| 931 #endif | 935 #endif |
| 932 | 936 |
| 933 // Tests non-recursive Delete() for a directory. | 937 // Tests non-recursive Delete() for a directory. |
| 934 TEST_F(FileUtilTest, DeleteDirNonRecursive) { | 938 TEST_F(FileUtilTest, DeleteDirNonRecursive) { |
| 935 // Create a subdirectory and put a file and two directories inside. | 939 // Create a subdirectory and put a file and two directories inside. |
| 936 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); | 940 FilePath test_subdir = |
| 941 temp_dir_.GetPath().Append(FPL("DeleteDirNonRecursive")); |
| 937 CreateDirectory(test_subdir); | 942 CreateDirectory(test_subdir); |
| 938 ASSERT_TRUE(PathExists(test_subdir)); | 943 ASSERT_TRUE(PathExists(test_subdir)); |
| 939 | 944 |
| 940 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); | 945 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); |
| 941 CreateTextFile(file_name, bogus_content); | 946 CreateTextFile(file_name, bogus_content); |
| 942 ASSERT_TRUE(PathExists(file_name)); | 947 ASSERT_TRUE(PathExists(file_name)); |
| 943 | 948 |
| 944 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 949 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
| 945 CreateDirectory(subdir_path1); | 950 CreateDirectory(subdir_path1); |
| 946 ASSERT_TRUE(PathExists(subdir_path1)); | 951 ASSERT_TRUE(PathExists(subdir_path1)); |
| 947 | 952 |
| 948 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 953 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
| 949 CreateDirectory(subdir_path2); | 954 CreateDirectory(subdir_path2); |
| 950 ASSERT_TRUE(PathExists(subdir_path2)); | 955 ASSERT_TRUE(PathExists(subdir_path2)); |
| 951 | 956 |
| 952 // Delete non-recursively and check that the empty dir got deleted | 957 // Delete non-recursively and check that the empty dir got deleted |
| 953 EXPECT_TRUE(DeleteFile(subdir_path2, false)); | 958 EXPECT_TRUE(DeleteFile(subdir_path2, false)); |
| 954 EXPECT_FALSE(PathExists(subdir_path2)); | 959 EXPECT_FALSE(PathExists(subdir_path2)); |
| 955 | 960 |
| 956 // Delete non-recursively and check that nothing got deleted | 961 // Delete non-recursively and check that nothing got deleted |
| 957 EXPECT_FALSE(DeleteFile(test_subdir, false)); | 962 EXPECT_FALSE(DeleteFile(test_subdir, false)); |
| 958 EXPECT_TRUE(PathExists(test_subdir)); | 963 EXPECT_TRUE(PathExists(test_subdir)); |
| 959 EXPECT_TRUE(PathExists(file_name)); | 964 EXPECT_TRUE(PathExists(file_name)); |
| 960 EXPECT_TRUE(PathExists(subdir_path1)); | 965 EXPECT_TRUE(PathExists(subdir_path1)); |
| 961 } | 966 } |
| 962 | 967 |
| 963 // Tests recursive Delete() for a directory. | 968 // Tests recursive Delete() for a directory. |
| 964 TEST_F(FileUtilTest, DeleteDirRecursive) { | 969 TEST_F(FileUtilTest, DeleteDirRecursive) { |
| 965 // Create a subdirectory and put a file and two directories inside. | 970 // Create a subdirectory and put a file and two directories inside. |
| 966 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); | 971 FilePath test_subdir = temp_dir_.GetPath().Append(FPL("DeleteDirRecursive")); |
| 967 CreateDirectory(test_subdir); | 972 CreateDirectory(test_subdir); |
| 968 ASSERT_TRUE(PathExists(test_subdir)); | 973 ASSERT_TRUE(PathExists(test_subdir)); |
| 969 | 974 |
| 970 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); | 975 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); |
| 971 CreateTextFile(file_name, bogus_content); | 976 CreateTextFile(file_name, bogus_content); |
| 972 ASSERT_TRUE(PathExists(file_name)); | 977 ASSERT_TRUE(PathExists(file_name)); |
| 973 | 978 |
| 974 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 979 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
| 975 CreateDirectory(subdir_path1); | 980 CreateDirectory(subdir_path1); |
| 976 ASSERT_TRUE(PathExists(subdir_path1)); | 981 ASSERT_TRUE(PathExists(subdir_path1)); |
| 977 | 982 |
| 978 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 983 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
| 979 CreateDirectory(subdir_path2); | 984 CreateDirectory(subdir_path2); |
| 980 ASSERT_TRUE(PathExists(subdir_path2)); | 985 ASSERT_TRUE(PathExists(subdir_path2)); |
| 981 | 986 |
| 982 // Delete recursively and check that the empty dir got deleted | 987 // Delete recursively and check that the empty dir got deleted |
| 983 EXPECT_TRUE(DeleteFile(subdir_path2, true)); | 988 EXPECT_TRUE(DeleteFile(subdir_path2, true)); |
| 984 EXPECT_FALSE(PathExists(subdir_path2)); | 989 EXPECT_FALSE(PathExists(subdir_path2)); |
| 985 | 990 |
| 986 // Delete recursively and check that everything got deleted | 991 // Delete recursively and check that everything got deleted |
| 987 EXPECT_TRUE(DeleteFile(test_subdir, true)); | 992 EXPECT_TRUE(DeleteFile(test_subdir, true)); |
| 988 EXPECT_FALSE(PathExists(file_name)); | 993 EXPECT_FALSE(PathExists(file_name)); |
| 989 EXPECT_FALSE(PathExists(subdir_path1)); | 994 EXPECT_FALSE(PathExists(subdir_path1)); |
| 990 EXPECT_FALSE(PathExists(test_subdir)); | 995 EXPECT_FALSE(PathExists(test_subdir)); |
| 991 } | 996 } |
| 992 | 997 |
| 993 TEST_F(FileUtilTest, MoveFileNew) { | 998 TEST_F(FileUtilTest, MoveFileNew) { |
| 994 // Create a file | 999 // Create a file |
| 995 FilePath file_name_from = | 1000 FilePath file_name_from = |
| 996 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1001 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 997 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1002 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 998 ASSERT_TRUE(PathExists(file_name_from)); | 1003 ASSERT_TRUE(PathExists(file_name_from)); |
| 999 | 1004 |
| 1000 // The destination. | 1005 // The destination. |
| 1001 FilePath file_name_to = temp_dir_.path().Append( | 1006 FilePath file_name_to = temp_dir_.GetPath().Append( |
| 1002 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); | 1007 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); |
| 1003 ASSERT_FALSE(PathExists(file_name_to)); | 1008 ASSERT_FALSE(PathExists(file_name_to)); |
| 1004 | 1009 |
| 1005 EXPECT_TRUE(Move(file_name_from, file_name_to)); | 1010 EXPECT_TRUE(Move(file_name_from, file_name_to)); |
| 1006 | 1011 |
| 1007 // Check everything has been moved. | 1012 // Check everything has been moved. |
| 1008 EXPECT_FALSE(PathExists(file_name_from)); | 1013 EXPECT_FALSE(PathExists(file_name_from)); |
| 1009 EXPECT_TRUE(PathExists(file_name_to)); | 1014 EXPECT_TRUE(PathExists(file_name_to)); |
| 1010 } | 1015 } |
| 1011 | 1016 |
| 1012 TEST_F(FileUtilTest, MoveFileExists) { | 1017 TEST_F(FileUtilTest, MoveFileExists) { |
| 1013 // Create a file | 1018 // Create a file |
| 1014 FilePath file_name_from = | 1019 FilePath file_name_from = |
| 1015 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1020 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1016 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1021 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1017 ASSERT_TRUE(PathExists(file_name_from)); | 1022 ASSERT_TRUE(PathExists(file_name_from)); |
| 1018 | 1023 |
| 1019 // The destination name. | 1024 // The destination name. |
| 1020 FilePath file_name_to = temp_dir_.path().Append( | 1025 FilePath file_name_to = temp_dir_.GetPath().Append( |
| 1021 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); | 1026 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); |
| 1022 CreateTextFile(file_name_to, L"Old file content"); | 1027 CreateTextFile(file_name_to, L"Old file content"); |
| 1023 ASSERT_TRUE(PathExists(file_name_to)); | 1028 ASSERT_TRUE(PathExists(file_name_to)); |
| 1024 | 1029 |
| 1025 EXPECT_TRUE(Move(file_name_from, file_name_to)); | 1030 EXPECT_TRUE(Move(file_name_from, file_name_to)); |
| 1026 | 1031 |
| 1027 // Check everything has been moved. | 1032 // Check everything has been moved. |
| 1028 EXPECT_FALSE(PathExists(file_name_from)); | 1033 EXPECT_FALSE(PathExists(file_name_from)); |
| 1029 EXPECT_TRUE(PathExists(file_name_to)); | 1034 EXPECT_TRUE(PathExists(file_name_to)); |
| 1030 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); | 1035 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); |
| 1031 } | 1036 } |
| 1032 | 1037 |
| 1033 TEST_F(FileUtilTest, MoveFileDirExists) { | 1038 TEST_F(FileUtilTest, MoveFileDirExists) { |
| 1034 // Create a file | 1039 // Create a file |
| 1035 FilePath file_name_from = | 1040 FilePath file_name_from = |
| 1036 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1041 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1037 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1042 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1038 ASSERT_TRUE(PathExists(file_name_from)); | 1043 ASSERT_TRUE(PathExists(file_name_from)); |
| 1039 | 1044 |
| 1040 // The destination directory | 1045 // The destination directory |
| 1041 FilePath dir_name_to = | 1046 FilePath dir_name_to = |
| 1042 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1047 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); |
| 1043 CreateDirectory(dir_name_to); | 1048 CreateDirectory(dir_name_to); |
| 1044 ASSERT_TRUE(PathExists(dir_name_to)); | 1049 ASSERT_TRUE(PathExists(dir_name_to)); |
| 1045 | 1050 |
| 1046 EXPECT_FALSE(Move(file_name_from, dir_name_to)); | 1051 EXPECT_FALSE(Move(file_name_from, dir_name_to)); |
| 1047 } | 1052 } |
| 1048 | 1053 |
| 1049 | 1054 |
| 1050 TEST_F(FileUtilTest, MoveNew) { | 1055 TEST_F(FileUtilTest, MoveNew) { |
| 1051 // Create a directory | 1056 // Create a directory |
| 1052 FilePath dir_name_from = | 1057 FilePath dir_name_from = |
| 1053 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1058 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
| 1054 CreateDirectory(dir_name_from); | 1059 CreateDirectory(dir_name_from); |
| 1055 ASSERT_TRUE(PathExists(dir_name_from)); | 1060 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1056 | 1061 |
| 1057 // Create a file under the directory | 1062 // Create a file under the directory |
| 1058 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1063 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1059 FilePath file_name_from = dir_name_from.Append(txt_file_name); | 1064 FilePath file_name_from = dir_name_from.Append(txt_file_name); |
| 1060 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1065 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1061 ASSERT_TRUE(PathExists(file_name_from)); | 1066 ASSERT_TRUE(PathExists(file_name_from)); |
| 1062 | 1067 |
| 1063 // Move the directory. | 1068 // Move the directory. |
| 1064 FilePath dir_name_to = | 1069 FilePath dir_name_to = |
| 1065 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_To_Subdir")); | 1070 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
| 1066 FilePath file_name_to = | 1071 FilePath file_name_to = |
| 1067 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1072 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1068 | 1073 |
| 1069 ASSERT_FALSE(PathExists(dir_name_to)); | 1074 ASSERT_FALSE(PathExists(dir_name_to)); |
| 1070 | 1075 |
| 1071 EXPECT_TRUE(Move(dir_name_from, dir_name_to)); | 1076 EXPECT_TRUE(Move(dir_name_from, dir_name_to)); |
| 1072 | 1077 |
| 1073 // Check everything has been moved. | 1078 // Check everything has been moved. |
| 1074 EXPECT_FALSE(PathExists(dir_name_from)); | 1079 EXPECT_FALSE(PathExists(dir_name_from)); |
| 1075 EXPECT_FALSE(PathExists(file_name_from)); | 1080 EXPECT_FALSE(PathExists(file_name_from)); |
| 1076 EXPECT_TRUE(PathExists(dir_name_to)); | 1081 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1077 EXPECT_TRUE(PathExists(file_name_to)); | 1082 EXPECT_TRUE(PathExists(file_name_to)); |
| 1078 | 1083 |
| 1079 // Test path traversal. | 1084 // Test path traversal. |
| 1080 file_name_from = dir_name_to.Append(txt_file_name); | 1085 file_name_from = dir_name_to.Append(txt_file_name); |
| 1081 file_name_to = dir_name_to.Append(FILE_PATH_LITERAL("..")); | 1086 file_name_to = dir_name_to.Append(FILE_PATH_LITERAL("..")); |
| 1082 file_name_to = file_name_to.Append(txt_file_name); | 1087 file_name_to = file_name_to.Append(txt_file_name); |
| 1083 EXPECT_FALSE(Move(file_name_from, file_name_to)); | 1088 EXPECT_FALSE(Move(file_name_from, file_name_to)); |
| 1084 EXPECT_TRUE(PathExists(file_name_from)); | 1089 EXPECT_TRUE(PathExists(file_name_from)); |
| 1085 EXPECT_FALSE(PathExists(file_name_to)); | 1090 EXPECT_FALSE(PathExists(file_name_to)); |
| 1086 EXPECT_TRUE(internal::MoveUnsafe(file_name_from, file_name_to)); | 1091 EXPECT_TRUE(internal::MoveUnsafe(file_name_from, file_name_to)); |
| 1087 EXPECT_FALSE(PathExists(file_name_from)); | 1092 EXPECT_FALSE(PathExists(file_name_from)); |
| 1088 EXPECT_TRUE(PathExists(file_name_to)); | 1093 EXPECT_TRUE(PathExists(file_name_to)); |
| 1089 } | 1094 } |
| 1090 | 1095 |
| 1091 TEST_F(FileUtilTest, MoveExist) { | 1096 TEST_F(FileUtilTest, MoveExist) { |
| 1092 // Create a directory | 1097 // Create a directory |
| 1093 FilePath dir_name_from = | 1098 FilePath dir_name_from = |
| 1094 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1099 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
| 1095 CreateDirectory(dir_name_from); | 1100 CreateDirectory(dir_name_from); |
| 1096 ASSERT_TRUE(PathExists(dir_name_from)); | 1101 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1097 | 1102 |
| 1098 // Create a file under the directory | 1103 // Create a file under the directory |
| 1099 FilePath file_name_from = | 1104 FilePath file_name_from = |
| 1100 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1105 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1101 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1106 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1102 ASSERT_TRUE(PathExists(file_name_from)); | 1107 ASSERT_TRUE(PathExists(file_name_from)); |
| 1103 | 1108 |
| 1104 // Move the directory | 1109 // Move the directory |
| 1105 FilePath dir_name_exists = | 1110 FilePath dir_name_exists = |
| 1106 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1111 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); |
| 1107 | 1112 |
| 1108 FilePath dir_name_to = | 1113 FilePath dir_name_to = |
| 1109 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); | 1114 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
| 1110 FilePath file_name_to = | 1115 FilePath file_name_to = |
| 1111 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1116 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1112 | 1117 |
| 1113 // Create the destination directory. | 1118 // Create the destination directory. |
| 1114 CreateDirectory(dir_name_exists); | 1119 CreateDirectory(dir_name_exists); |
| 1115 ASSERT_TRUE(PathExists(dir_name_exists)); | 1120 ASSERT_TRUE(PathExists(dir_name_exists)); |
| 1116 | 1121 |
| 1117 EXPECT_TRUE(Move(dir_name_from, dir_name_to)); | 1122 EXPECT_TRUE(Move(dir_name_from, dir_name_to)); |
| 1118 | 1123 |
| 1119 // Check everything has been moved. | 1124 // Check everything has been moved. |
| 1120 EXPECT_FALSE(PathExists(dir_name_from)); | 1125 EXPECT_FALSE(PathExists(dir_name_from)); |
| 1121 EXPECT_FALSE(PathExists(file_name_from)); | 1126 EXPECT_FALSE(PathExists(file_name_from)); |
| 1122 EXPECT_TRUE(PathExists(dir_name_to)); | 1127 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1123 EXPECT_TRUE(PathExists(file_name_to)); | 1128 EXPECT_TRUE(PathExists(file_name_to)); |
| 1124 } | 1129 } |
| 1125 | 1130 |
| 1126 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { | 1131 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { |
| 1127 // Create a directory. | 1132 // Create a directory. |
| 1128 FilePath dir_name_from = | 1133 FilePath dir_name_from = |
| 1129 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1134 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1130 CreateDirectory(dir_name_from); | 1135 CreateDirectory(dir_name_from); |
| 1131 ASSERT_TRUE(PathExists(dir_name_from)); | 1136 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1132 | 1137 |
| 1133 // Create a file under the directory. | 1138 // Create a file under the directory. |
| 1134 FilePath file_name_from = | 1139 FilePath file_name_from = |
| 1135 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1140 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1136 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1141 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1137 ASSERT_TRUE(PathExists(file_name_from)); | 1142 ASSERT_TRUE(PathExists(file_name_from)); |
| 1138 | 1143 |
| 1139 // Create a subdirectory. | 1144 // Create a subdirectory. |
| 1140 FilePath subdir_name_from = | 1145 FilePath subdir_name_from = |
| 1141 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1146 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1142 CreateDirectory(subdir_name_from); | 1147 CreateDirectory(subdir_name_from); |
| 1143 ASSERT_TRUE(PathExists(subdir_name_from)); | 1148 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1144 | 1149 |
| 1145 // Create a file under the subdirectory. | 1150 // Create a file under the subdirectory. |
| 1146 FilePath file_name2_from = | 1151 FilePath file_name2_from = |
| 1147 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1152 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1148 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1153 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 1149 ASSERT_TRUE(PathExists(file_name2_from)); | 1154 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1150 | 1155 |
| 1151 // Copy the directory recursively. | 1156 // Copy the directory recursively. |
| 1152 FilePath dir_name_to = | 1157 FilePath dir_name_to = |
| 1153 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1158 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1154 FilePath file_name_to = | 1159 FilePath file_name_to = |
| 1155 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1160 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1156 FilePath subdir_name_to = | 1161 FilePath subdir_name_to = |
| 1157 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1162 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 1158 FilePath file_name2_to = | 1163 FilePath file_name2_to = |
| 1159 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1164 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1160 | 1165 |
| 1161 ASSERT_FALSE(PathExists(dir_name_to)); | 1166 ASSERT_FALSE(PathExists(dir_name_to)); |
| 1162 | 1167 |
| 1163 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, true)); | 1168 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, true)); |
| 1164 | 1169 |
| 1165 // Check everything has been copied. | 1170 // Check everything has been copied. |
| 1166 EXPECT_TRUE(PathExists(dir_name_from)); | 1171 EXPECT_TRUE(PathExists(dir_name_from)); |
| 1167 EXPECT_TRUE(PathExists(file_name_from)); | 1172 EXPECT_TRUE(PathExists(file_name_from)); |
| 1168 EXPECT_TRUE(PathExists(subdir_name_from)); | 1173 EXPECT_TRUE(PathExists(subdir_name_from)); |
| 1169 EXPECT_TRUE(PathExists(file_name2_from)); | 1174 EXPECT_TRUE(PathExists(file_name2_from)); |
| 1170 EXPECT_TRUE(PathExists(dir_name_to)); | 1175 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1171 EXPECT_TRUE(PathExists(file_name_to)); | 1176 EXPECT_TRUE(PathExists(file_name_to)); |
| 1172 EXPECT_TRUE(PathExists(subdir_name_to)); | 1177 EXPECT_TRUE(PathExists(subdir_name_to)); |
| 1173 EXPECT_TRUE(PathExists(file_name2_to)); | 1178 EXPECT_TRUE(PathExists(file_name2_to)); |
| 1174 } | 1179 } |
| 1175 | 1180 |
| 1176 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { | 1181 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { |
| 1177 // Create a directory. | 1182 // Create a directory. |
| 1178 FilePath dir_name_from = | 1183 FilePath dir_name_from = |
| 1179 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1184 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1180 CreateDirectory(dir_name_from); | 1185 CreateDirectory(dir_name_from); |
| 1181 ASSERT_TRUE(PathExists(dir_name_from)); | 1186 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1182 | 1187 |
| 1183 // Create a file under the directory. | 1188 // Create a file under the directory. |
| 1184 FilePath file_name_from = | 1189 FilePath file_name_from = |
| 1185 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1190 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1186 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1191 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1187 ASSERT_TRUE(PathExists(file_name_from)); | 1192 ASSERT_TRUE(PathExists(file_name_from)); |
| 1188 | 1193 |
| 1189 // Create a subdirectory. | 1194 // Create a subdirectory. |
| 1190 FilePath subdir_name_from = | 1195 FilePath subdir_name_from = |
| 1191 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1196 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1192 CreateDirectory(subdir_name_from); | 1197 CreateDirectory(subdir_name_from); |
| 1193 ASSERT_TRUE(PathExists(subdir_name_from)); | 1198 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1194 | 1199 |
| 1195 // Create a file under the subdirectory. | 1200 // Create a file under the subdirectory. |
| 1196 FilePath file_name2_from = | 1201 FilePath file_name2_from = |
| 1197 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1202 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1198 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1203 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 1199 ASSERT_TRUE(PathExists(file_name2_from)); | 1204 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1200 | 1205 |
| 1201 // Copy the directory recursively. | 1206 // Copy the directory recursively. |
| 1202 FilePath dir_name_exists = | 1207 FilePath dir_name_exists = |
| 1203 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1208 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); |
| 1204 | 1209 |
| 1205 FilePath dir_name_to = | 1210 FilePath dir_name_to = |
| 1206 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1211 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1207 FilePath file_name_to = | 1212 FilePath file_name_to = |
| 1208 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1213 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1209 FilePath subdir_name_to = | 1214 FilePath subdir_name_to = |
| 1210 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1215 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 1211 FilePath file_name2_to = | 1216 FilePath file_name2_to = |
| 1212 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1217 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1213 | 1218 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1224 EXPECT_TRUE(PathExists(file_name2_from)); | 1229 EXPECT_TRUE(PathExists(file_name2_from)); |
| 1225 EXPECT_TRUE(PathExists(dir_name_to)); | 1230 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1226 EXPECT_TRUE(PathExists(file_name_to)); | 1231 EXPECT_TRUE(PathExists(file_name_to)); |
| 1227 EXPECT_TRUE(PathExists(subdir_name_to)); | 1232 EXPECT_TRUE(PathExists(subdir_name_to)); |
| 1228 EXPECT_TRUE(PathExists(file_name2_to)); | 1233 EXPECT_TRUE(PathExists(file_name2_to)); |
| 1229 } | 1234 } |
| 1230 | 1235 |
| 1231 TEST_F(FileUtilTest, CopyDirectoryNew) { | 1236 TEST_F(FileUtilTest, CopyDirectoryNew) { |
| 1232 // Create a directory. | 1237 // Create a directory. |
| 1233 FilePath dir_name_from = | 1238 FilePath dir_name_from = |
| 1234 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1239 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1235 CreateDirectory(dir_name_from); | 1240 CreateDirectory(dir_name_from); |
| 1236 ASSERT_TRUE(PathExists(dir_name_from)); | 1241 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1237 | 1242 |
| 1238 // Create a file under the directory. | 1243 // Create a file under the directory. |
| 1239 FilePath file_name_from = | 1244 FilePath file_name_from = |
| 1240 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1245 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1241 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1246 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1242 ASSERT_TRUE(PathExists(file_name_from)); | 1247 ASSERT_TRUE(PathExists(file_name_from)); |
| 1243 | 1248 |
| 1244 // Create a subdirectory. | 1249 // Create a subdirectory. |
| 1245 FilePath subdir_name_from = | 1250 FilePath subdir_name_from = |
| 1246 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1251 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1247 CreateDirectory(subdir_name_from); | 1252 CreateDirectory(subdir_name_from); |
| 1248 ASSERT_TRUE(PathExists(subdir_name_from)); | 1253 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1249 | 1254 |
| 1250 // Create a file under the subdirectory. | 1255 // Create a file under the subdirectory. |
| 1251 FilePath file_name2_from = | 1256 FilePath file_name2_from = |
| 1252 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1257 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1253 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1258 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 1254 ASSERT_TRUE(PathExists(file_name2_from)); | 1259 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1255 | 1260 |
| 1256 // Copy the directory not recursively. | 1261 // Copy the directory not recursively. |
| 1257 FilePath dir_name_to = | 1262 FilePath dir_name_to = |
| 1258 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1263 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1259 FilePath file_name_to = | 1264 FilePath file_name_to = |
| 1260 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1265 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1261 FilePath subdir_name_to = | 1266 FilePath subdir_name_to = |
| 1262 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1267 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 1263 | 1268 |
| 1264 ASSERT_FALSE(PathExists(dir_name_to)); | 1269 ASSERT_FALSE(PathExists(dir_name_to)); |
| 1265 | 1270 |
| 1266 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, false)); | 1271 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, false)); |
| 1267 | 1272 |
| 1268 // Check everything has been copied. | 1273 // Check everything has been copied. |
| 1269 EXPECT_TRUE(PathExists(dir_name_from)); | 1274 EXPECT_TRUE(PathExists(dir_name_from)); |
| 1270 EXPECT_TRUE(PathExists(file_name_from)); | 1275 EXPECT_TRUE(PathExists(file_name_from)); |
| 1271 EXPECT_TRUE(PathExists(subdir_name_from)); | 1276 EXPECT_TRUE(PathExists(subdir_name_from)); |
| 1272 EXPECT_TRUE(PathExists(file_name2_from)); | 1277 EXPECT_TRUE(PathExists(file_name2_from)); |
| 1273 EXPECT_TRUE(PathExists(dir_name_to)); | 1278 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1274 EXPECT_TRUE(PathExists(file_name_to)); | 1279 EXPECT_TRUE(PathExists(file_name_to)); |
| 1275 EXPECT_FALSE(PathExists(subdir_name_to)); | 1280 EXPECT_FALSE(PathExists(subdir_name_to)); |
| 1276 } | 1281 } |
| 1277 | 1282 |
| 1278 TEST_F(FileUtilTest, CopyDirectoryExists) { | 1283 TEST_F(FileUtilTest, CopyDirectoryExists) { |
| 1279 // Create a directory. | 1284 // Create a directory. |
| 1280 FilePath dir_name_from = | 1285 FilePath dir_name_from = |
| 1281 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1286 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1282 CreateDirectory(dir_name_from); | 1287 CreateDirectory(dir_name_from); |
| 1283 ASSERT_TRUE(PathExists(dir_name_from)); | 1288 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1284 | 1289 |
| 1285 // Create a file under the directory. | 1290 // Create a file under the directory. |
| 1286 FilePath file_name_from = | 1291 FilePath file_name_from = |
| 1287 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1292 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1288 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1293 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1289 ASSERT_TRUE(PathExists(file_name_from)); | 1294 ASSERT_TRUE(PathExists(file_name_from)); |
| 1290 | 1295 |
| 1291 // Create a subdirectory. | 1296 // Create a subdirectory. |
| 1292 FilePath subdir_name_from = | 1297 FilePath subdir_name_from = |
| 1293 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1298 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1294 CreateDirectory(subdir_name_from); | 1299 CreateDirectory(subdir_name_from); |
| 1295 ASSERT_TRUE(PathExists(subdir_name_from)); | 1300 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1296 | 1301 |
| 1297 // Create a file under the subdirectory. | 1302 // Create a file under the subdirectory. |
| 1298 FilePath file_name2_from = | 1303 FilePath file_name2_from = |
| 1299 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1304 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1300 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1305 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 1301 ASSERT_TRUE(PathExists(file_name2_from)); | 1306 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1302 | 1307 |
| 1303 // Copy the directory not recursively. | 1308 // Copy the directory not recursively. |
| 1304 FilePath dir_name_to = | 1309 FilePath dir_name_to = |
| 1305 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1310 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1306 FilePath file_name_to = | 1311 FilePath file_name_to = |
| 1307 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1312 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1308 FilePath subdir_name_to = | 1313 FilePath subdir_name_to = |
| 1309 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1314 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 1310 | 1315 |
| 1311 // Create the destination directory. | 1316 // Create the destination directory. |
| 1312 CreateDirectory(dir_name_to); | 1317 CreateDirectory(dir_name_to); |
| 1313 ASSERT_TRUE(PathExists(dir_name_to)); | 1318 ASSERT_TRUE(PathExists(dir_name_to)); |
| 1314 | 1319 |
| 1315 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, false)); | 1320 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, false)); |
| 1316 | 1321 |
| 1317 // Check everything has been copied. | 1322 // Check everything has been copied. |
| 1318 EXPECT_TRUE(PathExists(dir_name_from)); | 1323 EXPECT_TRUE(PathExists(dir_name_from)); |
| 1319 EXPECT_TRUE(PathExists(file_name_from)); | 1324 EXPECT_TRUE(PathExists(file_name_from)); |
| 1320 EXPECT_TRUE(PathExists(subdir_name_from)); | 1325 EXPECT_TRUE(PathExists(subdir_name_from)); |
| 1321 EXPECT_TRUE(PathExists(file_name2_from)); | 1326 EXPECT_TRUE(PathExists(file_name2_from)); |
| 1322 EXPECT_TRUE(PathExists(dir_name_to)); | 1327 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1323 EXPECT_TRUE(PathExists(file_name_to)); | 1328 EXPECT_TRUE(PathExists(file_name_to)); |
| 1324 EXPECT_FALSE(PathExists(subdir_name_to)); | 1329 EXPECT_FALSE(PathExists(subdir_name_to)); |
| 1325 } | 1330 } |
| 1326 | 1331 |
| 1327 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { | 1332 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { |
| 1328 // Create a file | 1333 // Create a file |
| 1329 FilePath file_name_from = | 1334 FilePath file_name_from = |
| 1330 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1335 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1331 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1336 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1332 ASSERT_TRUE(PathExists(file_name_from)); | 1337 ASSERT_TRUE(PathExists(file_name_from)); |
| 1333 | 1338 |
| 1334 // The destination name | 1339 // The destination name |
| 1335 FilePath file_name_to = temp_dir_.path().Append( | 1340 FilePath file_name_to = temp_dir_.GetPath().Append( |
| 1336 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); | 1341 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
| 1337 ASSERT_FALSE(PathExists(file_name_to)); | 1342 ASSERT_FALSE(PathExists(file_name_to)); |
| 1338 | 1343 |
| 1339 EXPECT_TRUE(CopyDirectory(file_name_from, file_name_to, true)); | 1344 EXPECT_TRUE(CopyDirectory(file_name_from, file_name_to, true)); |
| 1340 | 1345 |
| 1341 // Check the has been copied | 1346 // Check the has been copied |
| 1342 EXPECT_TRUE(PathExists(file_name_to)); | 1347 EXPECT_TRUE(PathExists(file_name_to)); |
| 1343 } | 1348 } |
| 1344 | 1349 |
| 1345 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { | 1350 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { |
| 1346 // Create a file | 1351 // Create a file |
| 1347 FilePath file_name_from = | 1352 FilePath file_name_from = |
| 1348 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1353 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1349 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1354 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1350 ASSERT_TRUE(PathExists(file_name_from)); | 1355 ASSERT_TRUE(PathExists(file_name_from)); |
| 1351 | 1356 |
| 1352 // The destination name | 1357 // The destination name |
| 1353 FilePath file_name_to = temp_dir_.path().Append( | 1358 FilePath file_name_to = temp_dir_.GetPath().Append( |
| 1354 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); | 1359 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
| 1355 CreateTextFile(file_name_to, L"Old file content"); | 1360 CreateTextFile(file_name_to, L"Old file content"); |
| 1356 ASSERT_TRUE(PathExists(file_name_to)); | 1361 ASSERT_TRUE(PathExists(file_name_to)); |
| 1357 | 1362 |
| 1358 EXPECT_TRUE(CopyDirectory(file_name_from, file_name_to, true)); | 1363 EXPECT_TRUE(CopyDirectory(file_name_from, file_name_to, true)); |
| 1359 | 1364 |
| 1360 // Check the has been copied | 1365 // Check the has been copied |
| 1361 EXPECT_TRUE(PathExists(file_name_to)); | 1366 EXPECT_TRUE(PathExists(file_name_to)); |
| 1362 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); | 1367 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); |
| 1363 } | 1368 } |
| 1364 | 1369 |
| 1365 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { | 1370 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { |
| 1366 // Create a file | 1371 // Create a file |
| 1367 FilePath file_name_from = | 1372 FilePath file_name_from = |
| 1368 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1373 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1369 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1374 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1370 ASSERT_TRUE(PathExists(file_name_from)); | 1375 ASSERT_TRUE(PathExists(file_name_from)); |
| 1371 | 1376 |
| 1372 // The destination | 1377 // The destination |
| 1373 FilePath dir_name_to = | 1378 FilePath dir_name_to = |
| 1374 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1379 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); |
| 1375 CreateDirectory(dir_name_to); | 1380 CreateDirectory(dir_name_to); |
| 1376 ASSERT_TRUE(PathExists(dir_name_to)); | 1381 ASSERT_TRUE(PathExists(dir_name_to)); |
| 1377 FilePath file_name_to = | 1382 FilePath file_name_to = |
| 1378 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1383 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1379 | 1384 |
| 1380 EXPECT_TRUE(CopyDirectory(file_name_from, dir_name_to, true)); | 1385 EXPECT_TRUE(CopyDirectory(file_name_from, dir_name_to, true)); |
| 1381 | 1386 |
| 1382 // Check the has been copied | 1387 // Check the has been copied |
| 1383 EXPECT_TRUE(PathExists(file_name_to)); | 1388 EXPECT_TRUE(PathExists(file_name_to)); |
| 1384 } | 1389 } |
| 1385 | 1390 |
| 1386 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { | 1391 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { |
| 1387 // Create a directory. | 1392 // Create a directory. |
| 1388 FilePath dir_name_from = | 1393 FilePath dir_name_from = |
| 1389 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1394 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1390 CreateDirectory(dir_name_from); | 1395 CreateDirectory(dir_name_from); |
| 1391 ASSERT_TRUE(PathExists(dir_name_from)); | 1396 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1392 | 1397 |
| 1393 // Create a file under the directory. | 1398 // Create a file under the directory. |
| 1394 FilePath file_name_from = | 1399 FilePath file_name_from = |
| 1395 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1400 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1396 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1401 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1397 ASSERT_TRUE(PathExists(file_name_from)); | 1402 ASSERT_TRUE(PathExists(file_name_from)); |
| 1398 | 1403 |
| 1399 // Copy the directory recursively. | 1404 // Copy the directory recursively. |
| 1400 FilePath dir_name_to = | 1405 FilePath dir_name_to = |
| 1401 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1406 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1402 FilePath file_name_to = | 1407 FilePath file_name_to = |
| 1403 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1408 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1404 | 1409 |
| 1405 // Create from path with trailing separators. | 1410 // Create from path with trailing separators. |
| 1406 #if defined(OS_WIN) | 1411 #if defined(OS_WIN) |
| 1407 FilePath from_path = | 1412 FilePath from_path = |
| 1408 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); | 1413 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); |
| 1409 #elif defined(OS_POSIX) | 1414 #elif defined(OS_POSIX) |
| 1410 FilePath from_path = | 1415 FilePath from_path = |
| 1411 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); | 1416 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); |
| 1412 #endif | 1417 #endif |
| 1413 | 1418 |
| 1414 EXPECT_TRUE(CopyDirectory(from_path, dir_name_to, true)); | 1419 EXPECT_TRUE(CopyDirectory(from_path, dir_name_to, true)); |
| 1415 | 1420 |
| 1416 // Check everything has been copied. | 1421 // Check everything has been copied. |
| 1417 EXPECT_TRUE(PathExists(dir_name_from)); | 1422 EXPECT_TRUE(PathExists(dir_name_from)); |
| 1418 EXPECT_TRUE(PathExists(file_name_from)); | 1423 EXPECT_TRUE(PathExists(file_name_from)); |
| 1419 EXPECT_TRUE(PathExists(dir_name_to)); | 1424 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1420 EXPECT_TRUE(PathExists(file_name_to)); | 1425 EXPECT_TRUE(PathExists(file_name_to)); |
| 1421 } | 1426 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 return attrs & FILE_ATTRIBUTE_READONLY; | 1460 return attrs & FILE_ATTRIBUTE_READONLY; |
| 1456 #else | 1461 #else |
| 1457 int mode = 0; | 1462 int mode = 0; |
| 1458 EXPECT_TRUE(GetPosixFilePermissions(path, &mode)); | 1463 EXPECT_TRUE(GetPosixFilePermissions(path, &mode)); |
| 1459 return !(mode & S_IWUSR); | 1464 return !(mode & S_IWUSR); |
| 1460 #endif | 1465 #endif |
| 1461 } | 1466 } |
| 1462 | 1467 |
| 1463 TEST_F(FileUtilTest, CopyDirectoryACL) { | 1468 TEST_F(FileUtilTest, CopyDirectoryACL) { |
| 1464 // Create source directories. | 1469 // Create source directories. |
| 1465 FilePath src = temp_dir_.path().Append(FILE_PATH_LITERAL("src")); | 1470 FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src")); |
| 1466 FilePath src_subdir = src.Append(FILE_PATH_LITERAL("subdir")); | 1471 FilePath src_subdir = src.Append(FILE_PATH_LITERAL("subdir")); |
| 1467 CreateDirectory(src_subdir); | 1472 CreateDirectory(src_subdir); |
| 1468 ASSERT_TRUE(PathExists(src_subdir)); | 1473 ASSERT_TRUE(PathExists(src_subdir)); |
| 1469 | 1474 |
| 1470 // Create a file under the directory. | 1475 // Create a file under the directory. |
| 1471 FilePath src_file = src.Append(FILE_PATH_LITERAL("src.txt")); | 1476 FilePath src_file = src.Append(FILE_PATH_LITERAL("src.txt")); |
| 1472 CreateTextFile(src_file, L"Gooooooooooooooooooooogle"); | 1477 CreateTextFile(src_file, L"Gooooooooooooooooooooogle"); |
| 1473 SetReadOnly(src_file, true); | 1478 SetReadOnly(src_file, true); |
| 1474 ASSERT_TRUE(IsReadOnly(src_file)); | 1479 ASSERT_TRUE(IsReadOnly(src_file)); |
| 1475 | 1480 |
| 1476 // Make directory read-only. | 1481 // Make directory read-only. |
| 1477 SetReadOnly(src_subdir, true); | 1482 SetReadOnly(src_subdir, true); |
| 1478 ASSERT_TRUE(IsReadOnly(src_subdir)); | 1483 ASSERT_TRUE(IsReadOnly(src_subdir)); |
| 1479 | 1484 |
| 1480 // Copy the directory recursively. | 1485 // Copy the directory recursively. |
| 1481 FilePath dst = temp_dir_.path().Append(FILE_PATH_LITERAL("dst")); | 1486 FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst")); |
| 1482 FilePath dst_file = dst.Append(FILE_PATH_LITERAL("src.txt")); | 1487 FilePath dst_file = dst.Append(FILE_PATH_LITERAL("src.txt")); |
| 1483 EXPECT_TRUE(CopyDirectory(src, dst, true)); | 1488 EXPECT_TRUE(CopyDirectory(src, dst, true)); |
| 1484 | 1489 |
| 1485 FilePath dst_subdir = dst.Append(FILE_PATH_LITERAL("subdir")); | 1490 FilePath dst_subdir = dst.Append(FILE_PATH_LITERAL("subdir")); |
| 1486 ASSERT_FALSE(IsReadOnly(dst_subdir)); | 1491 ASSERT_FALSE(IsReadOnly(dst_subdir)); |
| 1487 ASSERT_FALSE(IsReadOnly(dst_file)); | 1492 ASSERT_FALSE(IsReadOnly(dst_file)); |
| 1488 | 1493 |
| 1489 // Give write permissions to allow deletion. | 1494 // Give write permissions to allow deletion. |
| 1490 SetReadOnly(src_subdir, false); | 1495 SetReadOnly(src_subdir, false); |
| 1491 ASSERT_FALSE(IsReadOnly(src_subdir)); | 1496 ASSERT_FALSE(IsReadOnly(src_subdir)); |
| 1492 } | 1497 } |
| 1493 | 1498 |
| 1494 TEST_F(FileUtilTest, CopyFile) { | 1499 TEST_F(FileUtilTest, CopyFile) { |
| 1495 // Create a directory | 1500 // Create a directory |
| 1496 FilePath dir_name_from = | 1501 FilePath dir_name_from = |
| 1497 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1502 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1498 CreateDirectory(dir_name_from); | 1503 CreateDirectory(dir_name_from); |
| 1499 ASSERT_TRUE(PathExists(dir_name_from)); | 1504 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1500 | 1505 |
| 1501 // Create a file under the directory | 1506 // Create a file under the directory |
| 1502 FilePath file_name_from = | 1507 FilePath file_name_from = |
| 1503 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1508 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1504 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | 1509 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
| 1505 CreateTextFile(file_name_from, file_contents); | 1510 CreateTextFile(file_name_from, file_contents); |
| 1506 ASSERT_TRUE(PathExists(file_name_from)); | 1511 ASSERT_TRUE(PathExists(file_name_from)); |
| 1507 | 1512 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1525 const std::wstring read_contents = ReadTextFile(dest_file); | 1530 const std::wstring read_contents = ReadTextFile(dest_file); |
| 1526 EXPECT_EQ(file_contents, read_contents); | 1531 EXPECT_EQ(file_contents, read_contents); |
| 1527 EXPECT_FALSE(PathExists(dest_file2_test)); | 1532 EXPECT_FALSE(PathExists(dest_file2_test)); |
| 1528 EXPECT_FALSE(PathExists(dest_file2)); | 1533 EXPECT_FALSE(PathExists(dest_file2)); |
| 1529 } | 1534 } |
| 1530 | 1535 |
| 1531 TEST_F(FileUtilTest, CopyFileACL) { | 1536 TEST_F(FileUtilTest, CopyFileACL) { |
| 1532 // While FileUtilTest.CopyFile asserts the content is correctly copied over, | 1537 // While FileUtilTest.CopyFile asserts the content is correctly copied over, |
| 1533 // this test case asserts the access control bits are meeting expectations in | 1538 // this test case asserts the access control bits are meeting expectations in |
| 1534 // CopyFile(). | 1539 // CopyFile(). |
| 1535 FilePath src = temp_dir_.path().Append(FILE_PATH_LITERAL("src.txt")); | 1540 FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src.txt")); |
| 1536 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | 1541 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
| 1537 CreateTextFile(src, file_contents); | 1542 CreateTextFile(src, file_contents); |
| 1538 | 1543 |
| 1539 // Set the source file to read-only. | 1544 // Set the source file to read-only. |
| 1540 ASSERT_FALSE(IsReadOnly(src)); | 1545 ASSERT_FALSE(IsReadOnly(src)); |
| 1541 SetReadOnly(src, true); | 1546 SetReadOnly(src, true); |
| 1542 ASSERT_TRUE(IsReadOnly(src)); | 1547 ASSERT_TRUE(IsReadOnly(src)); |
| 1543 | 1548 |
| 1544 // Copy the file. | 1549 // Copy the file. |
| 1545 FilePath dst = temp_dir_.path().Append(FILE_PATH_LITERAL("dst.txt")); | 1550 FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst.txt")); |
| 1546 ASSERT_TRUE(CopyFile(src, dst)); | 1551 ASSERT_TRUE(CopyFile(src, dst)); |
| 1547 EXPECT_EQ(file_contents, ReadTextFile(dst)); | 1552 EXPECT_EQ(file_contents, ReadTextFile(dst)); |
| 1548 | 1553 |
| 1549 ASSERT_FALSE(IsReadOnly(dst)); | 1554 ASSERT_FALSE(IsReadOnly(dst)); |
| 1550 } | 1555 } |
| 1551 | 1556 |
| 1552 // file_util winds up using autoreleased objects on the Mac, so this needs | 1557 // file_util winds up using autoreleased objects on the Mac, so this needs |
| 1553 // to be a PlatformTest. | 1558 // to be a PlatformTest. |
| 1554 typedef PlatformTest ReadOnlyFileUtilTest; | 1559 typedef PlatformTest ReadOnlyFileUtilTest; |
| 1555 | 1560 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 EXPECT_FALSE(TextContentsEqual(first1_file, first2_file)); | 1646 EXPECT_FALSE(TextContentsEqual(first1_file, first2_file)); |
| 1642 EXPECT_TRUE(TextContentsEqual(empty1_file, empty2_file)); | 1647 EXPECT_TRUE(TextContentsEqual(empty1_file, empty2_file)); |
| 1643 EXPECT_FALSE(TextContentsEqual(original_file, empty1_file)); | 1648 EXPECT_FALSE(TextContentsEqual(original_file, empty1_file)); |
| 1644 EXPECT_TRUE(TextContentsEqual(blank_line_file, blank_line_crlf_file)); | 1649 EXPECT_TRUE(TextContentsEqual(blank_line_file, blank_line_crlf_file)); |
| 1645 } | 1650 } |
| 1646 | 1651 |
| 1647 // We don't need equivalent functionality outside of Windows. | 1652 // We don't need equivalent functionality outside of Windows. |
| 1648 #if defined(OS_WIN) | 1653 #if defined(OS_WIN) |
| 1649 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { | 1654 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { |
| 1650 // Create a directory | 1655 // Create a directory |
| 1651 FilePath dir_name_from = | 1656 FilePath dir_name_from = temp_dir_.GetPath().Append( |
| 1652 temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); | 1657 FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); |
| 1653 CreateDirectory(dir_name_from); | 1658 CreateDirectory(dir_name_from); |
| 1654 ASSERT_TRUE(PathExists(dir_name_from)); | 1659 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1655 | 1660 |
| 1656 // Create a file under the directory | 1661 // Create a file under the directory |
| 1657 FilePath file_name_from = | 1662 FilePath file_name_from = |
| 1658 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1663 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
| 1659 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1664 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1660 ASSERT_TRUE(PathExists(file_name_from)); | 1665 ASSERT_TRUE(PathExists(file_name_from)); |
| 1661 | 1666 |
| 1662 // Move the directory by using CopyAndDeleteDirectory | 1667 // Move the directory by using CopyAndDeleteDirectory |
| 1663 FilePath dir_name_to = temp_dir_.path().Append( | 1668 FilePath dir_name_to = |
| 1664 FILE_PATH_LITERAL("CopyAndDelete_To_Subdir")); | 1669 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("CopyAndDelete_To_Subdir")); |
| 1665 FilePath file_name_to = | 1670 FilePath file_name_to = |
| 1666 dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1671 dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
| 1667 | 1672 |
| 1668 ASSERT_FALSE(PathExists(dir_name_to)); | 1673 ASSERT_FALSE(PathExists(dir_name_to)); |
| 1669 | 1674 |
| 1670 EXPECT_TRUE(internal::CopyAndDeleteDirectory(dir_name_from, | 1675 EXPECT_TRUE(internal::CopyAndDeleteDirectory(dir_name_from, |
| 1671 dir_name_to)); | 1676 dir_name_to)); |
| 1672 | 1677 |
| 1673 // Check everything has been moved. | 1678 // Check everything has been moved. |
| 1674 EXPECT_FALSE(PathExists(dir_name_from)); | 1679 EXPECT_FALSE(PathExists(dir_name_from)); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 EXPECT_TRUE(CloseFile(fps[i])); | 1801 EXPECT_TRUE(CloseFile(fps[i])); |
| 1797 EXPECT_TRUE(DeleteFile(names[i], false)); | 1802 EXPECT_TRUE(DeleteFile(names[i], false)); |
| 1798 } | 1803 } |
| 1799 } | 1804 } |
| 1800 | 1805 |
| 1801 TEST_F(FileUtilTest, FileToFILE) { | 1806 TEST_F(FileUtilTest, FileToFILE) { |
| 1802 File file; | 1807 File file; |
| 1803 FILE* stream = FileToFILE(std::move(file), "w"); | 1808 FILE* stream = FileToFILE(std::move(file), "w"); |
| 1804 EXPECT_FALSE(stream); | 1809 EXPECT_FALSE(stream); |
| 1805 | 1810 |
| 1806 FilePath file_name = temp_dir_.path().Append(FPL("The file.txt")); | 1811 FilePath file_name = temp_dir_.GetPath().Append(FPL("The file.txt")); |
| 1807 file = File(file_name, File::FLAG_CREATE | File::FLAG_WRITE); | 1812 file = File(file_name, File::FLAG_CREATE | File::FLAG_WRITE); |
| 1808 EXPECT_TRUE(file.IsValid()); | 1813 EXPECT_TRUE(file.IsValid()); |
| 1809 | 1814 |
| 1810 stream = FileToFILE(std::move(file), "w"); | 1815 stream = FileToFILE(std::move(file), "w"); |
| 1811 EXPECT_TRUE(stream); | 1816 EXPECT_TRUE(stream); |
| 1812 EXPECT_FALSE(file.IsValid()); | 1817 EXPECT_FALSE(file.IsValid()); |
| 1813 EXPECT_TRUE(CloseFile(stream)); | 1818 EXPECT_TRUE(CloseFile(stream)); |
| 1814 } | 1819 } |
| 1815 | 1820 |
| 1816 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { | 1821 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { |
| 1817 FilePath temp_dir; | 1822 FilePath temp_dir; |
| 1818 ASSERT_TRUE(CreateNewTempDirectory(FilePath::StringType(), &temp_dir)); | 1823 ASSERT_TRUE(CreateNewTempDirectory(FilePath::StringType(), &temp_dir)); |
| 1819 EXPECT_TRUE(PathExists(temp_dir)); | 1824 EXPECT_TRUE(PathExists(temp_dir)); |
| 1820 EXPECT_TRUE(DeleteFile(temp_dir, false)); | 1825 EXPECT_TRUE(DeleteFile(temp_dir, false)); |
| 1821 } | 1826 } |
| 1822 | 1827 |
| 1823 TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) { | 1828 TEST_F(FileUtilTest, CreateNewTemporaryDirInDirTest) { |
| 1824 FilePath new_dir; | 1829 FilePath new_dir; |
| 1825 ASSERT_TRUE(CreateTemporaryDirInDir( | 1830 ASSERT_TRUE(CreateTemporaryDirInDir( |
| 1826 temp_dir_.path(), | 1831 temp_dir_.GetPath(), FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), |
| 1827 FILE_PATH_LITERAL("CreateNewTemporaryDirInDirTest"), | 1832 &new_dir)); |
| 1828 &new_dir)); | |
| 1829 EXPECT_TRUE(PathExists(new_dir)); | 1833 EXPECT_TRUE(PathExists(new_dir)); |
| 1830 EXPECT_TRUE(temp_dir_.path().IsParent(new_dir)); | 1834 EXPECT_TRUE(temp_dir_.GetPath().IsParent(new_dir)); |
| 1831 EXPECT_TRUE(DeleteFile(new_dir, false)); | 1835 EXPECT_TRUE(DeleteFile(new_dir, false)); |
| 1832 } | 1836 } |
| 1833 | 1837 |
| 1834 #if defined(OS_POSIX) | 1838 #if defined(OS_POSIX) |
| 1835 TEST_F(FileUtilTest, GetShmemTempDirTest) { | 1839 TEST_F(FileUtilTest, GetShmemTempDirTest) { |
| 1836 FilePath dir; | 1840 FilePath dir; |
| 1837 EXPECT_TRUE(GetShmemTempDir(false, &dir)); | 1841 EXPECT_TRUE(GetShmemTempDir(false, &dir)); |
| 1838 EXPECT_TRUE(DirectoryExists(dir)); | 1842 EXPECT_TRUE(DirectoryExists(dir)); |
| 1839 } | 1843 } |
| 1840 #endif | 1844 #endif |
| 1841 | 1845 |
| 1842 TEST_F(FileUtilTest, GetHomeDirTest) { | 1846 TEST_F(FileUtilTest, GetHomeDirTest) { |
| 1843 #if !defined(OS_ANDROID) // Not implemented on Android. | 1847 #if !defined(OS_ANDROID) // Not implemented on Android. |
| 1844 // We don't actually know what the home directory is supposed to be without | 1848 // We don't actually know what the home directory is supposed to be without |
| 1845 // calling some OS functions which would just duplicate the implementation. | 1849 // calling some OS functions which would just duplicate the implementation. |
| 1846 // So here we just test that it returns something "reasonable". | 1850 // So here we just test that it returns something "reasonable". |
| 1847 FilePath home = GetHomeDir(); | 1851 FilePath home = GetHomeDir(); |
| 1848 ASSERT_FALSE(home.empty()); | 1852 ASSERT_FALSE(home.empty()); |
| 1849 ASSERT_TRUE(home.IsAbsolute()); | 1853 ASSERT_TRUE(home.IsAbsolute()); |
| 1850 #endif | 1854 #endif |
| 1851 } | 1855 } |
| 1852 | 1856 |
| 1853 TEST_F(FileUtilTest, CreateDirectoryTest) { | 1857 TEST_F(FileUtilTest, CreateDirectoryTest) { |
| 1854 FilePath test_root = | 1858 FilePath test_root = |
| 1855 temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test")); | 1859 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("create_directory_test")); |
| 1856 #if defined(OS_WIN) | 1860 #if defined(OS_WIN) |
| 1857 FilePath test_path = | 1861 FilePath test_path = |
| 1858 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); | 1862 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); |
| 1859 #elif defined(OS_POSIX) | 1863 #elif defined(OS_POSIX) |
| 1860 FilePath test_path = | 1864 FilePath test_path = |
| 1861 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/")); | 1865 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/")); |
| 1862 #endif | 1866 #endif |
| 1863 | 1867 |
| 1864 EXPECT_FALSE(PathExists(test_path)); | 1868 EXPECT_FALSE(PathExists(test_path)); |
| 1865 EXPECT_TRUE(CreateDirectory(test_path)); | 1869 EXPECT_TRUE(CreateDirectory(test_path)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1900 invalid_drive.Append(FILE_PATH_LITERAL("some\\inaccessible\\dir")); | 1904 invalid_drive.Append(FILE_PATH_LITERAL("some\\inaccessible\\dir")); |
| 1901 if (!PathExists(invalid_drive)) { | 1905 if (!PathExists(invalid_drive)) { |
| 1902 EXPECT_FALSE(CreateDirectory(invalid_path)); | 1906 EXPECT_FALSE(CreateDirectory(invalid_path)); |
| 1903 } | 1907 } |
| 1904 #endif | 1908 #endif |
| 1905 } | 1909 } |
| 1906 | 1910 |
| 1907 TEST_F(FileUtilTest, DetectDirectoryTest) { | 1911 TEST_F(FileUtilTest, DetectDirectoryTest) { |
| 1908 // Check a directory | 1912 // Check a directory |
| 1909 FilePath test_root = | 1913 FilePath test_root = |
| 1910 temp_dir_.path().Append(FILE_PATH_LITERAL("detect_directory_test")); | 1914 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("detect_directory_test")); |
| 1911 EXPECT_FALSE(PathExists(test_root)); | 1915 EXPECT_FALSE(PathExists(test_root)); |
| 1912 EXPECT_TRUE(CreateDirectory(test_root)); | 1916 EXPECT_TRUE(CreateDirectory(test_root)); |
| 1913 EXPECT_TRUE(PathExists(test_root)); | 1917 EXPECT_TRUE(PathExists(test_root)); |
| 1914 EXPECT_TRUE(DirectoryExists(test_root)); | 1918 EXPECT_TRUE(DirectoryExists(test_root)); |
| 1915 // Check a file | 1919 // Check a file |
| 1916 FilePath test_path = | 1920 FilePath test_path = |
| 1917 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); | 1921 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); |
| 1918 EXPECT_FALSE(PathExists(test_path)); | 1922 EXPECT_FALSE(PathExists(test_path)); |
| 1919 CreateTextFile(test_path, L"test file"); | 1923 CreateTextFile(test_path, L"test file"); |
| 1920 EXPECT_TRUE(PathExists(test_path)); | 1924 EXPECT_TRUE(PathExists(test_path)); |
| 1921 EXPECT_FALSE(DirectoryExists(test_path)); | 1925 EXPECT_FALSE(DirectoryExists(test_path)); |
| 1922 EXPECT_TRUE(DeleteFile(test_path, false)); | 1926 EXPECT_TRUE(DeleteFile(test_path, false)); |
| 1923 | 1927 |
| 1924 EXPECT_TRUE(DeleteFile(test_root, true)); | 1928 EXPECT_TRUE(DeleteFile(test_root, true)); |
| 1925 } | 1929 } |
| 1926 | 1930 |
| 1927 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1931 TEST_F(FileUtilTest, FileEnumeratorTest) { |
| 1928 // Test an empty directory. | 1932 // Test an empty directory. |
| 1929 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1933 FileEnumerator f0(temp_dir_.GetPath(), true, FILES_AND_DIRECTORIES); |
| 1930 EXPECT_EQ(FPL(""), f0.Next().value()); | 1934 EXPECT_EQ(FPL(""), f0.Next().value()); |
| 1931 EXPECT_EQ(FPL(""), f0.Next().value()); | 1935 EXPECT_EQ(FPL(""), f0.Next().value()); |
| 1932 | 1936 |
| 1933 // Test an empty directory, non-recursively, including "..". | 1937 // Test an empty directory, non-recursively, including "..". |
| 1934 FileEnumerator f0_dotdot(temp_dir_.path(), false, | 1938 FileEnumerator f0_dotdot( |
| 1939 temp_dir_.GetPath(), false, |
| 1935 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); | 1940 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); |
| 1936 EXPECT_EQ(temp_dir_.path().Append(FPL("..")).value(), | 1941 EXPECT_EQ(temp_dir_.GetPath().Append(FPL("..")).value(), |
| 1937 f0_dotdot.Next().value()); | 1942 f0_dotdot.Next().value()); |
| 1938 EXPECT_EQ(FPL(""), f0_dotdot.Next().value()); | 1943 EXPECT_EQ(FPL(""), f0_dotdot.Next().value()); |
| 1939 | 1944 |
| 1940 // create the directories | 1945 // create the directories |
| 1941 FilePath dir1 = temp_dir_.path().Append(FPL("dir1")); | 1946 FilePath dir1 = temp_dir_.GetPath().Append(FPL("dir1")); |
| 1942 EXPECT_TRUE(CreateDirectory(dir1)); | 1947 EXPECT_TRUE(CreateDirectory(dir1)); |
| 1943 FilePath dir2 = temp_dir_.path().Append(FPL("dir2")); | 1948 FilePath dir2 = temp_dir_.GetPath().Append(FPL("dir2")); |
| 1944 EXPECT_TRUE(CreateDirectory(dir2)); | 1949 EXPECT_TRUE(CreateDirectory(dir2)); |
| 1945 FilePath dir2inner = dir2.Append(FPL("inner")); | 1950 FilePath dir2inner = dir2.Append(FPL("inner")); |
| 1946 EXPECT_TRUE(CreateDirectory(dir2inner)); | 1951 EXPECT_TRUE(CreateDirectory(dir2inner)); |
| 1947 | 1952 |
| 1948 // create the files | 1953 // create the files |
| 1949 FilePath dir2file = dir2.Append(FPL("dir2file.txt")); | 1954 FilePath dir2file = dir2.Append(FPL("dir2file.txt")); |
| 1950 CreateTextFile(dir2file, std::wstring()); | 1955 CreateTextFile(dir2file, std::wstring()); |
| 1951 FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); | 1956 FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); |
| 1952 CreateTextFile(dir2innerfile, std::wstring()); | 1957 CreateTextFile(dir2innerfile, std::wstring()); |
| 1953 FilePath file1 = temp_dir_.path().Append(FPL("file1.txt")); | 1958 FilePath file1 = temp_dir_.GetPath().Append(FPL("file1.txt")); |
| 1954 CreateTextFile(file1, std::wstring()); | 1959 CreateTextFile(file1, std::wstring()); |
| 1955 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) | 1960 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) |
| 1956 .Append(FPL("file2.txt")); | 1961 .Append(FPL("file2.txt")); |
| 1957 CreateTextFile(file2_rel, std::wstring()); | 1962 CreateTextFile(file2_rel, std::wstring()); |
| 1958 FilePath file2_abs = temp_dir_.path().Append(FPL("file2.txt")); | 1963 FilePath file2_abs = temp_dir_.GetPath().Append(FPL("file2.txt")); |
| 1959 | 1964 |
| 1960 // Only enumerate files. | 1965 // Only enumerate files. |
| 1961 FileEnumerator f1(temp_dir_.path(), true, FileEnumerator::FILES); | 1966 FileEnumerator f1(temp_dir_.GetPath(), true, FileEnumerator::FILES); |
| 1962 FindResultCollector c1(&f1); | 1967 FindResultCollector c1(&f1); |
| 1963 EXPECT_TRUE(c1.HasFile(file1)); | 1968 EXPECT_TRUE(c1.HasFile(file1)); |
| 1964 EXPECT_TRUE(c1.HasFile(file2_abs)); | 1969 EXPECT_TRUE(c1.HasFile(file2_abs)); |
| 1965 EXPECT_TRUE(c1.HasFile(dir2file)); | 1970 EXPECT_TRUE(c1.HasFile(dir2file)); |
| 1966 EXPECT_TRUE(c1.HasFile(dir2innerfile)); | 1971 EXPECT_TRUE(c1.HasFile(dir2innerfile)); |
| 1967 EXPECT_EQ(4, c1.size()); | 1972 EXPECT_EQ(4, c1.size()); |
| 1968 | 1973 |
| 1969 // Only enumerate directories. | 1974 // Only enumerate directories. |
| 1970 FileEnumerator f2(temp_dir_.path(), true, FileEnumerator::DIRECTORIES); | 1975 FileEnumerator f2(temp_dir_.GetPath(), true, FileEnumerator::DIRECTORIES); |
| 1971 FindResultCollector c2(&f2); | 1976 FindResultCollector c2(&f2); |
| 1972 EXPECT_TRUE(c2.HasFile(dir1)); | 1977 EXPECT_TRUE(c2.HasFile(dir1)); |
| 1973 EXPECT_TRUE(c2.HasFile(dir2)); | 1978 EXPECT_TRUE(c2.HasFile(dir2)); |
| 1974 EXPECT_TRUE(c2.HasFile(dir2inner)); | 1979 EXPECT_TRUE(c2.HasFile(dir2inner)); |
| 1975 EXPECT_EQ(3, c2.size()); | 1980 EXPECT_EQ(3, c2.size()); |
| 1976 | 1981 |
| 1977 // Only enumerate directories non-recursively. | 1982 // Only enumerate directories non-recursively. |
| 1978 FileEnumerator f2_non_recursive( | 1983 FileEnumerator f2_non_recursive(temp_dir_.GetPath(), false, |
| 1979 temp_dir_.path(), false, FileEnumerator::DIRECTORIES); | 1984 FileEnumerator::DIRECTORIES); |
| 1980 FindResultCollector c2_non_recursive(&f2_non_recursive); | 1985 FindResultCollector c2_non_recursive(&f2_non_recursive); |
| 1981 EXPECT_TRUE(c2_non_recursive.HasFile(dir1)); | 1986 EXPECT_TRUE(c2_non_recursive.HasFile(dir1)); |
| 1982 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); | 1987 EXPECT_TRUE(c2_non_recursive.HasFile(dir2)); |
| 1983 EXPECT_EQ(2, c2_non_recursive.size()); | 1988 EXPECT_EQ(2, c2_non_recursive.size()); |
| 1984 | 1989 |
| 1985 // Only enumerate directories, non-recursively, including "..". | 1990 // Only enumerate directories, non-recursively, including "..". |
| 1986 FileEnumerator f2_dotdot(temp_dir_.path(), false, | 1991 FileEnumerator f2_dotdot( |
| 1987 FileEnumerator::DIRECTORIES | | 1992 temp_dir_.GetPath(), false, |
| 1988 FileEnumerator::INCLUDE_DOT_DOT); | 1993 FileEnumerator::DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); |
| 1989 FindResultCollector c2_dotdot(&f2_dotdot); | 1994 FindResultCollector c2_dotdot(&f2_dotdot); |
| 1990 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); | 1995 EXPECT_TRUE(c2_dotdot.HasFile(dir1)); |
| 1991 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); | 1996 EXPECT_TRUE(c2_dotdot.HasFile(dir2)); |
| 1992 EXPECT_TRUE(c2_dotdot.HasFile(temp_dir_.path().Append(FPL("..")))); | 1997 EXPECT_TRUE(c2_dotdot.HasFile(temp_dir_.GetPath().Append(FPL("..")))); |
| 1993 EXPECT_EQ(3, c2_dotdot.size()); | 1998 EXPECT_EQ(3, c2_dotdot.size()); |
| 1994 | 1999 |
| 1995 // Enumerate files and directories. | 2000 // Enumerate files and directories. |
| 1996 FileEnumerator f3(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 2001 FileEnumerator f3(temp_dir_.GetPath(), true, FILES_AND_DIRECTORIES); |
| 1997 FindResultCollector c3(&f3); | 2002 FindResultCollector c3(&f3); |
| 1998 EXPECT_TRUE(c3.HasFile(dir1)); | 2003 EXPECT_TRUE(c3.HasFile(dir1)); |
| 1999 EXPECT_TRUE(c3.HasFile(dir2)); | 2004 EXPECT_TRUE(c3.HasFile(dir2)); |
| 2000 EXPECT_TRUE(c3.HasFile(file1)); | 2005 EXPECT_TRUE(c3.HasFile(file1)); |
| 2001 EXPECT_TRUE(c3.HasFile(file2_abs)); | 2006 EXPECT_TRUE(c3.HasFile(file2_abs)); |
| 2002 EXPECT_TRUE(c3.HasFile(dir2file)); | 2007 EXPECT_TRUE(c3.HasFile(dir2file)); |
| 2003 EXPECT_TRUE(c3.HasFile(dir2inner)); | 2008 EXPECT_TRUE(c3.HasFile(dir2inner)); |
| 2004 EXPECT_TRUE(c3.HasFile(dir2innerfile)); | 2009 EXPECT_TRUE(c3.HasFile(dir2innerfile)); |
| 2005 EXPECT_EQ(7, c3.size()); | 2010 EXPECT_EQ(7, c3.size()); |
| 2006 | 2011 |
| 2007 // Non-recursive operation. | 2012 // Non-recursive operation. |
| 2008 FileEnumerator f4(temp_dir_.path(), false, FILES_AND_DIRECTORIES); | 2013 FileEnumerator f4(temp_dir_.GetPath(), false, FILES_AND_DIRECTORIES); |
| 2009 FindResultCollector c4(&f4); | 2014 FindResultCollector c4(&f4); |
| 2010 EXPECT_TRUE(c4.HasFile(dir2)); | 2015 EXPECT_TRUE(c4.HasFile(dir2)); |
| 2011 EXPECT_TRUE(c4.HasFile(dir2)); | 2016 EXPECT_TRUE(c4.HasFile(dir2)); |
| 2012 EXPECT_TRUE(c4.HasFile(file1)); | 2017 EXPECT_TRUE(c4.HasFile(file1)); |
| 2013 EXPECT_TRUE(c4.HasFile(file2_abs)); | 2018 EXPECT_TRUE(c4.HasFile(file2_abs)); |
| 2014 EXPECT_EQ(4, c4.size()); | 2019 EXPECT_EQ(4, c4.size()); |
| 2015 | 2020 |
| 2016 // Enumerate with a pattern. | 2021 // Enumerate with a pattern. |
| 2017 FileEnumerator f5(temp_dir_.path(), true, FILES_AND_DIRECTORIES, FPL("dir*")); | 2022 FileEnumerator f5(temp_dir_.GetPath(), true, FILES_AND_DIRECTORIES, |
| 2023 FPL("dir*")); |
| 2018 FindResultCollector c5(&f5); | 2024 FindResultCollector c5(&f5); |
| 2019 EXPECT_TRUE(c5.HasFile(dir1)); | 2025 EXPECT_TRUE(c5.HasFile(dir1)); |
| 2020 EXPECT_TRUE(c5.HasFile(dir2)); | 2026 EXPECT_TRUE(c5.HasFile(dir2)); |
| 2021 EXPECT_TRUE(c5.HasFile(dir2file)); | 2027 EXPECT_TRUE(c5.HasFile(dir2file)); |
| 2022 EXPECT_TRUE(c5.HasFile(dir2inner)); | 2028 EXPECT_TRUE(c5.HasFile(dir2inner)); |
| 2023 EXPECT_TRUE(c5.HasFile(dir2innerfile)); | 2029 EXPECT_TRUE(c5.HasFile(dir2innerfile)); |
| 2024 EXPECT_EQ(5, c5.size()); | 2030 EXPECT_EQ(5, c5.size()); |
| 2025 | 2031 |
| 2026 #if defined(OS_WIN) | 2032 #if defined(OS_WIN) |
| 2027 { | 2033 { |
| 2028 // Make dir1 point to dir2. | 2034 // Make dir1 point to dir2. |
| 2029 ReparsePoint reparse_point(dir1, dir2); | 2035 ReparsePoint reparse_point(dir1, dir2); |
| 2030 EXPECT_TRUE(reparse_point.IsValid()); | 2036 EXPECT_TRUE(reparse_point.IsValid()); |
| 2031 | 2037 |
| 2032 if ((win::GetVersion() >= win::VERSION_VISTA)) { | 2038 if ((win::GetVersion() >= win::VERSION_VISTA)) { |
| 2033 // There can be a delay for the enumeration code to see the change on | 2039 // There can be a delay for the enumeration code to see the change on |
| 2034 // the file system so skip this test for XP. | 2040 // the file system so skip this test for XP. |
| 2035 // Enumerate the reparse point. | 2041 // Enumerate the reparse point. |
| 2036 FileEnumerator f6(dir1, true, FILES_AND_DIRECTORIES); | 2042 FileEnumerator f6(dir1, true, FILES_AND_DIRECTORIES); |
| 2037 FindResultCollector c6(&f6); | 2043 FindResultCollector c6(&f6); |
| 2038 FilePath inner2 = dir1.Append(FPL("inner")); | 2044 FilePath inner2 = dir1.Append(FPL("inner")); |
| 2039 EXPECT_TRUE(c6.HasFile(inner2)); | 2045 EXPECT_TRUE(c6.HasFile(inner2)); |
| 2040 EXPECT_TRUE(c6.HasFile(inner2.Append(FPL("innerfile.txt")))); | 2046 EXPECT_TRUE(c6.HasFile(inner2.Append(FPL("innerfile.txt")))); |
| 2041 EXPECT_TRUE(c6.HasFile(dir1.Append(FPL("dir2file.txt")))); | 2047 EXPECT_TRUE(c6.HasFile(dir1.Append(FPL("dir2file.txt")))); |
| 2042 EXPECT_EQ(3, c6.size()); | 2048 EXPECT_EQ(3, c6.size()); |
| 2043 } | 2049 } |
| 2044 | 2050 |
| 2045 // No changes for non recursive operation. | 2051 // No changes for non recursive operation. |
| 2046 FileEnumerator f7(temp_dir_.path(), false, FILES_AND_DIRECTORIES); | 2052 FileEnumerator f7(temp_dir_.GetPath(), false, FILES_AND_DIRECTORIES); |
| 2047 FindResultCollector c7(&f7); | 2053 FindResultCollector c7(&f7); |
| 2048 EXPECT_TRUE(c7.HasFile(dir2)); | 2054 EXPECT_TRUE(c7.HasFile(dir2)); |
| 2049 EXPECT_TRUE(c7.HasFile(dir2)); | 2055 EXPECT_TRUE(c7.HasFile(dir2)); |
| 2050 EXPECT_TRUE(c7.HasFile(file1)); | 2056 EXPECT_TRUE(c7.HasFile(file1)); |
| 2051 EXPECT_TRUE(c7.HasFile(file2_abs)); | 2057 EXPECT_TRUE(c7.HasFile(file2_abs)); |
| 2052 EXPECT_EQ(4, c7.size()); | 2058 EXPECT_EQ(4, c7.size()); |
| 2053 | 2059 |
| 2054 // Should not enumerate inside dir1 when using recursion. | 2060 // Should not enumerate inside dir1 when using recursion. |
| 2055 FileEnumerator f8(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 2061 FileEnumerator f8(temp_dir_.GetPath(), true, FILES_AND_DIRECTORIES); |
| 2056 FindResultCollector c8(&f8); | 2062 FindResultCollector c8(&f8); |
| 2057 EXPECT_TRUE(c8.HasFile(dir1)); | 2063 EXPECT_TRUE(c8.HasFile(dir1)); |
| 2058 EXPECT_TRUE(c8.HasFile(dir2)); | 2064 EXPECT_TRUE(c8.HasFile(dir2)); |
| 2059 EXPECT_TRUE(c8.HasFile(file1)); | 2065 EXPECT_TRUE(c8.HasFile(file1)); |
| 2060 EXPECT_TRUE(c8.HasFile(file2_abs)); | 2066 EXPECT_TRUE(c8.HasFile(file2_abs)); |
| 2061 EXPECT_TRUE(c8.HasFile(dir2file)); | 2067 EXPECT_TRUE(c8.HasFile(dir2file)); |
| 2062 EXPECT_TRUE(c8.HasFile(dir2inner)); | 2068 EXPECT_TRUE(c8.HasFile(dir2inner)); |
| 2063 EXPECT_TRUE(c8.HasFile(dir2innerfile)); | 2069 EXPECT_TRUE(c8.HasFile(dir2innerfile)); |
| 2064 EXPECT_EQ(7, c8.size()); | 2070 EXPECT_EQ(7, c8.size()); |
| 2065 } | 2071 } |
| 2066 #endif | 2072 #endif |
| 2067 | 2073 |
| 2068 // Make sure the destructor closes the find handle while in the middle of a | 2074 // Make sure the destructor closes the find handle while in the middle of a |
| 2069 // query to allow TearDown to delete the directory. | 2075 // query to allow TearDown to delete the directory. |
| 2070 FileEnumerator f9(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 2076 FileEnumerator f9(temp_dir_.GetPath(), true, FILES_AND_DIRECTORIES); |
| 2071 EXPECT_FALSE(f9.Next().value().empty()); // Should have found something | 2077 EXPECT_FALSE(f9.Next().value().empty()); // Should have found something |
| 2072 // (we don't care what). | 2078 // (we don't care what). |
| 2073 } | 2079 } |
| 2074 | 2080 |
| 2075 TEST_F(FileUtilTest, AppendToFile) { | 2081 TEST_F(FileUtilTest, AppendToFile) { |
| 2076 FilePath data_dir = | 2082 FilePath data_dir = |
| 2077 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 2083 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("FilePathTest")); |
| 2078 | 2084 |
| 2079 // Create a fresh, empty copy of this directory. | 2085 // Create a fresh, empty copy of this directory. |
| 2080 if (PathExists(data_dir)) { | 2086 if (PathExists(data_dir)) { |
| 2081 ASSERT_TRUE(DeleteFile(data_dir, true)); | 2087 ASSERT_TRUE(DeleteFile(data_dir, true)); |
| 2082 } | 2088 } |
| 2083 ASSERT_TRUE(CreateDirectory(data_dir)); | 2089 ASSERT_TRUE(CreateDirectory(data_dir)); |
| 2084 | 2090 |
| 2085 // Create a fresh, empty copy of this directory. | 2091 // Create a fresh, empty copy of this directory. |
| 2086 if (PathExists(data_dir)) { | 2092 if (PathExists(data_dir)) { |
| 2087 ASSERT_TRUE(DeleteFile(data_dir, true)); | 2093 ASSERT_TRUE(DeleteFile(data_dir, true)); |
| 2088 } | 2094 } |
| 2089 ASSERT_TRUE(CreateDirectory(data_dir)); | 2095 ASSERT_TRUE(CreateDirectory(data_dir)); |
| 2090 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 2096 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
| 2091 | 2097 |
| 2092 std::string data("hello"); | 2098 std::string data("hello"); |
| 2093 EXPECT_FALSE(AppendToFile(foobar, data.c_str(), data.size())); | 2099 EXPECT_FALSE(AppendToFile(foobar, data.c_str(), data.size())); |
| 2094 EXPECT_EQ(static_cast<int>(data.length()), | 2100 EXPECT_EQ(static_cast<int>(data.length()), |
| 2095 WriteFile(foobar, data.c_str(), data.length())); | 2101 WriteFile(foobar, data.c_str(), data.length())); |
| 2096 EXPECT_TRUE(AppendToFile(foobar, data.c_str(), data.size())); | 2102 EXPECT_TRUE(AppendToFile(foobar, data.c_str(), data.size())); |
| 2097 | 2103 |
| 2098 const std::wstring read_content = ReadTextFile(foobar); | 2104 const std::wstring read_content = ReadTextFile(foobar); |
| 2099 EXPECT_EQ(L"hellohello", read_content); | 2105 EXPECT_EQ(L"hellohello", read_content); |
| 2100 } | 2106 } |
| 2101 | 2107 |
| 2102 TEST_F(FileUtilTest, ReadFile) { | 2108 TEST_F(FileUtilTest, ReadFile) { |
| 2103 // Create a test file to be read. | 2109 // Create a test file to be read. |
| 2104 const std::string kTestData("The quick brown fox jumps over the lazy dog."); | 2110 const std::string kTestData("The quick brown fox jumps over the lazy dog."); |
| 2105 FilePath file_path = | 2111 FilePath file_path = |
| 2106 temp_dir_.path().Append(FILE_PATH_LITERAL("ReadFileTest")); | 2112 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("ReadFileTest")); |
| 2107 | 2113 |
| 2108 ASSERT_EQ(static_cast<int>(kTestData.size()), | 2114 ASSERT_EQ(static_cast<int>(kTestData.size()), |
| 2109 WriteFile(file_path, kTestData.data(), kTestData.size())); | 2115 WriteFile(file_path, kTestData.data(), kTestData.size())); |
| 2110 | 2116 |
| 2111 // Make buffers with various size. | 2117 // Make buffers with various size. |
| 2112 std::vector<char> small_buffer(kTestData.size() / 2); | 2118 std::vector<char> small_buffer(kTestData.size() / 2); |
| 2113 std::vector<char> exact_buffer(kTestData.size()); | 2119 std::vector<char> exact_buffer(kTestData.size()); |
| 2114 std::vector<char> large_buffer(kTestData.size() * 2); | 2120 std::vector<char> large_buffer(kTestData.size() * 2); |
| 2115 | 2121 |
| 2116 // Read the file with smaller buffer. | 2122 // Read the file with smaller buffer. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2129 | 2135 |
| 2130 // Read the file with larger buffer. | 2136 // Read the file with larger buffer. |
| 2131 int bytes_read_large = ReadFile( | 2137 int bytes_read_large = ReadFile( |
| 2132 file_path, &large_buffer[0], static_cast<int>(large_buffer.size())); | 2138 file_path, &large_buffer[0], static_cast<int>(large_buffer.size())); |
| 2133 EXPECT_EQ(static_cast<int>(kTestData.size()), bytes_read_large); | 2139 EXPECT_EQ(static_cast<int>(kTestData.size()), bytes_read_large); |
| 2134 EXPECT_EQ(kTestData, std::string(large_buffer.begin(), | 2140 EXPECT_EQ(kTestData, std::string(large_buffer.begin(), |
| 2135 large_buffer.begin() + kTestData.size())); | 2141 large_buffer.begin() + kTestData.size())); |
| 2136 | 2142 |
| 2137 // Make sure the return value is -1 if the file doesn't exist. | 2143 // Make sure the return value is -1 if the file doesn't exist. |
| 2138 FilePath file_path_not_exist = | 2144 FilePath file_path_not_exist = |
| 2139 temp_dir_.path().Append(FILE_PATH_LITERAL("ReadFileNotExistTest")); | 2145 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("ReadFileNotExistTest")); |
| 2140 EXPECT_EQ(-1, | 2146 EXPECT_EQ(-1, |
| 2141 ReadFile(file_path_not_exist, | 2147 ReadFile(file_path_not_exist, |
| 2142 &exact_buffer[0], | 2148 &exact_buffer[0], |
| 2143 static_cast<int>(exact_buffer.size()))); | 2149 static_cast<int>(exact_buffer.size()))); |
| 2144 } | 2150 } |
| 2145 | 2151 |
| 2146 TEST_F(FileUtilTest, ReadFileToString) { | 2152 TEST_F(FileUtilTest, ReadFileToString) { |
| 2147 const char kTestData[] = "0123"; | 2153 const char kTestData[] = "0123"; |
| 2148 std::string data; | 2154 std::string data; |
| 2149 | 2155 |
| 2150 FilePath file_path = | 2156 FilePath file_path = |
| 2151 temp_dir_.path().Append(FILE_PATH_LITERAL("ReadFileToStringTest")); | 2157 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("ReadFileToStringTest")); |
| 2152 FilePath file_path_dangerous = | 2158 FilePath file_path_dangerous = |
| 2153 temp_dir_.path().Append(FILE_PATH_LITERAL("..")). | 2159 temp_dir_.GetPath() |
| 2154 Append(temp_dir_.path().BaseName()). | 2160 .Append(FILE_PATH_LITERAL("..")) |
| 2155 Append(FILE_PATH_LITERAL("ReadFileToStringTest")); | 2161 .Append(temp_dir_.GetPath().BaseName()) |
| 2162 .Append(FILE_PATH_LITERAL("ReadFileToStringTest")); |
| 2156 | 2163 |
| 2157 // Create test file. | 2164 // Create test file. |
| 2158 ASSERT_EQ(4, WriteFile(file_path, kTestData, 4)); | 2165 ASSERT_EQ(4, WriteFile(file_path, kTestData, 4)); |
| 2159 | 2166 |
| 2160 EXPECT_TRUE(ReadFileToString(file_path, &data)); | 2167 EXPECT_TRUE(ReadFileToString(file_path, &data)); |
| 2161 EXPECT_EQ(kTestData, data); | 2168 EXPECT_EQ(kTestData, data); |
| 2162 | 2169 |
| 2163 data = "temp"; | 2170 data = "temp"; |
| 2164 EXPECT_FALSE(ReadFileToStringWithMaxSize(file_path, &data, 0)); | 2171 EXPECT_FALSE(ReadFileToStringWithMaxSize(file_path, &data, 0)); |
| 2165 EXPECT_EQ(0u, data.length()); | 2172 EXPECT_EQ(0u, data.length()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2195 EXPECT_FALSE(ReadFileToString(file_path, &data)); | 2202 EXPECT_FALSE(ReadFileToString(file_path, &data)); |
| 2196 EXPECT_EQ(0u, data.length()); | 2203 EXPECT_EQ(0u, data.length()); |
| 2197 | 2204 |
| 2198 data = "temp"; | 2205 data = "temp"; |
| 2199 EXPECT_FALSE(ReadFileToStringWithMaxSize(file_path, &data, 6)); | 2206 EXPECT_FALSE(ReadFileToStringWithMaxSize(file_path, &data, 6)); |
| 2200 EXPECT_EQ(0u, data.length()); | 2207 EXPECT_EQ(0u, data.length()); |
| 2201 } | 2208 } |
| 2202 | 2209 |
| 2203 TEST_F(FileUtilTest, TouchFile) { | 2210 TEST_F(FileUtilTest, TouchFile) { |
| 2204 FilePath data_dir = | 2211 FilePath data_dir = |
| 2205 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 2212 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("FilePathTest")); |
| 2206 | 2213 |
| 2207 // Create a fresh, empty copy of this directory. | 2214 // Create a fresh, empty copy of this directory. |
| 2208 if (PathExists(data_dir)) { | 2215 if (PathExists(data_dir)) { |
| 2209 ASSERT_TRUE(DeleteFile(data_dir, true)); | 2216 ASSERT_TRUE(DeleteFile(data_dir, true)); |
| 2210 } | 2217 } |
| 2211 ASSERT_TRUE(CreateDirectory(data_dir)); | 2218 ASSERT_TRUE(CreateDirectory(data_dir)); |
| 2212 | 2219 |
| 2213 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 2220 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
| 2214 std::string data("hello"); | 2221 std::string data("hello"); |
| 2215 ASSERT_TRUE(WriteFile(foobar, data.c_str(), data.length())); | 2222 ASSERT_TRUE(WriteFile(foobar, data.c_str(), data.length())); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2229 ASSERT_TRUE(TouchFile(foobar, access_time, modification_time)); | 2236 ASSERT_TRUE(TouchFile(foobar, access_time, modification_time)); |
| 2230 File::Info file_info; | 2237 File::Info file_info; |
| 2231 ASSERT_TRUE(GetFileInfo(foobar, &file_info)); | 2238 ASSERT_TRUE(GetFileInfo(foobar, &file_info)); |
| 2232 EXPECT_EQ(access_time.ToInternalValue(), | 2239 EXPECT_EQ(access_time.ToInternalValue(), |
| 2233 file_info.last_accessed.ToInternalValue()); | 2240 file_info.last_accessed.ToInternalValue()); |
| 2234 EXPECT_EQ(modification_time.ToInternalValue(), | 2241 EXPECT_EQ(modification_time.ToInternalValue(), |
| 2235 file_info.last_modified.ToInternalValue()); | 2242 file_info.last_modified.ToInternalValue()); |
| 2236 } | 2243 } |
| 2237 | 2244 |
| 2238 TEST_F(FileUtilTest, IsDirectoryEmpty) { | 2245 TEST_F(FileUtilTest, IsDirectoryEmpty) { |
| 2239 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); | 2246 FilePath empty_dir = |
| 2247 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("EmptyDir")); |
| 2240 | 2248 |
| 2241 ASSERT_FALSE(PathExists(empty_dir)); | 2249 ASSERT_FALSE(PathExists(empty_dir)); |
| 2242 | 2250 |
| 2243 ASSERT_TRUE(CreateDirectory(empty_dir)); | 2251 ASSERT_TRUE(CreateDirectory(empty_dir)); |
| 2244 | 2252 |
| 2245 EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); | 2253 EXPECT_TRUE(IsDirectoryEmpty(empty_dir)); |
| 2246 | 2254 |
| 2247 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 2255 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
| 2248 std::string bar("baz"); | 2256 std::string bar("baz"); |
| 2249 ASSERT_TRUE(WriteFile(foo, bar.c_str(), bar.length())); | 2257 ASSERT_TRUE(WriteFile(foo, bar.c_str(), bar.length())); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2264 class VerifyPathControlledByUserTest : public FileUtilTest { | 2272 class VerifyPathControlledByUserTest : public FileUtilTest { |
| 2265 protected: | 2273 protected: |
| 2266 void SetUp() override { | 2274 void SetUp() override { |
| 2267 FileUtilTest::SetUp(); | 2275 FileUtilTest::SetUp(); |
| 2268 | 2276 |
| 2269 // Create a basic structure used by each test. | 2277 // Create a basic structure used by each test. |
| 2270 // base_dir_ | 2278 // base_dir_ |
| 2271 // |-> sub_dir_ | 2279 // |-> sub_dir_ |
| 2272 // |-> text_file_ | 2280 // |-> text_file_ |
| 2273 | 2281 |
| 2274 base_dir_ = temp_dir_.path().AppendASCII("base_dir"); | 2282 base_dir_ = temp_dir_.GetPath().AppendASCII("base_dir"); |
| 2275 ASSERT_TRUE(CreateDirectory(base_dir_)); | 2283 ASSERT_TRUE(CreateDirectory(base_dir_)); |
| 2276 | 2284 |
| 2277 sub_dir_ = base_dir_.AppendASCII("sub_dir"); | 2285 sub_dir_ = base_dir_.AppendASCII("sub_dir"); |
| 2278 ASSERT_TRUE(CreateDirectory(sub_dir_)); | 2286 ASSERT_TRUE(CreateDirectory(sub_dir_)); |
| 2279 | 2287 |
| 2280 text_file_ = sub_dir_.AppendASCII("file.txt"); | 2288 text_file_ = sub_dir_.AppendASCII("file.txt"); |
| 2281 CreateTextFile(text_file_, L"This text file has some text in it."); | 2289 CreateTextFile(text_file_, L"This text file has some text in it."); |
| 2282 | 2290 |
| 2283 // Get the user and group files are created with from |base_dir_|. | 2291 // Get the user and group files are created with from |base_dir_|. |
| 2284 struct stat stat_buf; | 2292 struct stat stat_buf; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2615 // Trying to close it should crash. This is important for security. | 2623 // Trying to close it should crash. This is important for security. |
| 2616 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2624 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
| 2617 #endif | 2625 #endif |
| 2618 } | 2626 } |
| 2619 | 2627 |
| 2620 #endif // defined(OS_POSIX) | 2628 #endif // defined(OS_POSIX) |
| 2621 | 2629 |
| 2622 } // namespace | 2630 } // namespace |
| 2623 | 2631 |
| 2624 } // namespace base | 2632 } // namespace base |
| OLD | NEW |