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

Unified Diff: tests/RefCntTest.cpp

Issue 1752093002: sk_sp: Covariant Move Constructor and Move Assignment (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-03-01 (Tuesday) 18:11:07 EST Created 4 years, 10 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 e3f41bdd5d5fc78877aa0d710fa3e7e9658f05b9..c5693e790b40ede451265ef72f83dffb7a98e206 100644
--- a/tests/RefCntTest.cpp
+++ b/tests/RefCntTest.cpp
@@ -134,11 +134,26 @@ public:
}
};
-DEF_TEST(sk_sp, reporter) {
+struct EffectImpl : public Effect {
+ static sk_sp<EffectImpl> Create() {
+ return sk_sp<EffectImpl>(new EffectImpl);
+ }
+ int fValue;
+};
+static sk_sp<Effect> make_effect() {
+ auto foo = EffectImpl::Create();
+ foo->fValue = 42;
+ return std::move(foo);
+}
+
+static void reset_counters() {
gRefCounter = 0;
gUnrefCounter = 0;
gNewCounter = 0;
gDeleteCounter = 0;
+}
+DEF_TEST(sk_sp, reporter) {
+ reset_counters();
Paint paint;
REPORTER_ASSERT(reporter, paint.fEffect.get() == nullptr);
@@ -167,5 +182,68 @@ DEF_TEST(sk_sp, reporter) {
delete paint.get()->method();
check(reporter, 2, 1, 2, 1);
+
+ paint.set(nullptr);
+ e = nullptr;
+ paint2.set(nullptr);
+ check(reporter, 2, 4, 2, 2);
+
+ reset_counters();
+ {
+ // Test convertable sk_sp assignment.
mtklein 2016/03/01 23:19:14 convertible, fwiw
hal.canary 2016/03/01 23:21:09 fixed
+ check(reporter, 0, 0, 0, 0);
+ sk_sp<Effect> foo(nullptr);
+ REPORTER_ASSERT(reporter, !foo);
+ foo = make_effect();
+ REPORTER_ASSERT(reporter, foo);
+ check(reporter, 0, 0, 1, 0);
+ }
+ check(reporter, 0, 1, 1, 1);
+
+ // Test passing convertable rvalue into funtion.
+ reset_counters();
+ paint.set(EffectImpl::Create());
+ check(reporter, 0, 0, 1, 0);
+ paint.set(nullptr);
+ check(reporter, 0, 1, 1, 1);
+
+ reset_counters();
+ auto baz = EffectImpl::Create();
+ check(reporter, 0, 0, 1, 0);
+ paint.set(std::move(baz));
+ check(reporter, 0, 0, 1, 0);
+ REPORTER_ASSERT(reporter, !baz);
+ paint.set(nullptr);
+ check(reporter, 0, 1, 1, 1);
+
+ reset_counters();
+ {
+ // test comparison operator with convertable type.
+ sk_sp<EffectImpl> bar1 = EffectImpl::Create();
+ sk_sp<Effect> bar2(bar1); // convertable copy constructor
+ check(reporter, 1, 0, 1, 0);
+ REPORTER_ASSERT(reporter, bar1);
+ REPORTER_ASSERT(reporter, bar2);
+ REPORTER_ASSERT(reporter, bar1 == bar2);
+ REPORTER_ASSERT(reporter, bar2 == bar1);
+ REPORTER_ASSERT(reporter, !(bar1 != bar2));
+ REPORTER_ASSERT(reporter, !(bar2 != bar1));
+ sk_sp<Effect> bar3(nullptr);
+ bar3 = bar1; // convertable copy assignment
+ check(reporter, 2, 0, 1, 0);
+
+ }
+ check(reporter, 2, 3, 1, 1);
+
+ // test passing convertable copy into funtion.
+ reset_counters();
+ baz = EffectImpl::Create();
+ check(reporter, 0, 0, 1, 0);
+ paint.set(baz);
+ check(reporter, 1, 0, 1, 0);
+ baz = nullptr;
+ check(reporter, 1, 1, 1, 0);
+ paint.set(nullptr);
+ check(reporter, 1, 2, 1, 1);
}
« 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