Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Unified Diff: runtime/vm/fixed_cache_test.cc

Issue 2734323003: Re-landing of "replace TrySync with Metadata". (Closed)
Patch Set: Address review comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/fixed_cache.h ('k') | runtime/vm/flow_graph_compiler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « runtime/vm/fixed_cache.h ('k') | runtime/vm/flow_graph_compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698