PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/shared/stlport/test/eh/main.cpp

http://github.com/rhomobile/rhodes
C++ | 408 lines | 319 code | 37 blank | 52 comment | 76 complexity | f74e537042041509fc24e916c6669681 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, MIT, Apache-2.0, LGPL-2.1, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /***********************************************************************************
  2. Main.cpp
  3. * Copyright (c) 1997
  4. * Mark of the Unicorn, Inc.
  5. *
  6. * Permission to use, copy, modify, distribute and sell this software
  7. * and its documentation for any purpose is hereby granted without fee,
  8. * provided that the above copyright notice appear in all copies and
  9. * that both that copyright notice and this permission notice appear
  10. * in supporting documentation. Mark of the Unicorn makes no
  11. * representations about the suitability of this software for any
  12. * purpose. It is provided "as is" without express or implied warranty.
  13. * Copyright (c) 1997
  14. * Moscow Center for SPARC Technology
  15. *
  16. * Permission to use, copy, modify, distribute and sell this software
  17. * and its documentation for any purpose is hereby granted without fee,
  18. * provided that the above copyright notice appear in all copies and
  19. * that both that copyright notice and this permission notice appear
  20. * in supporting documentation. Moscow Center for SPARC Technology makes
  21. no
  22. * representations about the suitability of this software for any
  23. * purpose. It is provided "as is" without express or implied warranty.
  24. ***********************************************************************************/
  25. #include "Prefix.h"
  26. #include "Tests.h"
  27. #if defined (EH_NEW_IOSTREAMS)
  28. # include <iostream>
  29. # else
  30. # include <iostream.h>
  31. #endif
  32. #if defined(macintosh)&&(!defined(__MRC__) && !defined(__SC__)) || defined (_MAC) && defined(__MWERKS__)
  33. # include <console.h>
  34. # include <Types.h>
  35. # include <Strings.h>
  36. # ifdef EH_NEW_HEADERS
  37. # include <cstdio>
  38. # include <cstring>
  39. # include <cassert>
  40. # else
  41. # include <stdio.h>
  42. # include <string.h>
  43. # include <assert.h>
  44. # endif
  45. # if defined (_STL_DEBUG)
  46. # if defined ( EH_USE_SGI_STL )
  47. // Override assertion behavior
  48. # include <cstdarg>
  49. //# include <stldebug.h>
  50. void STLPORT::__stl_debug_message(const char * format_str, ...)
  51. {
  52. std::va_list args;
  53. va_start( args, format_str );
  54. char msg[256];
  55. std::vsnprintf(msg, sizeof(msg)/sizeof(*msg) - 1, format_str, args );
  56. DebugStr( c2pstr(msg) );
  57. }
  58. # else
  59. /*===================================================================================
  60. __assertion_failed (override standard library function)
  61. EFFECTS: Breaks into the debugger and shows the assertion. This implementation
  62. is Mac-specific; others could be added for other platforms.
  63. ====================================================================================*/
  64. extern "C"
  65. {
  66. void __assertion_failed(char *condition, char *testfilename, int lineno);
  67. void __assertion_failed(char *condition, char *testfilename, int lineno)
  68. {
  69. char msg[256];
  70. std::strncpy( msg, condition, 255 );
  71. std::strncat( msg, ": ", 255 );
  72. std::strncat( msg, testfilename, 255 );
  73. std::strncat( msg, ", ", 255 );
  74. char line[20];
  75. std::sprintf( line, "%d", lineno );
  76. std::strncat( msg, line, 255 );
  77. DebugStr( c2pstr( msg ) );
  78. }
  79. }
  80. # endif
  81. # endif
  82. #endif
  83. #include "nc_alloc.h"
  84. #if defined (EH_NEW_HEADERS)
  85. # include <vector>
  86. # include <cstring>
  87. # else
  88. # include <vector.h>
  89. # include <string.h>
  90. #endif
  91. #include "TestClass.h"
  92. #include "LeakCheck.h"
  93. #include "test_construct.h"
  94. #ifdef __BORLANDC__
  95. # include <except.h>
  96. #endif
  97. # if defined(EH_USE_NAMESPACES)
  98. namespace // dwa 1/21/00 - must use unnamed namespace here to avoid conflict under gcc using native streams
  99. {
  100. using namespace std;
  101. // using std::cerr;
  102. // using std::endl;
  103. }
  104. # endif
  105. /*===================================================================================
  106. usage (file-static helper)
  107. EFFECTS: Prints a message describing the command-line parameters
  108. ====================================================================================*/
  109. static void usage(const char* name)
  110. {
  111. cerr<<name<<
  112. " Usage : leak_test [-n <iterations>] [-s <size>] [-l] [-e] [-q]/[-v] [-t] [test_name...]\n";
  113. cerr<<"\t[-n <iterations>] : number of test iterations, default==100;"<<endl;
  114. cerr<<"\t[-s <size>] : base value for random container sizes, default==1000;"<<endl;
  115. cerr<<"\t[-e] : don't throw exceptions, test for leak in normal conditions;"<<endl;
  116. // This option was never actually used -- dwa 9/22/97
  117. // cerr<<"\t[-i] : ignore leak errors;"<<endl;
  118. cerr<<"\t[-q] : quiet mode;"<<endl;
  119. cerr<<"\t[-v] : verbose mode;"<<endl;
  120. cerr<<"\t[-t] : track each allocation;"<<endl;
  121. cerr<<"\t[test name [test name...]] : run only some of the tests by name (default==all tests):"<<endl;
  122. cerr<<"\t\tpossible test names are : algo vector bit_vector list slist deque set map hash_set hash_map rope string bitset valarray"<<endl;
  123. EH_CSTD::exit(1);
  124. }
  125. # ifdef EH_NEW_HEADERS
  126. # include <set>
  127. # else
  128. # include <set.h>
  129. # endif
  130. #if defined(_WIN32_WCE)
  131. #include <fstream>
  132. #endif
  133. int _STLP_CALL main(int argc, char** argv)
  134. {
  135. #if defined(_WIN32_WCE)
  136. std::ofstream file( "\\eh_test.txt" );
  137. std::streambuf* old_cout_buf = cout.rdbuf(file.rdbuf());
  138. std::streambuf* old_cerr_buf = cerr.rdbuf(file.rdbuf());
  139. #endif
  140. #if defined( __MWERKS__ ) && defined( macintosh ) // Get command line.
  141. argc = ccommand(&argv);
  142. // Allow the i/o window to be repositioned.
  143. // EH_STD::string s;
  144. // getline(EH_STD::cin, s);
  145. #endif
  146. unsigned int niters=2;
  147. bool run_all=true;
  148. bool run_slist = false;
  149. bool run_list = false;
  150. bool run_vector = false;
  151. bool run_bit_vector = false;
  152. bool run_deque = false;
  153. bool run_hash_map = false;
  154. bool run_hash_set = false;
  155. bool run_set = false;
  156. bool run_map = false;
  157. bool run_algo = false;
  158. bool run_algobase = false;
  159. bool run_rope = false;
  160. bool run_string = false;
  161. bool run_bitset = false;
  162. bool run_valarray = false;
  163. int cur_argv;
  164. char *p, *p1;
  165. #if defined (EH_NEW_IOSTREAMS)
  166. std::ios_base::sync_with_stdio(false);
  167. #endif
  168. cerr << argv[0]<<" : Exception handling testsuite.\n";
  169. cerr.flush();
  170. bool track_allocations = false;
  171. // parse parameters :
  172. // leak_test [-iterations] [-test] ...
  173. for (cur_argv=1; cur_argv<argc; cur_argv++) {
  174. p = argv[cur_argv];
  175. if (*p == '-') {
  176. switch (p[1]) {
  177. case 'q':
  178. gTestController.SetVerbose(false);
  179. break;
  180. case 'v':
  181. gTestController.SetVerbose(true);
  182. break;
  183. #if 0 // This option was never actually used -- dwa 9/22/97
  184. case 'i':
  185. gTestController.IgnoreLeaks(true);
  186. break;
  187. #endif
  188. case 'n':
  189. p1 = argv[++cur_argv];
  190. if (p1 && EH_CSTD::sscanf(p1, "%i", &niters)==1)
  191. cerr <<" Doing "<<niters<<" iterations\n";
  192. else
  193. usage(argv[0]);
  194. break;
  195. case 't':
  196. track_allocations = true;
  197. break;
  198. case 'e':
  199. gTestController.TurnOffExceptions();
  200. break;
  201. case 's':
  202. p1 = argv[++cur_argv];
  203. if (p1 && EH_CSTD::sscanf(p1, "%i", &random_base)==1)
  204. cerr <<" Setting "<<random_base<<" as base for random sizes.\n";
  205. else
  206. usage(argv[0]);
  207. break;
  208. default:
  209. usage(argv[0]);
  210. break;
  211. }
  212. } else {
  213. run_all = false;
  214. // test name
  215. if (EH_CSTD::strcmp(p, "algo")==0) {
  216. run_algo=true;
  217. } else if (EH_CSTD::strcmp(p, "vector")==0) {
  218. run_vector=true;
  219. } else if (EH_CSTD::strcmp(p, "bit_vector")==0) {
  220. run_bit_vector=true;
  221. } else if (EH_CSTD::strcmp(p, "list")==0) {
  222. run_list=true;
  223. } else if (EH_CSTD::strcmp(p, "slist")==0) {
  224. run_slist=true;
  225. } else if (EH_CSTD::strcmp(p, "deque")==0) {
  226. run_deque=true;
  227. } else if (EH_CSTD::strcmp(p, "set")==0) {
  228. run_set=true;
  229. } else if (EH_CSTD::strcmp(p, "map")==0) {
  230. run_map=true;
  231. } else if (EH_CSTD::strcmp(p, "hash_set")==0) {
  232. run_hash_set=true;
  233. } else if (EH_CSTD::strcmp(p, "hash_map")==0) {
  234. run_hash_map=true;
  235. } else if (EH_CSTD::strcmp(p, "rope")==0) {
  236. run_rope=true;
  237. } else if (EH_CSTD::strcmp(p, "string")==0) {
  238. run_string=true;
  239. } else if (EH_CSTD::strcmp(p, "bitset")==0) {
  240. run_bitset=true;
  241. } else if (EH_CSTD::strcmp(p, "valarray")==0) {
  242. run_valarray=true;
  243. } else {
  244. usage(argv[0]);
  245. }
  246. }
  247. }
  248. gTestController.TrackAllocations( track_allocations );
  249. // Over and over...
  250. for ( unsigned i = 0; i < niters ; i++ )
  251. {
  252. cerr << "iteration #" << i << "\n";
  253. if (run_all || run_algobase) {
  254. gTestController.SetCurrentContainer("algobase");
  255. cerr << "EH test : algobase" << endl;
  256. test_algobase();
  257. }
  258. if (run_all || run_algo) {
  259. gTestController.SetCurrentContainer("algo");
  260. cerr << "EH test : algo" << endl;
  261. test_algo();
  262. }
  263. if (run_all || run_vector) {
  264. gTestController.SetCurrentContainer("vector");
  265. cerr << "EH test : vector" << endl;
  266. test_vector();
  267. }
  268. #if defined( EH_BIT_VECTOR_IMPLEMENTED )
  269. if (run_all || run_bit_vector) {
  270. gTestController.SetCurrentContainer("bit_vector");
  271. cerr << "EH test : bit_vector" << endl;
  272. test_bit_vector();
  273. }
  274. #endif
  275. if (run_all || run_list) {
  276. gTestController.SetCurrentContainer("list");
  277. cerr << "EH test : list" << endl;
  278. test_list();
  279. }
  280. #if defined( EH_SLIST_IMPLEMENTED )
  281. if (run_all || run_slist) {
  282. gTestController.SetCurrentContainer("slist");
  283. cerr << "EH test : slist" << endl;
  284. test_slist();
  285. }
  286. #endif // EH_SLIST_IMPLEMENTED
  287. if (run_all || run_deque) {
  288. gTestController.SetCurrentContainer("deque");
  289. cerr << "EH test : deque" << endl;
  290. test_deque();
  291. }
  292. if (run_all || run_set) {
  293. gTestController.SetCurrentContainer("set");
  294. cerr << "EH test : set" << endl;
  295. test_set();
  296. gTestController.SetCurrentContainer("multiset");
  297. cerr << "EH test : multiset" << endl;
  298. test_multiset();
  299. }
  300. if (run_all || run_map) {
  301. gTestController.SetCurrentContainer("map");
  302. cerr << "EH test : map" << endl;
  303. test_map();
  304. gTestController.SetCurrentContainer("multimap");
  305. cerr << "EH test : multimap" << endl;
  306. test_multimap();
  307. }
  308. #if defined( EH_HASHED_CONTAINERS_IMPLEMENTED )
  309. if (run_all || run_hash_map) {
  310. gTestController.SetCurrentContainer("hash_map");
  311. cerr << "EH test : hash_map" << endl;
  312. test_hash_map();
  313. gTestController.SetCurrentContainer("hash_multimap");
  314. cerr << "EH test : hash_multimap" << endl;
  315. test_hash_multimap();
  316. }
  317. if (run_all || run_hash_set) {
  318. gTestController.SetCurrentContainer("hash_set");
  319. cerr << "EH test : hash_set" << endl;
  320. test_hash_set();
  321. gTestController.SetCurrentContainer("hash_multiset");
  322. cerr << "EH test : hash_multiset" << endl;
  323. test_hash_multiset();
  324. }
  325. #endif // EH_HASHED_CONTAINERS_IMPLEMENTED
  326. #if defined( EH_ROPE_IMPLEMENTED )
  327. // CW1.8 can't compile this for some reason!
  328. #if !( defined(__MWERKS__) && __MWERKS__ < 0x1900 )
  329. if (run_all || run_rope) {
  330. gTestController.SetCurrentContainer("rope");
  331. cerr << "EH test : rope" << endl;
  332. test_rope();
  333. }
  334. #endif
  335. #endif // EH_ROPE_IMPLEMENTED
  336. #if defined( EH_STRING_IMPLEMENTED )
  337. if (run_all || run_string) {
  338. gTestController.SetCurrentContainer("string");
  339. cerr << "EH test : string" << endl;
  340. test_string();
  341. }
  342. #endif
  343. #if defined( EH_BITSET_IMPLEMENTED )
  344. if (run_all || run_bitset) {
  345. gTestController.SetCurrentContainer("bitset");
  346. cerr << "EH test : bitset" << endl;
  347. test_bitset();
  348. }
  349. #endif
  350. #if defined( EH_VALARRAY_IMPLEMENTED )
  351. if (run_all || run_bitset) {
  352. gTestController.SetCurrentContainer("valarray");
  353. cerr << "EH test : valarray" << endl;
  354. test_valarray();
  355. }
  356. #endif
  357. }
  358. gTestController.TrackAllocations( false );
  359. cerr << "EH test : Done\n";
  360. #if defined(_WIN32_WCE)
  361. cout.rdbuf(old_cout_buf);
  362. cerr.rdbuf(old_cerr_buf);
  363. file.close();
  364. #endif
  365. return 0;
  366. }