Update contrib.
1 /***********************************************************************************
3 * Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5 * Mark of the Unicorn, Inc.
7 * Permission to use, copy, modify, distribute and sell this software
8 * and its documentation for any purpose is hereby granted without fee,
9 * provided that the above copyright notice appear in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation. Mark of the Unicorn makes no
12 * representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
16 * Moscow Center for SPARC Technology
18 * Permission to use, copy, modify, distribute and sell this software
19 * and its documentation for any purpose is hereby granted without fee,
20 * provided that the above copyright notice appear in all copies and
21 * that both that copyright notice and this permission notice appear
22 * in supporting documentation. Moscow Center for SPARC Technology makes
24 * representations about the suitability of this software for any
25 * purpose. It is provided "as is" without express or implied warranty.
27 ***********************************************************************************/
31 #if defined (EH_NEW_IOSTREAMS)
34 # include <iostream.h>
37 #if defined(macintosh)&&(!defined(__MRC__) && !defined(__SC__)) || defined (_MAC) && defined(__MWERKS__)
43 # ifdef EH_NEW_HEADERS
53 # if defined (_STL_DEBUG)
55 # if defined ( EH_USE_SGI_STL )
56 // Override assertion behavior
58 //# include <stldebug.h>
59 void STLPORT::__stl_debug_message(const char * format_str, ...)
62 va_start( args, format_str );
64 std::vsnprintf(msg, sizeof(msg)/sizeof(*msg) - 1, format_str, args );
65 DebugStr( c2pstr(msg) );
68 /*===================================================================================
69 __assertion_failed (override standard library function)
71 EFFECTS: Breaks into the debugger and shows the assertion. This implementation
72 is Mac-specific; others could be added for other platforms.
73 ====================================================================================*/
76 void __assertion_failed(char *condition, char *testfilename, int lineno);
77 void __assertion_failed(char *condition, char *testfilename, int lineno)
80 std::strncpy( msg, condition, 255 );
81 std::strncat( msg, ": ", 255 );
82 std::strncat( msg, testfilename, 255 );
83 std::strncat( msg, ", ", 255 );
85 std::sprintf( line, "%d", lineno );
86 std::strncat( msg, line, 255 );
87 DebugStr( c2pstr( msg ) );
98 #if defined (EH_NEW_HEADERS)
106 #include "TestClass.h"
107 #include "LeakCheck.h"
108 #include "test_construct.h"
113 # if defined(EH_USE_NAMESPACES)
114 namespace // dwa 1/21/00 - must use unnamed namespace here to avoid conflict under gcc using native streams
123 /*===================================================================================
124 usage (file-static helper)
126 EFFECTS: Prints a message describing the command-line parameters
127 ====================================================================================*/
128 static void usage(const char* name)
131 " Usage : leak_test [-n <iterations>] [-s <size>] [-l] [-e] [-q]/[-v] [-t] [test_name...]\n";
132 cerr<<"\t[-n <iterations>] : number of test iterations, default==100;"<<endl;
133 cerr<<"\t[-s <size>] : base value for random container sizes, default==1000;"<<endl;
134 cerr<<"\t[-e] : don't throw exceptions, test for leak in normal conditions;"<<endl;
135 // This option was never actually used -- dwa 9/22/97
136 // cerr<<"\t[-i] : ignore leak errors;"<<endl;
137 cerr<<"\t[-q] : quiet mode;"<<endl;
138 cerr<<"\t[-v] : verbose mode;"<<endl;
139 cerr<<"\t[-t] : track each allocation;"<<endl;
140 cerr<<"\t[test name [test name...]] : run only some of the tests by name (default==all tests):"<<endl;
141 cerr<<"\t\tpossible test names are : algo vector bit_vector list slist deque set map hash_set hash_map rope string bitset valarray"<<endl;
145 # ifdef EH_NEW_HEADERS
151 #if defined(_WIN32_WCE) || defined(__SYMBIAN32__)
155 int _STLP_CALL main(int argc, char** argv)
157 #if defined(_WIN32_WCE) || defined(__SYMBIAN32__)
158 std::ofstream file( "c:\\eh_test.txt" );
159 std::streambuf* old_cout_buf = cout.rdbuf(file.rdbuf());
160 std::streambuf* old_cerr_buf = cerr.rdbuf(file.rdbuf());
162 #if defined( __MWERKS__ ) && defined( macintosh ) // Get command line.
163 argc = ccommand(&argv);
164 // Allow the i/o window to be repositioned.
166 // getline(EH_STD::cin, s);
168 unsigned int niters=2;
170 bool run_slist = false;
171 bool run_list = false;
172 bool run_vector = false;
173 bool run_bit_vector = false;
174 bool run_deque = false;
175 bool run_hash_map = false;
176 bool run_hash_set = false;
177 bool run_set = false;
178 bool run_map = false;
179 bool run_algo = false;
180 bool run_algobase = false;
181 bool run_rope = false;
182 bool run_string = false;
183 bool run_bitset = false;
184 bool run_valarray = false;
188 #if defined (EH_NEW_IOSTREAMS)
189 std::ios_base::sync_with_stdio(false);
192 cerr << argv[0]<<" : Exception handling testsuite.\n";
195 bool track_allocations = false;
196 // parse parameters :
197 // leak_test [-iterations] [-test] ...
198 for (cur_argv=1; cur_argv<argc; cur_argv++) {
203 gTestController.SetVerbose(false);
206 gTestController.SetVerbose(true);
208 #if 0 // This option was never actually used -- dwa 9/22/97
210 gTestController.IgnoreLeaks(true);
214 p1 = argv[++cur_argv];
215 if (p1 && EH_CSTD::sscanf(p1, "%i", &niters)==1)
216 cerr <<" Doing "<<niters<<" iterations\n";
221 track_allocations = true;
224 gTestController.TurnOffExceptions();
227 p1 = argv[++cur_argv];
228 if (p1 && EH_CSTD::sscanf(p1, "%i", &random_base)==1)
229 cerr <<" Setting "<<random_base<<" as base for random sizes.\n";
240 if (EH_CSTD::strcmp(p, "algo")==0) {
242 } else if (EH_CSTD::strcmp(p, "vector")==0) {
244 } else if (EH_CSTD::strcmp(p, "bit_vector")==0) {
246 } else if (EH_CSTD::strcmp(p, "list")==0) {
248 } else if (EH_CSTD::strcmp(p, "slist")==0) {
250 } else if (EH_CSTD::strcmp(p, "deque")==0) {
252 } else if (EH_CSTD::strcmp(p, "set")==0) {
254 } else if (EH_CSTD::strcmp(p, "map")==0) {
256 } else if (EH_CSTD::strcmp(p, "hash_set")==0) {
258 } else if (EH_CSTD::strcmp(p, "hash_map")==0) {
260 } else if (EH_CSTD::strcmp(p, "rope")==0) {
262 } else if (EH_CSTD::strcmp(p, "string")==0) {
264 } else if (EH_CSTD::strcmp(p, "bitset")==0) {
266 } else if (EH_CSTD::strcmp(p, "valarray")==0) {
275 gTestController.TrackAllocations( track_allocations );
278 for ( unsigned i = 0; i < niters ; i++ )
280 cerr << "iteration #" << i << "\n";
281 if (run_all || run_algobase) {
282 gTestController.SetCurrentContainer("algobase");
283 cerr << "EH test : algobase" << endl;
286 if (run_all || run_algo) {
287 gTestController.SetCurrentContainer("algo");
288 cerr << "EH test : algo" << endl;
292 if (run_all || run_vector) {
293 gTestController.SetCurrentContainer("vector");
294 cerr << "EH test : vector" << endl;
298 #if defined( EH_BIT_VECTOR_IMPLEMENTED )
299 if (run_all || run_bit_vector) {
300 gTestController.SetCurrentContainer("bit_vector");
301 cerr << "EH test : bit_vector" << endl;
306 if (run_all || run_list) {
307 gTestController.SetCurrentContainer("list");
308 cerr << "EH test : list" << endl;
312 #if defined( EH_SLIST_IMPLEMENTED )
313 if (run_all || run_slist) {
314 gTestController.SetCurrentContainer("slist");
315 cerr << "EH test : slist" << endl;
318 #endif // EH_SLIST_IMPLEMENTED
320 if (run_all || run_deque) {
321 gTestController.SetCurrentContainer("deque");
322 cerr << "EH test : deque" << endl;
325 if (run_all || run_set) {
326 gTestController.SetCurrentContainer("set");
327 cerr << "EH test : set" << endl;
329 gTestController.SetCurrentContainer("multiset");
330 cerr << "EH test : multiset" << endl;
334 if (run_all || run_map) {
335 gTestController.SetCurrentContainer("map");
336 cerr << "EH test : map" << endl;
338 gTestController.SetCurrentContainer("multimap");
339 cerr << "EH test : multimap" << endl;
343 #if defined( EH_HASHED_CONTAINERS_IMPLEMENTED )
344 if (run_all || run_hash_map) {
345 gTestController.SetCurrentContainer("hash_map");
346 cerr << "EH test : hash_map" << endl;
348 gTestController.SetCurrentContainer("hash_multimap");
349 cerr << "EH test : hash_multimap" << endl;
351 test_hash_multimap();
354 if (run_all || run_hash_set) {
355 gTestController.SetCurrentContainer("hash_set");
356 cerr << "EH test : hash_set" << endl;
358 gTestController.SetCurrentContainer("hash_multiset");
359 cerr << "EH test : hash_multiset" << endl;
360 test_hash_multiset();
362 #endif // EH_HASHED_CONTAINERS_IMPLEMENTED
364 #if defined( EH_ROPE_IMPLEMENTED )
365 // CW1.8 can't compile this for some reason!
366 #if !( defined(__MWERKS__) && __MWERKS__ < 0x1900 )
367 if (run_all || run_rope) {
368 gTestController.SetCurrentContainer("rope");
369 cerr << "EH test : rope" << endl;
373 #endif // EH_ROPE_IMPLEMENTED
374 #if defined( EH_STRING_IMPLEMENTED )
375 if (run_all || run_string) {
376 gTestController.SetCurrentContainer("string");
377 cerr << "EH test : string" << endl;
381 #if defined( EH_BITSET_IMPLEMENTED )
382 if (run_all || run_bitset) {
383 gTestController.SetCurrentContainer("bitset");
384 cerr << "EH test : bitset" << endl;
388 #if defined( EH_VALARRAY_IMPLEMENTED )
389 if (run_all || run_bitset) {
390 gTestController.SetCurrentContainer("valarray");
391 cerr << "EH test : valarray" << endl;
397 gTestController.TrackAllocations( false );
398 cerr << "EH test : Done\n";
400 #if defined(_WIN32_WCE) || defined(__SYMBIAN32__)
401 cout.rdbuf(old_cout_buf);
402 cerr.rdbuf(old_cerr_buf);