Commit 2de0c407 authored by Dominik Charousset's avatar Dominik Charousset

Add test_constructor_attach() test case

parent 6475f47e
...@@ -894,6 +894,56 @@ void counting_actor(event_based_actor* self) { ...@@ -894,6 +894,56 @@ void counting_actor(event_based_actor* self) {
CAF_CHECK_EQUAL(self->mailbox().count(), 200); CAF_CHECK_EQUAL(self->mailbox().count(), 200);
} }
// tests attach_functor() inside of an actor's constructor
void test_constructor_attach() {
class testee : public event_based_actor {
public:
testee(actor buddy) : m_buddy(buddy) {
attach_functor([=](uint32_t reason) {
send(m_buddy, atom("done"), reason);
});
}
behavior make_behavior() {
return {
on(atom("die")) >> [=] {
quit(exit_reason::user_shutdown);
}
};
}
private:
actor m_buddy;
};
class spawner : public event_based_actor {
public:
spawner() : m_downs(0) {
}
behavior make_behavior() {
m_testee = spawn<testee, monitored>(this);
return {
[=](const down_msg& msg) {
CAF_CHECK_EQUAL(msg.reason, exit_reason::user_shutdown);
if (++m_downs == 2) {
quit(msg.reason);
}
},
on(atom("done"), arg_match) >> [=](uint32_t reason) {
CAF_CHECK_EQUAL(reason, exit_reason::user_shutdown);
if (++m_downs == 2) {
quit(reason);
}
},
others() >> [=] {
forward_to(m_testee);
}
};
}
private:
int m_downs;
actor m_testee;
};
anon_send(spawn<spawner>(), atom("die"));
}
} // namespace <anonymous> } // namespace <anonymous>
int main() { int main() {
...@@ -916,6 +966,9 @@ int main() { ...@@ -916,6 +966,9 @@ int main() {
} }
await_all_actors_done(); await_all_actors_done();
CAF_CHECKPOINT(); CAF_CHECKPOINT();
test_constructor_attach();
await_all_actors_done();
CAF_CHECKPOINT();
shutdown(); shutdown();
CAF_CHECKPOINT(); CAF_CHECKPOINT();
return CAF_TEST_RESULT(); return CAF_TEST_RESULT();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment