aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RefCntTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/RefCntTest.cpp')
-rw-r--r--tests/RefCntTest.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp
index 4d4ae3f54a..569e4e4602 100644
--- a/tests/RefCntTest.cpp
+++ b/tests/RefCntTest.cpp
@@ -11,9 +11,34 @@
#include "SkRefCnt.h"
#include "SkThreadUtils.h"
#include "SkWeakRefCnt.h"
+#include "SkTRefArray.h"
///////////////////////////////////////////////////////////////////////////////
+class InstCounterClass {
+public:
+ InstCounterClass() { gInstCounter += 1; }
+ ~InstCounterClass() { gInstCounter -= 1; }
+
+ static int gInstCounter;
+};
+
+int InstCounterClass::gInstCounter;
+
+static void test_refarray(skiatest::Reporter* reporter) {
+ REPORTER_ASSERT(reporter, 0 == InstCounterClass::gInstCounter);
+
+ int N = 10;
+ SkTRefArray<InstCounterClass>* array = SkTRefArray<InstCounterClass>::Create(N);
+ REPORTER_ASSERT(reporter, 1 == array->getRefCnt());
+
+ REPORTER_ASSERT(reporter, N == InstCounterClass::gInstCounter);
+ REPORTER_ASSERT(reporter, array->count() == N);
+
+ array->unref();
+ REPORTER_ASSERT(reporter, 0 == InstCounterClass::gInstCounter);
+}
+
static void bounce_ref(void* data) {
SkRefCnt* ref = static_cast<SkRefCnt*>(data);
for (int i = 0; i < 100000; ++i) {
@@ -89,6 +114,7 @@ static void test_weakRefCnt(skiatest::Reporter* reporter) {
static void test_refCntTests(skiatest::Reporter* reporter) {
test_refCnt(reporter);
test_weakRefCnt(reporter);
+ test_refarray(reporter);
}
#include "TestClassDef.h"