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

Side by Side Diff: chrome/installer/util/lzma_file_allocator_unittest.cc

Issue 2321573002: //chrome misc: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Fix Win compilation Created 4 years, 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/installer/util/lzma_file_allocator.h" 5 #include "chrome/installer/util/lzma_file_allocator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 23 matching lines...) Expand all
34 TEST_F(LzmaFileAllocatorTest, ReadAndWriteWithMultipleSizeTest) { 34 TEST_F(LzmaFileAllocatorTest, ReadAndWriteWithMultipleSizeTest) {
35 const char kSampleExpectedCharacter = 'a'; 35 const char kSampleExpectedCharacter = 'a';
36 SYSTEM_INFO sysinfo; 36 SYSTEM_INFO sysinfo;
37 ::GetSystemInfo(&sysinfo); 37 ::GetSystemInfo(&sysinfo);
38 EXPECT_GT(sysinfo.dwPageSize, 0U); 38 EXPECT_GT(sysinfo.dwPageSize, 0U);
39 39
40 size_t size_list[] = {1, 10, sysinfo.dwPageSize - 1, sysinfo.dwPageSize, 40 size_t size_list[] = {1, 10, sysinfo.dwPageSize - 1, sysinfo.dwPageSize,
41 sysinfo.dwPageSize + 1}; 41 sysinfo.dwPageSize + 1};
42 42
43 for (size_t size : size_list) { 43 for (size_t size : size_list) {
44 LzmaFileAllocator allocator(temp_dir_.path()); 44 LzmaFileAllocator allocator(temp_dir_.GetPath());
45 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, size)); 45 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, size));
46 std::fill_n(s, size, kSampleExpectedCharacter); 46 std::fill_n(s, size, kSampleExpectedCharacter);
47 char* ret = std::find_if(s, s + size, [&kSampleExpectedCharacter](char c) { 47 char* ret = std::find_if(s, s + size, [&kSampleExpectedCharacter](char c) {
48 return c != kSampleExpectedCharacter; 48 return c != kSampleExpectedCharacter;
49 }); 49 });
50 EXPECT_EQ(s + size, ret); 50 EXPECT_EQ(s + size, ret);
51 EXPECT_EQ(static_cast<DWORD>(MEM_MAPPED), GetMemoryType(s)); 51 EXPECT_EQ(static_cast<DWORD>(MEM_MAPPED), GetMemoryType(s));
52 52
53 IAlloc_Free(&allocator, s); 53 IAlloc_Free(&allocator, s);
54 } 54 }
55 } 55 }
56 56
57 TEST_F(LzmaFileAllocatorTest, SizeIsZeroTest) { 57 TEST_F(LzmaFileAllocatorTest, SizeIsZeroTest) {
58 LzmaFileAllocator allocator(temp_dir_.path()); 58 LzmaFileAllocator allocator(temp_dir_.GetPath());
59 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, 0)); 59 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, 0));
60 EXPECT_EQ(s, nullptr); 60 EXPECT_EQ(s, nullptr);
61 61
62 IAlloc_Free(&allocator, s); 62 IAlloc_Free(&allocator, s);
63 } 63 }
64 64
65 TEST_F(LzmaFileAllocatorTest, DeleteAfterCloseTest) { 65 TEST_F(LzmaFileAllocatorTest, DeleteAfterCloseTest) {
66 std::unique_ptr<LzmaFileAllocator> allocator = 66 std::unique_ptr<LzmaFileAllocator> allocator =
67 base::MakeUnique<LzmaFileAllocator>(temp_dir_.path()); 67 base::MakeUnique<LzmaFileAllocator>(temp_dir_.GetPath());
68 base::FilePath file_path = allocator->mapped_file_path_; 68 base::FilePath file_path = allocator->mapped_file_path_;
69 ASSERT_TRUE(base::PathExists(file_path)); 69 ASSERT_TRUE(base::PathExists(file_path));
70 allocator.reset(); 70 allocator.reset();
71 ASSERT_FALSE(base::PathExists(file_path)); 71 ASSERT_FALSE(base::PathExists(file_path));
72 } 72 }
73 73
74 TEST_F(LzmaFileAllocatorTest, ErrorAndFallbackTest) { 74 TEST_F(LzmaFileAllocatorTest, ErrorAndFallbackTest) {
75 LzmaFileAllocator allocator(temp_dir_.path()); 75 LzmaFileAllocator allocator(temp_dir_.GetPath());
76 allocator.mapped_file_.Close(); 76 allocator.mapped_file_.Close();
77 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, 10)); 77 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, 10));
78 EXPECT_NE(nullptr, s); 78 EXPECT_NE(nullptr, s);
79 ASSERT_FALSE(allocator.file_mapping_handle_.IsValid()); 79 ASSERT_FALSE(allocator.file_mapping_handle_.IsValid());
80 EXPECT_EQ(static_cast<DWORD>(MEM_PRIVATE), GetMemoryType(s)); 80 EXPECT_EQ(static_cast<DWORD>(MEM_PRIVATE), GetMemoryType(s));
81 81
82 IAlloc_Free(&allocator, s); 82 IAlloc_Free(&allocator, s);
83 } 83 }
OLDNEW
« no previous file with comments | « chrome/installer/util/logging_installer_unittest.cc ('k') | chrome/installer/util/lzma_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698