From a67573e25faa81ea65e6fc368f66d3f0c0a5f189 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Fri, 25 Feb 2011 18:10:29 +0000 Subject: http://codereview.appspot.com/4233041/ Add templated version of SkAutoTUnref. Add unittests for it. Remove unused helper apis on SkAutoUnref. git-svn-id: http://skia.googlecode.com/svn/trunk@858 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/UtilsTest.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tests/UtilsTest.cpp') diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp index 8ec063e77d..1e11bdcc2d 100644 --- a/tests/UtilsTest.cpp +++ b/tests/UtilsTest.cpp @@ -43,6 +43,27 @@ static void test_refptr(skiatest::Reporter* reporter) { r0->unref(); } +static void test_autounref(skiatest::Reporter* reporter) { + RefClass obj(0); + REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); + + SkAutoTUnref tmp(&obj); + REPORTER_ASSERT(reporter, &obj == tmp.get()); + REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); + + REPORTER_ASSERT(reporter, &obj == tmp.detach()); + REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); + REPORTER_ASSERT(reporter, NULL == tmp.detach()); + REPORTER_ASSERT(reporter, NULL == tmp.get()); + + obj.ref(); + REPORTER_ASSERT(reporter, 2 == obj.getRefCnt()); + { + SkAutoTUnref tmp2(&obj); + } + REPORTER_ASSERT(reporter, 1 == obj.getRefCnt()); +} + /////////////////////////////////////////////////////////////////////////////// #define kSEARCH_COUNT 91 @@ -145,7 +166,8 @@ static void TestUTF(skiatest::Reporter* reporter) { test_utf16(reporter); test_search(reporter); test_refptr(reporter); + test_autounref(reporter); } #include "TestClassDef.h" -DEFINE_TESTCLASS("UTF", UtfTestClass, TestUTF) +DEFINE_TESTCLASS("Utils", UtfTestClass, TestUTF) -- cgit v1.2.3