aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-10-20 13:46:11 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-20 13:46:11 -0700
commit1d932663e12dc5f56a66bb764c9f36eb3bab9502 (patch)
tree3341df9fb664e489586f32203379e13f69a9c0dc /tests
parent41966d49b0cc9dd2250dac4417ed3b365fb6d704 (diff)
SkLazyPtr suitable as a local or class member.
Diffstat (limited to 'tests')
-rw-r--r--tests/LazyPtr.cpp48
-rw-r--r--tests/OnceTest.cpp4
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/LazyPtr.cpp b/tests/LazyPtr.cpp
new file mode 100644
index 0000000000..ff235e6ed3
--- /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);
+ }
+}
diff --git a/tests/OnceTest.cpp b/tests/OnceTest.cpp
index 192abaaee3..e2711f00bb 100644
--- a/tests/OnceTest.cpp
+++ b/tests/OnceTest.cpp
@@ -31,6 +31,8 @@ static void add_six(int* x) {
*x += 6;
}
+namespace {
+
class Racer : public SkRunnable {
public:
SkOnceFlag* once;
@@ -41,6 +43,8 @@ public:
}
};
+} // namespace
+
DEF_TEST(SkOnce_Multithreaded, r) {
const int kTasks = 16;