aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RefDictTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-01-25 23:36:05 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-01-25 23:36:05 +0000
commit0e190d0e126991cfba4bc7415c1911761d7be87b (patch)
tree93cee043ffa6c09206bd63ff523d0bd17f8e31f4 /tests/RefDictTest.cpp
parent02cc5aa736086320649d8a932515691ae18a0dd5 (diff)
add refdict class, for holding a dictionary of reference-counted objects
-- experimental git-svn-id: http://skia.googlecode.com/svn/trunk@730 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/RefDictTest.cpp')
-rw-r--r--tests/RefDictTest.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/RefDictTest.cpp b/tests/RefDictTest.cpp
new file mode 100644
index 0000000000..61f64e9a2c
--- /dev/null
+++ b/tests/RefDictTest.cpp
@@ -0,0 +1,52 @@
+#include "Test.h"
+#include "SkRefDict.h"
+
+class TestRC : public SkRefCnt {
+};
+
+static void TestRefDict(skiatest::Reporter* reporter) {
+ TestRC data0, data1;
+ SkRefDict dict;
+
+ REPORTER_ASSERT(reporter, NULL == dict.find(NULL));
+ REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
+ REPORTER_ASSERT(reporter, NULL == dict.find("bar"));
+
+ dict.set("foo", &data0);
+ REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
+ REPORTER_ASSERT(reporter, 2 == data0.getRefCnt());
+
+ dict.set("foo", &data0);
+ REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
+ REPORTER_ASSERT(reporter, 2 == data0.getRefCnt());
+
+ dict.set("foo", &data1);
+ REPORTER_ASSERT(reporter, &data1 == dict.find("foo"));
+ REPORTER_ASSERT(reporter, 1 == data0.getRefCnt());
+ REPORTER_ASSERT(reporter, 2 == data1.getRefCnt());
+
+ dict.set("foo", NULL);
+ REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
+ REPORTER_ASSERT(reporter, 1 == data0.getRefCnt());
+ REPORTER_ASSERT(reporter, 1 == data1.getRefCnt());
+
+ dict.set("foo", &data0);
+ dict.set("bar", &data1);
+ REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
+ REPORTER_ASSERT(reporter, &data1 == dict.find("bar"));
+ REPORTER_ASSERT(reporter, 2 == data0.getRefCnt());
+ REPORTER_ASSERT(reporter, 2 == data1.getRefCnt());
+
+ dict.set("foo", &data1);
+ REPORTER_ASSERT(reporter, &data1 == dict.find("foo"));
+ REPORTER_ASSERT(reporter, &data1 == dict.find("bar"));
+ REPORTER_ASSERT(reporter, 1 == data0.getRefCnt());
+ REPORTER_ASSERT(reporter, 3 == data1.getRefCnt());
+
+ dict.removeAll();
+ REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
+ REPORTER_ASSERT(reporter, NULL == dict.find("bar"));
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("RefDict", RefDictTestClass, TestRefDict)