aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/HashTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/HashTest.cpp')
-rw-r--r--tests/HashTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/HashTest.cpp b/tests/HashTest.cpp
index 4a884e3b5b..667f8ea4c0 100644
--- a/tests/HashTest.cpp
+++ b/tests/HashTest.cpp
@@ -6,6 +6,7 @@
*/
#include "SkChecksum.h"
+#include "SkRefCnt.h"
#include "SkString.h"
#include "SkTHash.h"
#include "Test.h"
@@ -65,6 +66,21 @@ DEF_TEST(HashMap, r) {
map.reset();
REPORTER_ASSERT(r, map.count() == 0);
+
+ {
+ // Test that we don't leave dangling values in empty slots.
+ SkTHashMap<int, sk_sp<SkRefCnt>> refMap;
+ auto ref = sk_make_sp<SkRefCnt>();
+ REPORTER_ASSERT(r, ref->unique());
+
+ refMap.set(0, ref);
+ REPORTER_ASSERT(r, refMap.count() == 1);
+ REPORTER_ASSERT(r, !ref->unique());
+
+ refMap.remove(0);
+ REPORTER_ASSERT(r, refMap.count() == 0);
+ REPORTER_ASSERT(r, ref->unique());
+ }
}
DEF_TEST(HashSet, r) {