Fix for issue 222001.

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@725 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
SiyangXie@gmail.com 2010-11-04 02:40:06 +00:00
parent bbd8e82a7f
commit 4adb6f4f7b
4 changed files with 211 additions and 213 deletions

View file

@ -131,7 +131,7 @@ class TestAddressMapSerializer : public ::testing::Test {
} }
void TearDown() { void TearDown() {
delete serialized_data_; delete [] serialized_data_;
} }
google_breakpad::AddressMap<AddrType, EntryType> address_map_; google_breakpad::AddressMap<AddrType, EntryType> address_map_;
@ -206,7 +206,7 @@ class TestRangeMapSerializer : public ::testing::Test {
} }
void TearDown() { void TearDown() {
delete serialized_data_; delete [] serialized_data_;
} }
google_breakpad::RangeMap<AddrType, EntryType> range_map_; google_breakpad::RangeMap<AddrType, EntryType> range_map_;
@ -279,7 +279,7 @@ class TestContainedRangeMapSerializer : public ::testing::Test {
} }
void TearDown() { void TearDown() {
delete serialized_data_; delete [] serialized_data_;
} }
google_breakpad::ContainedRangeMap<AddrType, EntryType> crm_map_; google_breakpad::ContainedRangeMap<AddrType, EntryType> crm_map_;

View file

