Some code fixes done to multicast service classes.
[tourist.git] / App / testsuite / src / TestMulticast.cpp
blob388e98599afb274c35cfad406716d2611bd877a1
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;
10 using Poco::Thread;
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()
34 Config config_1;
35 config_1.setTCPEnable(true);
36 config_1.setTCPPort(5000);
38 Application app1(config_1);
39 assert(app1.init() == 0);
41 Config config_2;
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
49 //app1.setLevel(0);
50 //app2.setLevel(2);
53 Thread t1, t2;
54 t1.start(app1);
55 t2.start(app2);
57 Thread::sleep(20);
59 int i=0;
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);
72 Thread tm1, tm2;
73 tm1.start(multicast);
74 tm2.start(multicast2);
76 multicast2.levelChangeEvent(3, &app2Node);
78 Thread::sleep(100);
80 app1.stopApp();
81 app2.stopApp();
83 //wait for all the threads to finish
84 t1.join();
85 t2.join();
89 void TestMulticast::testCompleteMulticast()
91 Config config_1;
92 config_1.setTCPEnable(true);
93 config_1.setTCPPort(5000);
95 Application app1(config_1);
96 assert(app1.init() == 0);
98 Config config_2;
99 config_2.setTCPEnable(true);
100 config_2.setTCPPort(5010);
101 Application app2(config_2);
103 assert (app2.init() == 0);
105 //app1.setLevel(0);
106 //app2.setLevel(2);
109 Config config_3;
110 config_3.setTCPEnable(true);
111 config_3.setTCPPort(5020);
113 Application app3(config_3);
114 assert(app3.init() == 0);
117 Config config_4;
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;
126 t1.start(app1);
127 t2.start(app2);
128 t3.start(app3);
129 t4.start(app4);
132 Thread::sleep(20);
134 int i=0;
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);
168 Thread::sleep(5000);
170 app1.stopApp();
171 app2.stopApp();
172 app3.stopApp();
173 app4.stopApp();
175 //wait for all the threads to finish
176 t1.join();
177 t2.join();
178 t3.join();
179 t4.join();
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);
189 return pSuite;