summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-09-18 13:39:47 +0300
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-09-22 23:33:56 +0300
commit8b9794b1a7276d8ea2957d5aed7169fc0b40e25d (patch)
treee42da349f705a15dca3521e5535b558a79866659 /test
parentc17be060fd910dbcaf7334356743421ac6936e7e (diff)
downloadqtlocation-mapboxgl-8b9794b1a7276d8ea2957d5aed7169fc0b40e25d.tar.gz
[core] Actor/ActorRef - ask calls to void methods
- allows to wait for execution of void methods as well as non-void methods
Diffstat (limited to 'test')
-rw-r--r--test/actor/actor.test.cpp22
-rw-r--r--test/actor/actor_ref.test.cpp22
2 files changed, 44 insertions, 0 deletions
diff --git a/test/actor/actor.test.cpp b/test/actor/actor.test.cpp
index 4c7fc3666d..967dc152d9 100644
--- a/test/actor/actor.test.cpp
+++ b/test/actor/actor.test.cpp
@@ -306,6 +306,28 @@ TEST(Actor, Ask) {
ASSERT_EQ(2, result.get());
}
+TEST(Actor, AskVoid) {
+ // Ask waits for void methods
+
+ struct Test {
+ bool& executed;
+
+ Test(bool& executed_) : executed(executed_) {
+ }
+
+ void doIt() {
+ executed = true;
+ }
+ };
+
+ ThreadPool pool { 1 };
+ bool executed = false;
+ Actor<Test> actor(pool, executed);
+
+ actor.ask(&Test::doIt).get();
+ EXPECT_TRUE(executed);
+}
+
TEST(Actor, NoSelfActorRef) {
// Not all actors need a reference to self
diff --git a/test/actor/actor_ref.test.cpp b/test/actor/actor_ref.test.cpp
index 52b0de295b..20aa1c35c1 100644
--- a/test/actor/actor_ref.test.cpp
+++ b/test/actor/actor_ref.test.cpp
@@ -62,6 +62,28 @@ TEST(ActorRef, Ask) {
EXPECT_EQ(30, ref.ask(&Test::echo, 30).get());
}
+TEST(ActorRef, AskVoid) {
+ // Ask waits for void methods
+
+ struct Test {
+ bool& executed;
+
+ Test(bool& executed_) : executed(executed_) {
+ }
+
+ void doIt() {
+ executed = true;
+ }
+ };
+
+ ThreadPool pool { 1 };
+ bool executed = false;
+ Actor<Test> actor(pool, executed);
+ ActorRef<Test> ref = actor.self();
+
+ ref.ask(&Test::doIt).get();
+ EXPECT_TRUE(executed);
+}
TEST(ActorRef, AskOnDestroyedActor) {
// Tests behavior when calling ask() after the