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

Unified 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: const Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: util/numeric/checked_range_test.cc
diff --git a/util/numeric/checked_range_test.cc b/util/numeric/checked_range_test.cc
index 9c72526a6a8379a27d1d509be2eaff10a0c4d6fb..cbff6612e67c0e82147fc630863af6e6a29e7d60 100644
--- a/util/numeric/checked_range_test.cc
+++ b/util/numeric/checked_range_test.cc
@@ -246,6 +246,59 @@ TEST(CheckedRange, ContainsRange) {
}
}
+TEST(CheckedRange, OverlapsRange) {
+ const struct TestData {
+ uint32_t base;
+ uint32_t size;
+ bool valid;
Mark Mentovai 2015/10/01 17:38:58 This is more “overlaps” than valid. The member nam
scottmg 2015/10/01 18:10:02 Done.
+ } kTestData[] = {
+ {0, 0, false},
+ {0, 1, false},
+ {0x2000, 0x1000, true},
+ {0, 0x2000, false},
+ {0x3000, 0x1000, false},
+ {0x1800, 0x1000, true},
+ {0x1800, 0x2000, true},
+ {0x2800, 0x1000, true},
+ {0x2000, 0x800, true},
+ {0x2800, 0x800, true},
+ {0x2400, 0x800, true},
+ {0x2800, 0, true},
Mark Mentovai 2015/10/01 17:38:58 This one might be a little weird. Should a 0-sized
scottmg 2015/10/01 18:10:02 Yeah, the other weird case is <0x2000, 0> = false
Mark Mentovai 2015/10/01 18:29:12 scottmg wrote:
+ {0x2000, 0xffffdfff, true},
+ {0x2800, 0xffffd7ff, true},
+ {0x3000, 0xffffcfff, false},
+ {0xfffffffe, 1, false},
+ {0xffffffff, 0, false},
+ {0x1fff, 0, false},
+ {0x2000, 0, false},
+ {0x2001, 0, true},
+ {0x2fff, 0, true},
+ {0x3000, 0, false},
+ {0x3001, 0, false},
+ {0x1fff, 1, false},
+ {0x2000, 1, true},
+ {0x2001, 1, true},
+ {0x2fff, 1, true},
+ {0x3000, 1, false},
+ {0x3001, 1, false},
+ };
+
+ CheckedRange<uint32_t> first_range(0x2000, 0x1000);
+ ASSERT_TRUE(first_range.IsValid());
+
+ for (size_t index = 0; index < arraysize(kTestData); ++index) {
+ const TestData& testcase = kTestData[index];
+ SCOPED_TRACE(base::StringPrintf("index %" PRIuS ", base 0x%x, size 0x%x",
+ index,
+ testcase.base,
+ testcase.size));
+
+ CheckedRange<uint32_t> second_range(testcase.base, testcase.size);
+ ASSERT_TRUE(second_range.IsValid());
+ EXPECT_EQ(testcase.valid, first_range.OverlapsRange(second_range));
+ }
+}
+
} // namespace
} // namespace test
} // namespace crashpad

Powered by Google App Engine
This is Rietveld 408576698