aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/UtilsTest.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-07-08 06:48:17 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-08 06:48:17 -0700
commit4ae94ffce5ecf1b71cb5e295b68bf4ec9e697443 (patch)
tree6c734cf27a2f033bfb5f512420860fd035d0bbfa /tests/UtilsTest.cpp
parent3afef1f75f710b8f183113cdc5188416f7d01f28 (diff)
Remove ability for Release code to call getRefCnt() or getWeakRefCnt().
These getRefCnt() methods are not thread safe, so Skia code should not be calling them. unique() is fine. SkDEBUG code (SkASSERTs) can still call getRefCnt() / getWeakRefCnt(). This adds tools/RefCntIs.{h,cpp}, which lets tests make their assertions in both debug and release modes. BUG=skia:2726 R=senorblanco@chromium.org, mtklein@google.com, reed@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/378643003
Diffstat (limited to 'tests/UtilsTest.cpp')
-rw-r--r--tests/UtilsTest.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp
index 438a5cce47..9454b54e5c 100644
--- a/tests/UtilsTest.cpp
+++ b/tests/UtilsTest.cpp
@@ -10,6 +10,7 @@
#include "SkTSearch.h"
#include "SkTSort.h"
#include "SkUtils.h"
+#include "RefCntIs.h"
#include "Test.h"
class RefClass : public SkRefCnt {
@@ -27,30 +28,30 @@ private:
static void test_autounref(skiatest::Reporter* reporter) {
RefClass obj(0);
- REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj, 1));
SkAutoTUnref<RefClass> tmp(&obj);
REPORTER_ASSERT(reporter, &obj == tmp.get());
- REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj, 1));
REPORTER_ASSERT(reporter, &obj == tmp.detach());
- REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj, 1));
REPORTER_ASSERT(reporter, NULL == tmp.detach());
REPORTER_ASSERT(reporter, NULL == tmp.get());
obj.ref();
- REPORTER_ASSERT(reporter, 2 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj, 2));
{
SkAutoTUnref<RefClass> tmp2(&obj);
}
- REPORTER_ASSERT(reporter, 1 == obj.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj, 1));
}
static void test_autostarray(skiatest::Reporter* reporter) {
RefClass obj0(0);
RefClass obj1(1);
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 1));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 1));
{
SkAutoSTArray<2, SkRefPtr<RefClass> > tmp;
@@ -61,14 +62,14 @@ static void test_autostarray(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 4 == tmp.count());
tmp[0] = &obj0;
tmp[1] = &obj1;
- REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 2));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 2));
// test out reset with data in the array (and a new allocation)
tmp.reset(0);
REPORTER_ASSERT(reporter, 0 == tmp.count());
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 1));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 1));
tmp.reset(2); // this should use the preexisting allocation
REPORTER_ASSERT(reporter, 2 == tmp.count());
@@ -77,8 +78,8 @@ static void test_autostarray(skiatest::Reporter* reporter) {
}
// test out destructor with data in the array (and using existing allocation)
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 1));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 1));
{
// test out allocating ctor (this should allocate new memory)
@@ -87,32 +88,32 @@ static void test_autostarray(skiatest::Reporter* reporter) {
tmp[0] = &obj0;
tmp[1] = &obj1;
- REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 2));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 2));
// Test out resut with data in the array and malloced storage
tmp.reset(0);
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 1));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 1));
tmp.reset(2); // this should use the preexisting storage
tmp[0] = &obj0;
tmp[1] = &obj1;
- REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 2));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 2));
tmp.reset(4); // this should force a new malloc
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 1));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 1));
tmp[0] = &obj0;
tmp[1] = &obj1;
- REPORTER_ASSERT(reporter, 2 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 2 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 2));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 2));
}
- REPORTER_ASSERT(reporter, 1 == obj0.getRefCnt());
- REPORTER_ASSERT(reporter, 1 == obj1.getRefCnt());
+ REPORTER_ASSERT(reporter, RefCntIs(obj0, 1));
+ REPORTER_ASSERT(reporter, RefCntIs(obj1, 1));
}
/////////////////////////////////////////////////////////////////////////////