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

Side by Side Diff: util/numeric/checked_range_test.cc

Issue 1372183002: win: Add memory map range intersection helper (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 2 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
« no previous file with comments | « util/numeric/checked_range.h ('k') | util/win/process_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 testcase.size)); 148 testcase.size));
149 149
150 CheckedRange<int32_t, uint32_t> range(testcase.base, testcase.size); 150 CheckedRange<int32_t, uint32_t> range(testcase.base, testcase.size);
151 EXPECT_EQ(testcase.valid, range.IsValid()); 151 EXPECT_EQ(testcase.valid, range.IsValid());
152 } 152 }
153 } 153 }
154 154
155 TEST(CheckedRange, ContainsValue) { 155 TEST(CheckedRange, ContainsValue) {
156 const struct TestData { 156 const struct TestData {
157 uint32_t value; 157 uint32_t value;
158 bool valid; 158 bool contains;
159 } kTestData[] = { 159 } kTestData[] = {
160 {0, false}, 160 {0, false},
161 {1, false}, 161 {1, false},
162 {0x1fff, false}, 162 {0x1fff, false},
163 {0x2000, true}, 163 {0x2000, true},
164 {0x2001, true}, 164 {0x2001, true},
165 {0x2ffe, true}, 165 {0x2ffe, true},
166 {0x2fff, true}, 166 {0x2fff, true},
167 {0x3000, false}, 167 {0x3000, false},
168 {0x3001, false}, 168 {0x3001, false},
(...skipping 14 matching lines...) Expand all
183 }; 183 };
184 184
185 CheckedRange<uint32_t> parent_range(0x2000, 0x1000); 185 CheckedRange<uint32_t> parent_range(0x2000, 0x1000);
186 ASSERT_TRUE(parent_range.IsValid()); 186 ASSERT_TRUE(parent_range.IsValid());
187 187
188 for (size_t index = 0; index < arraysize(kTestData); ++index) { 188 for (size_t index = 0; index < arraysize(kTestData); ++index) {
189 const TestData& testcase = kTestData[index]; 189 const TestData& testcase = kTestData[index];
190 SCOPED_TRACE(base::StringPrintf( 190 SCOPED_TRACE(base::StringPrintf(
191 "index %" PRIuS ", value 0x%x", index, testcase.value)); 191 "index %" PRIuS ", value 0x%x", index, testcase.value));
192 192
193 EXPECT_EQ(testcase.valid, parent_range.ContainsValue(testcase.value)); 193 EXPECT_EQ(testcase.contains, parent_range.ContainsValue(testcase.value));
194 } 194 }
195 } 195 }
196 196
197 TEST(CheckedRange, ContainsRange) { 197 TEST(CheckedRange, ContainsRange) {
198 const struct TestData { 198 const struct TestData {
199 uint32_t base; 199 uint32_t base;
200 uint32_t size; 200 uint32_t size;
201 bool valid; 201 bool contains;
202 } kTestData[] = { 202 } kTestData[] = {
203 {0, 0, false}, 203 {0, 0, false},
204 {0, 1, false}, 204 {0, 1, false},
205 {0x2000, 0x1000, true}, 205 {0x2000, 0x1000, true},
206 {0, 0x2000, false}, 206 {0, 0x2000, false},
207 {0x3000, 0x1000, false}, 207 {0x3000, 0x1000, false},
208 {0x1800, 0x1000, false}, 208 {0x1800, 0x1000, false},
209 {0x2800, 0x1000, false}, 209 {0x2800, 0x1000, false},
210 {0x2000, 0x800, true}, 210 {0x2000, 0x800, true},
211 {0x2800, 0x800, true}, 211 {0x2800, 0x800, true},
(...skipping 23 matching lines...) Expand all
235 235
236 for (size_t index = 0; index < arraysize(kTestData); ++index) { 236 for (size_t index = 0; index < arraysize(kTestData); ++index) {
237 const TestData& testcase = kTestData[index]; 237 const TestData& testcase = kTestData[index];
238 SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x", 238 SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x",
239 index, 239 index,
240 testcase.base, 240 testcase.base,
241 testcase.size)); 241 testcase.size));
242 242
243 CheckedRange<uint32_t> child_range(testcase.base, testcase.size); 243 CheckedRange<uint32_t> child_range(testcase.base, testcase.size);
244 ASSERT_TRUE(child_range.IsValid()); 244 ASSERT_TRUE(child_range.IsValid());
245 EXPECT_EQ(testcase.valid, parent_range.ContainsRange(child_range)); 245 EXPECT_EQ(testcase.contains, parent_range.ContainsRange(child_range));
246 } 246 }
247 } 247 }
248 248
249 TEST(CheckedRange, OverlapsRange) {
250 const struct TestData {
251 uint32_t base;
252 uint32_t size;
253 bool overlaps;
254 } kTestData[] = {
255 {0, 0, false},
256 {0, 1, false},
257 {0x2000, 0x1000, true},
258 {0, 0x2000, false},
259 {0x3000, 0x1000, false},
260 {0x1800, 0x1000, true},
261 {0x1800, 0x2000, true},
262 {0x2800, 0x1000, true},
263 {0x2000, 0x800, true},
264 {0x2800, 0x800, true},
265 {0x2400, 0x800, true},
266 {0x2800, 0, false},
267 {0x2000, 0xffffdfff, true},
268 {0x2800, 0xffffd7ff, true},
269 {0x3000, 0xffffcfff, false},
270 {0xfffffffe, 1, false},
271 {0xffffffff, 0, false},
272 {0x1fff, 0, false},
273 {0x2000, 0, false},
274 {0x2001, 0, false},
275 {0x2fff, 0, false},
276 {0x3000, 0, false},
277 {0x3001, 0, false},
278 {0x1fff, 1, false},
279 {0x2000, 1, true},
280 {0x2001, 1, true},
281 {0x2fff, 1, true},
282 {0x3000, 1, false},
283 {0x3001, 1, false},
284 };
285
286 CheckedRange<uint32_t> first_range(0x2000, 0x1000);
287 ASSERT_TRUE(first_range.IsValid());
288
289 for (size_t index = 0; index < arraysize(kTestData); ++index) {
290 const TestData& testcase = kTestData[index];
291 SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x",
292 index,
293 testcase.base,
294 testcase.size));
295
296 CheckedRange<uint32_t> second_range(testcase.base, testcase.size);
297 ASSERT_TRUE(second_range.IsValid());
298 EXPECT_EQ(testcase.overlaps, first_range.OverlapsRange(second_range));
299 }
300 }
301
249 } // namespace 302 } // namespace
250 } // namespace test 303 } // namespace test
251 } // namespace crashpad 304 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/numeric/checked_range.h ('k') | util/win/process_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698