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

Unified Diff: tests/ImageCacheTest.cpp

Issue 569303002: Revert of Change SkResourceCache to take a Visitor inside its find(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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 | « src/core/SkResourceCache.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageCacheTest.cpp
diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp
index 9f893bb24c48c6b06024497961475bd8d8e31059..317ed6da155cfc306f70a3e9c7ca0e0b9dbb2b03 100644
--- a/tests/ImageCacheTest.cpp
+++ b/tests/ImageCacheTest.cpp
@@ -27,46 +27,49 @@
virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof(fValue); }
-
- static bool Visitor(const SkResourceCache::Rec& baseRec, void* context) {
- const TestingRec& rec = static_cast<const TestingRec&>(baseRec);
- intptr_t* result = (intptr_t*)context;
-
- *result = rec.fValue;
- return true;
- }
};
}
static const int COUNT = 10;
static const int DIM = 256;
-static void test_cache(skiatest::Reporter* reporter, SkResourceCache& cache, bool testPurge) {
+static void test_cache(skiatest::Reporter* reporter, SkResourceCache& cache,
+ bool testPurge) {
+ SkResourceCache::ID id;
+
for (int i = 0; i < COUNT; ++i) {
TestingKey key(i);
- intptr_t value = -1;
- REPORTER_ASSERT(reporter, !cache.find(key, TestingRec::Visitor, &value));
- REPORTER_ASSERT(reporter, -1 == value);
+ const TestingRec* rec = (const TestingRec*)cache.findAndLock(key);
+ REPORTER_ASSERT(reporter, NULL == rec);
- cache.add(SkNEW_ARGS(TestingRec, (key, i)));
+ TestingRec* newRec = SkNEW_ARGS(TestingRec, (key, i));
+ const TestingRec* addedRec = (const TestingRec*)cache.addAndLock(newRec);
+ REPORTER_ASSERT(reporter, addedRec);
- REPORTER_ASSERT(reporter, cache.find(key, TestingRec::Visitor, &value));
- REPORTER_ASSERT(reporter, i == value);
+ const TestingRec* foundRec = (const TestingRec*)cache.findAndLock(key);
+ REPORTER_ASSERT(reporter, foundRec == addedRec);
+ REPORTER_ASSERT(reporter, foundRec->fValue == i);
+ cache.unlock(foundRec);
+ cache.unlock(addedRec);
}
if (testPurge) {
// stress test, should trigger purges
for (size_t i = 0; i < COUNT * 100; ++i) {
TestingKey key(i);
- cache.add(SkNEW_ARGS(TestingRec, (key, i)));
+ SkResourceCache::ID id = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, i)));
+ REPORTER_ASSERT(reporter, id);
+ cache.unlock(id);
}
}
// test the originals after all that purging
for (int i = 0; i < COUNT; ++i) {
- intptr_t value;
- (void)cache.find(TestingKey(i), TestingRec::Visitor, &value);
+ id = cache.findAndLock(TestingKey(i));
+ if (id) {
+ cache.unlock(id);
+ }
}
cache.setTotalByteLimit(0);
@@ -106,11 +109,15 @@
TestingKey key(1);
- cache.add(SkNEW_ARGS(TestingRec, (key, 2)));
- cache.add(SkNEW_ARGS(TestingRec, (key, 3)));
+ SkResourceCache::ID id1 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 2)));
+ SkResourceCache::ID id2 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 3)));
+ // We don't really care if id1 == id2 as long as unlocking both works.
+ cache.unlock(id1);
+ cache.unlock(id2);
// Lookup can return either value.
- intptr_t value = -1;
- REPORTER_ASSERT(r, cache.find(key, TestingRec::Visitor, &value));
- REPORTER_ASSERT(r, 2 == value || 3 == value);
+ const TestingRec* rec = (const TestingRec*)cache.findAndLock(key);
+ REPORTER_ASSERT(r, rec);
+ REPORTER_ASSERT(r, 2 == rec->fValue || 3 == rec->fValue);
+ cache.unlock(rec);
}
« no previous file with comments | « src/core/SkResourceCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698