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

Unified Diff: tests/LazyPtrTest.cpp

Issue 669783002: SkLazyPtr follow ups (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: no static Created 6 years, 2 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 | « tests/LazyPtr.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/LazyPtrTest.cpp
diff --git a/tests/LazyPtr.cpp b/tests/LazyPtrTest.cpp
similarity index 50%
rename from tests/LazyPtr.cpp
rename to tests/LazyPtrTest.cpp
index ff235e6ed3b2dc0e3833a90d72e428c97d00c2c0..f719c2e0bf0bdcd8229192ae5b43e94b6ecdb82e 100644
--- a/tests/LazyPtr.cpp
+++ b/tests/LazyPtrTest.cpp
@@ -2,14 +2,45 @@
#include "SkLazyPtr.h"
#include "SkTaskGroup.h"
+namespace {
+
+struct CreateIntFromFloat {
+ CreateIntFromFloat(float val) : fVal(val) {}
+ int* operator()() const { return SkNEW_ARGS(int, ((int)fVal)); }
+ float fVal;
+};
+
+// As a template argument this must have external linkage.
+void custom_destroy(int* ptr) { *ptr = 99; }
+
+} // namespace
+
DEF_TEST(LazyPtr, r) {
+ // Basic usage: calls SkNEW(int).
SkLazyPtr<int> lazy;
int* ptr = lazy.get();
-
REPORTER_ASSERT(r, ptr);
REPORTER_ASSERT(r, lazy.get() == ptr);
+ // Advanced usage: calls a functor.
+ SkLazyPtr<int> lazyFunctor;
+ int* six = lazyFunctor.get(CreateIntFromFloat(6.4f));
+ REPORTER_ASSERT(r, six);
+ REPORTER_ASSERT(r, 6 == *six);
+
+ // Just makes sure this is safe.
SkLazyPtr<double> neverRead;
+
+ // SkLazyPtr supports custom destroy methods.
+ {
+ SkLazyPtr<int, custom_destroy> customDestroy;
+ ptr = customDestroy.get();
+ // custom_destroy called here.
+ }
+ REPORTER_ASSERT(r, ptr);
+ REPORTER_ASSERT(r, 99 == *ptr);
+ // Since custom_destroy didn't actually delete ptr, we do now.
+ SkDELETE(ptr);
}
namespace {
« no previous file with comments | « tests/LazyPtr.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698