Index: util/numeric/checked_address_range_test.cc |
diff --git a/util/mac/checked_mach_address_range_test.cc b/util/numeric/checked_address_range_test.cc |
similarity index 85% |
copy from util/mac/checked_mach_address_range_test.cc |
copy to util/numeric/checked_address_range_test.cc |
index 702715d092a0afec4aa4e7c36351cea658821785..d902387ca93feb42cafbe7624bac8c7851ffe849 100644 |
--- a/util/mac/checked_mach_address_range_test.cc |
+++ b/util/numeric/checked_address_range_test.cc |
@@ -12,13 +12,12 @@ |
// See the License for the specific language governing permissions and |
// limitations under the License. |
-#include "util/mac/checked_mach_address_range.h" |
- |
-#include <mach/mach.h> |
+#include "util/numeric/checked_address_range.h" |
#include <limits> |
#include "base/basictypes.h" |
+#include "base/format_macros.h" |
#include "base/strings/stringprintf.h" |
#include "build/build_config.h" |
#include "gtest/gtest.h" |
@@ -27,6 +26,9 @@ namespace crashpad { |
namespace test { |
namespace { |
+using CheckedAddressRange = |
+ internal::CheckedAddressRangeGeneric<uint64_t, uint64_t>; |
+ |
enum Validity { |
kInvalid = false, |
kValid, |
@@ -41,10 +43,10 @@ bool ExpectationForValidity64(Validity validity) { |
return validity == kValid || validity == kValid64Invalid32; |
} |
-TEST(CheckedMachAddressRange, IsValid) { |
+TEST(CheckedAddressRange, IsValid) { |
const struct TestData { |
- mach_vm_address_t base; |
- mach_vm_size_t size; |
+ uint64_t base; |
+ uint64_t size; |
Validity validity; |
} kTestData[] = { |
{0, 0, kValid}, |
@@ -117,22 +119,23 @@ TEST(CheckedMachAddressRange, IsValid) { |
for (size_t index = 0; index < arraysize(kTestData); ++index) { |
const TestData& testcase = kTestData[index]; |
- SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx", |
+ SCOPED_TRACE(base::StringPrintf("index %" PRIuS |
+ ", base 0x%llx, size 0x%llx", |
index, |
testcase.base, |
testcase.size)); |
- CheckedMachAddressRange range_32(false, testcase.base, testcase.size); |
+ CheckedAddressRange range_32(false, testcase.base, testcase.size); |
EXPECT_EQ(ExpectationForValidity32(testcase.validity), range_32.IsValid()); |
- CheckedMachAddressRange range_64(true, testcase.base, testcase.size); |
+ CheckedAddressRange range_64(true, testcase.base, testcase.size); |
EXPECT_EQ(ExpectationForValidity64(testcase.validity), range_64.IsValid()); |
} |
} |
-TEST(CheckedMachAddressRange, ContainsValue) { |
+TEST(CheckedAddressRange, ContainsValue) { |
const struct TestData { |
- mach_vm_address_t value; |
+ uint64_t value; |
bool expectation; |
} kTestData[] = { |
{0, false}, |
@@ -162,19 +165,19 @@ TEST(CheckedMachAddressRange, ContainsValue) { |
{0xffffffffffffffff, false}, |
}; |
- CheckedMachAddressRange parent_range_32(false, 0x2000, 0x1000); |
+ CheckedAddressRange parent_range_32(false, 0x2000, 0x1000); |
ASSERT_TRUE(parent_range_32.IsValid()); |
for (size_t index = 0; index < arraysize(kTestData); ++index) { |
const TestData& testcase = kTestData[index]; |
- SCOPED_TRACE( |
- base::StringPrintf("index %zu, value 0x%llx", index, testcase.value)); |
+ SCOPED_TRACE(base::StringPrintf( |
+ "index %" PRIuS ", value 0x%llx", index, testcase.value)); |
EXPECT_EQ(testcase.expectation, |
parent_range_32.ContainsValue(testcase.value)); |
} |
- CheckedMachAddressRange parent_range_64(true, 0x100000000, 0x1000); |
+ CheckedAddressRange parent_range_64(true, 0x100000000, 0x1000); |
ASSERT_TRUE(parent_range_64.IsValid()); |
EXPECT_FALSE(parent_range_64.ContainsValue(0xffffffff)); |
EXPECT_TRUE(parent_range_64.ContainsValue(0x100000000)); |
@@ -183,10 +186,10 @@ TEST(CheckedMachAddressRange, ContainsValue) { |
EXPECT_FALSE(parent_range_64.ContainsValue(0x100001000)); |
} |
-TEST(CheckedMachAddressRange, ContainsRange) { |
+TEST(CheckedAddressRange, ContainsRange) { |
const struct TestData { |
- mach_vm_address_t base; |
- mach_vm_size_t size; |
+ uint64_t base; |
+ uint64_t size; |
bool expectation; |
} kTestData[] = { |
{0, 0, false}, |
@@ -219,26 +222,27 @@ TEST(CheckedMachAddressRange, ContainsRange) { |
{0x3001, 1, false}, |
}; |
- CheckedMachAddressRange parent_range_32(false, 0x2000, 0x1000); |
+ CheckedAddressRange parent_range_32(false, 0x2000, 0x1000); |
ASSERT_TRUE(parent_range_32.IsValid()); |
for (size_t index = 0; index < arraysize(kTestData); ++index) { |
const TestData& testcase = kTestData[index]; |
- SCOPED_TRACE(base::StringPrintf("index %zu, base 0x%llx, size 0x%llx", |
+ SCOPED_TRACE(base::StringPrintf("index %" PRIuS |
+ ", base 0x%llx, size 0x%llx", |
index, |
testcase.base, |
testcase.size)); |
- CheckedMachAddressRange child_range_32(false, testcase.base, testcase.size); |
+ CheckedAddressRange child_range_32(false, testcase.base, testcase.size); |
ASSERT_TRUE(child_range_32.IsValid()); |
EXPECT_EQ(testcase.expectation, |
parent_range_32.ContainsRange(child_range_32)); |
} |
- CheckedMachAddressRange parent_range_64(true, 0x100000000, 0x1000); |
+ CheckedAddressRange parent_range_64(true, 0x100000000, 0x1000); |
ASSERT_TRUE(parent_range_64.IsValid()); |
- CheckedMachAddressRange child_range_64(true, 0xffffffff, 2); |
+ CheckedAddressRange child_range_64(true, 0xffffffff, 2); |
EXPECT_FALSE(parent_range_64.ContainsRange(child_range_64)); |
child_range_64.SetRange(true, 0x100000000, 2); |