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); |
+ } |
+} |