Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Unified Diff: tests/RefCntTest.cpp

Issue 1767983002: Fix behavior of sk_sp::reset() and add unittest. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use unique() correctly Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkRefCnt.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RefCntTest.cpp
diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp
index 8914ccff49a092fc2ca8d337cf80a1f9090fb15a..f5345b6a54162354d782bf5466af19f4f1e83e1e 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());
+}
« no previous file with comments | « include/core/SkRefCnt.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698