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 "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 15 matching lines...) Expand all Loading... | |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "testing/platform_test.h" | 27 #include "testing/platform_test.h" |
28 | 28 |
29 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
30 #include "base/win/scoped_handle.h" | 30 #include "base/win/scoped_handle.h" |
31 #endif | 31 #endif |
32 | 32 |
33 // This macro helps avoid wrapped lines in the test structs. | 33 // This macro helps avoid wrapped lines in the test structs. |
34 #define FPL(x) FILE_PATH_LITERAL(x) | 34 #define FPL(x) FILE_PATH_LITERAL(x) |
35 | 35 |
36 // Declare some internal functions that get exercised below. | |
37 #if defined(OS_WIN) | |
38 namespace file_util { | |
39 namespace internal { | |
40 | |
41 bool PartialPreReadPeFile(const wchar_t* file_path, | |
Sigurður Ásgeirsson
2012/01/26 18:59:20
IMHO it's preferable to declare these in the file_
Roger McFarlane (Google)
2012/01/27 05:24:08
Done.
| |
42 size_t percentage, | |
chrisha
2012/01/26 18:23:09
indent - 1
Roger McFarlane (Google)
2012/01/27 05:24:08
Done.
| |
43 size_t max_chunk_size); | |
44 bool PartialPreReadPeImage(const wchar_t* file_path, | |
45 size_t percentage, | |
46 size_t step_size); | |
47 | |
48 } // namespace file_util::internal | |
49 } // namepsace file_util | |
50 #endif // defined(OS_WIN) | |
51 | |
36 namespace { | 52 namespace { |
37 | 53 |
38 // To test that file_util::Normalize FilePath() deals with NTFS reparse points | 54 // To test that file_util::Normalize FilePath() deals with NTFS reparse points |
39 // correctly, we need functions to create and delete reparse points. | 55 // correctly, we need functions to create and delete reparse points. |
40 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
41 typedef struct _REPARSE_DATA_BUFFER { | 57 typedef struct _REPARSE_DATA_BUFFER { |
42 ULONG ReparseTag; | 58 ULONG ReparseTag; |
43 USHORT ReparseDataLength; | 59 USHORT ReparseDataLength; |
44 USHORT Reserved; | 60 USHORT Reserved; |
45 union { | 61 union { |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | 678 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
663 NULL)); | 679 NULL)); |
664 ASSERT_TRUE(dir.IsValid()); | 680 ASSERT_TRUE(dir.IsValid()); |
665 base::PlatformFileInfo info; | 681 base::PlatformFileInfo info; |
666 EXPECT_TRUE(base::GetPlatformFileInfo(dir.Get(), &info)); | 682 EXPECT_TRUE(base::GetPlatformFileInfo(dir.Get(), &info)); |
667 EXPECT_TRUE(info.is_directory); | 683 EXPECT_TRUE(info.is_directory); |
668 EXPECT_FALSE(info.is_symbolic_link); | 684 EXPECT_FALSE(info.is_symbolic_link); |
669 EXPECT_EQ(0, info.size); | 685 EXPECT_EQ(0, info.size); |
670 } | 686 } |
671 | 687 |
688 TEST_F(FileUtilTest, PreReadImage) { | |
689 using file_util::PreReadImage; | |
690 | |
691 const size_t kStepSize = 2 * 1024 * 1024; | |
692 wchar_t module_path[MAX_PATH]; | |
693 ASSERT_TRUE(::GetModuleFileName(NULL, | |
694 &module_path[0], | |
695 arraysize(module_path))); | |
696 | |
697 int64 file_size_64 = 0; | |
698 ASSERT_TRUE(file_util::GetFileSize(FilePath(module_path), &file_size_64)); | |
699 ASSERT_TRUE(file_size_64 < std::numeric_limits<std::size_t>::max()); | |
700 size_t file_size = static_cast<size_t>(file_size_64); | |
701 | |
702 ASSERT_TRUE(PreReadImage(module_path, 0, kStepSize)); | |
703 ASSERT_TRUE(PreReadImage(module_path, file_size / 4, kStepSize)); | |
704 ASSERT_TRUE(PreReadImage(module_path, file_size / 2, kStepSize)); | |
705 ASSERT_TRUE(PreReadImage(module_path, file_size, kStepSize)); | |
706 ASSERT_TRUE(PreReadImage(module_path, file_size * 2, kStepSize)); | |
chrisha
2012/01/26 18:23:09
Is there any reason why these specific parameter v
Roger McFarlane (Google)
2012/01/27 05:24:08
All I'm really testing is that the function return
| |
707 } | |
708 | |
709 TEST_F(FileUtilTest, PartialPreReadImage) { | |
710 using file_util::PartialPreReadImage; | |
711 | |
712 const size_t kStepSize = 2 * 1024 * 1024; | |
713 wchar_t module_path[MAX_PATH]; | |
714 ASSERT_TRUE(::GetModuleFileName(NULL, | |
715 &module_path[0], | |
716 arraysize(module_path))); | |
717 | |
718 ASSERT_TRUE(PartialPreReadImage(module_path, 0, kStepSize)); | |
Sigurður Ásgeirsson
2012/01/26 18:59:20
For these tests, it would be more possible, and mo
Roger McFarlane (Google)
2012/01/27 05:24:08
I'll look at doing that. Added a TODO for now.
| |
719 ASSERT_TRUE(PartialPreReadImage(module_path, 25, kStepSize)); | |
720 ASSERT_TRUE(PartialPreReadImage(module_path, 50, kStepSize)); | |
721 ASSERT_TRUE(PartialPreReadImage(module_path, 100, kStepSize)); | |
722 ASSERT_TRUE(PartialPreReadImage(module_path, 150, kStepSize)); | |
chrisha
2012/01/26 18:23:09
Ditto for these tests and others.
Roger McFarlane (Google)
2012/01/27 05:24:08
Ditto for my previous reply.
| |
723 } | |
724 | |
725 TEST_F(FileUtilTest, PartialPreReadPeFile) { | |
726 using file_util::internal::PartialPreReadPeFile; | |
727 | |
728 const size_t kStepSize = 2 * 1024 * 1024; | |
729 wchar_t module_path[MAX_PATH]; | |
730 ASSERT_TRUE(::GetModuleFileName(NULL, | |
731 &module_path[0], | |
732 arraysize(module_path))); | |
733 | |
734 ASSERT_TRUE(PartialPreReadPeFile(module_path, 0, kStepSize)); | |
735 ASSERT_TRUE(PartialPreReadPeFile(module_path, 25, kStepSize)); | |
736 ASSERT_TRUE(PartialPreReadPeFile(module_path, 50, kStepSize)); | |
737 ASSERT_TRUE(PartialPreReadPeFile(module_path, 100, kStepSize)); | |
738 ASSERT_TRUE(PartialPreReadPeFile(module_path, 150, kStepSize)); | |
739 } | |
740 | |
741 TEST_F(FileUtilTest, PartialPreReadPeImage) { | |
742 using file_util::internal::PartialPreReadPeImage; | |
743 | |
744 const size_t kStepSize = 4096; | |
745 wchar_t module_path[MAX_PATH]; | |
746 ASSERT_TRUE(::GetModuleFileName(NULL, | |
747 &module_path[0], | |
748 arraysize(module_path))); | |
749 | |
750 ASSERT_TRUE(PartialPreReadPeImage(module_path, 0, kStepSize)); | |
751 ASSERT_TRUE(PartialPreReadPeImage(module_path, 25, kStepSize)); | |
752 ASSERT_TRUE(PartialPreReadPeImage(module_path, 50, kStepSize)); | |
753 ASSERT_TRUE(PartialPreReadPeImage(module_path, 100, kStepSize)); | |
754 ASSERT_TRUE(PartialPreReadPeImage(module_path, 150, kStepSize)); | |
755 } | |
756 | |
672 #endif // defined(OS_WIN) | 757 #endif // defined(OS_WIN) |
673 | 758 |
674 #if defined(OS_POSIX) | 759 #if defined(OS_POSIX) |
675 | 760 |
676 TEST_F(FileUtilTest, CreateAndReadSymlinks) { | 761 TEST_F(FileUtilTest, CreateAndReadSymlinks) { |
677 FilePath link_from = temp_dir_.path().Append(FPL("from_file")); | 762 FilePath link_from = temp_dir_.path().Append(FPL("from_file")); |
678 FilePath link_to = temp_dir_.path().Append(FPL("to_file")); | 763 FilePath link_to = temp_dir_.path().Append(FPL("to_file")); |
679 CreateTextFile(link_to, bogus_content); | 764 CreateTextFile(link_to, bogus_content); |
680 | 765 |
681 ASSERT_TRUE(file_util::CreateSymbolicLink(link_to, link_from)) | 766 ASSERT_TRUE(file_util::CreateSymbolicLink(link_to, link_from)) |
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2286 file_util::VerifyPathControlledByUser( | 2371 file_util::VerifyPathControlledByUser( |
2287 base_dir_, text_file_, uid_, ok_gids_)); | 2372 base_dir_, text_file_, uid_, ok_gids_)); |
2288 EXPECT_TRUE( | 2373 EXPECT_TRUE( |
2289 file_util::VerifyPathControlledByUser( | 2374 file_util::VerifyPathControlledByUser( |
2290 sub_dir_, text_file_, uid_, ok_gids_)); | 2375 sub_dir_, text_file_, uid_, ok_gids_)); |
2291 } | 2376 } |
2292 | 2377 |
2293 #endif // defined(OS_POSIX) | 2378 #endif // defined(OS_POSIX) |
2294 | 2379 |
2295 } // namespace | 2380 } // namespace |
OLD | NEW |