aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/RefCntTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/RefCntTest.cpp')
-rw-r--r--tests/RefCntTest.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp
index 8914ccff49..f5345b6a54 100644
--- a/tests/RefCntTest.cpp
+++ b/tests/RefCntTest.cpp
@@ -290,3 +290,21 @@ static sk_sp<FooAbstract> make_foo() {
DEF_TEST(sk_make_sp, r) {
auto x = make_foo();
}
+
+// Test that reset() "adopts" ownership from the caller, even if we are given the same ptr twice
+//
+DEF_TEST(sk_sp_reset, r) {
+ SkRefCnt* rc = new SkRefCnt;
+ REPORTER_ASSERT(r, rc->unique());
+
+ sk_sp<SkRefCnt> sp;
+ sp.reset(rc);
+ // We have transfered our ownership over to sp
+ REPORTER_ASSERT(r, rc->unique());
+
+ rc->ref(); // now "rc" is also an owner
+ REPORTER_ASSERT(r, !rc->unique());
+
+ sp.reset(rc); // this should transfer our ownership over to sp
+ REPORTER_ASSERT(r, rc->unique());
+}