Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmain.cpp
Go to the documentation of this file.
00001 /*********************************************************************************** 00002 Main.cpp 00003 00004 * Copyright (c) 1997 00005 * Mark of the Unicorn, Inc. 00006 * 00007 * Permission to use, copy, modify, distribute and sell this software 00008 * and its documentation for any purpose is hereby granted without fee, 00009 * provided that the above copyright notice appear in all copies and 00010 * that both that copyright notice and this permission notice appear 00011 * in supporting documentation. Mark of the Unicorn makes no 00012 * representations about the suitability of this software for any 00013 * purpose. It is provided "as is" without express or implied warranty. 00014 00015 * Copyright (c) 1997 00016 * Moscow Center for SPARC Technology 00017 * 00018 * Permission to use, copy, modify, distribute and sell this software 00019 * and its documentation for any purpose is hereby granted without fee, 00020 * provided that the above copyright notice appear in all copies and 00021 * that both that copyright notice and this permission notice appear 00022 * in supporting documentation. Moscow Center for SPARC Technology makes 00023 no 00024 * representations about the suitability of this software for any 00025 * purpose. It is provided "as is" without express or implied warranty. 00026 00027 ***********************************************************************************/ 00028 #include "Prefix.h" 00029 #include "Tests.h" 00030 00031 #if defined (EH_NEW_IOSTREAMS) 00032 # include <iostream> 00033 # else 00034 # include <iostream.h> 00035 #endif 00036 00037 #if defined(macintosh)&&(!defined(__MRC__) && !defined(__SC__)) || defined (_MAC) && defined(__MWERKS__) 00038 00039 # include <console.h> 00040 # include <Types.h> 00041 # include <Strings.h> 00042 00043 # ifdef EH_NEW_HEADERS 00044 # include <cstdio> 00045 # include <cstring> 00046 # include <cassert> 00047 # else 00048 # include <stdio.h> 00049 # include <string.h> 00050 # include <assert.h> 00051 # endif 00052 00053 # if defined (_STL_DEBUG) 00054 00055 # if defined ( EH_USE_SGI_STL ) 00056 // Override assertion behavior 00057 # include <cstdarg> 00058 //# include <stldebug.h> 00059 void STLPORT::__stl_debug_message(const char * format_str, ...) 00060 { 00061 std::va_list args; 00062 va_start( args, format_str ); 00063 char msg[256]; 00064 std::vsnprintf(msg, sizeof(msg)/sizeof(*msg) - 1, format_str, args ); 00065 DebugStr( c2pstr(msg) ); 00066 } 00067 # else 00068 /*=================================================================================== 00069 __assertion_failed (override standard library function) 00070 00071 EFFECTS: Breaks into the debugger and shows the assertion. This implementation 00072 is Mac-specific; others could be added for other platforms. 00073 ====================================================================================*/ 00074 extern "C" 00075 { 00076 void __assertion_failed(char *condition, char *testfilename, int lineno); 00077 void __assertion_failed(char *condition, char *testfilename, int lineno) 00078 { 00079 char msg[256]; 00080 std::strncpy( msg, condition, 255 ); 00081 std::strncat( msg, ": ", 255 ); 00082 std::strncat( msg, testfilename, 255 ); 00083 std::strncat( msg, ", ", 255 ); 00084 char line[20]; 00085 std::sprintf( line, "%d", lineno ); 00086 std::strncat( msg, line, 255 ); 00087 DebugStr( c2pstr( msg ) ); 00088 } 00089 } 00090 # endif 00091 00092 # endif 00093 00094 #endif 00095 00096 #include "nc_alloc.h" 00097 00098 #if defined (EH_NEW_HEADERS) 00099 # include <vector> 00100 # include <cstring> 00101 # else 00102 # include <vector.h> 00103 # include <string.h> 00104 #endif 00105 00106 #include "TestClass.h" 00107 #include "LeakCheck.h" 00108 #include "test_construct.h" 00109 #ifdef __BORLANDC__ 00110 # include <except.h> 00111 #endif 00112 00113 # if defined(EH_USE_NAMESPACES) 00114 namespace // dwa 1/21/00 - must use unnamed namespace here to avoid conflict under gcc using native streams 00115 { 00116 using namespace std; 00117 // using std::cerr; 00118 // using std::endl; 00119 } 00120 # endif 00121 00122 00123 /*=================================================================================== 00124 usage (file-static helper) 00125 00126 EFFECTS: Prints a message describing the command-line parameters 00127 ====================================================================================*/ 00128 static void usage(const char* name) 00129 { 00130 cerr<<"Usage : "<<name<<" [-n <iterations>] [-s <size>] [-l] [-e] [-q]/[-v] [-t] [test_name...]\n"; 00131 cerr<<"\t[-n <iterations>] : number of test iterations, default==100;"<<endl; 00132 cerr<<"\t[-s <size>] : base value for random container sizes, default==1000;"<<endl; 00133 cerr<<"\t[-e] : don't throw exceptions, test for leak in normal conditions;"<<endl; 00134 // This option was never actually used -- dwa 9/22/97 00135 // cerr<<"\t[-i] : ignore leak errors;"<<endl; 00136 cerr<<"\t[-q] : quiet mode;"<<endl; 00137 cerr<<"\t[-v] : verbose mode;"<<endl; 00138 cerr<<"\t[-t] : track each allocation;"<<endl; 00139 cerr<<"\t[test name [test name...]] : run only some of the tests by name (default==all tests):"<<endl; 00140 cerr<<"\t\tpossible test names are : algo vector bit_vector list slist deque set map hash_set hash_map rope string bitset valarray"<<endl; 00141 EH_CSTD::exit(1); 00142 } 00143 00144 #ifdef EH_NEW_HEADERS 00145 # include <set> 00146 #else 00147 # include <set.h> 00148 #endif 00149 00150 #if defined(_WIN32_WCE) 00151 #include <fstream> 00152 #endif 00153 00154 int _STLP_CALL main(int argc, char** argv) 00155 { 00156 #if defined(_WIN32_WCE) 00157 std::ofstream file( "\\eh_test.txt" ); 00158 std::streambuf* old_cout_buf = cout.rdbuf(file.rdbuf()); 00159 std::streambuf* old_cerr_buf = cerr.rdbuf(file.rdbuf()); 00160 #endif 00161 #if defined( __MWERKS__ ) && defined( macintosh ) // Get command line. 00162 argc = ccommand(&argv); 00163 // Allow the i/o window to be repositioned. 00164 // EH_STD::string s; 00165 // getline(EH_STD::cin, s); 00166 #endif 00167 unsigned int niters=2; 00168 bool run_all=true; 00169 bool run_slist = false; 00170 bool run_list = false; 00171 bool run_vector = false; 00172 bool run_bit_vector = false; 00173 bool run_deque = false; 00174 bool run_hash_map = false; 00175 bool run_hash_set = false; 00176 bool run_set = false; 00177 bool run_map = false; 00178 bool run_algo = false; 00179 bool run_algobase = false; 00180 bool run_rope = false; 00181 bool run_string = false; 00182 bool run_bitset = false; 00183 bool run_valarray = false; 00184 00185 int cur_argv; 00186 char *p, *p1; 00187 #if defined (EH_NEW_IOSTREAMS) 00188 std::ios_base::sync_with_stdio(false); 00189 #endif 00190 00191 cerr << argv[0]<<" : Exception handling testsuite.\n"; 00192 cerr.flush(); 00193 00194 bool track_allocations = false; 00195 // parse parameters : 00196 // leak_test [-iterations] [-test] ... 00197 for (cur_argv=1; cur_argv<argc; cur_argv++) { 00198 p = argv[cur_argv]; 00199 if (*p == '-') { 00200 switch (p[1]) { 00201 case 'q': 00202 gTestController.SetVerbose(false); 00203 break; 00204 case 'v': 00205 gTestController.SetVerbose(true); 00206 break; 00207 #if 0 // This option was never actually used -- dwa 9/22/97 00208 case 'i': 00209 gTestController.IgnoreLeaks(true); 00210 break; 00211 #endif 00212 case 'n': 00213 p1 = argv[++cur_argv]; 00214 if (p1 && EH_CSTD::sscanf(p1, "%i", &niters)==1) 00215 cerr <<" Doing "<<niters<<" iterations\n"; 00216 else 00217 usage(argv[0]); 00218 break; 00219 case 't': 00220 track_allocations = true; 00221 break; 00222 case 'e': 00223 gTestController.TurnOffExceptions(); 00224 break; 00225 case 's': 00226 p1 = argv[++cur_argv]; 00227 if (p1 && EH_CSTD::sscanf(p1, "%i", &random_base)==1) 00228 cerr <<" Setting "<<random_base<<" as base for random sizes.\n"; 00229 else 00230 usage(argv[0]); 00231 break; 00232 default: 00233 usage(argv[0]); 00234 break; 00235 } 00236 } else { 00237 run_all = false; 00238 // test name 00239 if (EH_CSTD::strcmp(p, "algo")==0) { 00240 run_algo=true; 00241 } else if (EH_CSTD::strcmp(p, "vector")==0) { 00242 run_vector=true; 00243 } else if (EH_CSTD::strcmp(p, "bit_vector")==0) { 00244 run_bit_vector=true; 00245 } else if (EH_CSTD::strcmp(p, "list")==0) { 00246 run_list=true; 00247 } else if (EH_CSTD::strcmp(p, "slist")==0) { 00248 run_slist=true; 00249 } else if (EH_CSTD::strcmp(p, "deque")==0) { 00250 run_deque=true; 00251 } else if (EH_CSTD::strcmp(p, "set")==0) { 00252 run_set=true; 00253 } else if (EH_CSTD::strcmp(p, "map")==0) { 00254 run_map=true; 00255 } else if (EH_CSTD::strcmp(p, "hash_set")==0) { 00256 run_hash_set=true; 00257 } else if (EH_CSTD::strcmp(p, "hash_map")==0) { 00258 run_hash_map=true; 00259 } else if (EH_CSTD::strcmp(p, "rope")==0) { 00260 run_rope=true; 00261 } else if (EH_CSTD::strcmp(p, "string")==0) { 00262 run_string=true; 00263 } else if (EH_CSTD::strcmp(p, "bitset")==0) { 00264 run_bitset=true; 00265 } else if (EH_CSTD::strcmp(p, "valarray")==0) { 00266 run_valarray=true; 00267 } else { 00268 usage(argv[0]); 00269 } 00270 00271 } 00272 } 00273 00274 gTestController.TrackAllocations( track_allocations ); 00275 00276 // Over and over... 00277 for ( unsigned i = 0; i < niters ; i++ ) 00278 { 00279 cerr << "iteration #" << i << "\n"; 00280 if (run_all || run_algobase) { 00281 gTestController.SetCurrentContainer("algobase"); 00282 cerr << "EH test : algobase" << endl; 00283 test_algobase(); 00284 } 00285 if (run_all || run_algo) { 00286 gTestController.SetCurrentContainer("algo"); 00287 cerr << "EH test : algo" << endl; 00288 test_algo(); 00289 } 00290 00291 if (run_all || run_vector) { 00292 gTestController.SetCurrentContainer("vector"); 00293 cerr << "EH test : vector" << endl; 00294 test_vector(); 00295 } 00296 00297 #if defined( EH_BIT_VECTOR_IMPLEMENTED ) 00298 if (run_all || run_bit_vector) { 00299 gTestController.SetCurrentContainer("bit_vector"); 00300 cerr << "EH test : bit_vector" << endl; 00301 test_bit_vector(); 00302 } 00303 #endif 00304 00305 if (run_all || run_list) { 00306 gTestController.SetCurrentContainer("list"); 00307 cerr << "EH test : list" << endl; 00308 test_list(); 00309 } 00310 00311 #if defined( EH_SLIST_IMPLEMENTED ) 00312 if (run_all || run_slist) { 00313 gTestController.SetCurrentContainer("slist"); 00314 cerr << "EH test : slist" << endl; 00315 test_slist(); 00316 } 00317 #endif // EH_SLIST_IMPLEMENTED 00318 00319 if (run_all || run_deque) { 00320 gTestController.SetCurrentContainer("deque"); 00321 cerr << "EH test : deque" << endl; 00322 test_deque(); 00323 } 00324 if (run_all || run_set) { 00325 gTestController.SetCurrentContainer("set"); 00326 cerr << "EH test : set" << endl; 00327 test_set(); 00328 gTestController.SetCurrentContainer("multiset"); 00329 cerr << "EH test : multiset" << endl; 00330 test_multiset(); 00331 } 00332 00333 if (run_all || run_map) { 00334 gTestController.SetCurrentContainer("map"); 00335 cerr << "EH test : map" << endl; 00336 test_map(); 00337 gTestController.SetCurrentContainer("multimap"); 00338 cerr << "EH test : multimap" << endl; 00339 test_multimap(); 00340 } 00341 00342 #if defined( EH_HASHED_CONTAINERS_IMPLEMENTED ) 00343 if (run_all || run_hash_map) { 00344 gTestController.SetCurrentContainer("hash_map"); 00345 cerr << "EH test : hash_map" << endl; 00346 test_hash_map(); 00347 gTestController.SetCurrentContainer("hash_multimap"); 00348 cerr << "EH test : hash_multimap" << endl; 00349 test_hash_multimap(); 00350 } 00351 00352 if (run_all || run_hash_set) { 00353 gTestController.SetCurrentContainer("hash_set"); 00354 cerr << "EH test : hash_set" << endl; 00355 test_hash_set(); 00356 gTestController.SetCurrentContainer("hash_multiset"); 00357 cerr << "EH test : hash_multiset" << endl; 00358 test_hash_multiset(); 00359 } 00360 #endif // EH_HASHED_CONTAINERS_IMPLEMENTED 00361 00362 #if defined( EH_ROPE_IMPLEMENTED ) 00363 // CW1.8 can't compile this for some reason! 00364 #if !( defined(__MWERKS__) && __MWERKS__ < 0x1900 ) 00365 if (run_all || run_rope) { 00366 gTestController.SetCurrentContainer("rope"); 00367 cerr << "EH test : rope" << endl; 00368 test_rope(); 00369 } 00370 #endif 00371 #endif // EH_ROPE_IMPLEMENTED 00372 #if defined( EH_STRING_IMPLEMENTED ) 00373 if (run_all || run_string) { 00374 gTestController.SetCurrentContainer("string"); 00375 cerr << "EH test : string" << endl; 00376 test_string(); 00377 } 00378 #endif 00379 #if defined( EH_BITSET_IMPLEMENTED ) 00380 if (run_all || run_bitset) { 00381 gTestController.SetCurrentContainer("bitset"); 00382 cerr << "EH test : bitset" << endl; 00383 test_bitset(); 00384 } 00385 #endif 00386 #if defined( EH_VALARRAY_IMPLEMENTED ) 00387 if (run_all || run_bitset) { 00388 gTestController.SetCurrentContainer("valarray"); 00389 cerr << "EH test : valarray" << endl; 00390 test_valarray(); 00391 } 00392 #endif 00393 } 00394 00395 gTestController.TrackAllocations( false ); 00396 00397 cerr << "EH test : Done\n"; 00398 00399 #if defined(_WIN32_WCE) 00400 cout.rdbuf(old_cout_buf); 00401 cerr.rdbuf(old_cerr_buf); 00402 file.close(); 00403 #endif 00404 00405 return 0; 00406 } 00407 Generated on Sun May 27 2012 04:28:38 for ReactOS by
1.7.6.1
|