1 // This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
2 // the main distribution directory for license terms and copyright or visit
3 // https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
4 
5 #define CAF_SUITE unit
6 
7 #include "caf/unit.hpp"
8 
9 #include "core-test.hpp"
10 
11 #include "caf/actor_system.hpp"
12 #include "caf/actor_system_config.hpp"
13 #include "caf/event_based_actor.hpp"
14 #include "caf/scoped_actor.hpp"
15 
16 using namespace caf;
17 
testee(event_based_actor * self)18 behavior testee(event_based_actor* self) {
19   return {
20     [](add_atom) -> result<unit_t> { return unit; },
21     [](get_atom) -> result<void> { return {}; },
22     [](put_atom) -> unit_t { return unit; },
23     [](resolve_atom) -> void {},
24     [=](update_atom) -> result<unit_t> {
25       auto rp = self->make_response_promise<unit_t>();
26       rp.deliver(unit);
27       return rp;
28     },
29   };
30 }
31 
CAF_TEST(unit_results)32 CAF_TEST(unit_results) {
33   actor_system_config cfg;
34   actor_system sys{cfg};
35   scoped_actor self{sys};
36   auto aut = sys.spawn(testee);
37   message as[] = {
38     make_message(add_atom_v),    make_message(get_atom_v),
39     make_message(put_atom_v),    make_message(resolve_atom_v),
40     make_message(update_atom_v),
41   };
42   for (auto a : as) {
43     self->request(aut, infinite, a)
44       .receive(
45         [&] {
46           CAF_MESSAGE("actor under test correctly replied to " << to_string(a));
47         },
48         [&](const error&) {
49           CAF_FAIL("actor under test failed at input " << to_string(a));
50         });
51   }
52 }
53