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); |
} |