Index: runtime/vm/fixed_cache_test.cc |
diff --git a/runtime/vm/fixed_cache_test.cc b/runtime/vm/fixed_cache_test.cc |
index a4fbf28e83ee0f30e4f9315c919282b0850489e1..b27202890ff1b0368b4003b138ee1809928ea9d4 100644 |
--- a/runtime/vm/fixed_cache_test.cc |
+++ b/runtime/vm/fixed_cache_test.cc |
@@ -44,41 +44,53 @@ UNIT_TEST_CASE(FixedCacheHalfFull) { |
struct Resource { |
- Resource() : id(0), stuff(NULL) {} |
- explicit Resource(int id_) : id(id_), stuff(new int) {} |
+ Resource() : id(0) { copies++; } |
+ explicit Resource(int id_) : id(id_) { copies++; } |
+ |
+ Resource(const Resource& r) { |
+ id = r.id; |
+ copies++; |
+ } |
+ |
+ Resource& operator=(const Resource& r) { |
+ id = r.id; |
+ return *this; |
+ } |
+ |
+ ~Resource() { copies--; } |
int id; |
- int* stuff; |
+ static int copies; |
}; |
-static void freeResource(Resource* res) { |
- delete res->stuff; |
-} |
- |
+int Resource::copies = 0; |
-UNIT_TEST_CASE(FixedCacheFullDeleter) { |
- FixedCache<int, Resource, 6> cache(freeResource); |
- cache.Insert(10, Resource(2)); |
- cache.Insert(20, Resource(4)); |
- cache.Insert(40, Resource(16)); |
- cache.Insert(30, Resource(8)); |
- EXPECT(cache.Lookup(40)->id == 16); |
- EXPECT(cache.Lookup(5) == NULL); |
- EXPECT(cache.Lookup(0) == NULL); |
- // Insert in the front, middle. |
- cache.Insert(5, Resource(1)); |
- cache.Insert(15, Resource(3)); |
- cache.Insert(25, Resource(6)); |
- // 40 got removed by shifting. |
- EXPECT(cache.Lookup(40) == NULL); |
- EXPECT(cache.Lookup(5)->id == 1); |
- EXPECT(cache.Lookup(15)->id == 3); |
- EXPECT(cache.Lookup(25)->id == 6); |
+UNIT_TEST_CASE(FixedCacheFullResource) { |
+ { |
+ FixedCache<int, Resource, 6> cache; |
+ cache.Insert(10, Resource(2)); |
+ cache.Insert(20, Resource(4)); |
+ cache.Insert(40, Resource(16)); |
+ cache.Insert(30, Resource(8)); |
+ EXPECT(cache.Lookup(40)->id == 16); |
+ EXPECT(cache.Lookup(5) == NULL); |
+ EXPECT(cache.Lookup(0) == NULL); |
+ // Insert in the front, middle. |
+ cache.Insert(5, Resource(1)); |
+ cache.Insert(15, Resource(3)); |
+ cache.Insert(25, Resource(6)); |
+ // 40 got removed by shifting. |
+ EXPECT(cache.Lookup(40) == NULL); |
+ EXPECT(cache.Lookup(5)->id == 1); |
+ EXPECT(cache.Lookup(15)->id == 3); |
+ EXPECT(cache.Lookup(25)->id == 6); |
- // Insert at end top - 30 gets replaced by 40. |
- cache.Insert(40, Resource(16)); |
- EXPECT(cache.Lookup(40)->id == 16); |
- EXPECT(cache.Lookup(30) == NULL); |
+ // Insert at end top - 30 gets replaced by 40. |
+ cache.Insert(40, Resource(16)); |
+ EXPECT(cache.Lookup(40)->id == 16); |
+ EXPECT(cache.Lookup(30) == NULL); |
+ } |
+ EXPECT(Resource::copies == 0); |
} |
} // namespace dart |