Chromium Code Reviews| Index: tests/RefCntTest.cpp |
| diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp |
| index 8914ccff49a092fc2ca8d337cf80a1f9090fb15a..f9be9e80ba51ba12e8be652c861b8c876b3bfcca 100644 |
| --- a/tests/RefCntTest.cpp |
| +++ b/tests/RefCntTest.cpp |
| @@ -290,3 +290,23 @@ 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, 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.
|
| + |
| + sk_sp<SkRefCnt> sp; |
| + sp.reset(rc); |
| + // We have transfered our ownership over to sp |
| + REPORTER_ASSERT(r, 1 == rc->unique()); |
| + |
| + rc->ref(); // now "rc" is also an owner |
| +#ifdef SK_DEBUG |
| + REPORTER_ASSERT(r, 2 == rc->getRefCnt()); |
| +#endif |
| + |
| + sp.reset(rc); // this should transfer our ownership over to sp |
| + REPORTER_ASSERT(r, 1 == rc->unique()); |
| +} |