Commit 193c39fb authored by Dominik Charousset's avatar Dominik Charousset

Fix formatting

parent 6c6ba45f
...@@ -21,15 +21,15 @@ ...@@ -21,15 +21,15 @@
// exclude this suite; seems to be too much to swallow for MSVC // exclude this suite; seems to be too much to swallow for MSVC
#ifndef CAF_WINDOWS #ifndef CAF_WINDOWS
#define CAF_SUITE typed_spawn # define CAF_SUITE typed_spawn
#include "caf/test/unit_test.hpp"
#include "caf/string_algorithms.hpp" # include "caf/test/unit_test.hpp"
#include "caf/all.hpp" # include "caf/string_algorithms.hpp"
#define ERROR_HANDLER \ # include "caf/all.hpp"
[&](error& err) { CAF_FAIL(system.render(err)); }
# define ERROR_HANDLER [&](error& err) { CAF_FAIL(system.render(err)); }
using std::string; using std::string;
...@@ -40,7 +40,7 @@ using passed_atom = caf::atom_constant<caf::atom("passed")>; ...@@ -40,7 +40,7 @@ using passed_atom = caf::atom_constant<caf::atom("passed")>;
namespace { namespace {
enum class mock_errc : uint8_t { enum class mock_errc : uint8_t {
cannot_revert_empty = 1 cannot_revert_empty = 1,
}; };
error make_error(mock_errc x) { error make_error(mock_errc x) {
...@@ -56,9 +56,6 @@ using dummy2 = dummy1::extend<reacts_to<ok_atom>>; ...@@ -56,9 +56,6 @@ using dummy2 = dummy1::extend<reacts_to<ok_atom>>;
static_assert(std::is_convertible<dummy2, dummy1>::value, static_assert(std::is_convertible<dummy2, dummy1>::value,
"handle not assignable to narrower definition"); "handle not assignable to narrower definition");
//static_assert(!std::is_convertible<dummy1, dummy2>::value,
// "handle is assignable to broader definition");
using dummy3 = typed_actor<reacts_to<float, int>>; using dummy3 = typed_actor<reacts_to<float, int>>;
using dummy4 = typed_actor<replies_to<int>::with<double>>; using dummy4 = typed_actor<replies_to<int>::with<double>>;
using dummy5 = dummy4::extend_with<dummy3>; using dummy5 = dummy4::extend_with<dummy3>;
...@@ -69,12 +66,6 @@ static_assert(std::is_convertible<dummy5, dummy3>::value, ...@@ -69,12 +66,6 @@ static_assert(std::is_convertible<dummy5, dummy3>::value,
static_assert(std::is_convertible<dummy5, dummy4>::value, static_assert(std::is_convertible<dummy5, dummy4>::value,
"handle not assignable to narrower definition"); "handle not assignable to narrower definition");
//static_assert(!std::is_convertible<dummy3, dummy5>::value,
// "handle is assignable to broader definition");
//static_assert(!std::is_convertible<dummy4, dummy5>::value,
// "handle is assignable to broader definition");
/****************************************************************************** /******************************************************************************
* simple request/response test * * simple request/response test *
******************************************************************************/ ******************************************************************************/
...@@ -93,9 +84,7 @@ using server_type = typed_actor<replies_to<my_request>::with<bool>>; ...@@ -93,9 +84,7 @@ using server_type = typed_actor<replies_to<my_request>::with<bool>>;
server_type::behavior_type typed_server1() { server_type::behavior_type typed_server1() {
return { return {
[](const my_request& req) { [](const my_request& req) { return req.a == req.b; },
return req.a == req.b;
}
}; };
} }
...@@ -106,7 +95,7 @@ server_type::behavior_type typed_server2(server_type::pointer) { ...@@ -106,7 +95,7 @@ server_type::behavior_type typed_server2(server_type::pointer) {
class typed_server3 : public server_type::base { class typed_server3 : public server_type::base {
public: public:
typed_server3(actor_config& cfg, const string& line, actor buddy) typed_server3(actor_config& cfg, const string& line, actor buddy)
: server_type::base(cfg) { : server_type::base(cfg) {
anon_send(buddy, line); anon_send(buddy, line);
} }
...@@ -115,18 +104,15 @@ public: ...@@ -115,18 +104,15 @@ public:
} }
}; };
void client(event_based_actor* self, const actor& parent, const server_type& serv) { void client(event_based_actor* self, const actor& parent,
self->request(serv, infinite, my_request{0, 0}).then( const server_type& serv) {
[=](bool val1) { self->request(serv, infinite, my_request{0, 0}).then([=](bool val1) {
CAF_CHECK_EQUAL(val1, true); CAF_CHECK_EQUAL(val1, true);
self->request(serv, infinite, my_request{10, 20}).then( self->request(serv, infinite, my_request{10, 20}).then([=](bool val2) {
[=](bool val2) { CAF_CHECK_EQUAL(val2, false);
CAF_CHECK_EQUAL(val2, false); self->send(parent, passed_atom::value);
self->send(parent, passed_atom::value); });
} });
);
}
);
} }
/****************************************************************************** /******************************************************************************
...@@ -135,10 +121,9 @@ void client(event_based_actor* self, const actor& parent, const server_type& ser ...@@ -135,10 +121,9 @@ void client(event_based_actor* self, const actor& parent, const server_type& ser
struct get_state_msg {}; struct get_state_msg {};
using event_testee_type = typed_actor<replies_to<get_state_msg>::with<string>, using event_testee_type = typed_actor<
replies_to<string>::with<void>, replies_to<get_state_msg>::with<string>, replies_to<string>::with<void>,
replies_to<float>::with<void>, replies_to<float>::with<void>, replies_to<int>::with<int>>;
replies_to<int>::with<int>>;
class event_testee : public event_testee_type::base { class event_testee : public event_testee_type::base {
public: public:
...@@ -148,53 +133,31 @@ public: ...@@ -148,53 +133,31 @@ public:
behavior_type wait4string() { behavior_type wait4string() {
return { return {
[](const get_state_msg&) { [=](const get_state_msg&) { return "wait4string"; },
return "wait4string"; [=](const string&) { become(wait4int()); },
}, [=](float) { return skip(); },
[=](const string&) { [=](int) { return skip(); },
become(wait4int());
},
[](float) {
return skip();
},
[](int) {
return skip();
}
}; };
} }
behavior_type wait4int() { behavior_type wait4int() {
return { return {
[](const get_state_msg&) { [=](const get_state_msg&) { return "wait4int"; },
return "wait4int";
},
[=](int) -> int { [=](int) -> int {
become(wait4float()); become(wait4float());
return 42; return 42;
}, },
[](float) { [=](float) { return skip(); },
return skip(); [=](const string&) { return skip(); },
},
[](const string&) {
return skip();
}
}; };
} }
behavior_type wait4float() { behavior_type wait4float() {
return { return {
[](const get_state_msg&) { [=](const get_state_msg&) { return "wait4float"; },
return "wait4float"; [=](float) { become(wait4string()); },
}, [=](const string&) { return skip(); },
[=](float) { [=](int) { return skip(); },
become(wait4string());
},
[](const string&) {
return skip();
},
[](int) {
return skip();
}
}; };
} }
...@@ -214,7 +177,7 @@ string_actor::behavior_type string_reverter() { ...@@ -214,7 +177,7 @@ string_actor::behavior_type string_reverter() {
[](string& str) -> string { [](string& str) -> string {
std::reverse(str.begin(), str.end()); std::reverse(str.begin(), str.end());
return std::move(str); return std::move(str);
} },
}; };
} }
...@@ -226,12 +189,12 @@ string_actor::behavior_type string_delegator(string_actor::pointer self, ...@@ -226,12 +189,12 @@ string_actor::behavior_type string_delegator(string_actor::pointer self,
return { return {
[=](string& str) -> delegated<string> { [=](string& str) -> delegated<string> {
return self->delegate(next, std::move(str)); return self->delegate(next, std::move(str));
} },
}; };
} }
using maybe_string_actor = typed_actor<replies_to<string> using maybe_string_actor = typed_actor<
::with<ok_atom, string>>; replies_to<string>::with<ok_atom, string>>;
maybe_string_actor::behavior_type maybe_string_reverter() { maybe_string_actor::behavior_type maybe_string_reverter() {
return { return {
...@@ -240,17 +203,18 @@ maybe_string_actor::behavior_type maybe_string_reverter() { ...@@ -240,17 +203,18 @@ maybe_string_actor::behavior_type maybe_string_reverter() {
return mock_errc::cannot_revert_empty; return mock_errc::cannot_revert_empty;
std::reverse(str.begin(), str.end()); std::reverse(str.begin(), str.end());
return {ok_atom::value, std::move(str)}; return {ok_atom::value, std::move(str)};
} },
}; };
} }
maybe_string_actor::behavior_type maybe_string_actor::behavior_type
maybe_string_delegator(maybe_string_actor::pointer self, const maybe_string_actor& x) { maybe_string_delegator(maybe_string_actor::pointer self,
const maybe_string_actor& x) {
self->link_to(x); self->link_to(x);
return { return {
[=](string& s) -> delegated<ok_atom, string> { [=](string& s) -> delegated<ok_atom, string> {
return self->delegate(x, std::move(s)); return self->delegate(x, std::move(s));
} },
}; };
} }
...@@ -264,7 +228,7 @@ using float_actor = typed_actor<reacts_to<float>>; ...@@ -264,7 +228,7 @@ using float_actor = typed_actor<reacts_to<float>>;
int_actor::behavior_type int_fun() { int_actor::behavior_type int_fun() {
return { return {
[](int i) { return i * i; } [](int i) { return i * i; },
}; };
} }
...@@ -273,7 +237,7 @@ behavior foo(event_based_actor* self) { ...@@ -273,7 +237,7 @@ behavior foo(event_based_actor* self) {
[=](int i, int_actor server) { [=](int i, int_actor server) {
self->delegate(server, i); self->delegate(server, i);
self->quit(); self->quit();
} },
}; };
} }
...@@ -295,7 +259,7 @@ behavior foo2(event_based_actor* self) { ...@@ -295,7 +259,7 @@ behavior foo2(event_based_actor* self) {
[=](int i, int_actor server) { [=](int i, int_actor server) {
self->delegate(server, i); self->delegate(server, i);
self->quit(); self->quit();
} },
}; };
} }
...@@ -304,7 +268,7 @@ float_actor::behavior_type float_fun(float_actor::pointer self) { ...@@ -304,7 +268,7 @@ float_actor::behavior_type float_fun(float_actor::pointer self) {
[=](float a) { [=](float a) {
CAF_CHECK_EQUAL(a, 1.0f); CAF_CHECK_EQUAL(a, 1.0f);
self->quit(exit_reason::user_shutdown); self->quit(exit_reason::user_shutdown);
} },
}; };
} }
...@@ -312,9 +276,7 @@ int_actor::behavior_type foo3(int_actor::pointer self) { ...@@ -312,9 +276,7 @@ int_actor::behavior_type foo3(int_actor::pointer self) {
auto b = self->spawn<linked>(float_fun); auto b = self->spawn<linked>(float_fun);
self->send(b, 1.0f); self->send(b, 1.0f);
return { return {
[=](int) { [=](int) { return 0; },
return 0;
}
}; };
} }
...@@ -335,39 +297,20 @@ struct fixture { ...@@ -335,39 +297,20 @@ struct fixture {
void test_typed_spawn(server_type ts) { void test_typed_spawn(server_type ts) {
self->send(ts, my_request{1, 2}); self->send(ts, my_request{1, 2});
self->receive( self->receive([](bool value) { CAF_CHECK_EQUAL(value, false); });
[](bool value) {
CAF_CHECK_EQUAL(value, false);
}
);
CAF_MESSAGE("async send + receive"); CAF_MESSAGE("async send + receive");
self->send(ts, my_request{42, 42}); self->send(ts, my_request{42, 42});
self->receive( self->receive([](bool value) { CAF_CHECK_EQUAL(value, true); });
[](bool value) {
CAF_CHECK_EQUAL(value, true);
}
);
CAF_MESSAGE("request + receive with result true"); CAF_MESSAGE("request + receive with result true");
self->request(ts, infinite, my_request{10, 20}).receive( self->request(ts, infinite, my_request{10, 20})
[](bool value) { .receive([](bool value) { CAF_CHECK_EQUAL(value, false); },
CAF_CHECK_EQUAL(value, false); ERROR_HANDLER);
},
ERROR_HANDLER
);
CAF_MESSAGE("request + receive with result false"); CAF_MESSAGE("request + receive with result false");
self->request(ts, infinite, my_request{0, 0}).receive( self->request(ts, infinite, my_request{0, 0})
[](bool value) { .receive([](bool value) { CAF_CHECK_EQUAL(value, true); }, ERROR_HANDLER);
CAF_CHECK_EQUAL(value, true);
},
ERROR_HANDLER
);
CAF_CHECK_EQUAL(system.registry().running(), 2u); CAF_CHECK_EQUAL(system.registry().running(), 2u);
auto c1 = self->spawn(client, self, ts); auto c1 = self->spawn(client, self, ts);
self->receive( self->receive([](passed_atom) { CAF_MESSAGE("received `passed_atom`"); });
[](passed_atom) {
CAF_MESSAGE("received `passed_atom`");
}
);
self->wait_for(c1); self->wait_for(c1);
CAF_CHECK_EQUAL(system.registry().running(), 2u); CAF_CHECK_EQUAL(system.registry().running(), 2u);
} }
...@@ -391,11 +334,7 @@ CAF_TEST(typed_spawns) { ...@@ -391,11 +334,7 @@ CAF_TEST(typed_spawns) {
self->await_all_other_actors_done(); self->await_all_other_actors_done();
CAF_MESSAGE("finished test series with `typed_server2`"); CAF_MESSAGE("finished test series with `typed_server2`");
test_typed_spawn(self->spawn<typed_server3>("hi there", self)); test_typed_spawn(self->spawn<typed_server3>("hi there", self));
self->receive( self->receive([](const string& str) { CAF_REQUIRE_EQUAL(str, "hi there"); });
[](const string& str) {
CAF_REQUIRE_EQUAL(str, "hi there");
}
);
} }
CAF_TEST(event_testee_series) { CAF_TEST(event_testee_series) {
...@@ -420,30 +359,22 @@ CAF_TEST(event_testee_series) { ...@@ -420,30 +359,22 @@ CAF_TEST(event_testee_series) {
// we expect three 42s // we expect three 42s
int i = 0; int i = 0;
self->receive_for(i, 3)([](int value) { CAF_CHECK_EQUAL(value, 42); }); self->receive_for(i, 3)([](int value) { CAF_CHECK_EQUAL(value, 42); });
self->receive( self->receive([&](const string& str) { result = str; },
[&](const string& str) { after(std::chrono::minutes(1)) >>
result = str; [&] { CAF_FAIL("event_testee does not reply"); });
},
after(std::chrono::minutes(1)) >> [&] {
CAF_FAIL("event_testee does not reply");
}
);
CAF_CHECK_EQUAL(result, "wait4int"); CAF_CHECK_EQUAL(result, "wait4int");
} }
CAF_TEST(string_delegator_chain) { CAF_TEST(string_delegator_chain) {
// run test series with string reverter // run test series with string reverter
auto aut = self->spawn<monitored>(string_delegator, auto aut = self->spawn<monitored>(string_delegator,
system.spawn(string_reverter), system.spawn(string_reverter), true);
true);
std::set<string> iface{"caf::replies_to<@str>::with<@str>"}; std::set<string> iface{"caf::replies_to<@str>::with<@str>"};
CAF_CHECK_EQUAL(aut->message_types(), iface); CAF_CHECK_EQUAL(aut->message_types(), iface);
self->request(aut, infinite, "Hello World!").receive( self->request(aut, infinite, "Hello World!")
[](const string& answer) { .receive([](const string&
CAF_CHECK_EQUAL(answer, "!dlroW olleH"); answer) { CAF_CHECK_EQUAL(answer, "!dlroW olleH"); },
}, ERROR_HANDLER);
ERROR_HANDLER
);
} }
CAF_TEST(maybe_string_delegator_chain) { CAF_TEST(maybe_string_delegator_chain) {
...@@ -451,42 +382,31 @@ CAF_TEST(maybe_string_delegator_chain) { ...@@ -451,42 +382,31 @@ CAF_TEST(maybe_string_delegator_chain) {
auto aut = system.spawn(maybe_string_delegator, auto aut = system.spawn(maybe_string_delegator,
system.spawn(maybe_string_reverter)); system.spawn(maybe_string_reverter));
CAF_MESSAGE("send empty string, expect error"); CAF_MESSAGE("send empty string, expect error");
self->request(aut, infinite, "").receive( self->request(aut, infinite, "")
[](ok_atom, const string&) { .receive([](ok_atom,
CAF_FAIL("unexpected string response"); const string&) { CAF_FAIL("unexpected string response"); },
}, [](const error& err) {
[](const error& err) { CAF_CHECK_EQUAL(err.category(), atom("mock"));
CAF_CHECK_EQUAL(err.category(), atom("mock")); CAF_CHECK_EQUAL(err.code(), static_cast<uint8_t>(
CAF_CHECK_EQUAL(err.code(), mock_errc::cannot_revert_empty));
static_cast<uint8_t>(mock_errc::cannot_revert_empty)); });
}
);
CAF_MESSAGE("send abcd string, expect dcba"); CAF_MESSAGE("send abcd string, expect dcba");
self->request(aut, infinite, "abcd").receive( self->request(aut, infinite, "abcd")
[](ok_atom, const string& str) { .receive([](ok_atom, const string& str) { CAF_CHECK_EQUAL(str, "dcba"); },
CAF_CHECK_EQUAL(str, "dcba"); ERROR_HANDLER);
},
ERROR_HANDLER
);
} }
CAF_TEST(sending_typed_actors) { CAF_TEST(sending_typed_actors) {
auto aut = system.spawn(int_fun); auto aut = system.spawn(int_fun);
self->send(self->spawn(foo), 10, aut); self->send(self->spawn(foo), 10, aut);
self->receive( self->receive([](int i) { CAF_CHECK_EQUAL(i, 100); });
[](int i) {
CAF_CHECK_EQUAL(i, 100);
}
);
self->spawn(foo3); self->spawn(foo3);
} }
CAF_TEST(sending_typed_actors_and_down_msg) { CAF_TEST(sending_typed_actors_and_down_msg) {
auto aut = system.spawn(int_fun2); auto aut = system.spawn(int_fun2);
self->send(self->spawn(foo2), 10, aut); self->send(self->spawn(foo2), 10, aut);
self->receive([](int i) { self->receive([](int i) { CAF_CHECK_EQUAL(i, 100); });
CAF_CHECK_EQUAL(i, 100);
});
} }
CAF_TEST(check_signature) { CAF_TEST(check_signature) {
...@@ -495,20 +415,16 @@ CAF_TEST(check_signature) { ...@@ -495,20 +415,16 @@ CAF_TEST(check_signature) {
using bar_type = typed_actor<reacts_to<ok_atom>>; using bar_type = typed_actor<reacts_to<ok_atom>>;
auto foo_action = [](foo_type::pointer ptr) -> foo_type::behavior_type { auto foo_action = [](foo_type::pointer ptr) -> foo_type::behavior_type {
return { return {
[=] (put_atom) -> foo_result_type { [=](put_atom) -> foo_result_type {
ptr->quit(); ptr->quit();
return {ok_atom::value}; return {ok_atom::value};
} },
}; };
}; };
auto bar_action = [=](bar_type::pointer ptr) -> bar_type::behavior_type { auto bar_action = [=](bar_type::pointer ptr) -> bar_type::behavior_type {
auto foo = ptr->spawn<linked>(foo_action); auto foo = ptr->spawn<linked>(foo_action);
ptr->send(foo, put_atom::value); ptr->send(foo, put_atom::value);
return { return {[=](ok_atom) { ptr->quit(); }};
[=](ok_atom) {
ptr->quit();
}
};
}; };
auto x = self->spawn(bar_action); auto x = self->spawn(bar_action);
self->wait_for(x); self->wait_for(x);
......
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