| OLD | NEW |
| 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 <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 class LzmaFileAllocatorTest : public testing::Test { | 17 class LzmaFileAllocatorTest : public testing::Test { |
| 17 protected: | 18 protected: |
| 18 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } | 19 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } |
| 19 // Returns the type of the memory page identified by |address|; one of | 20 // Returns the type of the memory page identified by |address|; one of |
| 20 // MEM_IMAGE, MEM_MAPPED or MEM_PRIVATE. | 21 // MEM_IMAGE, MEM_MAPPED or MEM_PRIVATE. |
| 21 static DWORD GetMemoryType(void* address); | 22 static DWORD GetMemoryType(void* address); |
| 22 | 23 |
| 23 base::ScopedTempDir temp_dir_; | 24 base::ScopedTempDir temp_dir_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 56 |
| 56 TEST_F(LzmaFileAllocatorTest, SizeIsZeroTest) { | 57 TEST_F(LzmaFileAllocatorTest, SizeIsZeroTest) { |
| 57 LzmaFileAllocator allocator(temp_dir_.path()); | 58 LzmaFileAllocator allocator(temp_dir_.path()); |
| 58 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, 0)); | 59 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, 0)); |
| 59 EXPECT_EQ(s, nullptr); | 60 EXPECT_EQ(s, nullptr); |
| 60 | 61 |
| 61 IAlloc_Free(&allocator, s); | 62 IAlloc_Free(&allocator, s); |
| 62 } | 63 } |
| 63 | 64 |
| 64 TEST_F(LzmaFileAllocatorTest, DeleteAfterCloseTest) { | 65 TEST_F(LzmaFileAllocatorTest, DeleteAfterCloseTest) { |
| 65 scoped_ptr<LzmaFileAllocator> allocator = | 66 std::unique_ptr<LzmaFileAllocator> allocator = |
| 66 make_scoped_ptr(new LzmaFileAllocator(temp_dir_.path())); | 67 base::WrapUnique(new LzmaFileAllocator(temp_dir_.path())); |
| 67 base::FilePath file_path = allocator->mapped_file_path_; | 68 base::FilePath file_path = allocator->mapped_file_path_; |
| 68 ASSERT_TRUE(base::PathExists(file_path)); | 69 ASSERT_TRUE(base::PathExists(file_path)); |
| 69 allocator.reset(); | 70 allocator.reset(); |
| 70 ASSERT_FALSE(base::PathExists(file_path)); | 71 ASSERT_FALSE(base::PathExists(file_path)); |
| 71 } | 72 } |
| 72 | 73 |
| 73 TEST_F(LzmaFileAllocatorTest, ErrorAndFallbackTest) { | 74 TEST_F(LzmaFileAllocatorTest, ErrorAndFallbackTest) { |
| 74 LzmaFileAllocator allocator(temp_dir_.path()); | 75 LzmaFileAllocator allocator(temp_dir_.path()); |
| 75 allocator.mapped_file_.Close(); | 76 allocator.mapped_file_.Close(); |
| 76 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, 10)); | 77 char* s = reinterpret_cast<char*>(IAlloc_Alloc(&allocator, 10)); |
| 77 EXPECT_NE(nullptr, s); | 78 EXPECT_NE(nullptr, s); |
| 78 ASSERT_FALSE(allocator.file_mapping_handle_.IsValid()); | 79 ASSERT_FALSE(allocator.file_mapping_handle_.IsValid()); |
| 79 EXPECT_EQ(static_cast<DWORD>(MEM_PRIVATE), GetMemoryType(s)); | 80 EXPECT_EQ(static_cast<DWORD>(MEM_PRIVATE), GetMemoryType(s)); |
| 80 | 81 |
| 81 IAlloc_Free(&allocator, s); | 82 IAlloc_Free(&allocator, s); |
| 82 } | 83 } |
| OLD | NEW |