00001 /***************************** License ********************************** 00002 00003 Copyright (C) 2008 by Communicative Machines 00004 http://www.cmlabs.com All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 ************************************************************************/ 00021 00022 00023 // CoreTest.cpp : Defines the entry point for the console application. 00024 // 00025 00026 #include "CoreTest.h" 00027 #include "JTime.h" 00028 #include "DynamicLoader.h" 00029 00030 #include "thirdparty/CVML.h" 00031 00032 #include "Bitmap.h" 00033 00034 // bool runMyTest(); 00035 00036 using namespace cmlabs; 00037 00038 void printbits( unsigned int size, unsigned char * bits, int type) 00039 { 00040 int k=0,i,j; 00041 for(i=size-1;i>=0;i--) { 00042 for(j=7;j>=0;j--) 00043 printf("%c",(bits[i] & (1<<j)) ? '1' : '0'); 00044 printf(" "); 00045 }; 00046 printf("\n"); 00047 } 00048 00049 /* 00050 #define TGET_DRGB_FROM_2RGBS(a,b) (((unsigned int)GET_R_FROM_RGBA(a)>>3)<<27) + (((unsigned int)GET_G_FROM_RGBA(a)>>2)<<21) + (((unsigned int)GET_B_FROM_RGBA(a)>>3)<<16) + (((unsigned int)GET_R_FROM_RGBA(b)>>3)<<11) + (((unsigned int)GET_G_FROM_RGBA(b)>>2)<<5) + (((unsigned int)GET_B_FROM_RGBA(b)>>3)<<0) 00051 #define TGET_FIRSTRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)((a>>16)&0xF800)>>8)) + ((unsigned int)((unsigned short)((a>>16)&0xE000)>>13)) + ((unsigned int)((unsigned short)((a>>16)&0x07E0)<<6)) + ((unsigned int)((unsigned short)((a>>16)&0x0700))) + ((unsigned int)((unsigned short)(a>>16)&0x001F)<<19) + (((unsigned int)(unsigned short)(a>>16)&0x001C)<<14) 00052 #define TGET_SECONDRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)(a&0xF800)>>8)) + ((unsigned int)((unsigned short)(a&0xE000)>>13)) + ((unsigned int)((unsigned short)(a&0x07E0)<<6)) + ((unsigned int)((unsigned short)(a&0x0700))) + ((unsigned int)((unsigned short)a&0x001F)<<19) + (((unsigned int)(unsigned short)a&0x001C)<<14) 00053 #define TGET_DRGB_FROM_2RGBS(a,b) (((unsigned int)GET_R_FROM_RGBA(a)>>3)<<27) + (((unsigned int)GET_G_FROM_RGBA(a)>>2)<<21) + (((unsigned int)GET_B_FROM_RGBA(a)>>3)<<16) + (((unsigned int)GET_R_FROM_RGBA(b)>>3)<<11) + (((unsigned int)GET_G_FROM_RGBA(b)>>2)<<5) + (((unsigned int)GET_B_FROM_RGBA(b)>>3)<<0) 00054 #define TGET_FIRSTRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)((a>>16)&0xF800)>>8)) | ((unsigned int)((unsigned short)((a>>16)&0xE000)>>13)) | ((unsigned int)((unsigned short)((a>>16)&0x07E0)<<5)) | ((unsigned int)((unsigned short)((a>>16)&0x0600))>>1) | ((unsigned int)((unsigned short)(a>>16)&0x001F)<<19) | (((unsigned int)(unsigned short)(a>>16)&0x001C)<<14) 00055 #define TGET_SECONDRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)(a&0xF800)>>8)) | ((unsigned int)((unsigned short)(a&0xE000)>>13)) | ((unsigned int)((unsigned short)(a&0x07E0)<<5)) | ((unsigned int)((unsigned short)(a&0x0600))>>1) | ((unsigned int)((unsigned short)a&0x001F)<<19) | (((unsigned int)(unsigned short)a&0x001C)<<14) 00056 #define XGET_FIRSTRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)((a>>16)&0xF800)>>8)) + ((unsigned int)((unsigned short)((a>>16)&0x07E0)<<6)) + ((unsigned int)((unsigned short)(a>>16)&0x001F)<<19) 00057 #define XGET_SECONDRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)(a&0xF800)>>8)) + ((unsigned int)((unsigned short)(a&0x07E0)<<6)) + ((unsigned int)((unsigned short)a&0x001F)<<19) 00058 */ 00059 00060 #ifdef WIN32 00061 #if !defined(_WIN32_WCE) 00062 #ifdef _DEBUG 00063 #define _CRTDBG_MAP_ALLOC 00064 #define MY_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__) 00065 #define new MY_NEW 00066 #endif 00067 #endif 00068 #endif 00069 00070 int main(int argc, char* argv[]) 00071 { 00072 #ifdef WIN32 00073 // _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 00074 #endif 00075 00076 /* DataSample* sample = NULL; 00077 JString curSource = "../../Video/Frame000.bmp"; 00078 00079 if (!JFile::doesAFileExist(curSource)) { 00080 printf("File does not exist!\n"); 00081 exit(0); 00082 } 00083 sample = new Bitmap(curSource); 00084 if (sample->getDataSize() > 0) { 00085 printf("File read OK!\n"); 00086 exit(0); 00087 } 00088 else { 00089 printf("File could not be read!\n"); 00090 exit(0); 00091 } 00092 */ 00093 /* 00094 JString sss = "company=nova system=Viamão date=2006-07-03"; 00095 Dictionary dict = sss.splitCommandLine(); 00096 printf("%s\n", (char*) dict.printListLine("\n")); 00097 00098 Collection coll = sss.splitOnWhiteSpaces(); 00099 printf("%s\n", (char*) coll.printListLine("\n")); 00100 00101 dict = sss.split(" ","="); 00102 printf("%s\n", (char*) dict.printListLine("\n")); 00103 */ 00104 /* 00105 RetrieveSpec* spec = new RetrieveSpec(); 00106 spec->content = "*id=\"4\"*"; 00107 JString x = spec->toXML(); 00108 00109 RetrieveSpec* spec2 = new RetrieveSpec(); 00110 spec2->fromXML(x); 00111 */ 00112 int eee = 0; 00113 00114 /* JTime t1; 00115 JTime t2; 00116 00117 JString s1; 00118 int kkk = 0; 00119 00120 while (true) { 00121 t1 = JTime(); 00122 s1 = JString::format("Time: %s\nGMT: %s\n%d %d %d %d", (char*) t1.print(), (char*) t1.toHTTP(), t1.timebuffer.time, t1.timebuffer.millitm, (int)t1.timebuffer.timezone, (int)t1.timebuffer.dstflag); 00123 printf("%s\n", (char*) s1); 00124 getchar(); 00125 } 00126 */ 00127 /* 00128 unsigned int a = 0x00998844; 00129 unsigned int b = 0x00448899; 00130 00131 unsigned int c = TGET_DRGB_FROM_2RGBS(a, b); 00132 00133 unsigned int aa = TGET_FIRSTRGB_FROM_DRGB(c); 00134 unsigned int bb = TGET_SECONDRGB_FROM_DRGB(c); 00135 00136 unsigned int aaa = XGET_FIRSTRGB_FROM_DRGB(c); 00137 unsigned int bbb = XGET_SECONDRGB_FROM_DRGB(c); 00138 00139 printf("%X\t", a); 00140 printbits(4, (unsigned char*) &a, 0); 00141 printf("%X\t", aa); 00142 printbits(4, (unsigned char*) &aa, 0); 00143 printf("%X\t", aaa); 00144 printbits(4, (unsigned char*) &aaa, 0); 00145 printf("%X\t", b); 00146 printbits(4, (unsigned char*) &b, 0); 00147 printf("%X\t", bb); 00148 printbits(4, (unsigned char*) &bb, 0); 00149 printf("%X\t", bbb); 00150 printbits(4, (unsigned char*) &bbb, 0); 00151 00152 printf("\n%X\t", c); 00153 printbits(4, (unsigned char*) &c, 0); 00154 */ 00155 // StopWatch watch; 00156 // watch.start(); 00157 // Bitmap* bm = new Bitmap("t:\\map.bmp"); 00158 // watch.setMark("Loaded bitmap"); 00159 // Bitmap* bm2 = bm->getResizedCopy(2); 00160 // watch.setMark("Resized bitmap"); 00161 // Bitmap* bm2 = new Bitmap(u); 00162 // bm2->saveToFile("t:\\testout.bmp"); 00163 // delete(bm); 00164 // delete(bm2); 00165 // watch.stop(); 00166 // delete(u); 00167 // printf("%s\n", (char*) watch.printDetails()); 00168 // exit(0); 00169 00170 JString arg1, arg2; 00171 if (argc > 1) 00172 arg1 = JString(argv[1]); 00173 if (argc > 2) 00174 arg2 = JString(argv[2]); 00175 00176 MediaTestServer* mediaTestServer; 00177 int mediaTestServerPort = 8765; 00178 00179 if (arg1.equalsIgnoreCase("sysinfo")) { 00180 SysInfo sysInfo = Object::getSystemInfo(); 00181 printf("\n\n%s\n\n", (char*) sysInfo.print()); 00182 exit(0); 00183 } 00184 else if (arg1.equalsIgnoreCase("netinfo")) { 00185 JSocket* con = new JSocket("localhost", 25471, ""); 00186 Collection addresses = con->getLocalIPAddresses(); 00187 printf("NetInfo:\n\nFound %d local IP addresses:\n\t%s\n\n", addresses.getCount(), (char*) addresses.printListLine("\n\t")); 00188 Dictionary interfaces = con->getLocalInterfaceAddresses(); 00189 printf("Found %d local interfaces:\n\t%s\n\n", interfaces.getCount(), (char*) interfaces.printListLine("\n\t")); 00190 printf("This computer is '%s' with primary IP address %s\n\n", (char*) con->getLocalHostname(), (char*) con->getLocalIPAddress()); 00191 exit(0); 00192 } 00193 else if (arg1.equalsIgnoreCase("net")) { 00194 testSockets(new SocketTester(10500)); 00195 testNetwork(new Network(), 10500+100); 00196 testMediaServer(new MediaServer("Test Media Server"), 10500+200); 00197 exit(0); 00198 } 00199 else if (arg1.equalsIgnoreCase("media")) { 00200 testMediaServer(new MediaServer("Test Media Server"), 10500+200); 00201 exit(0); 00202 } 00203 else if (arg1.equalsIgnoreCase("thread")) { 00204 JThread* myThread = new JThread(false); 00205 myThread->priorityTest(); 00206 delete(myThread); 00207 exit(0); 00208 } 00209 else if (arg1.equalsIgnoreCase("mediaserver")) { 00210 // If this is a test over time 00211 if (arg2.equalsIgnoreCase("time")) { 00212 mediaTestServer = createMediaTestServer(mediaTestServerPort, "", 1, true); 00213 } 00214 else { 00215 // arg2 contains number of connections to expect before starting 00216 int count = arg2.toInt(); 00217 if (count <= 0) count = 1; 00218 mediaTestServer = createMediaTestServer(mediaTestServerPort, "", count, false); 00219 } 00220 if (mediaTestServer == NULL) { 00221 printf("Could not initiate MediaTestServer...\n"); 00222 exit(0); 00223 } 00224 mediaTestServer->start(); 00225 while (!mediaTestServer->isTestComplete()) 00226 Object::wait(1000); 00227 exit(0); 00228 } 00229 else if (arg1.equalsIgnoreCase("mediaclient")) { 00230 // Now start the local test client... 00231 runMediaTestClient("", arg2, mediaTestServerPort); 00232 exit(0); 00233 } 00234 else if (arg1.equalsIgnoreCase("medialocal")) { 00235 // If this is a test over time 00236 if (arg2.equalsIgnoreCase("time")) { 00237 mediaTestServer = createMediaTestServer(mediaTestServerPort, "", 1, true); 00238 } 00239 else { 00240 // arg2 contains number of connections to expect before starting 00241 int count = arg2.toInt(); 00242 if (count <= 0) count = 1; 00243 mediaTestServer = createMediaTestServer(mediaTestServerPort, "", count, false); 00244 } 00245 if (mediaTestServer == NULL) { 00246 printf("Could not initiate MediaTestServer...\n"); 00247 exit(0); 00248 } 00249 mediaTestServer->start(); 00250 00251 // Now start the local test client... 00252 runMediaTestClient("", mediaTestServer->getLocation()); 00253 exit(0); 00254 } 00255 00256 int systemTestPort = 10500; 00257 JString str; 00258 00259 int count = 1; 00260 if (argc > 1) { 00261 str = JString(argv[1]); 00262 count = str.toInt(); 00263 } 00264 00265 JString testlib; 00266 if (argc > 2) { 00267 testlib = JString(argv[2]); 00268 } 00269 00270 printf("\nRunning tests %d times\n\n", count); 00271 00272 for (int n=1; n<=count; n++) { 00273 runTests(systemTestPort+(n*10), testlib); 00274 } 00275 00276 // printf("\n\nPress any key to exit..."); 00277 // getchar(); 00278 printf("\n\n"); 00279 return 0; 00280 } 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 /* 00291 00292 class MyRec : public TCPReceiver { 00293 public: 00294 MyRec() {} 00295 void tcpInput(JString str, NetworkConnection* con) {} 00296 00297 Message* netObjectReceive(Message* msg, NetworkConnection* con) { 00298 Message* hmsg = (Message*) msg->clone(); 00299 delete(msg); 00300 return hmsg; 00301 } 00302 00303 JString getName() {return "Test";} 00304 }; 00305 00306 00307 00308 bool runMyTest() { 00309 00310 bool shouldContinue = true; 00311 MyRec* rec = new MyRec(); 00312 NetworkConnection* con = new NetworkConnection("localhost", 10000, new NetMessageProtocol(), NULL); 00313 00314 if (con->isConnected()) { 00315 printf("Connected and ready\n"); fflush(stdout); 00316 } 00317 else { 00318 printf("Never connected...\n"); fflush(stdout); 00319 shouldContinue = false; 00320 } 00321 00322 while (shouldContinue) { 00323 shouldContinue = con->isConnected(); 00324 con->wait(500); 00325 printf("."); fflush(stdout); 00326 } 00327 00328 printf("Not connected anymore\n"); fflush(stdout); 00329 con->wait(10000); 00330 return true; 00331 } 00332 */ 00333 00334 00335 00336 00337 00338