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 "base/files/file.h" | 5 #include "base/files/file.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 base::File::FLAG_WRITE | | 479 base::File::FLAG_WRITE | |
480 base::File::FLAG_DELETE_ON_CLOSE)); | 480 base::File::FLAG_DELETE_ON_CLOSE)); |
481 ASSERT_TRUE(file.IsValid()); | 481 ASSERT_TRUE(file.IsValid()); |
482 File file2(file.Duplicate()); | 482 File file2(file.Duplicate()); |
483 ASSERT_TRUE(file2.IsValid()); | 483 ASSERT_TRUE(file2.IsValid()); |
484 file.Close(); | 484 file.Close(); |
485 file2.Close(); | 485 file2.Close(); |
486 ASSERT_FALSE(base::PathExists(file_path)); | 486 ASSERT_FALSE(base::PathExists(file_path)); |
487 } | 487 } |
488 | 488 |
489 #if defined(OS_WIN) | |
490 TEST(FileTest, GetInfoForDirectory) { | |
491 base::ScopedTempDir temp_dir; | |
492 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
493 FilePath empty_dir = temp_dir.path().Append(FILE_PATH_LITERAL("gpfi_test")); | |
494 ASSERT_TRUE(CreateDirectory(empty_dir)); | |
495 | |
496 base::File dir( | |
497 ::CreateFile(empty_dir.value().c_str(), | |
498 FILE_ALL_ACCESS, | |
499 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | |
500 NULL, | |
501 OPEN_EXISTING, | |
502 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | |
503 NULL)); | |
504 ASSERT_TRUE(dir.IsValid()); | |
505 | |
506 base::File::Info info; | |
507 EXPECT_TRUE(dir.GetInfo(&info)); | |
508 EXPECT_TRUE(info.is_directory); | |
509 EXPECT_FALSE(info.is_symbolic_link); | |
510 EXPECT_EQ(0, info.size); | |
511 } | |
512 #endif // defined(OS_WIN) | |
513 | |
514 #if defined(OS_POSIX) && defined(GTEST_HAS_DEATH_TEST) | 489 #if defined(OS_POSIX) && defined(GTEST_HAS_DEATH_TEST) |
515 TEST(FileTest, MemoryCorruption) { | 490 TEST(FileTest, MemoryCorruption) { |
516 { | 491 { |
517 // Test that changing the checksum value is detected. | 492 // Test that changing the checksum value is detected. |
518 base::File file; | 493 base::File file; |
519 EXPECT_NE(file.file_.file_memory_checksum_, | 494 EXPECT_NE(file.file_.file_memory_checksum_, |
520 implicit_cast<unsigned int>(file.GetPlatformFile())); | 495 implicit_cast<unsigned int>(file.GetPlatformFile())); |
521 file.file_.file_memory_checksum_ = file.GetPlatformFile(); | 496 file.file_.file_memory_checksum_ = file.GetPlatformFile(); |
522 EXPECT_DEATH(file.IsValid(), ""); | 497 EXPECT_DEATH(file.IsValid(), ""); |
523 | 498 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 EXPECT_DEATH(file.Seek(File::FROM_BEGIN, 0), ""); | 546 EXPECT_DEATH(file.Seek(File::FROM_BEGIN, 0), ""); |
572 EXPECT_DEATH(file.Read(0, NULL, 0), ""); | 547 EXPECT_DEATH(file.Read(0, NULL, 0), ""); |
573 EXPECT_DEATH(file.ReadAtCurrentPos(NULL, 0), ""); | 548 EXPECT_DEATH(file.ReadAtCurrentPos(NULL, 0), ""); |
574 EXPECT_DEATH(file.Write(0, NULL, 0), ""); | 549 EXPECT_DEATH(file.Write(0, NULL, 0), ""); |
575 | 550 |
576 ignore_result(file.file_.file_.release()); | 551 ignore_result(file.file_.file_.release()); |
577 file.file_.UpdateChecksum(); | 552 file.file_.UpdateChecksum(); |
578 } | 553 } |
579 } | 554 } |
580 #endif // defined(OS_POSIX) | 555 #endif // defined(OS_POSIX) |
OLD | NEW |