Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: base/file_util_unittest.cc

Issue 9235053: Add a PartialPreReadImage function to file_util (on Windows). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address Robert's feedback and refactor as inspired by Chris Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/file_util.h ('k') | base/file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. 662 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory.
663 NULL)); 663 NULL));
664 ASSERT_TRUE(dir.IsValid()); 664 ASSERT_TRUE(dir.IsValid());
665 base::PlatformFileInfo info; 665 base::PlatformFileInfo info;
666 EXPECT_TRUE(base::GetPlatformFileInfo(dir.Get(), &info)); 666 EXPECT_TRUE(base::GetPlatformFileInfo(dir.Get(), &info));
667 EXPECT_TRUE(info.is_directory); 667 EXPECT_TRUE(info.is_directory);
668 EXPECT_FALSE(info.is_symbolic_link); 668 EXPECT_FALSE(info.is_symbolic_link);
669 EXPECT_EQ(0, info.size); 669 EXPECT_EQ(0, info.size);
670 } 670 }
671 671
672 // TODO(rogerm): Flesh out the *PreReadImage* tests to validate an observed
673 // change in paging behaviour between raw loading and pre-reading.
674
675 // TODO(rogerm): Add checks to the *PreREadImage* tests to validate the
Sigurður Ásgeirsson 2012/01/27 14:18:31 nit: PreREadImage -> PreReadImage
Roger McFarlane (Google) 2012/01/27 14:53:23 Done.
676 // handling of invalid pe files and paths as input.
677
678 TEST_F(FileUtilTest, PreReadImage) {
679 using file_util::PreReadImage;
680
681 const size_t kStepSize = 2 * 1024 * 1024;
682 wchar_t module_path[MAX_PATH];
683 ASSERT_TRUE(::GetModuleFileName(NULL,
Sigurður Ásgeirsson 2012/01/27 14:18:31 nit: this is available through PathService, see ht
Roger McFarlane (Google) 2012/01/27 14:53:23 Done.
684 &module_path[0],
685 arraysize(module_path)));
686
687 int64 file_size_64 = 0;
688 ASSERT_TRUE(file_util::GetFileSize(FilePath(module_path), &file_size_64));
689 ASSERT_TRUE(file_size_64 < std::numeric_limits<std::size_t>::max());
690 size_t file_size = static_cast<size_t>(file_size_64);
691
692 ASSERT_TRUE(PreReadImage(module_path, 0, kStepSize));
693 ASSERT_TRUE(PreReadImage(module_path, file_size / 4, kStepSize));
694 ASSERT_TRUE(PreReadImage(module_path, file_size / 2, kStepSize));
695 ASSERT_TRUE(PreReadImage(module_path, file_size, kStepSize));
696 ASSERT_TRUE(PreReadImage(module_path, file_size * 2, kStepSize));
697 }
698
699 TEST_F(FileUtilTest, PartialPreReadImage) {
700 using file_util::PartialPreReadImage;
701
702 const size_t kStepSize = 2 * 1024 * 1024;
703 wchar_t module_path[MAX_PATH];
704 ASSERT_TRUE(::GetModuleFileName(NULL,
705 &module_path[0],
706 arraysize(module_path)));
707
708 ASSERT_TRUE(PartialPreReadImage(module_path, 0, kStepSize));
709 ASSERT_TRUE(PartialPreReadImage(module_path, 25, kStepSize));
710 ASSERT_TRUE(PartialPreReadImage(module_path, 50, kStepSize));
711 ASSERT_TRUE(PartialPreReadImage(module_path, 100, kStepSize));
712 ASSERT_TRUE(PartialPreReadImage(module_path, 150, kStepSize));
713 }
714
715 TEST_F(FileUtilTest, PartialPreReadImageOnDisk) {
716 using file_util::internal::PartialPreReadImageOnDisk;
717
718 const size_t kChunkSize = 2 * 1024 * 1024;
719 wchar_t module_path[MAX_PATH];
720 ASSERT_TRUE(::GetModuleFileName(NULL,
721 &module_path[0],
722 arraysize(module_path)));
723
724 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 0, kChunkSize));
725 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 25, kChunkSize));
726 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 50, kChunkSize));
727 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 100, kChunkSize));
728 ASSERT_TRUE(PartialPreReadImageOnDisk(module_path, 150, kChunkSize));
729 }
730
731 TEST_F(FileUtilTest, PartialPreReadImageInMemory) {
732 using file_util::internal::PartialPreReadImageInMemory;
733
734 wchar_t module_path[MAX_PATH];
735 ASSERT_TRUE(::GetModuleFileName(NULL,
736 &module_path[0],
737 arraysize(module_path)));
738
739 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 0));
740 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 25));
741 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 50));
742 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 100));
743 ASSERT_TRUE(PartialPreReadImageInMemory(module_path, 150));
744 }
745
672 #endif // defined(OS_WIN) 746 #endif // defined(OS_WIN)
673 747
674 #if defined(OS_POSIX) 748 #if defined(OS_POSIX)
675 749
676 TEST_F(FileUtilTest, CreateAndReadSymlinks) { 750 TEST_F(FileUtilTest, CreateAndReadSymlinks) {
677 FilePath link_from = temp_dir_.path().Append(FPL("from_file")); 751 FilePath link_from = temp_dir_.path().Append(FPL("from_file"));
678 FilePath link_to = temp_dir_.path().Append(FPL("to_file")); 752 FilePath link_to = temp_dir_.path().Append(FPL("to_file"));
679 CreateTextFile(link_to, bogus_content); 753 CreateTextFile(link_to, bogus_content);
680 754
681 ASSERT_TRUE(file_util::CreateSymbolicLink(link_to, link_from)) 755 ASSERT_TRUE(file_util::CreateSymbolicLink(link_to, link_from))
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after
2286 file_util::VerifyPathControlledByUser( 2360 file_util::VerifyPathControlledByUser(
2287 base_dir_, text_file_, uid_, ok_gids_)); 2361 base_dir_, text_file_, uid_, ok_gids_));
2288 EXPECT_TRUE( 2362 EXPECT_TRUE(
2289 file_util::VerifyPathControlledByUser( 2363 file_util::VerifyPathControlledByUser(
2290 sub_dir_, text_file_, uid_, ok_gids_)); 2364 sub_dir_, text_file_, uid_, ok_gids_));
2291 } 2365 }
2292 2366
2293 #endif // defined(OS_POSIX) 2367 #endif // defined(OS_POSIX)
2294 2368
2295 } // namespace 2369 } // namespace
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698