Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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, 1 == rc->unique()); | |
|
bungeman-skia
2016/03/06 14:01:44
This reads a little funny with the unexpected thin
reed1
2016/03/06 19:03:43
Done.
| |
| 299 | |
| 300 sk_sp<SkRefCnt> sp; | |
| 301 sp.reset(rc); | |
| 302 // We have transfered our ownership over to sp | |
| 303 REPORTER_ASSERT(r, 1 == rc->unique()); | |
| 304 | |
| 305 rc->ref(); // now "rc" is also an owner | |
| 306 #ifdef SK_DEBUG | |
| 307 REPORTER_ASSERT(r, 2 == rc->getRefCnt()); | |
| 308 #endif | |
| 309 | |
| 310 sp.reset(rc); // this should transfer our ownership over to sp | |
| 311 REPORTER_ASSERT(r, 1 == rc->unique()); | |
| 312 } | |
| OLD | NEW |