summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-01-20 17:49:25 +0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-01-20 19:54:20 +0200
commita11f7d6ef3a8ff00371346412ca9b3b72f17ce15 (patch)
tree06a17ae5234150b5a8db20988d91cba9b88e3359
parentadcd0eaaac76305402049c23528f36d30c8a7277 (diff)
downloadqtlocation-mapboxgl-a11f7d6ef3a8ff00371346412ca9b3b72f17ce15.tar.gz
[tests] Added utests for RunLoop refcounting
-rw-r--r--test/miscellaneous/run_loop.cpp75
-rw-r--r--test/test.gypi1
2 files changed, 76 insertions, 0 deletions
diff --git a/test/miscellaneous/run_loop.cpp b/test/miscellaneous/run_loop.cpp
new file mode 100644
index 0000000000..f00f7248b5
--- /dev/null
+++ b/test/miscellaneous/run_loop.cpp
@@ -0,0 +1,75 @@
+#include <mbgl/util/run_loop.hpp>
+#include <mbgl/util/timer.hpp>
+
+#include "../fixtures/util.hpp"
+
+using namespace mbgl::util;
+
+TEST(RunLoop, Stop) {
+ RunLoop loop(RunLoop::Type::New);
+
+ Timer timer;
+ timer.start(mbgl::Duration::zero(), mbgl::Duration::zero(), [&] {
+ loop.stop();
+ });
+
+ loop.run();
+}
+
+TEST(RunLoop, MultipleStop) {
+ RunLoop loop(RunLoop::Type::New);
+
+ Timer timer;
+ timer.start(mbgl::Duration::zero(), mbgl::Duration::zero(), [&] {
+ loop.stop();
+ loop.stop();
+ loop.stop();
+ loop.stop();
+ });
+
+ loop.run();
+}
+
+TEST(RunLoop, UnrefShouldStop) {
+ RunLoop loop(RunLoop::Type::New);
+
+ Timer timer;
+ timer.start(mbgl::Duration::zero(), mbgl::Duration::zero(), [&] {
+ loop.unref();
+ });
+
+ loop.run();
+}
+
+TEST(RunLoop, RefUnref) {
+ RunLoop loop(RunLoop::Type::New);
+
+ Timer timer;
+ auto zero = mbgl::Duration::zero();
+
+ auto cb3 = [&] {
+ loop.stop();
+ };
+
+ auto cb2 = [&] {
+ loop.unref();
+ loop.unref();
+
+ loop.ref();
+
+ timer.start(zero, zero, cb3);
+ };
+
+ auto cb1 = [&] {
+ loop.ref();
+ loop.ref();
+
+ loop.unref();
+
+ timer.start(zero, zero, cb2);
+ };
+
+ timer.start(zero, zero, cb1);
+
+ loop.run();
+}
diff --git a/test/test.gypi b/test/test.gypi
index 194744198e..e0d0951759 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -57,6 +57,7 @@
'miscellaneous/mapbox.cpp',
'miscellaneous/merge_lines.cpp',
'miscellaneous/style_parser.cpp',
+ 'miscellaneous/run_loop.cpp',
'miscellaneous/text_conversions.cpp',
'miscellaneous/thread.cpp',
'miscellaneous/thread_local.cpp',