aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/UtilsTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-04-16 20:35:47 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-04-16 20:35:47 +0000
commitb00cd7258c5ccf856c0dc72840e082306251b278 (patch)
tree478434cc090185cf4c7f4c5eb43d4951a5291a6f /tests/UtilsTest.cpp
parent51709c748e32bb115103b1468eb507f4ccaa7ee8 (diff)
add SkRefPtr class (for testing at the moment)
git-svn-id: http://skia.googlecode.com/svn/trunk@555 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/UtilsTest.cpp')
-rw-r--r--tests/UtilsTest.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp
index 8a8319c74b..8ec063e77d 100644
--- a/tests/UtilsTest.cpp
+++ b/tests/UtilsTest.cpp
@@ -1,9 +1,50 @@
#include "Test.h"
#include "SkRandom.h"
+#include "SkRefCnt.h"
#include "SkTSearch.h"
#include "SkTSort.h"
#include "SkUtils.h"
+class RefClass : public SkRefCnt {
+public:
+ RefClass(int n) : fN(n) {}
+ int get() const { return fN; }
+
+private:
+ int fN;
+};
+
+static void test_refptr(skiatest::Reporter* reporter) {
+ RefClass* r0 = new RefClass(0);
+
+ SkRefPtr<RefClass> rc0;
+ REPORTER_ASSERT(reporter, rc0.get() == NULL);
+ REPORTER_ASSERT(reporter, !rc0);
+
+ SkRefPtr<RefClass> rc1;
+ REPORTER_ASSERT(reporter, rc0 == rc1);
+ REPORTER_ASSERT(reporter, rc0 != r0);
+
+ rc0 = r0;
+ REPORTER_ASSERT(reporter, rc0);
+ REPORTER_ASSERT(reporter, rc0 != rc1);
+ REPORTER_ASSERT(reporter, rc0 == r0);
+
+ rc1 = rc0;
+ REPORTER_ASSERT(reporter, rc1);
+ REPORTER_ASSERT(reporter, rc0 == rc1);
+ REPORTER_ASSERT(reporter, rc0 == r0);
+
+ rc0 = NULL;
+ REPORTER_ASSERT(reporter, rc0.get() == NULL);
+ REPORTER_ASSERT(reporter, !rc0);
+ REPORTER_ASSERT(reporter, rc0 != rc1);
+
+ r0->unref();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
#define kSEARCH_COUNT 91
static void test_search(skiatest::Reporter* reporter) {
@@ -103,6 +144,7 @@ static void TestUTF(skiatest::Reporter* reporter) {
test_utf16(reporter);
test_search(reporter);
+ test_refptr(reporter);
}
#include "TestClassDef.h"