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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « include/core/SkRefCnt.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkRefCnt.h" 8 #include "SkRefCnt.h"
9 #include "SkThreadUtils.h" 9 #include "SkThreadUtils.h"
10 #include "SkTypes.h" 10 #include "SkTypes.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 }; 283 };
284 } 284 }
285 static sk_sp<FooAbstract> make_foo() { 285 static sk_sp<FooAbstract> make_foo() {
286 // can not cast FooConcrete to FooAbstract. 286 // can not cast FooConcrete to FooAbstract.
287 // can cast FooConcrete* to FooAbstract*. 287 // can cast FooConcrete* to FooAbstract*.
288 return sk_make_sp<FooConcrete>(); 288 return sk_make_sp<FooConcrete>();
289 } 289 }
290 DEF_TEST(sk_make_sp, r) { 290 DEF_TEST(sk_make_sp, r) {
291 auto x = make_foo(); 291 auto x = make_foo();
292 } 292 }
293
294 // Test that reset() "adopts" ownership from the caller, even if we are given th e same ptr twice
295 //
296 DEF_TEST(sk_sp_reset, r) {
297 SkRefCnt* rc = new SkRefCnt;
298 REPORTER_ASSERT(r, rc->unique());
299
300 sk_sp<SkRefCnt> sp;
301 sp.reset(rc);
302 // We have transfered our ownership over to sp
303 REPORTER_ASSERT(r, rc->unique());
304
305 rc->ref(); // now "rc" is also an owner
306 REPORTER_ASSERT(r, !rc->unique());
307
308 sp.reset(rc); // this should transfer our ownership over to sp
309 REPORTER_ASSERT(r, rc->unique());
310 }
OLDNEW
« 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