| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/lib/serialization_util.h" | 10 #include "mojo/public/cpp/bindings/lib/serialization_util.h" |
| 11 #include "mojo/public/cpp/bindings/lib/validation_context.h" | 11 #include "mojo/public/cpp/bindings/lib/validation_context.h" |
| 12 #include "mojo/public/cpp/system/core.h" | 12 #include "mojo/public/cpp/system/core.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 namespace test { | 16 namespace test { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 using Handle_Data = mojo::internal::Handle_Data; | 19 using Handle_Data = mojo::internal::Handle_Data; |
| 20 using AssociatedEndpointHandle_Data = |
| 21 mojo::internal::AssociatedEndpointHandle_Data; |
| 20 | 22 |
| 21 const void* ToPtr(uintptr_t ptr) { | 23 const void* ToPtr(uintptr_t ptr) { |
| 22 return reinterpret_cast<const void*>(ptr); | 24 return reinterpret_cast<const void*>(ptr); |
| 23 } | 25 } |
| 24 | 26 |
| 25 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 27 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| 26 TEST(ValidationContextTest, ConstructorRangeOverflow) { | 28 TEST(ValidationContextTest, ConstructorRangeOverflow) { |
| 27 { | 29 { |
| 28 // Test memory range overflow. | 30 // Test memory range overflow. |
| 29 internal::ValidationContext context( | 31 internal::ValidationContext context( |
| 30 ToPtr(std::numeric_limits<uintptr_t>::max() - 3000), 5000, 0); | 32 ToPtr(std::numeric_limits<uintptr_t>::max() - 3000), 5000, 0, 0); |
| 31 | 33 |
| 32 EXPECT_FALSE(context.IsValidRange( | 34 EXPECT_FALSE(context.IsValidRange( |
| 33 ToPtr(std::numeric_limits<uintptr_t>::max() - 3000), 1)); | 35 ToPtr(std::numeric_limits<uintptr_t>::max() - 3000), 1)); |
| 34 EXPECT_FALSE(context.ClaimMemory( | 36 EXPECT_FALSE(context.ClaimMemory( |
| 35 ToPtr(std::numeric_limits<uintptr_t>::max() - 3000), 1)); | 37 ToPtr(std::numeric_limits<uintptr_t>::max() - 3000), 1)); |
| 36 } | 38 } |
| 37 | 39 |
| 38 if (sizeof(size_t) > sizeof(uint32_t)) { | 40 if (sizeof(size_t) <= sizeof(uint32_t)) |
| 41 return; |
| 42 |
| 43 { |
| 39 // Test handle index range overflow. | 44 // Test handle index range overflow. |
| 40 size_t num_handles = | 45 size_t num_handles = |
| 41 static_cast<size_t>(std::numeric_limits<uint32_t>::max()) + 5; | 46 static_cast<size_t>(std::numeric_limits<uint32_t>::max()) + 5; |
| 42 internal::ValidationContext context(ToPtr(0), 0, num_handles); | 47 internal::ValidationContext context(ToPtr(0), 0, num_handles, 0); |
| 43 | 48 |
| 44 EXPECT_FALSE(context.ClaimHandle(Handle_Data(0))); | 49 EXPECT_FALSE(context.ClaimHandle(Handle_Data(0))); |
| 45 EXPECT_FALSE(context.ClaimHandle( | 50 EXPECT_FALSE(context.ClaimHandle( |
| 46 Handle_Data(std::numeric_limits<uint32_t>::max() - 1))); | 51 Handle_Data(std::numeric_limits<uint32_t>::max() - 1))); |
| 47 | 52 |
| 48 EXPECT_TRUE(context.ClaimHandle( | 53 EXPECT_TRUE(context.ClaimHandle( |
| 49 Handle_Data(internal::kEncodedInvalidHandleValue))); | 54 Handle_Data(internal::kEncodedInvalidHandleValue))); |
| 50 } | 55 } |
| 56 |
| 57 { |
| 58 size_t num_associated_endpoint_handles = |
| 59 static_cast<size_t>(std::numeric_limits<uint32_t>::max()) + 5; |
| 60 internal::ValidationContext context(ToPtr(0), 0, 0, |
| 61 num_associated_endpoint_handles); |
| 62 |
| 63 EXPECT_FALSE(context.ClaimAssociatedEndpointHandle( |
| 64 AssociatedEndpointHandle_Data(0))); |
| 65 EXPECT_FALSE( |
| 66 context.ClaimAssociatedEndpointHandle(AssociatedEndpointHandle_Data( |
| 67 std::numeric_limits<uint32_t>::max() - 1))); |
| 68 |
| 69 EXPECT_TRUE(context.ClaimAssociatedEndpointHandle( |
| 70 AssociatedEndpointHandle_Data(internal::kEncodedInvalidHandleValue))); |
| 71 } |
| 51 } | 72 } |
| 52 #endif | 73 #endif |
| 53 | 74 |
| 54 TEST(ValidationContextTest, IsValidRange) { | 75 TEST(ValidationContextTest, IsValidRange) { |
| 55 { | 76 { |
| 56 internal::ValidationContext context(ToPtr(1234), 100, 0); | 77 internal::ValidationContext context(ToPtr(1234), 100, 0, 0); |
| 57 | 78 |
| 58 // Basics. | 79 // Basics. |
| 59 EXPECT_FALSE(context.IsValidRange(ToPtr(100), 5)); | 80 EXPECT_FALSE(context.IsValidRange(ToPtr(100), 5)); |
| 60 EXPECT_FALSE(context.IsValidRange(ToPtr(1230), 50)); | 81 EXPECT_FALSE(context.IsValidRange(ToPtr(1230), 50)); |
| 61 EXPECT_TRUE(context.IsValidRange(ToPtr(1234), 5)); | 82 EXPECT_TRUE(context.IsValidRange(ToPtr(1234), 5)); |
| 62 EXPECT_TRUE(context.IsValidRange(ToPtr(1240), 50)); | 83 EXPECT_TRUE(context.IsValidRange(ToPtr(1240), 50)); |
| 63 EXPECT_TRUE(context.IsValidRange(ToPtr(1234), 100)); | 84 EXPECT_TRUE(context.IsValidRange(ToPtr(1234), 100)); |
| 64 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 101)); | 85 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 101)); |
| 65 EXPECT_FALSE(context.IsValidRange(ToPtr(1240), 100)); | 86 EXPECT_FALSE(context.IsValidRange(ToPtr(1240), 100)); |
| 66 EXPECT_FALSE(context.IsValidRange(ToPtr(1333), 5)); | 87 EXPECT_FALSE(context.IsValidRange(ToPtr(1333), 5)); |
| 67 EXPECT_FALSE(context.IsValidRange(ToPtr(2234), 5)); | 88 EXPECT_FALSE(context.IsValidRange(ToPtr(2234), 5)); |
| 68 | 89 |
| 69 // ClaimMemory() updates the valid range. | 90 // ClaimMemory() updates the valid range. |
| 70 EXPECT_TRUE(context.ClaimMemory(ToPtr(1254), 10)); | 91 EXPECT_TRUE(context.ClaimMemory(ToPtr(1254), 10)); |
| 71 | 92 |
| 72 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 1)); | 93 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 1)); |
| 73 EXPECT_FALSE(context.IsValidRange(ToPtr(1254), 10)); | 94 EXPECT_FALSE(context.IsValidRange(ToPtr(1254), 10)); |
| 74 EXPECT_FALSE(context.IsValidRange(ToPtr(1263), 1)); | 95 EXPECT_FALSE(context.IsValidRange(ToPtr(1263), 1)); |
| 75 EXPECT_FALSE(context.IsValidRange(ToPtr(1263), 10)); | 96 EXPECT_FALSE(context.IsValidRange(ToPtr(1263), 10)); |
| 76 EXPECT_TRUE(context.IsValidRange(ToPtr(1264), 10)); | 97 EXPECT_TRUE(context.IsValidRange(ToPtr(1264), 10)); |
| 77 EXPECT_TRUE(context.IsValidRange(ToPtr(1264), 70)); | 98 EXPECT_TRUE(context.IsValidRange(ToPtr(1264), 70)); |
| 78 EXPECT_FALSE(context.IsValidRange(ToPtr(1264), 71)); | 99 EXPECT_FALSE(context.IsValidRange(ToPtr(1264), 71)); |
| 79 } | 100 } |
| 80 | 101 |
| 81 { | 102 { |
| 82 internal::ValidationContext context(ToPtr(1234), 100, 0); | 103 internal::ValidationContext context(ToPtr(1234), 100, 0, 0); |
| 83 // Should return false for empty ranges. | 104 // Should return false for empty ranges. |
| 84 EXPECT_FALSE(context.IsValidRange(ToPtr(0), 0)); | 105 EXPECT_FALSE(context.IsValidRange(ToPtr(0), 0)); |
| 85 EXPECT_FALSE(context.IsValidRange(ToPtr(1200), 0)); | 106 EXPECT_FALSE(context.IsValidRange(ToPtr(1200), 0)); |
| 86 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 0)); | 107 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 0)); |
| 87 EXPECT_FALSE(context.IsValidRange(ToPtr(1240), 0)); | 108 EXPECT_FALSE(context.IsValidRange(ToPtr(1240), 0)); |
| 88 EXPECT_FALSE(context.IsValidRange(ToPtr(2234), 0)); | 109 EXPECT_FALSE(context.IsValidRange(ToPtr(2234), 0)); |
| 89 } | 110 } |
| 90 | 111 |
| 91 { | 112 { |
| 92 // The valid memory range is empty. | 113 // The valid memory range is empty. |
| 93 internal::ValidationContext context(ToPtr(1234), 0, 0); | 114 internal::ValidationContext context(ToPtr(1234), 0, 0, 0); |
| 94 | 115 |
| 95 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 1)); | 116 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 1)); |
| 96 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 0)); | 117 EXPECT_FALSE(context.IsValidRange(ToPtr(1234), 0)); |
| 97 } | 118 } |
| 98 | 119 |
| 99 { | 120 { |
| 100 internal::ValidationContext context( | 121 internal::ValidationContext context( |
| 101 ToPtr(std::numeric_limits<uintptr_t>::max() - 2000), 1000, 0); | 122 ToPtr(std::numeric_limits<uintptr_t>::max() - 2000), 1000, 0, 0); |
| 102 | 123 |
| 103 // Test overflow. | 124 // Test overflow. |
| 104 EXPECT_FALSE(context.IsValidRange( | 125 EXPECT_FALSE(context.IsValidRange( |
| 105 ToPtr(std::numeric_limits<uintptr_t>::max() - 1500), 4000)); | 126 ToPtr(std::numeric_limits<uintptr_t>::max() - 1500), 4000)); |
| 106 EXPECT_FALSE(context.IsValidRange( | 127 EXPECT_FALSE(context.IsValidRange( |
| 107 ToPtr(std::numeric_limits<uintptr_t>::max() - 1500), | 128 ToPtr(std::numeric_limits<uintptr_t>::max() - 1500), |
| 108 std::numeric_limits<uint32_t>::max())); | 129 std::numeric_limits<uint32_t>::max())); |
| 109 | 130 |
| 110 // This should be fine. | 131 // This should be fine. |
| 111 EXPECT_TRUE(context.IsValidRange( | 132 EXPECT_TRUE(context.IsValidRange( |
| 112 ToPtr(std::numeric_limits<uintptr_t>::max() - 1500), 200)); | 133 ToPtr(std::numeric_limits<uintptr_t>::max() - 1500), 200)); |
| 113 } | 134 } |
| 114 } | 135 } |
| 115 | 136 |
| 116 TEST(ValidationContextTest, ClaimHandle) { | 137 TEST(ValidationContextTest, ClaimHandle) { |
| 117 { | 138 { |
| 118 internal::ValidationContext context(ToPtr(0), 0, 10); | 139 internal::ValidationContext context(ToPtr(0), 0, 10, 0); |
| 119 | 140 |
| 120 // Basics. | 141 // Basics. |
| 121 EXPECT_TRUE(context.ClaimHandle(Handle_Data(0))); | 142 EXPECT_TRUE(context.ClaimHandle(Handle_Data(0))); |
| 122 EXPECT_FALSE(context.ClaimHandle(Handle_Data(0))); | 143 EXPECT_FALSE(context.ClaimHandle(Handle_Data(0))); |
| 123 | 144 |
| 124 EXPECT_TRUE(context.ClaimHandle(Handle_Data(9))); | 145 EXPECT_TRUE(context.ClaimHandle(Handle_Data(9))); |
| 125 EXPECT_FALSE(context.ClaimHandle(Handle_Data(10))); | 146 EXPECT_FALSE(context.ClaimHandle(Handle_Data(10))); |
| 126 | 147 |
| 127 // Should fail because it is smaller than the max index that has been | 148 // Should fail because it is smaller than the max index that has been |
| 128 // claimed. | 149 // claimed. |
| 129 EXPECT_FALSE(context.ClaimHandle(Handle_Data(8))); | 150 EXPECT_FALSE(context.ClaimHandle(Handle_Data(8))); |
| 130 | 151 |
| 131 // Should return true for invalid handle. | 152 // Should return true for invalid handle. |
| 132 EXPECT_TRUE(context.ClaimHandle( | 153 EXPECT_TRUE(context.ClaimHandle( |
| 133 Handle_Data(internal::kEncodedInvalidHandleValue))); | 154 Handle_Data(internal::kEncodedInvalidHandleValue))); |
| 134 EXPECT_TRUE(context.ClaimHandle( | 155 EXPECT_TRUE(context.ClaimHandle( |
| 135 Handle_Data(internal::kEncodedInvalidHandleValue))); | 156 Handle_Data(internal::kEncodedInvalidHandleValue))); |
| 136 } | 157 } |
| 137 | 158 |
| 138 { | 159 { |
| 139 // No handle to claim. | 160 // No handle to claim. |
| 140 internal::ValidationContext context(ToPtr(0), 0, 0); | 161 internal::ValidationContext context(ToPtr(0), 0, 0, 0); |
| 141 | 162 |
| 142 EXPECT_FALSE(context.ClaimHandle(Handle_Data(0))); | 163 EXPECT_FALSE(context.ClaimHandle(Handle_Data(0))); |
| 143 | 164 |
| 144 // Should still return true for invalid handle. | 165 // Should still return true for invalid handle. |
| 145 EXPECT_TRUE(context.ClaimHandle( | 166 EXPECT_TRUE(context.ClaimHandle( |
| 146 Handle_Data(internal::kEncodedInvalidHandleValue))); | 167 Handle_Data(internal::kEncodedInvalidHandleValue))); |
| 147 } | 168 } |
| 148 | 169 |
| 149 { | 170 { |
| 150 // Test the case that |num_handles| is the same value as | 171 // Test the case that |num_handles| is the same value as |
| 151 // |internal::kEncodedInvalidHandleValue|. | 172 // |internal::kEncodedInvalidHandleValue|. |
| 152 EXPECT_EQ(internal::kEncodedInvalidHandleValue, | 173 EXPECT_EQ(internal::kEncodedInvalidHandleValue, |
| 153 std::numeric_limits<uint32_t>::max()); | 174 std::numeric_limits<uint32_t>::max()); |
| 154 internal::ValidationContext context( | 175 internal::ValidationContext context( |
| 155 ToPtr(0), 0, std::numeric_limits<uint32_t>::max()); | 176 ToPtr(0), 0, std::numeric_limits<uint32_t>::max(), 0); |
| 156 | 177 |
| 157 EXPECT_TRUE(context.ClaimHandle( | 178 EXPECT_TRUE(context.ClaimHandle( |
| 158 Handle_Data(std::numeric_limits<uint32_t>::max() - 1))); | 179 Handle_Data(std::numeric_limits<uint32_t>::max() - 1))); |
| 159 EXPECT_FALSE(context.ClaimHandle( | 180 EXPECT_FALSE(context.ClaimHandle( |
| 160 Handle_Data(std::numeric_limits<uint32_t>::max() - 1))); | 181 Handle_Data(std::numeric_limits<uint32_t>::max() - 1))); |
| 161 EXPECT_FALSE(context.ClaimHandle(Handle_Data(0))); | 182 EXPECT_FALSE(context.ClaimHandle(Handle_Data(0))); |
| 162 | 183 |
| 163 // Should still return true for invalid handle. | 184 // Should still return true for invalid handle. |
| 164 EXPECT_TRUE(context.ClaimHandle( | 185 EXPECT_TRUE(context.ClaimHandle( |
| 165 Handle_Data(internal::kEncodedInvalidHandleValue))); | 186 Handle_Data(internal::kEncodedInvalidHandleValue))); |
| 166 } | 187 } |
| 167 } | 188 } |
| 168 | 189 |
| 190 TEST(ValidationContextTest, ClaimAssociatedEndpointHandle) { |
| 191 { |
| 192 internal::ValidationContext context(ToPtr(0), 0, 0, 10); |
| 193 |
| 194 // Basics. |
| 195 EXPECT_TRUE(context.ClaimAssociatedEndpointHandle( |
| 196 AssociatedEndpointHandle_Data(0))); |
| 197 EXPECT_FALSE(context.ClaimAssociatedEndpointHandle( |
| 198 AssociatedEndpointHandle_Data(0))); |
| 199 |
| 200 EXPECT_TRUE(context.ClaimAssociatedEndpointHandle( |
| 201 AssociatedEndpointHandle_Data(9))); |
| 202 EXPECT_FALSE(context.ClaimAssociatedEndpointHandle( |
| 203 AssociatedEndpointHandle_Data(10))); |
| 204 |
| 205 // Should fail because it is smaller than the max index that has been |
| 206 // claimed. |
| 207 EXPECT_FALSE(context.ClaimAssociatedEndpointHandle( |
| 208 AssociatedEndpointHandle_Data(8))); |
| 209 |
| 210 // Should return true for invalid handle. |
| 211 EXPECT_TRUE(context.ClaimAssociatedEndpointHandle( |
| 212 AssociatedEndpointHandle_Data(internal::kEncodedInvalidHandleValue))); |
| 213 EXPECT_TRUE(context.ClaimAssociatedEndpointHandle( |
| 214 AssociatedEndpointHandle_Data(internal::kEncodedInvalidHandleValue))); |
| 215 } |
| 216 |
| 217 { |
| 218 // No handle to claim. |
| 219 internal::ValidationContext context(ToPtr(0), 0, 0, 0); |
| 220 |
| 221 EXPECT_FALSE(context.ClaimAssociatedEndpointHandle( |
| 222 AssociatedEndpointHandle_Data(0))); |
| 223 |
| 224 // Should still return true for invalid handle. |
| 225 EXPECT_TRUE(context.ClaimAssociatedEndpointHandle( |
| 226 AssociatedEndpointHandle_Data(internal::kEncodedInvalidHandleValue))); |
| 227 } |
| 228 |
| 229 { |
| 230 // Test the case that |num_associated_endpoint_handles| is the same value as |
| 231 // |internal::kEncodedInvalidHandleValue|. |
| 232 EXPECT_EQ(internal::kEncodedInvalidHandleValue, |
| 233 std::numeric_limits<uint32_t>::max()); |
| 234 internal::ValidationContext context(ToPtr(0), 0, 0, |
| 235 std::numeric_limits<uint32_t>::max()); |
| 236 |
| 237 EXPECT_TRUE( |
| 238 context.ClaimAssociatedEndpointHandle(AssociatedEndpointHandle_Data( |
| 239 std::numeric_limits<uint32_t>::max() - 1))); |
| 240 EXPECT_FALSE( |
| 241 context.ClaimAssociatedEndpointHandle(AssociatedEndpointHandle_Data( |
| 242 std::numeric_limits<uint32_t>::max() - 1))); |
| 243 EXPECT_FALSE(context.ClaimAssociatedEndpointHandle( |
| 244 AssociatedEndpointHandle_Data(0))); |
| 245 |
| 246 // Should still return true for invalid handle. |
| 247 EXPECT_TRUE(context.ClaimAssociatedEndpointHandle( |
| 248 AssociatedEndpointHandle_Data(internal::kEncodedInvalidHandleValue))); |
| 249 } |
| 250 } |
| 251 |
| 169 TEST(ValidationContextTest, ClaimMemory) { | 252 TEST(ValidationContextTest, ClaimMemory) { |
| 170 { | 253 { |
| 171 internal::ValidationContext context(ToPtr(1000), 2000, 0); | 254 internal::ValidationContext context(ToPtr(1000), 2000, 0, 0); |
| 172 | 255 |
| 173 // Basics. | 256 // Basics. |
| 174 EXPECT_FALSE(context.ClaimMemory(ToPtr(500), 100)); | 257 EXPECT_FALSE(context.ClaimMemory(ToPtr(500), 100)); |
| 175 EXPECT_FALSE(context.ClaimMemory(ToPtr(800), 300)); | 258 EXPECT_FALSE(context.ClaimMemory(ToPtr(800), 300)); |
| 176 EXPECT_TRUE(context.ClaimMemory(ToPtr(1000), 100)); | 259 EXPECT_TRUE(context.ClaimMemory(ToPtr(1000), 100)); |
| 177 EXPECT_FALSE(context.ClaimMemory(ToPtr(1099), 100)); | 260 EXPECT_FALSE(context.ClaimMemory(ToPtr(1099), 100)); |
| 178 EXPECT_TRUE(context.ClaimMemory(ToPtr(1100), 200)); | 261 EXPECT_TRUE(context.ClaimMemory(ToPtr(1100), 200)); |
| 179 EXPECT_FALSE(context.ClaimMemory(ToPtr(2000), 1001)); | 262 EXPECT_FALSE(context.ClaimMemory(ToPtr(2000), 1001)); |
| 180 EXPECT_TRUE(context.ClaimMemory(ToPtr(2000), 500)); | 263 EXPECT_TRUE(context.ClaimMemory(ToPtr(2000), 500)); |
| 181 EXPECT_FALSE(context.ClaimMemory(ToPtr(2000), 500)); | 264 EXPECT_FALSE(context.ClaimMemory(ToPtr(2000), 500)); |
| 182 EXPECT_FALSE(context.ClaimMemory(ToPtr(1400), 100)); | 265 EXPECT_FALSE(context.ClaimMemory(ToPtr(1400), 100)); |
| 183 EXPECT_FALSE(context.ClaimMemory(ToPtr(3000), 1)); | 266 EXPECT_FALSE(context.ClaimMemory(ToPtr(3000), 1)); |
| 184 EXPECT_TRUE(context.ClaimMemory(ToPtr(2500), 500)); | 267 EXPECT_TRUE(context.ClaimMemory(ToPtr(2500), 500)); |
| 185 } | 268 } |
| 186 | 269 |
| 187 { | 270 { |
| 188 // No memory to claim. | 271 // No memory to claim. |
| 189 internal::ValidationContext context(ToPtr(10000), 0, 0); | 272 internal::ValidationContext context(ToPtr(10000), 0, 0, 0); |
| 190 | 273 |
| 191 EXPECT_FALSE(context.ClaimMemory(ToPtr(10000), 1)); | 274 EXPECT_FALSE(context.ClaimMemory(ToPtr(10000), 1)); |
| 192 EXPECT_FALSE(context.ClaimMemory(ToPtr(10000), 0)); | 275 EXPECT_FALSE(context.ClaimMemory(ToPtr(10000), 0)); |
| 193 } | 276 } |
| 194 | 277 |
| 195 { | 278 { |
| 196 internal::ValidationContext context( | 279 internal::ValidationContext context( |
| 197 ToPtr(std::numeric_limits<uintptr_t>::max() - 1000), 500, 0); | 280 ToPtr(std::numeric_limits<uintptr_t>::max() - 1000), 500, 0, 0); |
| 198 | 281 |
| 199 // Test overflow. | 282 // Test overflow. |
| 200 EXPECT_FALSE(context.ClaimMemory( | 283 EXPECT_FALSE(context.ClaimMemory( |
| 201 ToPtr(std::numeric_limits<uintptr_t>::max() - 750), 4000)); | 284 ToPtr(std::numeric_limits<uintptr_t>::max() - 750), 4000)); |
| 202 EXPECT_FALSE( | 285 EXPECT_FALSE( |
| 203 context.ClaimMemory(ToPtr(std::numeric_limits<uintptr_t>::max() - 750), | 286 context.ClaimMemory(ToPtr(std::numeric_limits<uintptr_t>::max() - 750), |
| 204 std::numeric_limits<uint32_t>::max())); | 287 std::numeric_limits<uint32_t>::max())); |
| 205 | 288 |
| 206 // This should be fine. | 289 // This should be fine. |
| 207 EXPECT_TRUE(context.ClaimMemory( | 290 EXPECT_TRUE(context.ClaimMemory( |
| 208 ToPtr(std::numeric_limits<uintptr_t>::max() - 750), 200)); | 291 ToPtr(std::numeric_limits<uintptr_t>::max() - 750), 200)); |
| 209 } | 292 } |
| 210 } | 293 } |
| 211 | 294 |
| 212 } // namespace | 295 } // namespace |
| 213 } // namespace test | 296 } // namespace test |
| 214 } // namespace mojo | 297 } // namespace mojo |
| OLD | NEW |