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