summaryrefslogtreecommitdiff
path: root/test/util/async_task.test.cpp
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-10-28 17:12:58 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-05 11:03:29 +0200
commit15715b911ccfb3d2fb912da820ca9fe462d35f73 (patch)
tree5004e352e2f1730ef7b2fd46fc8b77c2773dd3fd /test/util/async_task.test.cpp
parent5b38cfee18800cbb3c6a3186882744592662c3d6 (diff)
downloadqtlocation-mapboxgl-15715b911ccfb3d2fb912da820ca9fe462d35f73.tar.gz
[core] Add Scheduler::scheduleAndReplyValue() API
Diffstat (limited to 'test/util/async_task.test.cpp')
-rw-r--r--test/util/async_task.test.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/util/async_task.test.cpp b/test/util/async_task.test.cpp
index 682926a17d..214e490fd8 100644
--- a/test/util/async_task.test.cpp
+++ b/test/util/async_task.test.cpp
@@ -151,3 +151,22 @@ TEST(AsyncTask, ThreadSafety) {
// a valid result, although very unlikely (I hope).
EXPECT_GT(count, 0u);
}
+
+TEST(AsyncTask, scheduleAndReplyValue) {
+ RunLoop loop;
+ std::thread::id caller_id = std::this_thread::get_id();
+
+ auto runInBackground = [caller_id]() -> int {
+ EXPECT_NE(caller_id, std::this_thread::get_id());
+ return 42;
+ };
+ auto onResult = [caller_id, &loop](int res) {
+ EXPECT_EQ(caller_id, std::this_thread::get_id());
+ EXPECT_EQ(42, res);
+ loop.stop();
+ };
+
+ auto sheduler = Scheduler::GetBackground();
+ sheduler->scheduleAndReplyValue(runInBackground, onResult);
+ loop.run();
+} \ No newline at end of file