1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/main.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,408 @@
1.4 +/***********************************************************************************
1.5 + Main.cpp
1.6 + * Portions Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.7 + * Copyright (c) 1997
1.8 + * Mark of the Unicorn, Inc.
1.9 + *
1.10 + * Permission to use, copy, modify, distribute and sell this software
1.11 + * and its documentation for any purpose is hereby granted without fee,
1.12 + * provided that the above copyright notice appear in all copies and
1.13 + * that both that copyright notice and this permission notice appear
1.14 + * in supporting documentation. Mark of the Unicorn makes no
1.15 + * representations about the suitability of this software for any
1.16 + * purpose. It is provided "as is" without express or implied warranty.
1.17 +
1.18 + * Copyright (c) 1997
1.19 + * Moscow Center for SPARC Technology
1.20 + *
1.21 + * Permission to use, copy, modify, distribute and sell this software
1.22 + * and its documentation for any purpose is hereby granted without fee,
1.23 + * provided that the above copyright notice appear in all copies and
1.24 + * that both that copyright notice and this permission notice appear
1.25 + * in supporting documentation. Moscow Center for SPARC Technology makes
1.26 +no
1.27 + * representations about the suitability of this software for any
1.28 + * purpose. It is provided "as is" without express or implied warranty.
1.29 +
1.30 +***********************************************************************************/
1.31 +#include "Prefix.h"
1.32 +#include "Tests.h"
1.33 +
1.34 +#if defined (EH_NEW_IOSTREAMS)
1.35 +# include <iostream>
1.36 +# else
1.37 +# include <iostream.h>
1.38 +#endif
1.39 +
1.40 +#if defined(macintosh)&&(!defined(__MRC__) && !defined(__SC__)) || defined (_MAC) && defined(__MWERKS__)
1.41 +
1.42 +# include <console.h>
1.43 +# include <Types.h>
1.44 +# include <Strings.h>
1.45 +
1.46 +# ifdef EH_NEW_HEADERS
1.47 +# include <cstdio>
1.48 +# include <cstring>
1.49 +# include <cassert>
1.50 +# else
1.51 +# include <stdio.h>
1.52 +# include <string.h>
1.53 +# include <assert.h>
1.54 +# endif
1.55 +
1.56 +# if defined (_STL_DEBUG)
1.57 +
1.58 +# if defined ( EH_USE_SGI_STL )
1.59 +// Override assertion behavior
1.60 +# include <cstdarg>
1.61 +//# include <stldebug.h>
1.62 +void STLPORT::__stl_debug_message(const char * format_str, ...)
1.63 +{
1.64 + std::va_list args;
1.65 + va_start( args, format_str );
1.66 + char msg[256];
1.67 + std::vsnprintf(msg, sizeof(msg)/sizeof(*msg) - 1, format_str, args );
1.68 + DebugStr( c2pstr(msg) );
1.69 +}
1.70 +# else
1.71 +/*===================================================================================
1.72 + __assertion_failed (override standard library function)
1.73 +
1.74 + EFFECTS: Breaks into the debugger and shows the assertion. This implementation
1.75 + is Mac-specific; others could be added for other platforms.
1.76 +====================================================================================*/
1.77 +extern "C"
1.78 +{
1.79 + void __assertion_failed(char *condition, char *testfilename, int lineno);
1.80 + void __assertion_failed(char *condition, char *testfilename, int lineno)
1.81 + {
1.82 + char msg[256];
1.83 + std::strncpy( msg, condition, 255 );
1.84 + std::strncat( msg, ": ", 255 );
1.85 + std::strncat( msg, testfilename, 255 );
1.86 + std::strncat( msg, ", ", 255 );
1.87 + char line[20];
1.88 + std::sprintf( line, "%d", lineno );
1.89 + std::strncat( msg, line, 255 );
1.90 + DebugStr( c2pstr( msg ) );
1.91 + }
1.92 +}
1.93 +# endif
1.94 +
1.95 +# endif
1.96 +
1.97 +#endif
1.98 +
1.99 +#include "nc_alloc.h"
1.100 +
1.101 +#if defined (EH_NEW_HEADERS)
1.102 +# include <vector>
1.103 +# include <cstring>
1.104 +# else
1.105 +# include <vector.h>
1.106 +# include <string.h>
1.107 +#endif
1.108 +
1.109 +#include "TestClass.h"
1.110 +#include "LeakCheck.h"
1.111 +#include "test_construct.h"
1.112 +#ifdef __BORLANDC__
1.113 +# include <except.h>
1.114 +#endif
1.115 +
1.116 +# if defined(EH_USE_NAMESPACES)
1.117 +namespace // dwa 1/21/00 - must use unnamed namespace here to avoid conflict under gcc using native streams
1.118 +{
1.119 + using namespace std;
1.120 + // using std::cerr;
1.121 + // using std::endl;
1.122 +}
1.123 +# endif
1.124 +
1.125 +
1.126 +/*===================================================================================
1.127 + usage (file-static helper)
1.128 +
1.129 + EFFECTS: Prints a message describing the command-line parameters
1.130 +====================================================================================*/
1.131 +static void usage(const char* name)
1.132 +{
1.133 + cerr<<name<<
1.134 + " Usage : leak_test [-n <iterations>] [-s <size>] [-l] [-e] [-q]/[-v] [-t] [test_name...]\n";
1.135 + cerr<<"\t[-n <iterations>] : number of test iterations, default==100;"<<endl;
1.136 + cerr<<"\t[-s <size>] : base value for random container sizes, default==1000;"<<endl;
1.137 + cerr<<"\t[-e] : don't throw exceptions, test for leak in normal conditions;"<<endl;
1.138 +// This option was never actually used -- dwa 9/22/97
1.139 +// cerr<<"\t[-i] : ignore leak errors;"<<endl;
1.140 + cerr<<"\t[-q] : quiet mode;"<<endl;
1.141 + cerr<<"\t[-v] : verbose mode;"<<endl;
1.142 + cerr<<"\t[-t] : track each allocation;"<<endl;
1.143 + cerr<<"\t[test name [test name...]] : run only some of the tests by name (default==all tests):"<<endl;
1.144 + cerr<<"\t\tpossible test names are : algo vector bit_vector list slist deque set map hash_set hash_map rope string bitset valarray"<<endl;
1.145 + EH_CSTD::exit(1);
1.146 +}
1.147 +
1.148 +# ifdef EH_NEW_HEADERS
1.149 +# include <set>
1.150 +# else
1.151 +# include <set.h>
1.152 +# endif
1.153 +
1.154 +#if defined(_WIN32_WCE) || defined(__SYMBIAN32__)
1.155 +#include <fstream>
1.156 +#endif
1.157 +
1.158 +int _STLP_CALL main(int argc, char** argv)
1.159 +{
1.160 +#if defined(_WIN32_WCE) || defined(__SYMBIAN32__)
1.161 + std::ofstream file( "c:\\eh_test.txt" );
1.162 + std::streambuf* old_cout_buf = cout.rdbuf(file.rdbuf());
1.163 + std::streambuf* old_cerr_buf = cerr.rdbuf(file.rdbuf());
1.164 +#endif
1.165 +#if defined( __MWERKS__ ) && defined( macintosh ) // Get command line.
1.166 + argc = ccommand(&argv);
1.167 + // Allow the i/o window to be repositioned.
1.168 +// EH_STD::string s;
1.169 +// getline(EH_STD::cin, s);
1.170 +#endif
1.171 + unsigned int niters=2;
1.172 + bool run_all=true;
1.173 + bool run_slist = false;
1.174 + bool run_list = false;
1.175 + bool run_vector = false;
1.176 + bool run_bit_vector = false;
1.177 + bool run_deque = false;
1.178 + bool run_hash_map = false;
1.179 + bool run_hash_set = false;
1.180 + bool run_set = false;
1.181 + bool run_map = false;
1.182 + bool run_algo = false;
1.183 + bool run_algobase = false;
1.184 + bool run_rope = false;
1.185 + bool run_string = false;
1.186 + bool run_bitset = false;
1.187 + bool run_valarray = false;
1.188 +
1.189 + int cur_argv;
1.190 + char *p, *p1;
1.191 +#if defined (EH_NEW_IOSTREAMS)
1.192 + std::ios_base::sync_with_stdio(false);
1.193 +#endif
1.194 +
1.195 + cerr << argv[0]<<" : Exception handling testsuite.\n";
1.196 + cerr.flush();
1.197 +
1.198 + bool track_allocations = false;
1.199 + // parse parameters :
1.200 + // leak_test [-iterations] [-test] ...
1.201 + for (cur_argv=1; cur_argv<argc; cur_argv++) {
1.202 + p = argv[cur_argv];
1.203 + if (*p == '-') {
1.204 + switch (p[1]) {
1.205 + case 'q':
1.206 + gTestController.SetVerbose(false);
1.207 + break;
1.208 + case 'v':
1.209 + gTestController.SetVerbose(true);
1.210 + break;
1.211 +#if 0 // This option was never actually used -- dwa 9/22/97
1.212 + case 'i':
1.213 + gTestController.IgnoreLeaks(true);
1.214 + break;
1.215 +#endif
1.216 + case 'n':
1.217 + p1 = argv[++cur_argv];
1.218 + if (p1 && EH_CSTD::sscanf(p1, "%i", &niters)==1)
1.219 + cerr <<" Doing "<<niters<<" iterations\n";
1.220 + else
1.221 + usage(argv[0]);
1.222 + break;
1.223 + case 't':
1.224 + track_allocations = true;
1.225 + break;
1.226 + case 'e':
1.227 + gTestController.TurnOffExceptions();
1.228 + break;
1.229 + case 's':
1.230 + p1 = argv[++cur_argv];
1.231 + if (p1 && EH_CSTD::sscanf(p1, "%i", &random_base)==1)
1.232 + cerr <<" Setting "<<random_base<<" as base for random sizes.\n";
1.233 + else
1.234 + usage(argv[0]);
1.235 + break;
1.236 + default:
1.237 + usage(argv[0]);
1.238 + break;
1.239 + }
1.240 + } else {
1.241 + run_all = false;
1.242 + // test name
1.243 + if (EH_CSTD::strcmp(p, "algo")==0) {
1.244 + run_algo=true;
1.245 + } else if (EH_CSTD::strcmp(p, "vector")==0) {
1.246 + run_vector=true;
1.247 + } else if (EH_CSTD::strcmp(p, "bit_vector")==0) {
1.248 + run_bit_vector=true;
1.249 + } else if (EH_CSTD::strcmp(p, "list")==0) {
1.250 + run_list=true;
1.251 + } else if (EH_CSTD::strcmp(p, "slist")==0) {
1.252 + run_slist=true;
1.253 + } else if (EH_CSTD::strcmp(p, "deque")==0) {
1.254 + run_deque=true;
1.255 + } else if (EH_CSTD::strcmp(p, "set")==0) {
1.256 + run_set=true;
1.257 + } else if (EH_CSTD::strcmp(p, "map")==0) {
1.258 + run_map=true;
1.259 + } else if (EH_CSTD::strcmp(p, "hash_set")==0) {
1.260 + run_hash_set=true;
1.261 + } else if (EH_CSTD::strcmp(p, "hash_map")==0) {
1.262 + run_hash_map=true;
1.263 + } else if (EH_CSTD::strcmp(p, "rope")==0) {
1.264 + run_rope=true;
1.265 + } else if (EH_CSTD::strcmp(p, "string")==0) {
1.266 + run_string=true;
1.267 + } else if (EH_CSTD::strcmp(p, "bitset")==0) {
1.268 + run_bitset=true;
1.269 + } else if (EH_CSTD::strcmp(p, "valarray")==0) {
1.270 + run_valarray=true;
1.271 + } else {
1.272 + usage(argv[0]);
1.273 + }
1.274 +
1.275 + }
1.276 + }
1.277 +
1.278 + gTestController.TrackAllocations( track_allocations );
1.279 +
1.280 + // Over and over...
1.281 + for ( unsigned i = 0; i < niters ; i++ )
1.282 + {
1.283 + cerr << "iteration #" << i << "\n";
1.284 + if (run_all || run_algobase) {
1.285 + gTestController.SetCurrentContainer("algobase");
1.286 + cerr << "EH test : algobase" << endl;
1.287 + test_algobase();
1.288 + }
1.289 + if (run_all || run_algo) {
1.290 + gTestController.SetCurrentContainer("algo");
1.291 + cerr << "EH test : algo" << endl;
1.292 + test_algo();
1.293 + }
1.294 +
1.295 + if (run_all || run_vector) {
1.296 + gTestController.SetCurrentContainer("vector");
1.297 + cerr << "EH test : vector" << endl;
1.298 + test_vector();
1.299 + }
1.300 +
1.301 +#if defined( EH_BIT_VECTOR_IMPLEMENTED )
1.302 + if (run_all || run_bit_vector) {
1.303 + gTestController.SetCurrentContainer("bit_vector");
1.304 + cerr << "EH test : bit_vector" << endl;
1.305 + test_bit_vector();
1.306 + }
1.307 +#endif
1.308 +
1.309 + if (run_all || run_list) {
1.310 + gTestController.SetCurrentContainer("list");
1.311 + cerr << "EH test : list" << endl;
1.312 + test_list();
1.313 + }
1.314 +
1.315 +#if defined( EH_SLIST_IMPLEMENTED )
1.316 + if (run_all || run_slist) {
1.317 + gTestController.SetCurrentContainer("slist");
1.318 + cerr << "EH test : slist" << endl;
1.319 + test_slist();
1.320 + }
1.321 +#endif // EH_SLIST_IMPLEMENTED
1.322 +
1.323 + if (run_all || run_deque) {
1.324 + gTestController.SetCurrentContainer("deque");
1.325 + cerr << "EH test : deque" << endl;
1.326 + test_deque();
1.327 + }
1.328 + if (run_all || run_set) {
1.329 + gTestController.SetCurrentContainer("set");
1.330 + cerr << "EH test : set" << endl;
1.331 + test_set();
1.332 + gTestController.SetCurrentContainer("multiset");
1.333 + cerr << "EH test : multiset" << endl;
1.334 + test_multiset();
1.335 + }
1.336 +
1.337 + if (run_all || run_map) {
1.338 + gTestController.SetCurrentContainer("map");
1.339 + cerr << "EH test : map" << endl;
1.340 + test_map();
1.341 + gTestController.SetCurrentContainer("multimap");
1.342 + cerr << "EH test : multimap" << endl;
1.343 + test_multimap();
1.344 + }
1.345 +
1.346 +#if defined( EH_HASHED_CONTAINERS_IMPLEMENTED )
1.347 + if (run_all || run_hash_map) {
1.348 + gTestController.SetCurrentContainer("hash_map");
1.349 + cerr << "EH test : hash_map" << endl;
1.350 + test_hash_map();
1.351 + gTestController.SetCurrentContainer("hash_multimap");
1.352 + cerr << "EH test : hash_multimap" << endl;
1.353 +
1.354 + test_hash_multimap();
1.355 + }
1.356 +
1.357 + if (run_all || run_hash_set) {
1.358 + gTestController.SetCurrentContainer("hash_set");
1.359 + cerr << "EH test : hash_set" << endl;
1.360 + test_hash_set();
1.361 + gTestController.SetCurrentContainer("hash_multiset");
1.362 + cerr << "EH test : hash_multiset" << endl;
1.363 + test_hash_multiset();
1.364 + }
1.365 +#endif // EH_HASHED_CONTAINERS_IMPLEMENTED
1.366 +
1.367 +#if defined( EH_ROPE_IMPLEMENTED )
1.368 + // CW1.8 can't compile this for some reason!
1.369 +#if !( defined(__MWERKS__) && __MWERKS__ < 0x1900 )
1.370 + if (run_all || run_rope) {
1.371 + gTestController.SetCurrentContainer("rope");
1.372 + cerr << "EH test : rope" << endl;
1.373 + test_rope();
1.374 + }
1.375 +#endif
1.376 +#endif // EH_ROPE_IMPLEMENTED
1.377 +#if defined( EH_STRING_IMPLEMENTED )
1.378 + if (run_all || run_string) {
1.379 + gTestController.SetCurrentContainer("string");
1.380 + cerr << "EH test : string" << endl;
1.381 + test_string();
1.382 + }
1.383 +#endif
1.384 +#if defined( EH_BITSET_IMPLEMENTED )
1.385 + if (run_all || run_bitset) {
1.386 + gTestController.SetCurrentContainer("bitset");
1.387 + cerr << "EH test : bitset" << endl;
1.388 + test_bitset();
1.389 + }
1.390 +#endif
1.391 +#if defined( EH_VALARRAY_IMPLEMENTED )
1.392 + if (run_all || run_bitset) {
1.393 + gTestController.SetCurrentContainer("valarray");
1.394 + cerr << "EH test : valarray" << endl;
1.395 + test_valarray();
1.396 + }
1.397 +#endif
1.398 + }
1.399 +
1.400 + gTestController.TrackAllocations( false );
1.401 + cerr << "EH test : Done\n";
1.402 +
1.403 +#if defined(_WIN32_WCE) || defined(__SYMBIAN32__)
1.404 + cout.rdbuf(old_cout_buf);
1.405 + cerr.rdbuf(old_cerr_buf);
1.406 + file.close();
1.407 +#endif
1.408 +
1.409 + return 0;
1.410 +}
1.411 +