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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah."); | 350 CreateTextFile(new_file_name, L"Waaaaaaaaaaaaaah."); |
351 | 351 |
352 // We should see only the new file. | 352 // We should see only the new file. |
353 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_, now)); | 353 EXPECT_EQ(1, file_util::CountFilesCreatedAfter(test_dir_, now)); |
354 | 354 |
355 // Delete new file, we should see no files after cutoff now | 355 // Delete new file, we should see no files after cutoff now |
356 EXPECT_TRUE(file_util::Delete(new_file_name, false)); | 356 EXPECT_TRUE(file_util::Delete(new_file_name, false)); |
357 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); | 357 EXPECT_EQ(0, file_util::CountFilesCreatedAfter(test_dir_, now)); |
358 } | 358 } |
359 | 359 |
| 360 TEST_F(FileUtilTest, FileAndDirectorySize) { |
| 361 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize |
| 362 // should return 53 bytes. |
| 363 FilePath file_01 = test_dir_.Append(FPL("The file 01.txt")); |
| 364 CreateTextFile(file_01, L"12345678901234567890"); |
| 365 int64 size_f1 = 0; |
| 366 ASSERT_TRUE(file_util::GetFileSize(file_01, &size_f1)); |
| 367 EXPECT_EQ(20ll, size_f1); |
| 368 |
| 369 FilePath subdir_path = test_dir_.Append(FPL("Level2")); |
| 370 file_util::CreateDirectory(subdir_path); |
| 371 |
| 372 FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); |
| 373 CreateTextFile(file_02, L"123456789012345678901234567890"); |
| 374 int64 size_f2 = 0; |
| 375 ASSERT_TRUE(file_util::GetFileSize(file_02, &size_f2)); |
| 376 EXPECT_EQ(30ll, size_f2); |
| 377 |
| 378 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); |
| 379 file_util::CreateDirectory(subsubdir_path); |
| 380 |
| 381 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); |
| 382 CreateTextFile(file_03, L"123"); |
| 383 |
| 384 int64 computed_size = file_util::ComputeDirectorySize(test_dir_); |
| 385 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); |
| 386 } |
| 387 |
360 // Tests that the Delete function works as expected, especially | 388 // Tests that the Delete function works as expected, especially |
361 // the recursion flag. Also coincidentally tests PathExists. | 389 // the recursion flag. Also coincidentally tests PathExists. |
362 TEST_F(FileUtilTest, Delete) { | 390 TEST_F(FileUtilTest, Delete) { |
363 // Create a file | 391 // Create a file |
364 FilePath file_name = test_dir_.Append(FILE_PATH_LITERAL("Test File.txt")); | 392 FilePath file_name = test_dir_.Append(FILE_PATH_LITERAL("Test File.txt")); |
365 CreateTextFile(file_name, L"I'm cannon fodder."); | 393 CreateTextFile(file_name, L"I'm cannon fodder."); |
366 | 394 |
367 ASSERT_TRUE(file_util::PathExists(file_name)); | 395 ASSERT_TRUE(file_util::PathExists(file_name)); |
368 | 396 |
369 FilePath subdir_path = test_dir_.Append(FILE_PATH_LITERAL("Subdirectory")); | 397 FilePath subdir_path = test_dir_.Append(FILE_PATH_LITERAL("Subdirectory")); |
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 // modification times with 2s resolution. | 1442 // modification times with 2s resolution. |
1415 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", | 1443 ASSERT_TRUE(base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", |
1416 &modification_time)); | 1444 &modification_time)); |
1417 ASSERT_TRUE(file_util::SetLastModifiedTime(foobar, modification_time)); | 1445 ASSERT_TRUE(file_util::SetLastModifiedTime(foobar, modification_time)); |
1418 file_util::FileInfo file_info; | 1446 file_util::FileInfo file_info; |
1419 ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info)); | 1447 ASSERT_TRUE(file_util::GetFileInfo(foobar, &file_info)); |
1420 ASSERT_TRUE(file_info.last_modified == modification_time); | 1448 ASSERT_TRUE(file_info.last_modified == modification_time); |
1421 } | 1449 } |
1422 | 1450 |
1423 } // namespace | 1451 } // namespace |
OLD | NEW |