Add operator* and operator safe-bool to sk_sp.
This greatly reduces the need to use '.get()' in conditionals.
Review URL: https://codereview.chromium.org/1760453004
diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp
index bda4531..60a34ec 100644
--- a/tests/RefCntTest.cpp
+++ b/tests/RefCntTest.cpp
@@ -164,9 +164,31 @@
check(reporter, 0, 0, 1, 0);
REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 1);
+ if (paint.get()) {
+ REPORTER_ASSERT(reporter, true);
+ } else {
+ REPORTER_ASSERT(reporter, false);
+ }
+ if (!paint.get()) {
+ REPORTER_ASSERT(reporter, false);
+ } else {
+ REPORTER_ASSERT(reporter, true);
+ }
+
paint.set(nullptr);
check(reporter, 0, 1, 1, 1);
+ if (paint.get()) {
+ REPORTER_ASSERT(reporter, false);
+ } else {
+ REPORTER_ASSERT(reporter, true);
+ }
+ if (!paint.get()) {
+ REPORTER_ASSERT(reporter, true);
+ } else {
+ REPORTER_ASSERT(reporter, false);
+ }
+
auto e = Create();
REPORTER_ASSERT(reporter, sizeof(e) == sizeof(void*));
@@ -180,9 +202,14 @@
check(reporter, 2, 1, 2, 1);
REPORTER_ASSERT(reporter, paint.fEffect.get()->fRefCnt == 3);
+ // Test sk_sp::operator->
delete paint.get()->method();
check(reporter, 2, 1, 2, 1);
+ // Test sk_sp::operator*
+ delete (*paint.get()).method();
+ check(reporter, 2, 1, 2, 1);
+
paint.set(nullptr);
e = nullptr;
paint2.set(nullptr);