Line data Source code
1 : #include "../package/broker/broker/broker.hpp"
2 : #include <wfc/module/testing_domain.hpp>
3 : #include <fas/testing.hpp>
4 : #include <memory>
5 :
6 : namespace {
7 :
8 : struct _test_;
9 :
10 4 : wfc::iinterface::data_ptr make_data(const std::string& s)
11 : {
12 4 : return std::make_unique<wfc::iinterface::data_type>( s.begin(), s.end() );
13 : }
14 :
15 2 : struct receiver: wfc::domain_object<wfc::iinterface, fas::empty_type>
16 : {
17 2 : void virtual perform_io(data_ptr d, io_id_t, output_handler_t handler) override
18 : {
19 2 : handler(make_data(this->name() + ":" + std::string(d->begin(), d->end())));
20 2 : }
21 : };
22 :
23 3 : UNIT(init, "")
24 : {
25 : using namespace fas::testing;
26 1 : GET_REF(_test_) = std::make_shared<wfc::testing_domain>();
27 1 : t << nothing;
28 1 : }
29 :
30 3 : UNIT(broker, "")
31 : {
32 : using namespace fas::testing;
33 : using namespace wfc::io;
34 :
35 1 : auto tst = GET_REF(_test_);
36 2 : broker::domain_config bopt;
37 1 : bopt.name = "broker1";
38 1 : bopt.target = "receiver1";
39 1 : bopt.rules.resize(1);
40 1 : bopt.rules[0].target = "receiver2";
41 1 : bopt.rules[0].regex ="(sub)(.*)";
42 2 : auto br = tst->template create<broker>(bopt);
43 2 : receiver::domain_config ropt;
44 1 : ropt.name = "receiver1";
45 2 : auto rv1 = tst->template create<receiver>(ropt);
46 1 : ropt.name = "receiver2";
47 2 : auto rv2 = tst->template create<receiver>(ropt);
48 1 : tst->start();
49 :
50 1 : int count = 0;
51 2 : br->perform_io(make_data("object"), 1, [&t, &count](wfc::iinterface::data_ptr d){
52 : using namespace fas::testing;
53 1 : std::string ins(d->begin(), d->end() );
54 1 : t << equal_str<expect>(ins, "receiver1:object") << FAS_FL;
55 1 : ++count;
56 1 : });
57 2 : br->perform_io(make_data("subect"), 1, [&t, &count](wfc::iinterface::data_ptr d){
58 : using namespace fas::testing;
59 1 : std::string ins(d->begin(), d->end() );
60 1 : t << equal_str<expect>(ins, "receiver2:subect") << FAS_FL;
61 1 : ++count;
62 1 : });
63 2 : t << equal<expect>(count, 2) << FAS_FL;
64 1 : }
65 :
66 : }
67 :
68 1 : BEGIN_SUITE(package_suite, "")
69 : ADD_VALUE( _test_, std::shared_ptr<wfc::testing_domain> )
70 : ADD_UNIT( init )
71 : ADD_UNIT( broker )
72 7 : END_SUITE(package_suite)
|