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

Unified Diff: tests/LazyPtr.cpp

Issue 653183006: SkLazyPtr suitable as a local or class member. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: namespace 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 | « src/core/SkLazyPtr.h ('k') | tests/OnceTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/LazyPtr.cpp
diff --git a/tests/LazyPtr.cpp b/tests/LazyPtr.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ff235e6ed3b2dc0e3833a90d72e428c97d00c2c0
--- /dev/null
+++ b/tests/LazyPtr.cpp
@@ -0,0 +1,48 @@
+#include "Test.h"
+#include "SkLazyPtr.h"
+#include "SkTaskGroup.h"
+
+DEF_TEST(LazyPtr, r) {
+ SkLazyPtr<int> lazy;
+ int* ptr = lazy.get();
+
+ REPORTER_ASSERT(r, ptr);
+ REPORTER_ASSERT(r, lazy.get() == ptr);
+
+ SkLazyPtr<double> neverRead;
+}
+
+namespace {
+
+struct Racer : public SkRunnable {
+ Racer() : fLazy(NULL), fSeen(NULL) {}
+
+ virtual void run() SK_OVERRIDE { fSeen = fLazy->get(); }
+
+ SkLazyPtr<int>* fLazy;
+ int* fSeen;
+};
+
+} // namespace
+
+DEF_TEST(LazyPtr_Threaded, r) {
+ static const int kRacers = 321;
+
+ SkLazyPtr<int> lazy;
+
+ Racer racers[kRacers];
+ for (int i = 0; i < kRacers; i++) {
+ racers[i].fLazy = &lazy;
+ }
+
+ SkTaskGroup tg;
+ for (int i = 0; i < kRacers; i++) {
+ tg.add(racers + i);
+ }
+ tg.wait();
+
+ for (int i = 1; i < kRacers; i++) {
+ REPORTER_ASSERT(r, racers[i].fSeen);
+ REPORTER_ASSERT(r, racers[i].fSeen == racers[0].fSeen);
+ }
+}
« no previous file with comments | « src/core/SkLazyPtr.h ('k') | tests/OnceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698