@ -84,7 +84,7 @@ class TestStaticAddressMap : public ::testing::Test {
void TearDown() { void TearDown() {
for (int i = 0; i < kNumberTestCases; ++i) { for (int i = 0; i < kNumberTestCases; ++i) {
delete map_data[i]; delete [] map_data[i];
delete [] testdata[i]; delete [] testdata[i];
} }
} }

View file

@ -42,6 +42,10 @@
#include "processor/logging.h" #include "processor/logging.h"
namespace { namespace {
typedef google_breakpad::ContainedRangeMap<unsigned int, int> CRMMap;
typedef google_breakpad::StaticContainedRangeMap<unsigned int, int> TestMap;
// Each element in test_data contains the expected result when calling // Each element in test_data contains the expected result when calling
// RetrieveRange on an address. // RetrieveRange on an address.
const int test_data[] = { const int test_data[] = {
@ -146,12 +150,10 @@ namespace {
0, // 98 0, // 98
0 // 99 0 // 99
}; };
} // namespace } // namespace
namespace google_breakpad {
typedef google_breakpad::ContainedRangeMap<unsigned int, int> CRMMap;
typedef google_breakpad::StaticContainedRangeMap<unsigned int, int> TestMap;
using google_breakpad::scoped_ptr;
class TestStaticCRMMap : public ::testing::Test { class TestStaticCRMMap : public ::testing::Test {
protected: protected:
@ -167,7 +169,7 @@ class TestStaticCRMMap : public ::testing::Test {
google_breakpad::ContainedRangeMapSerializer<unsigned int, int> serializer_; google_breakpad::ContainedRangeMapSerializer<unsigned int, int> serializer_;
scoped_ptr<char> serialized_data_; scoped_array<char> serialized_data_;
}; };
void TestStaticCRMMap::SetUp() { void TestStaticCRMMap::SetUp() {
@ -236,7 +238,7 @@ TEST_F(TestStaticCRMMap, TestEmptyMap) {
CRMMap empty_crm_map; CRMMap empty_crm_map;
unsigned int size; unsigned int size;
scoped_ptr<char> serialized_data; scoped_array<char> serialized_data;
serialized_data.reset(serializer_.Serialize(&empty_crm_map, &size)); serialized_data.reset(serializer_.Serialize(&empty_crm_map, &size));
scoped_ptr<TestMap> test_map(new TestMap(serialized_data.get())); scoped_ptr<TestMap> test_map(new TestMap(serialized_data.get()));
@ -256,7 +258,7 @@ TEST_F(TestStaticCRMMap, TestSingleElementMap) {
crm_map.StoreRange(10, 10, entry); crm_map.StoreRange(10, 10, entry);
unsigned int size; unsigned int size;
scoped_ptr<char> serialized_data; scoped_array<char> serialized_data;
serialized_data.reset(serializer_.Serialize(&crm_map, &size)); serialized_data.reset(serializer_.Serialize(&crm_map, &size));
scoped_ptr<TestMap> test_map(new TestMap(serialized_data.get())); scoped_ptr<TestMap> test_map(new TestMap(serialized_data.get()));
@ -310,6 +312,8 @@ TEST_F(TestStaticCRMMap, RunTestData) {
#endif // GENERATE_TEST_DATA #endif // GENERATE_TEST_DATA
} }
} // namespace google_breakpad
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);

View file

@ -40,14 +40,12 @@
#include "processor/logging.h" #include "processor/logging.h"
#include "processor/scoped_ptr.h" #include "processor/scoped_ptr.h"
using google_breakpad::StaticRangeMap; namespace {
using google_breakpad::RangeMap;
// Types used for testing. // Types used for testing.
typedef int AddressType; typedef int AddressType;
typedef int EntryType; typedef int EntryType;
typedef StaticRangeMap< AddressType, EntryType > TestMap; typedef google_breakpad::StaticRangeMap< AddressType, EntryType > TestMap;
typedef RangeMap< AddressType, EntryType > RMap; typedef google_breakpad::RangeMap< AddressType, EntryType > RMap;
// RangeTest contains data to use for store and retrieve tests. See // RangeTest contains data to use for store and retrieve tests. See
// RunTests for descriptions of the tests. // RunTests for descriptions of the tests.
@ -75,7 +73,6 @@ struct RangeTestSet {
unsigned int range_test_count; unsigned int range_test_count;
}; };
namespace {
// These tests will be run sequentially. The first set of tests exercises // These tests will be run sequentially. The first set of tests exercises
// most functions of RangeTest, and verifies all of the bounds-checking. // most functions of RangeTest, and verifies all of the bounds-checking.
const RangeTest range_tests_0[] = { const RangeTest range_tests_0[] = {
@ -163,8 +160,10 @@ namespace {
{ range_tests_3, sizeof(range_tests_3) / sizeof(RangeTest) }, { range_tests_3, sizeof(range_tests_3) / sizeof(RangeTest) },
{ range_tests_0, sizeof(range_tests_0) / sizeof(RangeTest) } // Run again { range_tests_0, sizeof(range_tests_0) / sizeof(RangeTest) } // Run again
}; };
}
} // namespace
namespace google_breakpad {
class TestStaticRangeMap : public ::testing::Test { class TestStaticRangeMap : public ::testing::Test {
protected: protected:
void SetUp() { void SetUp() {
@ -194,7 +193,7 @@ class TestStaticRangeMap : public ::testing::Test {
void RunTestCase(int test_case); void RunTestCase(int test_case);
unsigned int kTestCasesCount_; unsigned int kTestCasesCount_;
google_breakpad::RangeMapSerializer<AddressType, EntryType> serializer_; RangeMapSerializer<AddressType, EntryType> serializer_;
}; };
void TestStaticRangeMap::StoreTest(RMap* range_map, 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) { void TestStaticRangeMap::RunTestCase(int test_case) {
// Maintain the range map in a pointer so that deletion can be meaningfully // Maintain the range map in a pointer so that deletion can be meaningfully
// tested. // tested.
RMap* rmap = new RMap(); scoped_ptr<RMap> rmap(new RMap());
const RangeTest* range_tests = range_test_sets[test_case].range_tests; const RangeTest* range_tests = range_test_sets[test_case].range_tests;
unsigned int range_test_count = range_test_sets[test_case].range_test_count; 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 < range_test_count;
++range_test_index) { ++range_test_index) {
const RangeTest* range_test = &range_tests[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) if (range_test->expect_storable)
++stored_count; ++stored_count;
} }
char *memaddr = serializer_.Serialize(*rmap, NULL); scoped_array<char> memaddr(serializer_.Serialize(*rmap, NULL));
TestMap* static_range_map = new TestMap(memaddr); scoped_ptr<TestMap> static_range_map(new TestMap(memaddr.get()));
// The RangeMap's own count of objects should also match. // The RangeMap's own count of objects should also match.
EXPECT_EQ(static_range_map->GetCount(), stored_count); 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 < range_test_count;
++range_test_index) { ++range_test_index) {
const RangeTest* range_test = &range_tests[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); RetrieveIndexTest(static_range_map.get(), 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;
} }
TEST_F(TestStaticRangeMap, TestCase0) { TEST_F(TestStaticRangeMap, TestCase0) {
@ -420,6 +412,8 @@ TEST_F(TestStaticRangeMap, RunTestCase0Again) {
RunTestCase(test_case); RunTestCase(test_case);
} }
} // namespace google_breakpad
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);