Chromium Code Reviews| 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 "mojo/edk/embedder/simple_platform_shared_buffer.h" | 5 #include "mojo/edk/embedder/simple_platform_shared_buffer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 EXPECT_FALSE(buffer->Map(50, 51)); | 127 EXPECT_FALSE(buffer->Map(50, 51)); |
| 128 EXPECT_FALSE(buffer->IsValidMap(50, 51)); | 128 EXPECT_FALSE(buffer->IsValidMap(50, 51)); |
| 129 EXPECT_FALSE(buffer->Map(51, 50)); | 129 EXPECT_FALSE(buffer->Map(51, 50)); |
| 130 EXPECT_FALSE(buffer->IsValidMap(51, 50)); | 130 EXPECT_FALSE(buffer->IsValidMap(51, 50)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 TEST(SimplePlatformSharedBufferTest, TooBig) { | 133 TEST(SimplePlatformSharedBufferTest, TooBig) { |
| 134 // If |size_t| is 32-bit, it's quite possible/likely that |Create()| succeeds | 134 // If |size_t| is 32-bit, it's quite possible/likely that |Create()| succeeds |
| 135 // (since it only involves creating a 4 GB file). | 135 // (since it only involves creating a 4 GB file). |
| 136 size_t max_size = std::numeric_limits<size_t>::max(); | 136 size_t max_size = std::numeric_limits<size_t>::max(); |
| 137 if (max_size > static_cast<size_t>(base::SysInfo::AmountOfVirtualMemory())) | 137 if (base::SysInfo::AmountOfVirtualMemory() && |
|
jam
2015/12/03 03:42:36
I added this recently to make the test pass on Win
yzshen1
2015/12/03 18:04:33
nit: please consider adding the reason as a commen
| |
| 138 max_size > static_cast<size_t>(base::SysInfo::AmountOfVirtualMemory())) | |
| 138 max_size = static_cast<size_t>(base::SysInfo::AmountOfVirtualMemory()); | 139 max_size = static_cast<size_t>(base::SysInfo::AmountOfVirtualMemory()); |
| 139 scoped_refptr<SimplePlatformSharedBuffer> buffer( | 140 scoped_refptr<SimplePlatformSharedBuffer> buffer( |
| 140 SimplePlatformSharedBuffer::Create(max_size)); | 141 SimplePlatformSharedBuffer::Create(max_size)); |
| 141 // But, assuming |sizeof(size_t) == sizeof(void*)|, mapping all of it should | 142 // But, assuming |sizeof(size_t) == sizeof(void*)|, mapping all of it should |
| 142 // always fail. | 143 // always fail. |
| 143 if (buffer) | 144 if (buffer) |
| 144 EXPECT_FALSE(buffer->Map(0, max_size)); | 145 EXPECT_FALSE(buffer->Map(0, max_size)); |
| 145 } | 146 } |
| 146 | 147 |
| 147 // Tests that separate mappings get distinct addresses. | 148 // Tests that separate mappings get distinct addresses. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 | 186 |
| 186 EXPECT_EQ('x', static_cast<char*>(mapping2->GetBase())[0]); | 187 EXPECT_EQ('x', static_cast<char*>(mapping2->GetBase())[0]); |
| 187 | 188 |
| 188 static_cast<char*>(mapping2->GetBase())[1] = 'y'; | 189 static_cast<char*>(mapping2->GetBase())[1] = 'y'; |
| 189 EXPECT_EQ('y', static_cast<char*>(mapping1->GetBase())[51]); | 190 EXPECT_EQ('y', static_cast<char*>(mapping1->GetBase())[51]); |
| 190 } | 191 } |
| 191 | 192 |
| 192 } // namespace | 193 } // namespace |
| 193 } // namespace edk | 194 } // namespace edk |
| 194 } // namespace mojo | 195 } // namespace mojo |
| OLD | NEW |