1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#define CAF_SUITE composition
#include "caf/test/dsl.hpp"
using namespace std;
using namespace caf;
namespace {
behavior multiplier(int x) {
return {
[=](int y) {
return x * y;
},
[=](int y1, int y2) {
return x * y1 * y2;
}
};
}
behavior adder(int x) {
return {
[=](int y) {
return x + y;
},
[=](int y1, int y2) {
return x + y1 + y2;
}
};
}
behavior float_adder(float x) {
return {
[=](float y) {
return x + y;
}
};
}
using fixture = test_coordinator_fixture<>;
} // namespace
CAF_TEST_FIXTURE_SCOPE(composition_tests, fixture)
CAF_TEST(depth2) {
auto stage1 = sys.spawn(multiplier, 4);
auto stage2 = sys.spawn(adder, 10);
auto testee = stage2 * stage1;
self->send(testee, 1);
expect((int), from(self).to(stage1).with(1));
expect((int), from(self).to(stage2).with(4));
expect((int), from(stage2).to(self).with(14));
}
CAF_TEST(depth3) {
auto stage1 = sys.spawn(multiplier, 4);
auto stage2 = sys.spawn(adder, 10);
auto testee = stage1 * stage2 * stage1;
self->send(testee, 1);
expect((int), from(self).to(stage1).with(1));
expect((int), from(self).to(stage2).with(4));
expect((int), from(self).to(stage1).with(14));
expect((int), from(stage1).to(self).with(56));
}
CAF_TEST(depth2_type_mismatch) {
auto stage1 = sys.spawn(multiplier, 4);
auto stage2 = sys.spawn(float_adder, 10);
auto testee = stage2 * stage1;
self->send(testee, 1);
expect((int), from(self).to(stage1).with(1));
expect((int), from(self).to(stage2).with(4));
expect((error), from(stage2).to(self).with(sec::unexpected_message));
}
CAF_TEST_FIXTURE_SCOPE_END()
|