Commit a850de8e authored by Dominik Charousset's avatar Dominik Charousset

Port actor_factory test to deterministic API

parent cb4f6977
...@@ -16,109 +16,94 @@ ...@@ -16,109 +16,94 @@
* http://www.boost.org/LICENSE_1_0.txt. * * http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/ ******************************************************************************/
#include "caf/config.hpp"
#define CAF_SUITE actor_factory #define CAF_SUITE actor_factory
#include "caf/test/unit_test.hpp"
#include "caf/all.hpp"
#include "caf/actor_registry.hpp" #include "caf/actor_registry.hpp"
#include "caf/test/dsl.hpp"
#include "caf/all.hpp"
using namespace caf; using namespace caf;
using std::endl; using std::endl;
namespace { namespace {
using down_atom = atom_constant<atom("down")>; behavior no_args_1() {
return {};
struct fixture { }
actor_system_config cfg;
behavior no_args_2(event_based_actor*) {
void test_spawn(message args, bool expect_fail = false) { return {};
actor_system system{cfg}; }
scoped_actor self{system};
CAF_MESSAGE("set aut");
strong_actor_ptr res;
std::set<std::string> ifs;
scoped_execution_unit context{&system};
actor_config actor_cfg{&context};
auto aut = system.spawn<actor>("test_actor", std::move(args));
if (expect_fail) {
CAF_REQUIRE(!aut);
return;
}
CAF_REQUIRE(aut);
self->wait_for(*aut);
CAF_MESSAGE("aut done");
}
};
struct test_actor_no_args : event_based_actor { struct no_args_3 : event_based_actor {
using event_based_actor::event_based_actor; using super = event_based_actor;
using super::super;
}; };
struct test_actor_one_arg : event_based_actor { behavior one_arg_1(int value) {
test_actor_one_arg(actor_config& conf, int value) : event_based_actor(conf) {
CAF_CHECK_EQUAL(value, 42); CAF_CHECK_EQUAL(value, 42);
} return {};
}; }
} // namespace <anonymous> behavior one_arg_2(event_based_actor*, int value) {
CAF_CHECK_EQUAL(value, 42);
return {};
}
CAF_TEST_FIXTURE_SCOPE(add_actor_type_tests, fixture) struct one_arg_3 : event_based_actor {
using super = event_based_actor;
CAF_TEST(fun_no_args) { one_arg_3(actor_config& conf, int value) : super(conf) {
auto test_actor_one_arg = [] { CAF_CHECK_EQUAL(value, 42);
CAF_MESSAGE("inside test_actor"); }
}; };
cfg.add_actor_type("test_actor", test_actor_one_arg);
test_spawn(make_message());
CAF_MESSAGE("test_spawn done");
}
CAF_TEST(fun_no_args_selfptr) { struct config : actor_system_config {
auto test_actor_one_arg = [](event_based_actor*) { config() {
CAF_MESSAGE("inside test_actor"); add_actor_type("no_args_1", no_args_1);
}; add_actor_type("no_args_2", no_args_2);
cfg.add_actor_type("test_actor", test_actor_one_arg); add_actor_type<no_args_3>("no_args_3");
test_spawn(make_message()); add_actor_type("one_arg_1", one_arg_1);
} add_actor_type("one_arg_2", one_arg_2);
CAF_TEST(fun_one_arg) { add_actor_type<one_arg_3, const int&>("one_arg_3");
auto test_actor_one_arg = [](int i) { }
CAF_CHECK_EQUAL(i, 42); };
};
cfg.add_actor_type("test_actor", test_actor_one_arg);
test_spawn(make_message(42));
}
CAF_TEST(fun_one_arg_selfptr) { struct fixture : test_coordinator_fixture<config> {
auto test_actor_one_arg = [](event_based_actor*, int i) { template <class... Ts>
CAF_CHECK_EQUAL(i, 42); expected<actor> test_spawn(const char* name, Ts&&... xs) {
}; CAF_MESSAGE("spawn testee of type " << name);
cfg.add_actor_type("test_actor", test_actor_one_arg); actor_config actor_cfg{sys.dummy_execution_unit()};
test_spawn(make_message(42)); return sys.spawn<actor>(name, make_message(std::forward<Ts>(xs)...));
} }
CAF_TEST(class_no_arg_invalid) { error invalid_args = sec::cannot_spawn_actor_from_arguments;
cfg.add_actor_type<test_actor_no_args>("test_actor"); };
test_spawn(make_message(42), true);
}
CAF_TEST(class_no_arg_valid) { } // namespace <anonymous>
cfg.add_actor_type<test_actor_no_args>("test_actor");
test_spawn(make_message()); CAF_TEST_FIXTURE_SCOPE(add_actor_type_tests, fixture)
}
CAF_TEST(class_one_arg_invalid) { CAF_TEST(no_args) {
cfg.add_actor_type<test_actor_one_arg, const int&>("test_actor"); CAF_CHECK_NOT_EQUAL(test_spawn("no_args_1"), none);
test_spawn(make_message(), true); CAF_CHECK_NOT_EQUAL(test_spawn("no_args_2"), none);
CAF_CHECK_NOT_EQUAL(test_spawn("no_args_3"), none);
CAF_CHECK_EQUAL(test_spawn("no_args_1", 42), invalid_args);
CAF_CHECK_EQUAL(test_spawn("no_args_2", 42), invalid_args);
CAF_CHECK_EQUAL(test_spawn("no_args_3", 42), invalid_args);
} }
CAF_TEST(class_one_arg_valid) { CAF_TEST(one_arg) {
cfg.add_actor_type<test_actor_one_arg, const int&>("test_actor"); CAF_CHECK_NOT_EQUAL(test_spawn("one_arg_1", 42), none);
test_spawn(make_message(42)); CAF_CHECK_NOT_EQUAL(test_spawn("one_arg_2", 42), none);
CAF_CHECK_NOT_EQUAL(test_spawn("one_arg_3", 42), none);
CAF_CHECK_EQUAL(test_spawn("one_arg_1"), invalid_args);
CAF_CHECK_EQUAL(test_spawn("one_arg_2"), invalid_args);
CAF_CHECK_EQUAL(test_spawn("one_arg_3"), invalid_args);
} }
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
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