OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/files/memory_mapped_file.h" | 5 #include "base/files/memory_mapped_file.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 // Check that the watermark sequence is consistent with the |offset| provided. | 24 // Check that the watermark sequence is consistent with the |offset| provided. |
25 bool CheckBufferContents(const uint8* data, size_t size, size_t offset) { | 25 bool CheckBufferContents(const uint8* data, size_t size, size_t offset) { |
26 scoped_ptr<uint8[]> test_data(CreateTestBuffer(size, offset)); | 26 scoped_ptr<uint8[]> test_data(CreateTestBuffer(size, offset)); |
27 return memcmp(test_data.get(), data, size) == 0; | 27 return memcmp(test_data.get(), data, size) == 0; |
28 } | 28 } |
29 | 29 |
30 class MemoryMappedFileTest : public PlatformTest { | 30 class MemoryMappedFileTest : public PlatformTest { |
31 protected: | 31 protected: |
32 virtual void SetUp() override { | 32 void SetUp() override { |
33 PlatformTest::SetUp(); | 33 PlatformTest::SetUp(); |
34 CreateTemporaryFile(&temp_file_path_); | 34 CreateTemporaryFile(&temp_file_path_); |
35 } | 35 } |
36 | 36 |
37 virtual void TearDown() { EXPECT_TRUE(DeleteFile(temp_file_path_, false)); } | 37 void TearDown() override { EXPECT_TRUE(DeleteFile(temp_file_path_, false)); } |
38 | 38 |
39 void CreateTemporaryTestFile(size_t size) { | 39 void CreateTemporaryTestFile(size_t size) { |
40 File file(temp_file_path_, | 40 File file(temp_file_path_, |
41 File::FLAG_CREATE_ALWAYS | File::FLAG_READ | File::FLAG_WRITE); | 41 File::FLAG_CREATE_ALWAYS | File::FLAG_READ | File::FLAG_WRITE); |
42 EXPECT_TRUE(file.IsValid()); | 42 EXPECT_TRUE(file.IsValid()); |
43 | 43 |
44 scoped_ptr<uint8[]> test_data(CreateTestBuffer(size, 0)); | 44 scoped_ptr<uint8[]> test_data(CreateTestBuffer(size, 0)); |
45 size_t bytes_written = | 45 size_t bytes_written = |
46 file.Write(0, reinterpret_cast<char*>(test_data.get()), size); | 46 file.Write(0, reinterpret_cast<char*>(test_data.get()), size); |
47 EXPECT_EQ(size, bytes_written); | 47 EXPECT_EQ(size, bytes_written); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 map.Initialize(file.Pass(), MemoryMappedFile::Region(kOffset, kPartialSize)); | 157 map.Initialize(file.Pass(), MemoryMappedFile::Region(kOffset, kPartialSize)); |
158 ASSERT_EQ(kPartialSize, map.length()); | 158 ASSERT_EQ(kPartialSize, map.length()); |
159 ASSERT_TRUE(map.data() != NULL); | 159 ASSERT_TRUE(map.data() != NULL); |
160 EXPECT_TRUE(map.IsValid()); | 160 EXPECT_TRUE(map.IsValid()); |
161 ASSERT_TRUE(CheckBufferContents(map.data(), kPartialSize, kOffset)); | 161 ASSERT_TRUE(CheckBufferContents(map.data(), kPartialSize, kOffset)); |
162 } | 162 } |
163 | 163 |
164 } // namespace | 164 } // namespace |
165 | 165 |
166 } // namespace base | 166 } // namespace base |
OLD | NEW |