00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "CoreTest.h"
00025
00026 #ifdef WIN32
00027
00028
00029
00030 #endif
00031
00032 namespace cmlabs {
00033
00034 int debugLevel = 0;
00035 int verboseness = 1;
00036
00037
00038 bool runSystemTest(int testport) {
00039 return true;
00040 }
00041
00042 void runTests(int cnsport, JString testlib) {
00043
00044 srand( (unsigned)time( NULL ) );
00045 printf("\n\n*** Welcome to the Generic Core Test %d ***\n\n", cnsport);
00046
00047
00048
00049
00050
00051
00052
00053 test(new DataSample());
00054 test(new XMLParser());
00055
00056 testCommunicationRecorder();
00057 test(new InfoItem());
00058 test(new JString());
00059 test(new Message());
00060 test(new Dictionary());
00061 test(new ObjectDictionary());
00062 test(new Collection());
00063 test(new ObjectCollection());
00064 test(new SortedCollection());
00065 test(new SortedDictionary());
00066 test(new SortedObjectCollection());
00067 test(new SortedObjectDictionary());
00068 test(new ObjectTable());
00069
00070 test(new Parameter("TestParameter", "Integer"));
00071 test(new JTime(""));
00072 test(new OSCommand());
00073 test(new DotString(""));
00074
00075 if (testlib.length() > 0) {
00076 DynamicLoader* loader = new DynamicLoader();
00077 loader->setTestLib(testlib);
00078 test(loader);
00079 }
00080
00081 test(new Queue());
00082 test(new RequestQueue());
00083 test(new ObjectRequestQueue());
00084
00085 testJThread(new JThread());
00086 test(new TimerManager());
00087
00088 testSockets(new SocketTester(cnsport+1));
00089 testNetwork(new Network(), cnsport+100);
00090 testMediaServer(new MediaServer("Test Media Server"), cnsport+200);
00091
00092 printf("\n*** Generic Core Test complete ***\n\n");
00093 }
00094
00095 JString runTest(int c) {
00096
00097
00098
00099 switch(c) {
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 case 0:
00112 return testText(new JTime());
00113 break;
00114 case 1:
00115 return testText(new DotString());
00116 break;
00117 case 2:
00118 return testText(new Dictionary());
00119 break;
00120 case 3:
00121 return testText(new Queue());
00122 break;
00123 case 4:
00124 return testText(new XMLParser());
00125 break;
00126 case 5:
00127 return testTextThread(new JThread());
00128 break;
00129 case 6:
00130 return testText(new ObjectDictionary());
00131 break;
00132 case 7:
00133 return testText(new Collection());
00134 break;
00135 case 8:
00136 return testText(new SortedCollection());
00137 break;
00138 case 9:
00139 return testText(new Queue());
00140 break;
00141 case 10:
00142 return testText(new RequestQueue());
00143 break;
00144 case 11:
00145 return testText(new ObjectRequestQueue());
00146 break;
00147 case 12:
00148 return testText(new Parameter("TestParameter", "Integer"));
00149 break;
00150 case 13:
00151 return testText(new TimerManager());
00152 break;
00153 case 14:
00154 return testTextSockets(new SocketTester(20001));
00155 break;
00156 case 15:
00157 return testTextNetwork(new Network(), 20002);
00158 break;
00159 case 16:
00160 return testTextMediaServer(new MediaServer("Test Media Server"), 20003);
00161 break;
00162
00163 }
00164
00165 return "";
00166
00167
00168
00169
00170 return JString::format("Exception during Test %d...", c);
00171 }
00172
00173 void test(Object* obj) {
00174
00175 JString str = obj->getClass() + " Unit Test: ";
00176
00177 printf("%.70s ", (char*) str);
00178
00179 if (obj->unitTest())
00180 printf("PASSED\n");
00181 else {
00182 printf("FAILED\n");
00183 printf("Test log:\n%s", (char*) obj->getUnitTestLog());
00184 }
00185 obj->getUnitTestLog();
00186 delete(obj);
00187 }
00188
00189 JString testText(Object* obj) {
00190 JString str = obj->getClass() + " Unit Test: ";
00191 str = str.getFirst(30) + "\t";
00192
00193
00194
00195 if (obj->unitTest())
00196 str += "PASSED";
00197 else {
00198 str += JString::format("FAILED\nTest log:\n%s", (char*) obj->getUnitTestLog());
00199 }
00200 obj->getUnitTestLog();
00201 delete(obj);
00202 return str;
00203 }
00204
00205 void testJThread(JThread* obj) {
00206
00207
00208
00209 JString str = "Threading Unit Test: ";
00210
00211
00212 printf("%.70s ", (char*) str);
00213
00214 if (obj->unitTest())
00215 printf("PASSED\n");
00216 else {
00217 printf("FAILED\n");
00218 printf("Test log:\n%s", (char*) obj->unitTestString);
00219 }
00220 delete(obj);
00221 }
00222
00223 JString testTextThread(JThread* obj) {
00224
00225 JString str = "Threading Unit Test: ";
00226 str = str.getFirst(30) + "\t";
00227
00228
00229 if (obj->unitTest())
00230 str += "PASSED";
00231 else {
00232 str += JString::format("FAILED\nTest log:\n%s", (char*) obj->unitTestString);
00233 }
00234 delete(obj);
00235 return str;
00236 }
00237
00238 void testNetwork(Network* network, int testport) {
00239
00240 JString str = "Network Unit Test: ";
00241 printf("%.70s ", (char*) str);
00242
00243 if (!network->init(testport)) {
00244 delete(network);
00245 printf("FAILED\n");
00246 printf(" Network failed to get port %d\n", testport);
00247 return;
00248 }
00249 network->start();
00250 network->wait(100);
00251 if (network->unitTest())
00252 printf("PASSED\n");
00253 else {
00254 printf("FAILED\n");
00255 printf("Test log:\n%s", (char*) network->getUnitTestLog());
00256 }
00257
00258 network->getUnitTestLog();
00259 delete(network);
00260
00261 }
00262
00263 JString testTextNetwork(Network* network, int testport) {
00264
00265 JString str = "Network Unit Test: ";
00266 str = str.getFirst(30) + "\t";
00267
00268 if (!network->init(testport)) {
00269 delete(network);
00270 str += JString::format("FAILED\nNetwork failed to get port %d\n", testport);
00271 return str;
00272 }
00273 network->start();
00274 network->wait(100);
00275 if (network->unitTest())
00276 str += "PASSED";
00277 else {
00278 str += JString::format("FAILED\nTest log:\n%s", (char*) network->getUnitTestLog());
00279 }
00280 network->getUnitTestLog();
00281 delete(network);
00282 return str;
00283 }
00284
00285 void testSockets(SocketTester* obj) {
00286
00287 obj->start();
00288
00289 JString str = "Sockets Unit Test: ";
00290
00291
00292 if (obj->unitTest()) {
00293 printf("%.70s ", (char*) str);
00294 printf("PASSED\n");
00295 }
00296 else {
00297 printf("%.70s ", (char*) str);
00298 printf("FAILED\n");
00299 printf("Test log:\n%s", (char*) obj->getUnitTestLog());
00300 }
00301 obj->getUnitTestLog();
00302
00303 delete(obj);
00304 }
00305
00306 JString testTextSockets(SocketTester* obj) {
00307
00308 obj->start();
00309
00310 JString str = "Sockets Unit Test: ";
00311 str = str.getFirst(30) + "\t";
00312
00313
00314 if (obj->unitTest())
00315 str += "PASSED";
00316 else {
00317 JString slog = "*";
00318 if (obj->server != NULL)
00319 slog = obj->server->getUnitTestLog();
00320 str += JString::format("FAILED\nTest log:\n'%s'\n%s", (char*) obj->getUnitTestLog(), (char*) slog);
00321 }
00322 obj->getUnitTestLog();
00323 delete(obj);
00324 return str;
00325 }
00326
00327 void testMediaServer(MediaServer* obj, int testport) {
00328
00329 JString str = "MediaServer Unit Test: ";
00330 printf("%.70s ", (char*) str);
00331
00332 if (!obj->init(testport)) {
00333 delete(obj);
00334 printf("FAILED\n");
00335 printf(" MediaServer failed to get port %d\n", testport);
00336 return;
00337 }
00338
00339 obj->start();
00340
00341
00342
00343 if (obj->unitTest()) {
00344 printf("PASSED\n");
00345 }
00346 else {
00347 printf("%.70s ", (char*) str);
00348 printf("FAILED\n");
00349 printf("Test log:\n%s", (char*) obj->getUnitTestLog());
00350 }
00351 obj->getUnitTestLog();
00352
00353 delete(obj);
00354 }
00355
00356 JString testTextMediaServer(MediaServer* obj, int testport) {
00357
00358 JString str = "MediaServer Unit Test: ";
00359 str = str.getFirst(30) + "\t";
00360
00361 if (!obj->init(testport)) {
00362 delete(obj);
00363 str += JString::format("FAILED\nMediaServer failed to get port %d\n", testport);
00364 return str;
00365 }
00366 obj->start();
00367
00368
00369 if (obj->unitTest())
00370 str += "PASSED";
00371 else {
00372 str += JString::format("FAILED\nTest log:\n'%s'\n%s", (char*) obj->getUnitTestLog());
00373 }
00374 obj->getUnitTestLog();
00375 delete(obj);
00376 return str;
00377 }
00378
00379
00380 void testCommunicationRecorder() {
00381
00382 JString str = "CommunicationRecorder Unit Test: ";
00383 printf("%.70s ", (char*) str);
00384
00385 JString dir = "ComRecorderTest";
00386 CommunicationRecorder* comWriter = new CommunicationRecorder(dir, true);
00387 if (!comWriter->initWriting()) {
00388 delete(comWriter);
00389 printf("FAILED\n");
00390 printf(" CommunicationRecorder Writer failed to initialise\n");
00391 return;
00392 }
00393 comWriter->start();
00394
00395
00396 if (comWriter->unitTest()) {
00397 printf("PASSED\n");
00398 }
00399 else {
00400 printf("FAILED\n");
00401 printf("Test log:\n%s", (char*) comWriter->getUnitTestLog());
00402 }
00403 comWriter->getUnitTestLog();
00404 delete(comWriter);
00405 JFile::deleteADir(dir, true);
00406 }
00407
00408
00409
00410 }