Commit fa492b95 authored by Dominik Charousset's avatar Dominik Charousset

Port the action test to the new framework

parent 26e940bc
...@@ -71,6 +71,7 @@ caf_add_component( ...@@ -71,6 +71,7 @@ caf_add_component(
caf/abstract_group.cpp caf/abstract_group.cpp
caf/abstract_mailbox.cpp caf/abstract_mailbox.cpp
caf/action.cpp caf/action.cpp
caf/action.test.cpp
caf/actor.cpp caf/actor.cpp
caf/actor_addr.cpp caf/actor_addr.cpp
caf/actor_clock.cpp caf/actor_clock.cpp
...@@ -232,7 +233,6 @@ caf_add_component( ...@@ -232,7 +233,6 @@ caf_add_component(
tests/legacy/core-test.cpp tests/legacy/core-test.cpp
tests/legacy/nasty.cpp tests/legacy/nasty.cpp
LEGACY_TEST_SUITES LEGACY_TEST_SUITES
action
actor_clock actor_clock
actor_factory actor_factory
actor_lifetime actor_lifetime
......
...@@ -2,21 +2,15 @@ ...@@ -2,21 +2,15 @@
// the main distribution directory for license terms and copyright or visit // the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE. // https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#define CAF_SUITE action
#include "caf/action.hpp" #include "caf/action.hpp"
#include "core-test.hpp" #include "caf/test/caf_test_main.hpp"
#include "caf/test/fixture/deterministic.hpp"
using namespace caf; #include "caf/test/scenario.hpp"
namespace {
using fixture = test_coordinator_fixture<>; #include "caf/event_based_actor.hpp"
} // namespace using namespace caf;
BEGIN_FIXTURE_SCOPE(fixture)
SCENARIO("actions wrap function calls") { SCENARIO("actions wrap function calls") {
GIVEN("an action wrapping a lambda") { GIVEN("an action wrapping a lambda") {
...@@ -24,21 +18,21 @@ SCENARIO("actions wrap function calls") { ...@@ -24,21 +18,21 @@ SCENARIO("actions wrap function calls") {
THEN("it calls the lambda and transitions from scheduled to invoked") { THEN("it calls the lambda and transitions from scheduled to invoked") {
auto called = false; auto called = false;
auto uut = make_action([&called] { called = true; }); auto uut = make_action([&called] { called = true; });
CHECK(uut.scheduled()); check(uut.scheduled());
uut.run(); uut.run();
CHECK(called); check(called);
} }
} }
WHEN("disposing the action") { WHEN("disposing the action") {
THEN("it transitions to disposed and run no longer calls the lambda") { THEN("it transitions to disposed and run no longer calls the lambda") {
auto called = false; auto called = false;
auto uut = make_action([&called] { called = true; }); auto uut = make_action([&called] { called = true; });
CHECK(uut.scheduled()); check(uut.scheduled());
uut.dispose(); uut.dispose();
CHECK(uut.disposed()); check(uut.disposed());
uut.run(); uut.run();
CHECK(!called); check(!called);
CHECK(uut.disposed()); check(uut.disposed());
} }
} }
WHEN("running the action multiple times") { WHEN("running the action multiple times") {
...@@ -48,7 +42,7 @@ SCENARIO("actions wrap function calls") { ...@@ -48,7 +42,7 @@ SCENARIO("actions wrap function calls") {
uut.run(); uut.run();
uut.run(); uut.run();
uut.run(); uut.run();
CHECK_EQ(n, 3); check_eq(n, 3);
} }
} }
WHEN("converting an action to a disposable") { WHEN("converting an action to a disposable") {
...@@ -56,13 +50,15 @@ SCENARIO("actions wrap function calls") { ...@@ -56,13 +50,15 @@ SCENARIO("actions wrap function calls") {
auto uut = make_action([] {}); auto uut = make_action([] {});
auto d1 = uut.as_disposable(); // const& overload auto d1 = uut.as_disposable(); // const& overload
auto d2 = action{uut}.as_disposable(); // && overload auto d2 = action{uut}.as_disposable(); // && overload
CHECK_EQ(uut.ptr(), d1.ptr()); check_eq(uut.ptr(), d1.ptr());
CHECK_EQ(uut.ptr(), d2.ptr()); check_eq(uut.ptr(), d2.ptr());
} }
} }
} }
} }
WITH_FIXTURE(test::fixture::deterministic) {
SCENARIO("actors run actions that they receive") { SCENARIO("actors run actions that they receive") {
GIVEN("a scheduled actor") { GIVEN("a scheduled actor") {
WHEN("sending it an action") { WHEN("sending it an action") {
...@@ -73,11 +69,13 @@ SCENARIO("actors run actions that they receive") { ...@@ -73,11 +69,13 @@ SCENARIO("actors run actions that they receive") {
}; };
}); });
auto n = 0; auto n = 0;
inject((action), to(aut).with(make_action([&n] { ++n; }))); inject().with(make_action([&n] { ++n; })).to(aut);
CHECK_EQ(n, 1); check_eq(n, 1);
} }
} }
} }
} }
END_FIXTURE_SCOPE() } // WITH_FIXTURE(test::fixture::deterministic)
CAF_TEST_MAIN()
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