From f79430350d9f06a72b307af879d7f3bdec7ff706 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Mon, 23 Jul 2012 14:50:38 +0000 Subject: 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 --- tests/RefCntTest.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'tests/RefCntTest.cpp') 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* array = SkTRefArray::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::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); } -- cgit v1.2.3