OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); | 380 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); |
381 file_util::CreateDirectory(subsubdir_path); | 381 file_util::CreateDirectory(subsubdir_path); |
382 | 382 |
383 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); | 383 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); |
384 CreateTextFile(file_03, L"123"); | 384 CreateTextFile(file_03, L"123"); |
385 | 385 |
386 int64 computed_size = file_util::ComputeDirectorySize(test_dir_); | 386 int64 computed_size = file_util::ComputeDirectorySize(test_dir_); |
387 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); | 387 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); |
388 } | 388 } |
389 | 389 |
| 390 #if defined(OS_POSIX) |
| 391 TEST_F(FileUtilTest, RealPath) { |
| 392 // Get the real test directory, in case some future change to the |
| 393 // test setup makes the path to test_dir_ include a symlink. |
| 394 FilePath real_test_dir; |
| 395 ASSERT_TRUE(file_util::RealPath(test_dir_, &real_test_dir)); |
| 396 |
| 397 FilePath real_path; |
| 398 ASSERT_TRUE(file_util::RealPath(real_test_dir, &real_path)); |
| 399 ASSERT_TRUE(real_test_dir == real_path); |
| 400 |
| 401 // Link one file to another. |
| 402 FilePath link_from = real_test_dir.Append(FPL("from_file")); |
| 403 FilePath link_to = real_test_dir.Append(FPL("to_file")); |
| 404 CreateTextFile(link_to, bogus_content); |
| 405 |
| 406 ASSERT_EQ(0, symlink(link_to.value().c_str(), link_from.value().c_str())) |
| 407 << "Failed to create file symlink."; |
| 408 |
| 409 // Check that RealPath sees the link. |
| 410 ASSERT_TRUE(file_util::RealPath(link_from, &real_path)); |
| 411 ASSERT_TRUE(link_to != link_from); |
| 412 ASSERT_TRUE(link_to == real_path); |
| 413 |
| 414 |
| 415 // Link to a directory. |
| 416 link_from = real_test_dir.Append(FPL("from_dir")); |
| 417 link_to = real_test_dir.Append(FPL("to_dir")); |
| 418 file_util::CreateDirectory(link_to); |
| 419 |
| 420 ASSERT_EQ(0, symlink(link_to.value().c_str(), link_from.value().c_str())) |
| 421 << "Failed to create directory symlink."; |
| 422 |
| 423 ASSERT_TRUE(file_util::RealPath(link_from, &real_path)); |
| 424 ASSERT_TRUE(link_to != link_from); |
| 425 ASSERT_TRUE(link_to == real_path); |
| 426 |
| 427 |
| 428 // Test that a loop in the links causes RealPath() to return false. |
| 429 link_from = real_test_dir.Append(FPL("link_a")); |
| 430 link_to = real_test_dir.Append(FPL("link_b")); |
| 431 ASSERT_EQ(0, symlink(link_to.value().c_str(), link_from.value().c_str())) |
| 432 << "Failed to create loop symlink a."; |
| 433 ASSERT_EQ(0, symlink(link_from.value().c_str(), link_to.value().c_str())) |
| 434 << "Failed to create loop symlink b."; |
| 435 |
| 436 // Infinite loop! |
| 437 ASSERT_FALSE(file_util::RealPath(link_from, &real_path)); |
| 438 } |
| 439 #endif // defined(OS_POSIX) |
| 440 |
390 TEST_F(FileUtilTest, DeleteNonExistent) { | 441 TEST_F(FileUtilTest, DeleteNonExistent) { |
391 FilePath non_existent = test_dir_.AppendASCII("bogus_file_dne.foobar"); | 442 FilePath non_existent = test_dir_.AppendASCII("bogus_file_dne.foobar"); |
392 ASSERT_FALSE(file_util::PathExists(non_existent)); | 443 ASSERT_FALSE(file_util::PathExists(non_existent)); |
393 | 444 |
394 EXPECT_TRUE(file_util::Delete(non_existent, false)); | 445 EXPECT_TRUE(file_util::Delete(non_existent, false)); |
395 ASSERT_FALSE(file_util::PathExists(non_existent)); | 446 ASSERT_FALSE(file_util::PathExists(non_existent)); |
396 EXPECT_TRUE(file_util::Delete(non_existent, true)); | 447 EXPECT_TRUE(file_util::Delete(non_existent, true)); |
397 ASSERT_FALSE(file_util::PathExists(non_existent)); | 448 ASSERT_FALSE(file_util::PathExists(non_existent)); |
398 } | 449 } |
399 | 450 |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1565 // modification times with 2s resolution. | 1616 // modification times with 2s resolution. |
1566 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", | 1617 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", |
1567 &modification_time)); | 1618 &modification_time)); |
1568 ASSERT_TRUE(file_util::SetLastModifiedTime(foobar, modification_time)); | 1619 ASSERT_TRUE(file_util::SetLastModifiedTime(foobar, modification_time)); |
1569 file_util::FileInfo file_info; | 1620 file_util::FileInfo file_info; |
1570 ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info)); | 1621 ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info)); |
1571 ASSERT_TRUE(file_info.last_modified == modification_time); | 1622 ASSERT_TRUE(file_info.last_modified == modification_time); |
1572 } | 1623 } |
1573 | 1624 |
1574 } // namespace | 1625 } // namespace |
OLD | NEW |