summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-06-24 16:50:55 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-06-25 16:26:21 +0300
commit57ddb386d8d1cbc71856abd48b62441294a175b8 (patch)
tree023691133f36d9f96b6400947212bd3f528c8ec6 /test
parenta8b6b67dfeb79a2e7904a2aec6354161c4eb1b16 (diff)
downloadqtlocation-mapboxgl-57ddb386d8d1cbc71856abd48b62441294a175b8.tar.gz
Add unit tests for ThreadContext
Diffstat (limited to 'test')
-rw-r--r--test/miscellaneous/thread.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/miscellaneous/thread.cpp b/test/miscellaneous/thread.cpp
index 9767bc4b79..f8d91bf97f 100644
--- a/test/miscellaneous/thread.cpp
+++ b/test/miscellaneous/thread.cpp
@@ -54,6 +54,12 @@ public:
return string;
}
+ bool checkContext() const {
+ return ThreadContext::currentlyOn(ThreadType::Worker)
+ && ThreadContext::getName() == "Test"
+ && ThreadContext::getPriority() == ThreadPriority::Low;
+ }
+
const std::thread::id tid;
};
@@ -100,3 +106,26 @@ TEST(Thread, invoke) {
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}
+
+TEST(Thread, context) {
+ bool isMainThreadContext = ThreadContext::currentlyOn(ThreadType::Main)
+ && ThreadContext::getName() == "Main"
+ && ThreadContext::getPriority() == ThreadPriority::Regular;
+
+ EXPECT_EQ(isMainThreadContext, true);
+
+ const std::thread::id tid = std::this_thread::get_id();
+
+ RunLoop loop(uv_default_loop());
+
+ loop.invoke([&] {
+ Thread<TestObject> thread({"Test", ThreadType::Worker, ThreadPriority::Low}, tid);
+
+ thread.invokeWithResult<bool>(&TestObject::checkContext, [&] (bool inTestThreadContext) {
+ EXPECT_EQ(inTestThreadContext, true);
+ loop.stop();
+ });
+ });
+
+ uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+}