diff options
author | SiyangXie@gmail.com <SiyangXie@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2010-11-04 02:40:06 +0000 |
---|---|---|
committer | SiyangXie@gmail.com <SiyangXie@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2010-11-04 02:40:06 +0000 |
commit | 4adb6f4f7b6e87801eac85aac721846a2293f2df (patch) | |
tree | dd4ad4e9a11973a0bb76bbaa249c83bc8cbdf0c1 | |
parent | Make memory allocation/deallocation consistent: use new char[] instead of ope... (diff) | |
download | breakpad-4adb6f4f7b6e87801eac85aac721846a2293f2df.tar.xz |
Fix for issue 222001.
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@725 4c0a9323-5329-0410-9bdc-e9ce6186880e
-rw-r--r-- | src/processor/map_serializers_unittest.cc | 6 | ||||
-rw-r--r-- | src/processor/static_address_map_unittest.cc | 2 | ||||
-rw-r--r-- | src/processor/static_contained_range_map_unittest.cc | 224 | ||||
-rw-r--r-- | src/processor/static_range_map_unittest.cc | 210 |
4 files changed, 220 insertions, 222 deletions
diff --git a/src/processor/map_serializers_unittest.cc b/src/processor/map_serializers_unittest.cc index c20ea0dc..abaef976 100644 --- a/src/processor/map_serializers_unittest.cc +++ b/src/processor/map_serializers_unittest.cc @@ -131,7 +131,7 @@ class TestAddressMapSerializer : public ::testing::Test { } void TearDown() { - delete serialized_data_; + delete [] serialized_data_; } google_breakpad::AddressMap<AddrType, EntryType> address_map_; @@ -206,7 +206,7 @@ class TestRangeMapSerializer : public ::testing::Test { } void TearDown() { - delete serialized_data_; + delete [] serialized_data_; } google_breakpad::RangeMap<AddrType, EntryType> range_map_; @@ -279,7 +279,7 @@ class TestContainedRangeMapSerializer : public ::testing::Test { } void TearDown() { - delete serialized_data_; + delete [] serialized_data_; } google_breakpad::ContainedRangeMap<AddrType, EntryType> crm_map_; diff --git a/src/processor/static_address_map_unittest.cc b/src/processor/static_address_map_unittest.cc index b1edbe77..5ef03455 100644 --- a/src/processor/static_address_map_unittest.cc +++ b/src/processor/static_address_map_unittest.cc @@ -84,7 +84,7 @@ class TestStaticAddressMap : public ::testing::Test { void TearDown() { for (int i = 0; i < kNumberTestCases; ++i) { - delete map_data[i]; + delete [] map_data[i]; delete [] testdata[i]; } } diff --git a/src/processor/static_contained_range_map_unittest.cc b/src/processor/static_contained_range_map_unittest.cc index 908e11c1..4c0c72d6 100644 --- a/src/processor/static_contained_range_map_unittest.cc +++ b/src/processor/static_contained_range_map_unittest.cc @@ -42,116 +42,118 @@ #include "processor/logging.h" namespace { - // Each element in test_data contains the expected result when calling - // RetrieveRange on an address. - const int test_data[] = { - 0, // 0 - 0, // 1 - 0, // 2 - 0, // 3 - 0, // 4 - 0, // 5 - 0, // 6 - 0, // 7 - 9, // 8 - 7, // 9 - 1, // 10 - 5, // 11 - 6, // 12 - 6, // 13 - 6, // 14 - 6, // 15 - 6, // 16 - 6, // 17 - 6, // 18 - 5, // 19 - 7, // 20 - 8, // 21 - 0, // 22 - 0, // 23 - 0, // 24 - 0, // 25 - 0, // 26 - 0, // 27 - 0, // 28 - 0, // 29 - 10, // 30 - 10, // 31 - 10, // 32 - 11, // 33 - 11, // 34 - 11, // 35 - 0, // 36 - 0, // 37 - 0, // 38 - 0, // 39 - 14, // 40 - 14, // 41 - 14, // 42 - 14, // 43 - 15, // 44 - 15, // 45 - 15, // 46 - 15, // 47 - 0, // 48 - 0, // 49 - 19, // 50 - 18, // 51 - 18, // 52 - 18, // 53 - 18, // 54 - 18, // 55 - 18, // 56 - 18, // 57 - 18, // 58 - 20, // 59 - 21, // 60 - 25, // 61 - 26, // 62 - 26, // 63 - 26, // 64 - 26, // 65 - 26, // 66 - 26, // 67 - 24, // 68 - 22, // 69 - 30, // 70 - 30, // 71 - 30, // 72 - 30, // 73 - 31, // 74 - 31, // 75 - 30, // 76 - 32, // 77 - 32, // 78 - 30, // 79 - 34, // 80 - 35, // 81 - 36, // 82 - 39, // 83 - 38, // 84 - 37, // 85 - 43, // 86 - 44, // 87 - 41, // 88 - 45, // 89 - 42, // 90 - 0, // 91 - 0, // 92 - 0, // 93 - 0, // 94 - 0, // 95 - 0, // 96 - 0, // 97 - 0, // 98 - 0 // 99 - }; -} // namespace - typedef google_breakpad::ContainedRangeMap<unsigned int, int> CRMMap; typedef google_breakpad::StaticContainedRangeMap<unsigned int, int> TestMap; -using google_breakpad::scoped_ptr; + +// Each element in test_data contains the expected result when calling +// RetrieveRange on an address. +const int test_data[] = { + 0, // 0 + 0, // 1 + 0, // 2 + 0, // 3 + 0, // 4 + 0, // 5 + 0, // 6 + 0, // 7 + 9, // 8 + 7, // 9 + 1, // 10 + 5, // 11 + 6, // 12 + 6, // 13 + 6, // 14 + 6, // 15 + 6, // 16 + 6, // 17 + 6, // 18 + 5, // 19 + 7, // 20 + 8, // 21 + 0, // 22 + 0, // 23 + 0, // 24 + 0, // 25 + 0, // 26 + 0, // 27 + 0, // 28 + 0, // 29 + 10, // 30 + 10, // 31 + 10, // 32 + 11, // 33 + 11, // 34 + 11, // 35 + 0, // 36 + 0, // 37 + 0, // 38 + 0, // 39 + 14, // 40 + 14, // 41 + 14, // 42 + 14, // 43 + 15, // 44 + 15, // 45 + 15, // 46 + 15, // 47 + 0, // 48 + 0, // 49 + 19, // 50 + 18, // 51 + 18, // 52 + 18, // 53 + 18, // 54 + 18, // 55 + 18, // 56 + 18, // 57 + 18, // 58 + 20, // 59 + 21, // 60 + 25, // 61 + 26, // 62 + 26, // 63 + 26, // 64 + 26, // 65 + 26, // 66 + 26, // 67 + 24, // 68 + 22, // 69 + 30, // 70 + 30, // 71 + 30, // 72 + 30, // 73 + 31, // 74 + 31, // 75 + 30, // 76 + 32, // 77 + 32, // 78 + 30, // 79 + 34, // 80 + 35, // 81 + 36, // 82 + 39, // 83 + 38, // 84 + 37, // 85 + 43, // 86 + 44, // 87 + 41, // 88 + 45, // 89 + 42, // 90 + 0, // 91 + 0, // 92 + 0, // 93 + 0, // 94 + 0, // 95 + 0, // 96 + 0, // 97 + 0, // 98 + 0 // 99 +}; + +} // namespace + +namespace google_breakpad { class TestStaticCRMMap : public ::testing::Test { protected: @@ -167,7 +169,7 @@ class TestStaticCRMMap : public ::testing::Test { google_breakpad::ContainedRangeMapSerializer<unsigned int, int> serializer_; - scoped_ptr<char> serialized_data_; + scoped_array<char> serialized_data_; }; void TestStaticCRMMap::SetUp() { @@ -236,7 +238,7 @@ TEST_F(TestStaticCRMMap, TestEmptyMap) { CRMMap empty_crm_map; unsigned int size; - scoped_ptr<char> serialized_data; + scoped_array<char> serialized_data; serialized_data.reset(serializer_.Serialize(&empty_crm_map, &size)); scoped_ptr<TestMap> test_map(new TestMap(serialized_data.get())); @@ -256,7 +258,7 @@ TEST_F(TestStaticCRMMap, TestSingleElementMap) { crm_map.StoreRange(10, 10, entry); unsigned int size; - scoped_ptr<char> serialized_data; + scoped_array<char> serialized_data; serialized_data.reset(serializer_.Serialize(&crm_map, &size)); scoped_ptr<TestMap> test_map(new TestMap(serialized_data.get())); @@ -310,6 +312,8 @@ TEST_F(TestStaticCRMMap, RunTestData) { #endif // GENERATE_TEST_DATA } +} // namespace google_breakpad + int main(int argc, char *argv[]) { ::testing::InitGoogleTest(&argc, argv); diff --git a/src/processor/static_range_map_unittest.cc b/src/processor/static_range_map_unittest.cc index d4163e28..82b26235 100644 --- a/src/processor/static_range_map_unittest.cc +++ b/src/processor/static_range_map_unittest.cc @@ -40,14 +40,12 @@ #include "processor/logging.h" #include "processor/scoped_ptr.h" -using google_breakpad::StaticRangeMap; -using google_breakpad::RangeMap; - +namespace { // Types used for testing. typedef int AddressType; typedef int EntryType; -typedef StaticRangeMap< AddressType, EntryType > TestMap; -typedef RangeMap< AddressType, EntryType > RMap; +typedef google_breakpad::StaticRangeMap< AddressType, EntryType > TestMap; +typedef google_breakpad::RangeMap< AddressType, EntryType > RMap; // RangeTest contains data to use for store and retrieve tests. See // RunTests for descriptions of the tests. @@ -75,96 +73,97 @@ struct RangeTestSet { unsigned int range_test_count; }; -namespace { - // These tests will be run sequentially. The first set of tests exercises - // most functions of RangeTest, and verifies all of the bounds-checking. - const RangeTest range_tests_0[] = { - { INT_MIN, 16, 1, true }, // lowest possible range - { -2, 5, 2, true }, // a range through zero - { INT_MAX - 9, 11, 3, false }, // tests anti-overflow - { INT_MAX - 9, 10, 4, true }, // highest possible range - { 5, 0, 5, false }, // tests anti-zero-size - { 5, 1, 6, true }, // smallest possible range - { -20, 15, 7, true }, // entirely negative - - { 10, 10, 10, true }, // causes the following tests to fail - { 9, 10, 11, false }, // one-less base, one-less high - { 9, 11, 12, false }, // one-less base, identical high - { 9, 12, 13, false }, // completely contains existing - { 10, 9, 14, false }, // identical base, one-less high - { 10, 10, 15, false }, // exactly identical to existing range - { 10, 11, 16, false }, // identical base, one-greater high - { 11, 8, 17, false }, // contained completely within - { 11, 9, 18, false }, // one-greater base, identical high - { 11, 10, 19, false }, // one-greater base, one-greater high - { 9, 2, 20, false }, // overlaps bottom by one - { 10, 1, 21, false }, // overlaps bottom by one, contained - { 19, 1, 22, false }, // overlaps top by one, contained - { 19, 2, 23, false }, // overlaps top by one - - { 9, 1, 24, true }, // directly below without overlap - { 20, 1, 25, true }, // directly above without overlap - - { 6, 3, 26, true }, // exactly between two ranges, gapless - { 7, 3, 27, false }, // tries to span two ranges - { 7, 5, 28, false }, // tries to span three ranges - { 4, 20, 29, false }, // tries to contain several ranges - - { 30, 50, 30, true }, - { 90, 25, 31, true }, - { 35, 65, 32, false }, // tries to span two noncontiguous - { 120, 10000, 33, true }, // > 8-bit - { 20000, 20000, 34, true }, // > 8-bit - { 0x10001, 0x10001, 35, true }, // > 16-bit - - { 27, -1, 36, false } // tests high < base - }; - - // Attempt to fill the entire space. The entire space must be filled with - // three stores because AddressType is signed for these tests, so RangeMap - // treats the size as signed and rejects sizes that appear to be negative. - // Even if these tests were run as unsigned, two stores would be needed - // to fill the space because the entire size of the space could only be - // described by using one more bit than would be present in AddressType. - const RangeTest range_tests_1[] = { - { INT_MIN, INT_MAX, 50, true }, // From INT_MIN to -2, inclusive - { -1, 2, 51, true }, // From -1 to 0, inclusive - { 1, INT_MAX, 52, true }, // From 1 to INT_MAX, inclusive - { INT_MIN, INT_MAX, 53, false }, // Can't fill the space twice - { -1, 2, 54, false }, - { 1, INT_MAX, 55, false }, - { -3, 6, 56, false }, // -3 to 2, inclusive - spans 3 ranges - }; - - // A light round of testing to verify that RetrieveRange does the right - // the right thing at the extremities of the range when nothing is stored - // there. Checks are forced without storing anything at the extremities - // by setting size = 0. - const RangeTest range_tests_2[] = { - { INT_MIN, 0, 100, false }, // makes RetrieveRange check low end - { -1, 3, 101, true }, - { INT_MAX, 0, 102, false }, // makes RetrieveRange check high end - }; - - // Similar to the previous test set, but with a couple of ranges closer - // to the extremities. - const RangeTest range_tests_3[] = { - { INT_MIN + 1, 1, 110, true }, - { INT_MAX - 1, 1, 111, true }, - { INT_MIN, 0, 112, false }, // makes RetrieveRange check low end - { INT_MAX, 0, 113, false } // makes RetrieveRange check high end - }; - - // The range map is cleared between sets of tests listed here. - const RangeTestSet range_test_sets[] = { - { range_tests_0, sizeof(range_tests_0) / sizeof(RangeTest) }, - { range_tests_1, sizeof(range_tests_1) / sizeof(RangeTest) }, - { range_tests_2, sizeof(range_tests_2) / sizeof(RangeTest) }, - { range_tests_3, sizeof(range_tests_3) / sizeof(RangeTest) }, - { range_tests_0, sizeof(range_tests_0) / sizeof(RangeTest) } // Run again - }; -} +// These tests will be run sequentially. The first set of tests exercises +// most functions of RangeTest, and verifies all of the bounds-checking. +const RangeTest range_tests_0[] = { + { INT_MIN, 16, 1, true }, // lowest possible range + { -2, 5, 2, true }, // a range through zero + { INT_MAX - 9, 11, 3, false }, // tests anti-overflow + { INT_MAX - 9, 10, 4, true }, // highest possible range + { 5, 0, 5, false }, // tests anti-zero-size + { 5, 1, 6, true }, // smallest possible range + { -20, 15, 7, true }, // entirely negative + + { 10, 10, 10, true }, // causes the following tests to fail + { 9, 10, 11, false }, // one-less base, one-less high + { 9, 11, 12, false }, // one-less base, identical high + { 9, 12, 13, false }, // completely contains existing + { 10, 9, 14, false }, // identical base, one-less high + { 10, 10, 15, false }, // exactly identical to existing range + { 10, 11, 16, false }, // identical base, one-greater high + { 11, 8, 17, false }, // contained completely within + { 11, 9, 18, false }, // one-greater base, identical high + { 11, 10, 19, false }, // one-greater base, one-greater high + { 9, 2, 20, false }, // overlaps bottom by one + { 10, 1, 21, false }, // overlaps bottom by one, contained + { 19, 1, 22, false }, // overlaps top by one, contained + { 19, 2, 23, false }, // overlaps top by one + + { 9, 1, 24, true }, // directly below without overlap + { 20, 1, 25, true }, // directly above without overlap + + { 6, 3, 26, true }, // exactly between two ranges, gapless + { 7, 3, 27, false }, // tries to span two ranges + { 7, 5, 28, false }, // tries to span three ranges + { 4, 20, 29, false }, // tries to contain several ranges + + { 30, 50, 30, true }, + { 90, 25, 31, true }, + { 35, 65, 32, false }, // tries to span two noncontiguous + { 120, 10000, 33, true }, // > 8-bit + { 20000, 20000, 34, true }, // > 8-bit + { 0x10001, 0x10001, 35, true }, // > 16-bit + + { 27, -1, 36, false } // tests high < base +}; + +// Attempt to fill the entire space. The entire space must be filled with +// three stores because AddressType is signed for these tests, so RangeMap +// treats the size as signed and rejects sizes that appear to be negative. +// Even if these tests were run as unsigned, two stores would be needed +// to fill the space because the entire size of the space could only be +// described by using one more bit than would be present in AddressType. +const RangeTest range_tests_1[] = { + { INT_MIN, INT_MAX, 50, true }, // From INT_MIN to -2, inclusive + { -1, 2, 51, true }, // From -1 to 0, inclusive + { 1, INT_MAX, 52, true }, // From 1 to INT_MAX, inclusive + { INT_MIN, INT_MAX, 53, false }, // Can't fill the space twice + { -1, 2, 54, false }, + { 1, INT_MAX, 55, false }, + { -3, 6, 56, false }, // -3 to 2, inclusive - spans 3 ranges +}; + +// A light round of testing to verify that RetrieveRange does the right +// the right thing at the extremities of the range when nothing is stored +// there. Checks are forced without storing anything at the extremities +// by setting size = 0. +const RangeTest range_tests_2[] = { + { INT_MIN, 0, 100, false }, // makes RetrieveRange check low end + { -1, 3, 101, true }, + { INT_MAX, 0, 102, false }, // makes RetrieveRange check high end +}; + +// Similar to the previous test set, but with a couple of ranges closer +// to the extremities. +const RangeTest range_tests_3[] = { + { INT_MIN + 1, 1, 110, true }, + { INT_MAX - 1, 1, 111, true }, + { INT_MIN, 0, 112, false }, // makes RetrieveRange check low end + { INT_MAX, 0, 113, false } // makes RetrieveRange check high end +}; + +// The range map is cleared between sets of tests listed here. +const RangeTestSet range_test_sets[] = { + { range_tests_0, sizeof(range_tests_0) / sizeof(RangeTest) }, + { range_tests_1, sizeof(range_tests_1) / sizeof(RangeTest) }, + { range_tests_2, sizeof(range_tests_2) / sizeof(RangeTest) }, + { range_tests_3, sizeof(range_tests_3) / sizeof(RangeTest) }, + { range_tests_0, sizeof(range_tests_0) / sizeof(RangeTest) } // Run again +}; + +} // namespace +namespace google_breakpad { class TestStaticRangeMap : public ::testing::Test { protected: void SetUp() { @@ -194,7 +193,7 @@ class TestStaticRangeMap : public ::testing::Test { void RunTestCase(int test_case); unsigned int kTestCasesCount_; - google_breakpad::RangeMapSerializer<AddressType, EntryType> serializer_; + RangeMapSerializer<AddressType, EntryType> serializer_; }; void TestStaticRangeMap::StoreTest(RMap* range_map, @@ -353,7 +352,7 @@ void TestStaticRangeMap::RetrieveIndexTest(const TestMap* range_map, int set) { void TestStaticRangeMap::RunTestCase(int test_case) { // Maintain the range map in a pointer so that deletion can be meaningfully // tested. - RMap* rmap = new RMap(); + scoped_ptr<RMap> rmap(new RMap()); const RangeTest* range_tests = range_test_sets[test_case].range_tests; unsigned int range_test_count = range_test_sets[test_case].range_test_count; @@ -365,14 +364,14 @@ void TestStaticRangeMap::RunTestCase(int test_case) { range_test_index < range_test_count; ++range_test_index) { const RangeTest* range_test = &range_tests[range_test_index]; - StoreTest(rmap, range_test); + StoreTest(rmap.get(), range_test); if (range_test->expect_storable) ++stored_count; } - char *memaddr = serializer_.Serialize(*rmap, NULL); - TestMap* static_range_map = new TestMap(memaddr); + scoped_array<char> memaddr(serializer_.Serialize(*rmap, NULL)); + scoped_ptr<TestMap> static_range_map(new TestMap(memaddr.get())); // The RangeMap's own count of objects should also match. EXPECT_EQ(static_range_map->GetCount(), stored_count); @@ -382,17 +381,10 @@ void TestStaticRangeMap::RunTestCase(int test_case) { range_test_index < range_test_count; ++range_test_index) { const RangeTest* range_test = &range_tests[range_test_index]; - RetrieveTest(static_range_map, range_test); + RetrieveTest(static_range_map.get(), range_test); } - RetrieveIndexTest(static_range_map, test_case); - - // Clear the map between test sets. If this is the final test set, - // delete the map instead to test destruction. - delete memaddr; - delete static_range_map; - rmap->Clear(); - delete rmap; + RetrieveIndexTest(static_range_map.get(), test_case); } TEST_F(TestStaticRangeMap, TestCase0) { @@ -420,6 +412,8 @@ TEST_F(TestStaticRangeMap, RunTestCase0Again) { RunTestCase(test_case); } +} // namespace google_breakpad + int main(int argc, char *argv[]) { ::testing::InitGoogleTest(&argc, argv); |