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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/files/file.h" | 6 #include "base/files/file.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 EXPECT_EQ(first_chunk_size, file.WriteAtCurrentPos(kData, first_chunk_size)); | 418 EXPECT_EQ(first_chunk_size, file.WriteAtCurrentPos(kData, first_chunk_size)); |
419 EXPECT_EQ(kDataSize - first_chunk_size, | 419 EXPECT_EQ(kDataSize - first_chunk_size, |
420 file.WriteAtCurrentPos(kData + first_chunk_size, | 420 file.WriteAtCurrentPos(kData + first_chunk_size, |
421 kDataSize - first_chunk_size)); | 421 kDataSize - first_chunk_size)); |
422 | 422 |
423 char buffer[kDataSize]; | 423 char buffer[kDataSize]; |
424 EXPECT_EQ(kDataSize, file.Read(0, buffer, kDataSize)); | 424 EXPECT_EQ(kDataSize, file.Read(0, buffer, kDataSize)); |
425 EXPECT_EQ(std::string(buffer, buffer + kDataSize), std::string(kData)); | 425 EXPECT_EQ(std::string(buffer, buffer + kDataSize), std::string(kData)); |
426 } | 426 } |
427 | 427 |
| 428 TEST(FileTest, Seek) { |
| 429 base::ScopedTempDir temp_dir; |
| 430 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 431 FilePath file_path = temp_dir.path().AppendASCII("seek_file"); |
| 432 File file(file_path, |
| 433 base::File::FLAG_CREATE | base::File::FLAG_READ | |
| 434 base::File::FLAG_WRITE); |
| 435 ASSERT_TRUE(file.IsValid()); |
| 436 |
| 437 const int64 kOffset = 10; |
| 438 EXPECT_EQ(kOffset, file.Seek(base::File::FROM_BEGIN, kOffset)); |
| 439 EXPECT_EQ(2 * kOffset, file.Seek(base::File::FROM_CURRENT, kOffset)); |
| 440 EXPECT_EQ(kOffset, file.Seek(base::File::FROM_CURRENT, -kOffset)); |
| 441 EXPECT_TRUE(file.SetLength(kOffset * 2)); |
| 442 EXPECT_EQ(kOffset, file.Seek(base::File::FROM_END, -kOffset)); |
| 443 } |
| 444 |
428 #if defined(OS_WIN) | 445 #if defined(OS_WIN) |
429 TEST(FileTest, GetInfoForDirectory) { | 446 TEST(FileTest, GetInfoForDirectory) { |
430 base::ScopedTempDir temp_dir; | 447 base::ScopedTempDir temp_dir; |
431 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 448 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
432 FilePath empty_dir = temp_dir.path().Append(FILE_PATH_LITERAL("gpfi_test")); | 449 FilePath empty_dir = temp_dir.path().Append(FILE_PATH_LITERAL("gpfi_test")); |
433 ASSERT_TRUE(CreateDirectory(empty_dir)); | 450 ASSERT_TRUE(CreateDirectory(empty_dir)); |
434 | 451 |
435 base::File dir( | 452 base::File dir( |
436 ::CreateFile(empty_dir.value().c_str(), | 453 ::CreateFile(empty_dir.value().c_str(), |
437 FILE_ALL_ACCESS, | 454 FILE_ALL_ACCESS, |
438 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 455 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
439 NULL, | 456 NULL, |
440 OPEN_EXISTING, | 457 OPEN_EXISTING, |
441 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | 458 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
442 NULL)); | 459 NULL)); |
443 ASSERT_TRUE(dir.IsValid()); | 460 ASSERT_TRUE(dir.IsValid()); |
444 | 461 |
445 base::File::Info info; | 462 base::File::Info info; |
446 EXPECT_TRUE(dir.GetInfo(&info)); | 463 EXPECT_TRUE(dir.GetInfo(&info)); |
447 EXPECT_TRUE(info.is_directory); | 464 EXPECT_TRUE(info.is_directory); |
448 EXPECT_FALSE(info.is_symbolic_link); | 465 EXPECT_FALSE(info.is_symbolic_link); |
449 EXPECT_EQ(0, info.size); | 466 EXPECT_EQ(0, info.size); |
450 } | 467 } |
451 #endif // defined(OS_WIN) | 468 #endif // defined(OS_WIN) |
OLD | NEW |