Index: tests/ImageCacheTest.cpp |
diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp |
index a4cfa739890ff08167cc2e959d3a965471ac231c..45dee92a2f02ba4b37436a80732564fb55be7938 100644 |
--- a/tests/ImageCacheTest.cpp |
+++ b/tests/ImageCacheTest.cpp |
@@ -14,8 +14,8 @@ static void* gGlobalAddress; |
struct TestingKey : public SkResourceCache::Key { |
intptr_t fValue; |
- TestingKey(intptr_t value) : fValue(value) { |
- this->init(&gGlobalAddress, sizeof(fValue)); |
+ TestingKey(intptr_t value, uint64_t sharedID = 0) : fValue(value) { |
+ this->init(&gGlobalAddress, sharedID, sizeof(fValue)); |
} |
}; |
struct TestingRec : public SkResourceCache::Rec { |
@@ -71,6 +71,38 @@ static void test_cache(skiatest::Reporter* reporter, SkResourceCache& cache, boo |
cache.setTotalByteLimit(0); |
} |
+static void test_cache_purge_shared_id(skiatest::Reporter* reporter, SkResourceCache& cache) { |
+ for (int i = 0; i < COUNT; ++i) { |
+ TestingKey key(i, i & 1); // every other key will have a 1 for its sharedID |
+ cache.add(SkNEW_ARGS(TestingRec, (key, i))); |
+ } |
+ |
+ // Ensure that everyone is present |
+ for (int i = 0; i < COUNT; ++i) { |
+ TestingKey key(i, i & 1); // every other key will have a 1 for its sharedID |
+ intptr_t value = -1; |
+ |
+ REPORTER_ASSERT(reporter, cache.find(key, TestingRec::Visitor, &value)); |
+ REPORTER_ASSERT(reporter, value == i); |
+ } |
+ |
+ // Now purge the ones that had a non-zero sharedID (the odd-indexed ones) |
+ cache.purgeSharedID(1); |
+ |
+ // Ensure that only the even ones are still present |
+ for (int i = 0; i < COUNT; ++i) { |
+ TestingKey key(i, i & 1); // every other key will have a 1 for its sharedID |
+ intptr_t value = -1; |
+ |
+ if (i & 1) { |
+ REPORTER_ASSERT(reporter, !cache.find(key, TestingRec::Visitor, &value)); |
+ } else { |
+ REPORTER_ASSERT(reporter, cache.find(key, TestingRec::Visitor, &value)); |
+ REPORTER_ASSERT(reporter, value == i); |
+ } |
+ } |
+} |
+ |
#include "SkDiscardableMemoryPool.h" |
static SkDiscardableMemoryPool* gPool; |
@@ -97,6 +129,10 @@ DEF_TEST(ImageCache, reporter) { |
SkResourceCache cache(SkDiscardableMemory::Create); |
test_cache(reporter, cache, false); |
} |
+ { |
+ SkResourceCache cache(defLimit); |
+ test_cache_purge_shared_id(reporter, cache); |
+ } |
} |
DEF_TEST(ImageCache_doubleAdd, r) { |