diff options
author | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-25 23:25:16 +0000 |
---|---|---|
committer | neb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-25 23:25:16 +0000 |
commit | 9e7e0e0c96dcd2773747077ac1041913e73a481a (patch) | |
tree | 715cf95cf9de7f75fd0eca1846cfb2c346c462eb /base/id_map_unittest.cc | |
parent | 1e730344d06a78c40062912a50aa3b4e61fc160d (diff) | |
download | chromium_src-9e7e0e0c96dcd2773747077ac1041913e73a481a.zip chromium_src-9e7e0e0c96dcd2773747077ac1041913e73a481a.tar.gz chromium_src-9e7e0e0c96dcd2773747077ac1041913e73a481a.tar.bz2 |
Refactor Pepper device API
Track Pepper DeviceContexts using ID (and reclaim them upon shutdown)
Refactor device-specific code into pepper_devices.h
Review URL: http://codereview.chromium.org/548100
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37060 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/id_map_unittest.cc')
-rw-r--r-- | base/id_map_unittest.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/base/id_map_unittest.cc b/base/id_map_unittest.cc index 7b12e35..58abf96 100644 --- a/base/id_map_unittest.cc +++ b/base/id_map_unittest.cc @@ -14,6 +14,14 @@ class IDMapTest : public testing::Test { class TestObject { }; +class DestructorCounter { + public: + explicit DestructorCounter(int* counter) : counter_(counter) {} + ~DestructorCounter() { ++(*counter_); } + private: + int* counter_; +}; + TEST_F(IDMapTest, Basic) { IDMap<TestObject> map; EXPECT_TRUE(map.IsEmpty()); @@ -103,4 +111,76 @@ TEST_F(IDMapTest, IteratorRemainsValidWhenRemovingOtherElements) { } } +TEST_F(IDMapTest, OwningPointersDeletesThemOnRemove) { + const int kCount = 3; + + int external_del_count = 0; + DestructorCounter* external_obj[kCount]; + int map_external_ids[kCount]; + + int owned_del_count = 0; + DestructorCounter* owned_obj[kCount]; + int map_owned_ids[kCount]; + + IDMap<DestructorCounter> map_external; + IDMap<DestructorCounter, IDMapOwnPointer> map_owned; + + for (int i = 0; i < kCount; ++i) { + external_obj[i] = new DestructorCounter(&external_del_count); + map_external_ids[i] = map_external.Add(external_obj[i]); + + owned_obj[i] = new DestructorCounter(&owned_del_count); + map_owned_ids[i] = map_owned.Add(owned_obj[i]); + } + + for (int i = 0; i < kCount; ++i) { + EXPECT_EQ(external_del_count, 0); + EXPECT_EQ(owned_del_count, i); + + map_external.Remove(map_external_ids[i]); + map_owned.Remove(map_owned_ids[i]); + } + + for (int i = 0; i < kCount; ++i) { + delete external_obj[i]; + } + + EXPECT_EQ(external_del_count, kCount); + EXPECT_EQ(owned_del_count, kCount); +} + +TEST_F(IDMapTest, OwningPointersDeletesThemOnDestruct) { + const int kCount = 3; + + int external_del_count = 0; + DestructorCounter* external_obj[kCount]; + int map_external_ids[kCount]; + + int owned_del_count = 0; + DestructorCounter* owned_obj[kCount]; + int map_owned_ids[kCount]; + + { + IDMap<DestructorCounter> map_external; + IDMap<DestructorCounter, IDMapOwnPointer> map_owned; + + for (int i = 0; i < kCount; ++i) { + external_obj[i] = new DestructorCounter(&external_del_count); + map_external_ids[i] = map_external.Add(external_obj[i]); + + owned_obj[i] = new DestructorCounter(&owned_del_count); + map_owned_ids[i] = map_owned.Add(owned_obj[i]); + } + } + + EXPECT_EQ(external_del_count, 0); + + for (int i = 0; i < kCount; ++i) { + delete external_obj[i]; + } + + EXPECT_EQ(external_del_count, kCount); + EXPECT_EQ(owned_del_count, kCount); +} + } // namespace |