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

Side by Side Diff: tests/RefCntTest.cpp

Issue 1773453002: Add element_type, swap, operators, fix reset on sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« include/core/SkRefCnt.h ('K') | « include/private/SkTLogic.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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // test passing convertible copy into funtion. 265 // test passing convertible copy into funtion.
266 reset_counters(); 266 reset_counters();
267 baz = EffectImpl::Create(); 267 baz = EffectImpl::Create();
268 check(reporter, 0, 0, 1, 0); 268 check(reporter, 0, 0, 1, 0);
269 paint.set(baz); 269 paint.set(baz);
270 check(reporter, 1, 0, 1, 0); 270 check(reporter, 1, 0, 1, 0);
271 baz = nullptr; 271 baz = nullptr;
272 check(reporter, 1, 1, 1, 0); 272 check(reporter, 1, 1, 1, 0);
273 paint.set(nullptr); 273 paint.set(nullptr);
274 check(reporter, 1, 2, 1, 1); 274 check(reporter, 1, 2, 1, 1);
275
276 {
277 sk_sp<SkRefCnt> empty;
278 sk_sp<SkRefCnt> notEmpty = sk_make_sp<SkRefCnt>();
279 REPORTER_ASSERT(reporter, empty == sk_sp<SkRefCnt>());
280
281 REPORTER_ASSERT(reporter, notEmpty != empty);
282 REPORTER_ASSERT(reporter, empty != notEmpty);
283
284 REPORTER_ASSERT(reporter, nullptr == empty);
285 REPORTER_ASSERT(reporter, empty == nullptr);
286 REPORTER_ASSERT(reporter, empty == empty);
287
288 REPORTER_ASSERT(reporter, nullptr <= empty);
289 REPORTER_ASSERT(reporter, empty <= nullptr);
290 REPORTER_ASSERT(reporter, empty <= empty);
291
292 REPORTER_ASSERT(reporter, nullptr >= empty);
293 REPORTER_ASSERT(reporter, empty >= nullptr);
294 REPORTER_ASSERT(reporter, empty >= empty);
295 }
296
297 {
298 sk_sp<SkRefCnt> a = sk_make_sp<SkRefCnt>();
299 sk_sp<SkRefCnt> b = sk_make_sp<SkRefCnt>();
300 REPORTER_ASSERT(reporter, a != b);
301 REPORTER_ASSERT(reporter, (a < b) != (b < a));
302 REPORTER_ASSERT(reporter, (b > a) != (a > b));
303 REPORTER_ASSERT(reporter, (a <= b) != (b <= a));
304 REPORTER_ASSERT(reporter, (b >= a) != (a >= b));
305
306 REPORTER_ASSERT(reporter, a == a);
307 REPORTER_ASSERT(reporter, a <= a);
308 REPORTER_ASSERT(reporter, a >= a);
309 }
310
311 {
312 class foo : public SkRefCnt {
313 public:
314 foo() : bar(this) {}
315 void reset() { bar.reset(); }
316 private:
317 sk_sp<foo> bar;
318 };
319 // The following should properly delete the object and not cause undefin ed behavior.
320 // This is an ugly example, but the same issue can arise in more subtle ways.
321 // http://wg21.cmeerw.net/lwg/issue998
322 (new foo)->reset();
323 }
275 } 324 }
276 325
277 namespace { 326 namespace {
278 struct FooAbstract : public SkRefCnt { 327 struct FooAbstract : public SkRefCnt {
279 virtual void f() = 0; 328 virtual void f() = 0;
280 }; 329 };
281 struct FooConcrete : public FooAbstract { 330 struct FooConcrete : public FooAbstract {
282 void f() override {} 331 void f() override {}
283 }; 332 };
284 } 333 }
(...skipping 16 matching lines...) Expand all
301 sp.reset(rc); 350 sp.reset(rc);
302 // We have transfered our ownership over to sp 351 // We have transfered our ownership over to sp
303 REPORTER_ASSERT(r, rc->unique()); 352 REPORTER_ASSERT(r, rc->unique());
304 353
305 rc->ref(); // now "rc" is also an owner 354 rc->ref(); // now "rc" is also an owner
306 REPORTER_ASSERT(r, !rc->unique()); 355 REPORTER_ASSERT(r, !rc->unique());
307 356
308 sp.reset(rc); // this should transfer our ownership over to sp 357 sp.reset(rc); // this should transfer our ownership over to sp
309 REPORTER_ASSERT(r, rc->unique()); 358 REPORTER_ASSERT(r, rc->unique());
310 } 359 }
OLDNEW
« include/core/SkRefCnt.h ('K') | « include/private/SkTLogic.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698