aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-23 14:50:38 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-23 14:50:38 +0000
commitf79430350d9f06a72b307af879d7f3bdec7ff706 (patch)
tree2b9a7ca41e1321cd4c549449f7e1f435bd2a95f8 /tests
parent8317e174483903dd3fba41d8e0074112badb1cfd (diff)
add protected method for internal_dispose overrides to jam fRefCnt before
calling destructor. move SkTRefArray to actually inherit from SkRefCnt Review URL: https://codereview.appspot.com/6422057 git-svn-id: http://skia.googlecode.com/svn/trunk@4719 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/RefCntTest.cpp40
1 files changed, 36 insertions, 4 deletions
diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp
index 569e4e4602..5197ffb86b 100644
--- a/tests/RefCntTest.cpp
+++ b/tests/RefCntTest.cpp
@@ -17,10 +17,15 @@
class InstCounterClass {
public:
- InstCounterClass() { gInstCounter += 1; }
- ~InstCounterClass() { gInstCounter -= 1; }
+ InstCounterClass() { fCount = gInstCounter++; }
+ InstCounterClass(const InstCounterClass& src) {
+ fCount = src.fCount;
+ gInstCounter += 1;
+ }
+ virtual ~InstCounterClass() { gInstCounter -= 1; }
static int gInstCounter;
+ int fCount;
};
int InstCounterClass::gInstCounter;
@@ -28,13 +33,40 @@ int InstCounterClass::gInstCounter;
static void test_refarray(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 0 == InstCounterClass::gInstCounter);
- int N = 10;
+ const int N = 10;
SkTRefArray<InstCounterClass>* array = SkTRefArray<InstCounterClass>::Create(N);
+
+ REPORTER_ASSERT(reporter, 1 == array->getRefCnt());
+ REPORTER_ASSERT(reporter, N == array->count());
+
+ REPORTER_ASSERT(reporter, N == InstCounterClass::gInstCounter);
+ array->unref();
+ REPORTER_ASSERT(reporter, 0 == InstCounterClass::gInstCounter);
+
+ // Now test the copy factory
+
+ int i;
+ InstCounterClass* src = new InstCounterClass[N];
+ REPORTER_ASSERT(reporter, N == InstCounterClass::gInstCounter);
+ for (i = 0; i < N; ++i) {
+ REPORTER_ASSERT(reporter, i == src[i].fCount);
+ }
+
+ array = SkTRefArray<InstCounterClass>::Create(src, N);
REPORTER_ASSERT(reporter, 1 == array->getRefCnt());
+ REPORTER_ASSERT(reporter, N == array->count());
+ REPORTER_ASSERT(reporter, 2*N == InstCounterClass::gInstCounter);
+ for (i = 0; i < N; ++i) {
+ REPORTER_ASSERT(reporter, i == (*array)[i].fCount);
+ }
+
+ delete[] src;
REPORTER_ASSERT(reporter, N == InstCounterClass::gInstCounter);
- REPORTER_ASSERT(reporter, array->count() == N);
+ for (i = 0; i < N; ++i) {
+ REPORTER_ASSERT(reporter, i == (*array)[i].fCount);
+ }
array->unref();
REPORTER_ASSERT(reporter, 0 == InstCounterClass::gInstCounter);
}