1 #include "TestMulticast.h"
2 #include "Tourist/App/Application.h"
3 #include "CppUnit/TestCaller.h"
4 #include "CppUnit/TestSuite.h"
5 #include "Poco/Thread.h"
6 #include "Tourist/App/Multicast.h"
7 #include "Tourist/LocalNode.h"
9 using Tourist::App::Application
;
11 using Tourist::LocalNode
; //remove it
13 using namespace Tourist::App
;
15 TestMulticast::TestMulticast(const std::string
& name
): CppUnit::TestCase(name
)
19 TestMulticast::~TestMulticast()
23 void TestMulticast::setUp()
27 void TestMulticast::tearDown()
31 void TestMulticast::testSendEvent()
35 config_1
.setTCPEnable(true);
36 config_1
.setTCPPort(5000);
38 Application
app1(config_1
);
39 assert(app1
.init() == 0);
42 config_2
.setTCPEnable(true);
43 config_2
.setTCPPort(5010);
44 Application
app2(config_2
);
46 assert (app2
.init() == 0);
48 //---> Prob here . NEED IMMEDIATE FIX
61 RemoteNode app1Node
, app2Node
;
62 app1
.getLocalNodeInfo(app1Node
);
63 app2
.getLocalNodeInfo(app2Node
);
64 std::cout
<<"\nApp1 Node Info: " << app1Node
.toString() << "\n";
65 std::cout
<<"\nApp2 Node Info: " << app2Node
.toString() << "\n";
67 app2
.addNewNode(&app1Node
);
69 Multicast
multicast(&app1
, 1);
70 Multicast
multicast2(&app2
, 2);
74 tm2
.start(multicast2
);
76 multicast2
.levelChangeEvent(3, &app2Node
);
83 //wait for all the threads to finish
89 void TestMulticast::testCompleteMulticast()
92 config_1
.setTCPEnable(true);
93 config_1
.setTCPPort(5000);
95 Application
app1(config_1
);
96 assert(app1
.init() == 0);
99 config_2
.setTCPEnable(true);
100 config_2
.setTCPPort(5010);
101 Application
app2(config_2
);
103 assert (app2
.init() == 0);
110 config_3
.setTCPEnable(true);
111 config_3
.setTCPPort(5020);
113 Application
app3(config_3
);
114 assert(app3
.init() == 0);
118 config_4
.setTCPEnable(true);
119 config_4
.setTCPPort(5030);
121 Application
app4(config_4
);
122 assert(app4
.init() == 0);
125 Thread t1
, t2
, t3
, t4
;
137 RemoteNode app1Node
, app2Node
, app3Node
, app4Node
;
138 app1
.getLocalNodeInfo(app1Node
);
139 app2
.getLocalNodeInfo(app2Node
);
140 app3
.getLocalNodeInfo(app3Node
);
141 app4
.getLocalNodeInfo(app4Node
);
143 std::cout
<<"\nApp1 Node Info: " << app1Node
.toString() << "\n";
144 std::cout
<<"\nApp2 Node Info: " << app2Node
.toString() << "\n";
145 std::cout
<<"\nApp3 Node Info: " << app3Node
.toString() << "\n";
146 std::cout
<<"\nApp4 Node Info: " << app4Node
.toString() << "\n";
148 app2
.addNewNode(&app1Node
);
149 app1
.addNewNode(&app3Node
);
150 app1
.addNewNode(&app4Node
);
151 app1
.addNewNode(&app2Node
);
153 Multicast
multicast(&app1
, 1);
154 Multicast
multicast2(&app2
, 2);
155 Multicast
multicast3(&app3
, 3);
156 Multicast
multicast4(&app4
, 4);
159 Thread tm1
, tm2
, tm3
, tm4
;
160 tm1
.start(multicast
);
161 tm2
.start(multicast2
);
162 tm3
.start(multicast3
);
163 tm4
.start(multicast4
);
165 multicast2
.levelChangeEvent(3, &app2Node
);
175 //wait for all the threads to finish
182 CppUnit::Test
* TestMulticast::suite()
184 CppUnit::TestSuite
* pSuite
= new CppUnit::TestSuite("TestMulticast");
185 //CppUnit_addTest(pSuite, TestMulticast, testSendEvent);
186 CppUnit_addTest(pSuite
, TestMulticast
, testCompleteMulticast
);