os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/string_test.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/string_test.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1517 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// To make GLib C++ closer to STLport behavior we need this macro:
    1.18 +// Only mandatory when building unit tests without STLport, do not change
    1.19 +// anything when building with STLport
    1.20 +// 
    1.21 +//
    1.22 +
    1.23 +#define _GLIBCXX_FULLY_DYNAMIC_STRING
    1.24 +
    1.25 +//Has to be first for StackAllocator swap overload to be taken
    1.26 +//into account (at least using GCC 4.0.1)
    1.27 +#include "stack_allocator.h"
    1.28 +
    1.29 +#include <vector>
    1.30 +#include <deque>
    1.31 +#include <string>
    1.32 +#include <algorithm>
    1.33 +#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
    1.34 +#  include <sstream>
    1.35 +#endif
    1.36 +
    1.37 +#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
    1.38 +#  include <stdexcept>
    1.39 +#endif
    1.40 +
    1.41 +#if !defined (STLPORT) || defined (_STLP_THREADS)
    1.42 +#  if defined (STLPORT) && defined (_STLP_PTHREADS) || \
    1.43 +      defined (__GNUC__) && !defined (__MINGW32__)
    1.44 +#    define USE_PTHREAD_API
    1.45 +#    include <pthread.h>
    1.46 +#  endif
    1.47 +
    1.48 +#  if defined (STLPORT) && defined (_STLP_WIN32THREADS) || \
    1.49 +      defined (__GNUC__) && defined (__MINGW32__) || \
    1.50 +      defined (_MSC_VER)
    1.51 +#    define USE_WINDOWS_API
    1.52 +#    include <windows.h>
    1.53 +#  endif
    1.54 +#endif
    1.55 +
    1.56 +#include "stack_allocator.h"
    1.57 +#include "cppunit/cppunit_proxy.h"
    1.58 +
    1.59 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
    1.60 +using namespace std;
    1.61 +#endif
    1.62 +
    1.63 +//
    1.64 +// TestCase class
    1.65 +//
    1.66 +class StringTest : public CPPUNIT_NS::TestCase
    1.67 +{
    1.68 +  CPPUNIT_TEST_SUITE(StringTest);
    1.69 +  CPPUNIT_TEST(constructor);
    1.70 +  CPPUNIT_TEST(reserve);
    1.71 +  CPPUNIT_TEST(assign);
    1.72 +  CPPUNIT_TEST(erase);
    1.73 +  CPPUNIT_TEST(data);
    1.74 +  CPPUNIT_TEST(c_str);
    1.75 +  CPPUNIT_TEST(null_char);
    1.76 +  CPPUNIT_TEST(insert);
    1.77 +  CPPUNIT_TEST(replace);
    1.78 +  CPPUNIT_TEST(resize);
    1.79 +  CPPUNIT_TEST(short_string);
    1.80 +  CPPUNIT_TEST(find);
    1.81 +  CPPUNIT_TEST(rfind);
    1.82 +  CPPUNIT_TEST(find_last_of);
    1.83 +  CPPUNIT_TEST(find_last_not_of);
    1.84 +  CPPUNIT_TEST(copy);
    1.85 +#if !defined (USE_PTHREAD_API) && !defined (USE_WINDOWS_API)
    1.86 +  CPPUNIT_IGNORE;
    1.87 +#endif
    1.88 +  CPPUNIT_TEST(mt);
    1.89 +  CPPUNIT_STOP_IGNORE;
    1.90 +  CPPUNIT_TEST(short_string_optim_bug);
    1.91 +  CPPUNIT_TEST(compare);
    1.92 +#if defined (__DMC__)
    1.93 +  CPPUNIT_IGNORE;
    1.94 +#endif
    1.95 +  CPPUNIT_TEST(template_expression);
    1.96 +#if defined (STLPORT) && defined (_STLP_MSVC) && (_STLP_MSVC < 1300)
    1.97 +#  define TE_TMP_TEST_IGNORED
    1.98 +  CPPUNIT_IGNORE;
    1.99 +#endif
   1.100 +  CPPUNIT_TEST(te_tmp);
   1.101 +#if defined (TE_TMP_TEST_IGNORED)
   1.102 +  CPPUNIT_STOP_IGNORE;
   1.103 +#endif
   1.104 +#if defined (STLPORT) && defined (_STLP_NO_WCHAR_T)
   1.105 +  CPPUNIT_IGNORE;
   1.106 +#endif
   1.107 +#if defined (__CYGWIN__) && !defined (STLPORT)
   1.108 +  CPPUNIT_IGNORE;
   1.109 +#endif
   1.110 +  CPPUNIT_TEST(template_wexpression);
   1.111 +  CPPUNIT_STOP_IGNORE;
   1.112 +#if defined (STLPORT) && defined (_STLP_USE_NO_IOSTREAMS)
   1.113 +  CPPUNIT_IGNORE;
   1.114 +#endif
   1.115 +  CPPUNIT_TEST(io);
   1.116 +  CPPUNIT_STOP_IGNORE;
   1.117 +#if defined (STLPORT) && defined (_STLP_NO_CUSTOM_IO) 
   1.118 +  CPPUNIT_IGNORE;
   1.119 +#endif
   1.120 +  CPPUNIT_TEST(allocator_with_state);
   1.121 +  CPPUNIT_STOP_IGNORE;
   1.122 +  CPPUNIT_TEST(capacity);
   1.123 +  CPPUNIT_TEST(str_cov1);
   1.124 +  CPPUNIT_TEST(str_cov2);
   1.125 +  CPPUNIT_TEST(str_cov3);
   1.126 +  CPPUNIT_TEST(str_cov4);
   1.127 +  CPPUNIT_TEST(str_cov5);
   1.128 +  CPPUNIT_TEST(str_cov6);
   1.129 +  CPPUNIT_TEST_SUITE_END();
   1.130 +
   1.131 +protected:
   1.132 +  void constructor();
   1.133 +  void reserve();
   1.134 +  void erase();
   1.135 +  void data();
   1.136 +  void c_str();
   1.137 +  void null_char();
   1.138 +  void insert();
   1.139 +  void replace();
   1.140 +  void resize();
   1.141 +  void short_string();
   1.142 +  void find();
   1.143 +  void rfind();
   1.144 +  void find_last_of();
   1.145 +  void find_last_not_of();
   1.146 +  void copy();
   1.147 +  void assign();
   1.148 +  void mt();
   1.149 +  void short_string_optim_bug();
   1.150 +  void compare();
   1.151 +  void template_expression();
   1.152 +  void te_tmp();
   1.153 +  void template_wexpression();
   1.154 +  void io();
   1.155 +  void allocator_with_state();
   1.156 +  void capacity();
   1.157 +  void str_cov1();
   1.158 +  void str_cov2();
   1.159 +  void str_cov3();
   1.160 +  void str_cov4();
   1.161 +  void str_cov5();
   1.162 +  void str_cov6();
   1.163 +  static string func(const string& par) {
   1.164 +    string tmp( par );
   1.165 +    return tmp;
   1.166 +  }
   1.167 +
   1.168 +#if defined (USE_PTHREAD_API) || defined (USE_WINDOWS_API)
   1.169 +#  if defined (USE_PTHREAD_API)
   1.170 +  static void* f(void*)
   1.171 +#  else
   1.172 +  static DWORD __stdcall f(void*)
   1.173 +#  endif
   1.174 +  {
   1.175 +    string s( "qyweyuewunfkHBUKGYUGL,wehbYGUW^(@T@H!BALWD:h^&@#*@(#:JKHWJ:CND" );
   1.176 +
   1.177 +    for ( int i = 0; i < 2000000; ++i ) {
   1.178 +      string sx = func( s );
   1.179 +    }
   1.180 +
   1.181 +    return 0;
   1.182 +  }
   1.183 +#endif
   1.184 +
   1.185 +};
   1.186 +
   1.187 +CPPUNIT_TEST_SUITE_REGISTRATION(StringTest);
   1.188 +
   1.189 +//
   1.190 +// tests implementation
   1.191 +//
   1.192 +void StringTest::constructor()
   1.193 +{
   1.194 +#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
   1.195 +  try {
   1.196 +    string s((size_t)-1, 'a');
   1.197 +    CPPUNIT_ASSERT( false );
   1.198 +  }
   1.199 +  catch (length_error const&) {
   1.200 +  }
   1.201 +  catch (...) {
   1.202 +    //Expected exception is length_error:
   1.203 +    CPPUNIT_ASSERT( false );
   1.204 +  }
   1.205 +#endif
   1.206 +}
   1.207 +
   1.208 +void StringTest::reserve()
   1.209 +{
   1.210 +  string s;
   1.211 +#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
   1.212 +  try {
   1.213 +    s.reserve(s.max_size() + 1);
   1.214 +    CPPUNIT_ASSERT( false );
   1.215 +  }
   1.216 +  catch (length_error const&) {
   1.217 +  }
   1.218 +  catch (...) {
   1.219 +    //Expected exception is length_error:
   1.220 +    CPPUNIT_ASSERT( false );
   1.221 +  }
   1.222 +#endif
   1.223 +}
   1.224 +
   1.225 +void StringTest::mt()
   1.226 +{
   1.227 +#if defined (USE_PTHREAD_API) || defined (USE_WINDOWS_API)
   1.228 +  const int nth = 2;
   1.229 +#  if defined (USE_PTHREAD_API)
   1.230 +  pthread_t t[nth];
   1.231 +
   1.232 +  for ( int i = 0; i < nth; ++i ) {
   1.233 +    pthread_create( &t[i], 0, f, 0 );
   1.234 +  }
   1.235 +
   1.236 +  for ( int i = 0; i < nth; ++i ) {
   1.237 +    pthread_join( t[i], 0 );
   1.238 +  }
   1.239 +#  endif // PTHREAD
   1.240 +
   1.241 +#  if defined (USE_WINDOWS_API)
   1.242 +  //DWORD start = GetTickCount();
   1.243 +
   1.244 +  HANDLE t[nth];
   1.245 +
   1.246 +  int i; // VC6 not support in-loop scope of cycle var
   1.247 +  for ( i = 0; i < nth; ++i ) {
   1.248 +    t[i] = CreateThread(NULL, 0, f, 0, 0, NULL);
   1.249 +  }
   1.250 +
   1.251 +  if (WaitForMultipleObjects(nth, t, TRUE, INFINITE) == WAIT_FAILED) {
   1.252 +    // On some platforms (evc3/evc4) WaitForMultipleObjects() with fWaitAll == TRUE
   1.253 +    // is not supported. We then wait with a loop on each thread:
   1.254 +    for ( i = 0; i < nth; ++i ) {
   1.255 +      WaitForSingleObject(t[i], INFINITE);
   1.256 +    }
   1.257 +  }
   1.258 +
   1.259 +  /*
   1.260 +  DWORD duration = GetTickCount() - start;
   1.261 +  ostringstream ostr;
   1.262 +  ostr << "Duration: " << duration << endl;
   1.263 +  CPPUNIT_MESSAGE(ostr.str().c_str());
   1.264 +  */
   1.265 +#  endif
   1.266 +#endif
   1.267 +}
   1.268 +
   1.269 +void StringTest::short_string()
   1.270 +{
   1.271 +  string const ref_short_str1("str1"), ref_short_str2("str2");
   1.272 +  string short_str1(ref_short_str1), short_str2(ref_short_str2);
   1.273 +  string const ref_long_str1("str                                                  1");
   1.274 +  string const ref_long_str2("str                                                  2");
   1.275 +  string long_str1(ref_long_str1), long_str2(ref_long_str2);
   1.276 +
   1.277 +  CPPUNIT_ASSERT(short_str1 == ref_short_str1);
   1.278 +  CPPUNIT_ASSERT(long_str1 == ref_long_str1);
   1.279 +
   1.280 +  {
   1.281 +    string str1(short_str1);
   1.282 +    str1 = long_str1;
   1.283 +    CPPUNIT_ASSERT(str1 == ref_long_str1);
   1.284 +  }
   1.285 +
   1.286 +  {
   1.287 +    string str1(long_str1);
   1.288 +    str1 = short_str1;
   1.289 +    CPPUNIT_ASSERT(str1 == ref_short_str1);
   1.290 +  }
   1.291 +
   1.292 +  {
   1.293 +    short_str1.swap(short_str2);
   1.294 +    CPPUNIT_ASSERT((short_str1 == ref_short_str2) && (short_str2 == ref_short_str1));
   1.295 +    short_str1.swap(short_str2);
   1.296 +  }
   1.297 +
   1.298 +  {
   1.299 +    long_str1.swap(long_str2);
   1.300 +    CPPUNIT_ASSERT((long_str1 == ref_long_str2) && (long_str2 == ref_long_str1));
   1.301 +    long_str1.swap(long_str2);
   1.302 +  }
   1.303 +
   1.304 +  {
   1.305 +    short_str1.swap(long_str1);
   1.306 +    CPPUNIT_ASSERT((short_str1 == ref_long_str1) && (long_str1 == ref_short_str1));
   1.307 +    short_str1.swap(long_str1);
   1.308 +  }
   1.309 +
   1.310 +  {
   1.311 +    long_str1.swap(short_str1);
   1.312 +    CPPUNIT_ASSERT((short_str1 == ref_long_str1) && (long_str1 == ref_short_str1));
   1.313 +    long_str1.swap(short_str1);
   1.314 +  }
   1.315 +
   1.316 +  {
   1.317 +    //This is to test move constructor
   1.318 +    vector<string> str_vect;
   1.319 +    str_vect.push_back(short_str1);
   1.320 +    str_vect.push_back(long_str1);
   1.321 +    str_vect.push_back(short_str2);
   1.322 +    str_vect.push_back(long_str2);
   1.323 +    CPPUNIT_ASSERT((str_vect[0] == ref_short_str1) &&
   1.324 +                   (str_vect[1] == ref_long_str1) &&
   1.325 +                   (str_vect[2] == ref_short_str2) &&
   1.326 +                   (str_vect[3] == ref_long_str2));
   1.327 +  }
   1.328 +}
   1.329 +
   1.330 +void StringTest::erase()
   1.331 +{
   1.332 +  char const* c_str = "Hello, World!";
   1.333 +  string str(c_str);
   1.334 +  CPPUNIT_ASSERT( str == c_str );
   1.335 +
   1.336 +  str.erase(str.begin() + 1, str.end() - 1); // Erase all but first and last.
   1.337 +
   1.338 +  size_t i;
   1.339 +  for (i = 0; i < str.size(); ++i) {
   1.340 +    switch ( i ) {
   1.341 +      case 0:
   1.342 +        CPPUNIT_ASSERT( str[i] == 'H' );
   1.343 +        break;
   1.344 +      case 1:
   1.345 +        CPPUNIT_ASSERT( str[i] == '!' );
   1.346 +        break;
   1.347 +      default:
   1.348 +        CPPUNIT_ASSERT( false );
   1.349 +    }
   1.350 +  }
   1.351 +
   1.352 +  str.insert(1, c_str);
   1.353 +  str.erase(str.begin()); // Erase first element.
   1.354 +  str.erase(str.end() - 1); // Erase last element.
   1.355 +  CPPUNIT_ASSERT( str == c_str );
   1.356 +  str.clear(); // Erase all.
   1.357 +  CPPUNIT_ASSERT( str.empty() );
   1.358 +
   1.359 +  str = c_str;
   1.360 +  CPPUNIT_ASSERT( str == c_str );
   1.361 +
   1.362 +  str.erase(1, str.size() - 1); // Erase all but first and last.
   1.363 +  for (i = 0; i < str.size(); i++) {
   1.364 +    switch ( i ) {
   1.365 +      case 0:
   1.366 +        CPPUNIT_ASSERT( str[i] == 'H' );
   1.367 +        break;
   1.368 +      case 1:
   1.369 +        CPPUNIT_ASSERT( str[i] == '!' );
   1.370 +        break;
   1.371 +      default:
   1.372 +        CPPUNIT_ASSERT( false );
   1.373 +    }
   1.374 +  }
   1.375 +
   1.376 +  str.erase(1);
   1.377 +  CPPUNIT_ASSERT( str == "H" );
   1.378 +}
   1.379 +
   1.380 +void StringTest::data()
   1.381 +{
   1.382 +  string xx;
   1.383 +
   1.384 +  CPPUNIT_ASSERT( xx.data() != 0 );  // ISO-IEC-14882:1998(E), 21.3.6, paragraph 3
   1.385 +#if 0
   1.386 +  /* This test really not required: in ISO-IEC-14882:1998(E) paragraph 3 stated:
   1.387 +   * '... and can have zero added to it', again: 'CAN', but not 'MUST'.
   1.388 +   * That's why I am comment this test. But I don't remove it due to I had
   1.389 +   * unevident problem with misinterpretation of data() return (i.e. data()
   1.390 +   * and c_str() provide different functionality!) and expect that this is
   1.391 +   * more-or-less common pitfall.
   1.392 +   *    - ptr
   1.393 +   */
   1.394 +  string low( "2004-01-01" );
   1.395 +  // Blocks A and B should follow each other.
   1.396 +  // Block A:
   1.397 +  xx = "123456";
   1.398 +  xx += low;
   1.399 +  if ( strcmp( xx.data(), "1234562004-01-01" ) != 0 ) {
   1.400 +    return -1;
   1.401 +  }
   1.402 +  // End of block A
   1.403 +
   1.404 +  // Block B:
   1.405 +  xx = "1234";
   1.406 +  xx += ";";
   1.407 +
   1.408 +  if ( strcmp( xx.data(), "1234;" ) != 0 ) {
   1.409 +    return -1;
   1.410 +  }
   1.411 +  // End of block B
   1.412 +#endif
   1.413 +}
   1.414 +
   1.415 +void StringTest::c_str()
   1.416 +{
   1.417 +  string low( "2004-01-01" );
   1.418 +  string xx;
   1.419 +  string yy;
   1.420 +
   1.421 +  CPPUNIT_ASSERT( *(yy.c_str()) == '\0' ); // ISO-IEC-14882:1998(E), 21.3.6, paragraph 1
   1.422 +
   1.423 +  // Blocks A and B should follow each other.
   1.424 +  // Block A:
   1.425 +  xx = "123456";
   1.426 +  xx += low;
   1.427 +  CPPUNIT_ASSERT( strcmp( xx.c_str(), "1234562004-01-01" ) == 0 );
   1.428 +  // End of block A
   1.429 +
   1.430 +  // Block B:
   1.431 +  xx = "1234";
   1.432 +  xx += ";";
   1.433 +  CPPUNIT_ASSERT( strcmp( xx.c_str(), "1234;" ) == 0 );
   1.434 +  // End of block B
   1.435 +}
   1.436 +
   1.437 +void StringTest::null_char()
   1.438 +{
   1.439 +  // ISO/IEC 14882:1998(E), ISO/IEC 14882:2003(E), 21.3.4 ('... the const version')
   1.440 +  const string s( "123456" );
   1.441 +
   1.442 +  CPPUNIT_CHECK( s[s.size()] == '\0' );
   1.443 +
   1.444 +#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
   1.445 +  try {
   1.446 +    //Check is only here to avoid warning about value of expression not used
   1.447 +    CPPUNIT_CHECK( s.at(s.size()) == '\0' );
   1.448 +    CPPUNIT_ASSERT( false );
   1.449 +  }
   1.450 +  catch (out_of_range const&) {
   1.451 +    CPPUNIT_ASSERT( true );
   1.452 +  }
   1.453 +  catch ( ... ) {
   1.454 +    CPPUNIT_ASSERT( false );
   1.455 +  }
   1.456 +#endif
   1.457 +}
   1.458 +
   1.459 +void StringTest::insert()
   1.460 +{
   1.461 +  string strorg = "This is test string for string calls";
   1.462 +  string str;
   1.463 +  /*
   1.464 +   * In case of reallocation there is no auto reference problem
   1.465 +   * so we reserve a big enough string to be sure to test this
   1.466 +   * particular point.
   1.467 +   */
   1.468 +  str.reserve(100);
   1.469 +  str = strorg;
   1.470 +
   1.471 +  //test self insertion:
   1.472 +  str.insert(10, str.c_str() + 5, 15);
   1.473 +  CPPUNIT_ASSERT( str == "This is teis test string st string for string calls" );
   1.474 +
   1.475 +  str = strorg;
   1.476 +  str.insert(15, str.c_str() + 5, 25);
   1.477 +  CPPUNIT_ASSERT( str == "This is test stis test string for stringring for string calls" );
   1.478 +
   1.479 +  str = strorg;
   1.480 +  str.insert(0, str.c_str() + str.size() - 4, 4);
   1.481 +  CPPUNIT_ASSERT( str == "allsThis is test string for string calls" );
   1.482 +
   1.483 +  str = strorg;
   1.484 +  str.insert(0, str.c_str() + str.size() / 2 - 1, str.size() / 2 + 1);
   1.485 +  CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" );
   1.486 +
   1.487 +  str = strorg;
   1.488 +  string::iterator b = str.begin();
   1.489 +  string::const_iterator s = str.begin() + str.size() / 2 - 1;
   1.490 +  string::const_iterator e = str.end();
   1.491 +  str.insert( b, s, e );
   1.492 +  CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" );
   1.493 +
   1.494 +  str = strorg;
   1.495 +  str.insert(str.begin(), str.begin() + str.size() / 2 - 1, str.end());
   1.496 +  CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" );
   1.497 +
   1.498 +#ifdef _STLP_MEMBER_TEMPLATES
   1.499 +  vector<int> int_vect;
   1.500 +  //Just a compile time test:
   1.501 +  str.insert(str.end(), int_vect.begin(), int_vect.end());
   1.502 +#endif
   1.503 +
   1.504 +  string str0;
   1.505 +  str0.insert(str0.begin(), 5, '0');
   1.506 +  CPPUNIT_ASSERT( str0 == "00000" );
   1.507 +
   1.508 +  string str1;
   1.509 +  {
   1.510 +    string::size_type pos = 0, nb = 2;
   1.511 +    str1.insert(pos, nb, '1');
   1.512 +  }
   1.513 +  CPPUNIT_ASSERT( str1 == "11" );
   1.514 +
   1.515 +  str0.insert(0, str1);
   1.516 +  CPPUNIT_ASSERT( str0 == "1100000" );
   1.517 +
   1.518 +  string str2("2345");
   1.519 +  str0.insert(str0.size(), str2, 1, 2);
   1.520 +  CPPUNIT_ASSERT( str0 == "110000034" );
   1.521 +
   1.522 +  str1.insert(str1.begin() + 1, 2, '2');
   1.523 +  CPPUNIT_ASSERT( str1 == "1221" );
   1.524 +
   1.525 +  str1.insert(2, "333333", 3);
   1.526 +  CPPUNIT_ASSERT( str1 == "1233321" );
   1.527 +
   1.528 +  str1.insert(4, "4444");
   1.529 +  CPPUNIT_ASSERT( str1 == "12334444321" );
   1.530 +
   1.531 +  str1.insert(str1.begin() + 6, '5');
   1.532 +  CPPUNIT_ASSERT( str1 == "123344544321" );
   1.533 +}
   1.534 +
   1.535 +void StringTest::replace()
   1.536 +{
   1.537 +  /*
   1.538 +   * This test case is for the non template basic_string::replace method,
   1.539 +   * this is why we play with the const iterators and reference to guaranty
   1.540 +   * that the right method is called.
   1.541 +   */
   1.542 +  const string v( "78" );
   1.543 +  string s( "123456" );
   1.544 +  string const& cs = s;
   1.545 +
   1.546 +  string::iterator i = s.begin() + 1;
   1.547 +  s.replace(i, i + 3, v.begin(), v.end());
   1.548 +  CPPUNIT_ASSERT( s == "17856" );
   1.549 +
   1.550 +  s = "123456";
   1.551 +  i = s.begin() + 1;
   1.552 +  s.replace(i, i + 1, v.begin(), v.end());
   1.553 +  CPPUNIT_ASSERT( s == "1783456" );
   1.554 +
   1.555 +  s = "123456";
   1.556 +  i = s.begin() + 1;
   1.557 +  string::const_iterator ci = s.begin() + 1;
   1.558 +  s.replace(i, i + 3, ci + 3, cs.end());
   1.559 +  CPPUNIT_ASSERT( s == "15656" );
   1.560 +
   1.561 +  s = "123456";
   1.562 +  i = s.begin() + 1;
   1.563 +  ci = s.begin() + 1;
   1.564 +  s.replace(i, i + 3, ci, ci + 2);
   1.565 +  CPPUNIT_ASSERT( s == "12356" );
   1.566 +
   1.567 +  s = "123456";
   1.568 +  i = s.begin() + 1;
   1.569 +  ci = s.begin() + 1;
   1.570 +  s.replace(i, i + 3, ci + 1, cs.end());
   1.571 +  CPPUNIT_ASSERT( s == "1345656" );
   1.572 +
   1.573 +  s = "123456";
   1.574 +  s.replace(s.begin() + 4, s.end(), cs.begin(), cs.end());
   1.575 +  CPPUNIT_ASSERT( s == "1234123456" );
   1.576 +
   1.577 +  /*
   1.578 +   * This is the test for the template replace method.
   1.579 +   */
   1.580 +  s = "123456";
   1.581 +  string::iterator b = s.begin() + 4;
   1.582 +  string::iterator e = s.end();
   1.583 +  string::const_iterator rb = s.begin();
   1.584 +  string::const_iterator re = s.end();
   1.585 +  s.replace(b, e, rb, re);
   1.586 +  CPPUNIT_ASSERT( s == "1234123456" );
   1.587 +
   1.588 +  s = "123456";
   1.589 +  s.replace(s.begin() + 4, s.end(), s.begin(), s.end());
   1.590 +  CPPUNIT_ASSERT( s == "1234123456" );
   1.591 +
   1.592 +  string strorg("This is test string for string calls");
   1.593 +  string str = strorg;
   1.594 +  str.replace(5, 15, str.c_str(), 10);
   1.595 +  CPPUNIT_ASSERT( str == "This This is tefor string calls" );
   1.596 +
   1.597 +  str = strorg;
   1.598 +  str.replace(5, 5, str.c_str(), 10);
   1.599 +  CPPUNIT_ASSERT( str == "This This is test string for string calls" );
   1.600 +
   1.601 +#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES)
   1.602 +  deque<char> cdeque;
   1.603 +  cdeque.push_back('I');
   1.604 +  str.replace(str.begin(), str.begin() + 11, cdeque.begin(), cdeque.end());
   1.605 +  CPPUNIT_ASSERT( str == "Is test string for string calls" );
   1.606 +#endif
   1.607 +}
   1.608 +
   1.609 +void StringTest::resize()
   1.610 +{
   1.611 +  string s;
   1.612 +
   1.613 +  s.resize(0);
   1.614 +
   1.615 +  CPPUNIT_ASSERT( *s.c_str() == 0 );
   1.616 +
   1.617 +  s = "1234567";
   1.618 +
   1.619 +  s.resize(0);
   1.620 +  CPPUNIT_ASSERT( *s.c_str() == 0 );
   1.621 +
   1.622 +  s = "1234567";
   1.623 +  s.resize(1);
   1.624 +  CPPUNIT_ASSERT( s.size() == 1 );
   1.625 +  CPPUNIT_ASSERT( *s.c_str() == '1' );
   1.626 +  CPPUNIT_ASSERT( *(s.c_str() + 1) == 0 );
   1.627 +
   1.628 +  s = "1234567";
   1.629 +  s.resize(10);
   1.630 +  CPPUNIT_ASSERT( s.size() == 10 );
   1.631 +  CPPUNIT_ASSERT( s[6] == '7' );
   1.632 +  CPPUNIT_ASSERT( s[7] == 0 );
   1.633 +  CPPUNIT_ASSERT( s[8] == 0 );
   1.634 +  CPPUNIT_ASSERT( s[9] == 0 );
   1.635 +}
   1.636 +
   1.637 +void StringTest::find()
   1.638 +{
   1.639 +  string s("one two three one two three");
   1.640 +  CPPUNIT_ASSERT( s.find("one") == 0 );
   1.641 +  CPPUNIT_ASSERT( s.find('t') == 4 );
   1.642 +  CPPUNIT_ASSERT( s.find('t', 5) == 8 );
   1.643 +  //We are trying to get a const reference to the npos string static member to
   1.644 +  //force the compiler to allocate memory for this variable. It used to reveal
   1.645 +  //a bug of STLport which was simply declaring npos without instanciating it.
   1.646 +#if !defined (STLPORT) || !defined (_STLP_STATIC_CONST_INIT_BUG)
   1.647 +  string::size_type const& npos_local = string::npos;
   1.648 +#else
   1.649 +#  define npos_local string::npos
   1.650 +#endif
   1.651 +  CPPUNIT_ASSERT( s.find("four") == npos_local );
   1.652 +  CPPUNIT_ASSERT( s.find("one", string::npos) == npos_local );
   1.653 +
   1.654 +  CPPUNIT_ASSERT( s.find_first_of("abcde") == 2 );
   1.655 +
   1.656 +  CPPUNIT_ASSERT( s.find_first_not_of("enotw ") == 9 );
   1.657 +}
   1.658 +
   1.659 +void StringTest::rfind()
   1.660 +{
   1.661 +  // 21.3.6.2
   1.662 +  string s("one two three one two three");
   1.663 +
   1.664 +  CPPUNIT_ASSERT( s.rfind("two") == 18 );
   1.665 +  CPPUNIT_ASSERT( s.rfind("two", 0) == string::npos );
   1.666 +  CPPUNIT_ASSERT( s.rfind("two", 11) == 4 );
   1.667 +  CPPUNIT_ASSERT( s.rfind('w') == 19 );
   1.668 +
   1.669 +  string test( "aba" );
   1.670 +
   1.671 +  CPPUNIT_CHECK( test.rfind( "a", 2, 1 ) == 2 );
   1.672 +  CPPUNIT_CHECK( test.rfind( "a", 1, 1 ) == 0 );
   1.673 +  CPPUNIT_CHECK( test.rfind( "a", 0, 1 ) == 0 );
   1.674 +
   1.675 +  CPPUNIT_CHECK( test.rfind( 'a', 2 ) == 2 );
   1.676 +  CPPUNIT_CHECK( test.rfind( 'a', 1 ) == 0 );
   1.677 +  CPPUNIT_CHECK( test.rfind( 'a', 0 ) == 0 );
   1.678 +}
   1.679 +
   1.680 +void StringTest::find_last_of()
   1.681 +{
   1.682 +  // 21.3.6.4
   1.683 +  string s("one two three one two three");
   1.684 +
   1.685 +  CPPUNIT_ASSERT( s.find_last_of("abcde") == 26 );
   1.686 +
   1.687 +  string test( "aba" );
   1.688 +
   1.689 +  CPPUNIT_CHECK( test.find_last_of( "a", 2, 1 ) == 2 );
   1.690 +  CPPUNIT_CHECK( test.find_last_of( "a", 1, 1 ) == 0 );
   1.691 +  CPPUNIT_CHECK( test.find_last_of( "a", 0, 1 ) == 0 );
   1.692 +
   1.693 +  CPPUNIT_CHECK( test.find_last_of( 'a', 2 ) == 2 );
   1.694 +  CPPUNIT_CHECK( test.find_last_of( 'a', 1 ) == 0 );
   1.695 +  CPPUNIT_CHECK( test.find_last_of( 'a', 0 ) == 0 );
   1.696 +}
   1.697 +
   1.698 +void StringTest::find_last_not_of()
   1.699 +{
   1.700 +  // 21.3.6.6
   1.701 +  string s("one two three one two three");
   1.702 +
   1.703 +  CPPUNIT_ASSERT( s.find_last_not_of("ehortw ") == 15 );
   1.704 +
   1.705 +  string test( "aba" );
   1.706 +
   1.707 +  CPPUNIT_CHECK( test.find_last_not_of( "a", 2, 1 ) == 1 );
   1.708 +  CPPUNIT_CHECK( test.find_last_not_of( "b", 2, 1 ) == 2 );
   1.709 +  CPPUNIT_CHECK( test.find_last_not_of( "a", 1, 1 ) == 1 );
   1.710 +  CPPUNIT_CHECK( test.find_last_not_of( "b", 1, 1 ) == 0 );
   1.711 +  CPPUNIT_CHECK( test.find_last_not_of( "a", 0, 1 ) == string::npos );
   1.712 +  CPPUNIT_CHECK( test.find_last_not_of( "b", 0, 1 ) == 0 );
   1.713 +
   1.714 +  CPPUNIT_CHECK( test.find_last_not_of( 'a', 2 ) == 1 );
   1.715 +  CPPUNIT_CHECK( test.find_last_not_of( 'b', 2 ) == 2 );
   1.716 +  CPPUNIT_CHECK( test.find_last_not_of( 'a', 1 ) == 1 );
   1.717 +  CPPUNIT_CHECK( test.find_last_not_of( 'b', 1 ) == 0 );
   1.718 +  CPPUNIT_CHECK( test.find_last_not_of( 'a', 0 ) == string::npos );
   1.719 +  CPPUNIT_CHECK( test.find_last_not_of( 'b', 0 ) == 0 );
   1.720 +}
   1.721 +
   1.722 +void StringTest::copy()
   1.723 +{
   1.724 +  string s("foo");
   1.725 +  char dest[4];
   1.726 +  dest[0] = dest[1] = dest[2] = dest[3] = 1;
   1.727 +  s.copy(dest, 4);
   1.728 +  int pos = 0;
   1.729 +  CPPUNIT_ASSERT( dest[pos++] == 'f' );
   1.730 +  CPPUNIT_ASSERT( dest[pos++] == 'o' );
   1.731 +  CPPUNIT_ASSERT( dest[pos++] == 'o' );
   1.732 +  CPPUNIT_ASSERT( dest[pos++] == 1 );
   1.733 +
   1.734 +  dest[0] = dest[1] = dest[2] = dest[3] = 1;
   1.735 +  s.copy(dest, 4, 2);
   1.736 +  pos = 0;
   1.737 +  CPPUNIT_ASSERT( dest[pos++] == 'o' );
   1.738 +  CPPUNIT_ASSERT( dest[pos++] == 1 );
   1.739 +
   1.740 +#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
   1.741 +  try {
   1.742 +    s.copy(dest, 4, 5);
   1.743 +    CPPUNIT_ASSERT( false );
   1.744 +  }
   1.745 +  catch (out_of_range const&) {
   1.746 +    CPPUNIT_ASSERT( true );
   1.747 +  }
   1.748 +  catch ( ... ) {
   1.749 +    CPPUNIT_ASSERT( false );
   1.750 +  }
   1.751 +#endif
   1.752 +}
   1.753 +
   1.754 +void StringTest::assign()
   1.755 +{
   1.756 +  string s;
   1.757 +  char const* cstr = "test string for assign";
   1.758 +
   1.759 +  s.assign(cstr, cstr + 22);
   1.760 +  CPPUNIT_ASSERT( s == "test string for assign" );
   1.761 +
   1.762 +  string s2("other test string");
   1.763 +  s.assign(s2);
   1.764 +  CPPUNIT_ASSERT( s == s2 );
   1.765 +
   1.766 +  static string str1;
   1.767 +  static string str2;
   1.768 +
   1.769 +  // short string optim:
   1.770 +  str1 = "123456";
   1.771 +  // longer than short string:
   1.772 +  str2 = "1234567890123456789012345678901234567890";
   1.773 +
   1.774 +  CPPUNIT_ASSERT(str1[5] == '6');
   1.775 +  CPPUNIT_ASSERT(str2[29] == '0');
   1.776 +}
   1.777 +
   1.778 +/* This test is to check if std::string properly supports the short string
   1.779 + * optimization. It has been found out that eMbedded Visual C++ 3.0 and .NET
   1.780 + * compilers for the ARM platform fail to pass structs and classes of certain
   1.781 + * size per value. This seems to be a known compiler bug. For other processors
   1.782 + * (e.g. x86) the error doesn't occur.
   1.783 + * (The ARM compiler creates a temporary object from teststr on the stack, to
   1.784 + * pass it to the helper function. It uses the copy constructor for this.
   1.785 + * After this the temporary object is copied to another place on the stack.
   1.786 + * The result is that the _M_finish pointer then points to the wrong buffer
   1.787 + * end and the size of the short string is incorrectly calculated.)
   1.788 + */
   1.789 +void StringTest::short_string_optim_bug()
   1.790 +{
   1.791 +   string teststr("shortest");
   1.792 +
   1.793 +   bool short_string_optim_bug_helper(string teststr);
   1.794 +
   1.795 +   CPPUNIT_ASSERT(true == short_string_optim_bug_helper(teststr));
   1.796 +}
   1.797 +
   1.798 +bool short_string_optim_bug_helper(string teststr)
   1.799 +{
   1.800 +   size_t ss = teststr.size();
   1.801 +   return (ss == 8);
   1.802 +}
   1.803 +
   1.804 +void StringTest::compare()
   1.805 +{
   1.806 +  string str1("abcdef");
   1.807 +  string str2;
   1.808 +
   1.809 +  str2 = "abcdef";
   1.810 +  CPPUNIT_ASSERT( str1.compare(str2) == 0 );
   1.811 +  str2 = "abcde";
   1.812 +  CPPUNIT_ASSERT( str1.compare(str2) > 0 );
   1.813 +  str2 = "abcdefg";
   1.814 +  CPPUNIT_ASSERT( str1.compare(str2) < 0 );
   1.815 +
   1.816 +  CPPUNIT_ASSERT( str1.compare("abcdef") == 0 );
   1.817 +  CPPUNIT_ASSERT( str1.compare("abcde") > 0 );
   1.818 +  CPPUNIT_ASSERT( str1.compare("abcdefg") < 0 );
   1.819 +
   1.820 +  str2 = "cde";
   1.821 +  CPPUNIT_ASSERT( str1.compare(2, 3, str2) == 0 );
   1.822 +  str2 = "cd";
   1.823 +  CPPUNIT_ASSERT( str1.compare(2, 3, str2) > 0 );
   1.824 +  str2 = "cdef";
   1.825 +  CPPUNIT_ASSERT( str1.compare(2, 3, str2) < 0 );
   1.826 +
   1.827 +  str2 = "abcdef";
   1.828 +  CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 3) == 0 );
   1.829 +  CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 2) > 0 );
   1.830 +  CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 4) < 0 );
   1.831 +
   1.832 +  CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 3) == 0 );
   1.833 +  CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 2) > 0 );
   1.834 +  CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 4) < 0 );
   1.835 +}
   1.836 +
   1.837 +/*
   1.838 +class mystring : public string {
   1.839 +public:
   1.840 +  mystring() {}
   1.841 +  mystring(string const& s) : string(s) {}
   1.842 +
   1.843 +  mystring& operator = (string const& s) {
   1.844 +    string::operator = (s);
   1.845 +    return *this;
   1.846 +  };
   1.847 +};
   1.848 +*/
   1.849 +
   1.850 +void StringTest::template_expression()
   1.851 +{
   1.852 +  string one("one"), two("two"), three("three");
   1.853 +  string space(1, ' ');
   1.854 +
   1.855 +  // check availability of [un]equality operators
   1.856 +  {
   1.857 +      // string-string
   1.858 +      one == two;
   1.859 +      one != two;
   1.860 +      // string-literal
   1.861 +      one == "two";
   1.862 +      one != "two";
   1.863 +      // literal-string
   1.864 +      "one" == two;
   1.865 +      "one" != two;
   1.866 +      // strsum-string
   1.867 +      (one + two) == three;
   1.868 +      (one + two) != three;
   1.869 +      // string-strsum
   1.870 +      one == (two + three);
   1.871 +      one != (two + three);
   1.872 +      // strsum-literal
   1.873 +      (one + two) == "three";
   1.874 +      (one + two) != "three";
   1.875 +      // literal-strsum
   1.876 +      "one" == (two + three);
   1.877 +      "one" != (two + three);
   1.878 +      // strsum-strsum
   1.879 +      (one + two) == (two + three);
   1.880 +      (one + two) != (two + three);
   1.881 +  }
   1.882 +
   1.883 +  {
   1.884 +    string result(one + ' ' + two + ' ' + three);
   1.885 +    CPPUNIT_CHECK( result == "one two three" );
   1.886 +  }
   1.887 +
   1.888 +  {
   1.889 +    string result(one + ' ' + two + ' ' + three, 4);
   1.890 +    CPPUNIT_CHECK( result == "two three" );
   1.891 +  }
   1.892 +
   1.893 +  {
   1.894 +    string result(one + ' ' + two + ' ' + three, 4, 3);
   1.895 +    CPPUNIT_CHECK( result == "two" );
   1.896 +  }
   1.897 +
   1.898 +  //2 members expressions:
   1.899 +  CPPUNIT_CHECK( (' ' + one) == " one" );
   1.900 +  CPPUNIT_CHECK( (one + ' ') == "one " );
   1.901 +  CPPUNIT_CHECK( (one + " two") == "one two" );
   1.902 +  CPPUNIT_CHECK( ("one " + two) == "one two" );
   1.903 +  CPPUNIT_CHECK( (one + space) == "one " );
   1.904 +
   1.905 +  //3 members expressions:
   1.906 +  CPPUNIT_CHECK( ((one + space) + "two") == "one two" );
   1.907 +  CPPUNIT_CHECK( ("one" + (space + two)) == "one two" );
   1.908 +  CPPUNIT_CHECK( ((one + space) + two) == "one two" );
   1.909 +  CPPUNIT_CHECK( (one + (space + two)) == "one two" );
   1.910 +  CPPUNIT_CHECK( ((one + space) + 't') == "one t" );
   1.911 +  CPPUNIT_CHECK( ('o' + (space + two)) == "o two" );
   1.912 +
   1.913 +  //4 members expressions:
   1.914 +  CPPUNIT_CHECK( ((one + space) + (two + space)) == "one two " );
   1.915 +
   1.916 +  //special operators
   1.917 +  {
   1.918 +    string result;
   1.919 +    result = one + space + two;
   1.920 +    CPPUNIT_CHECK( result == "one two" );
   1.921 +
   1.922 +    result += space + three;
   1.923 +    CPPUNIT_CHECK( result == "one two three" );
   1.924 +  }
   1.925 +
   1.926 +  //special append method
   1.927 +  {
   1.928 +    string result;
   1.929 +    //Use reserve to avoid reallocation and really test auto-referencing problems:
   1.930 +    result.reserve(64);
   1.931 +
   1.932 +    result.append(one + space + two);
   1.933 +    CPPUNIT_CHECK( result == "one two" );
   1.934 +
   1.935 +    result.append(space + result + space + three);
   1.936 +    CPPUNIT_CHECK( result == "one two one two three" );
   1.937 +
   1.938 +    result = "one two";
   1.939 +    result.append(space + three, 1, 2);
   1.940 +    CPPUNIT_ASSERT( result == "one twoth" );
   1.941 +
   1.942 +    result.append(space + result);
   1.943 +    CPPUNIT_CHECK( result == "one twoth one twoth" );
   1.944 +  }
   1.945 +
   1.946 +  //special assign method
   1.947 +  {
   1.948 +    string result;
   1.949 +    //Use reserve to avoid reallocation and really test auto-referencing problems:
   1.950 +    result.reserve(64);
   1.951 +
   1.952 +    result.assign(one + space + two + space + three);
   1.953 +    CPPUNIT_CHECK( result == "one two three" );
   1.954 +
   1.955 +    result.assign(one + space + two + space + three, 3, 5);
   1.956 +    CPPUNIT_CHECK( result == " two " );
   1.957 +
   1.958 +    result.assign(one + result + three);
   1.959 +    CPPUNIT_CHECK( result == "one two three" );
   1.960 +  }
   1.961 +
   1.962 +  {
   1.963 +    CPPUNIT_CHECK( !(one + ' ' + two).empty() );
   1.964 +
   1.965 +    char result = (one + ' ' + two)[3];
   1.966 +    CPPUNIT_CHECK( result == ' ' );
   1.967 +
   1.968 +    result = (one + ' ' + two).at(3);
   1.969 +    CPPUNIT_CHECK( result == ' ' );
   1.970 +
   1.971 +#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
   1.972 +    try {
   1.973 +      result = (one + ' ' + two).at(10);
   1.974 +      CPPUNIT_ASSERT(false);
   1.975 +    }
   1.976 +    catch (out_of_range const&) {
   1.977 +      CPPUNIT_ASSERT( result == ' ' );
   1.978 +    }
   1.979 +    catch (...) {
   1.980 +      CPPUNIT_ASSERT(false);
   1.981 +    }
   1.982 +#endif
   1.983 +  }
   1.984 +
   1.985 +  /*
   1.986 +  mystring a("ing");
   1.987 +  //gcc failed to compile following expression when template expressions are activated.
   1.988 +  //MSVC sees no problem. gcc limitation or MSVC is too cool ??
   1.989 +  mystring b = "str" + a;
   1.990 +  */
   1.991 +}
   1.992 +
   1.993 +#if !defined (TE_TMP_TEST_IGNORED)
   1.994 +class superstring
   1.995 +{
   1.996 +  public:
   1.997 +    superstring() :
   1.998 +      s("super")
   1.999 +    {}
  1.1000 +
  1.1001 +    superstring( const string& str ) :
  1.1002 +      s( str )
  1.1003 +    {}
  1.1004 +
  1.1005 +  superstring operator / (const string& str )
  1.1006 +    { return superstring( s + "/" + str ); }
  1.1007 +
  1.1008 +  superstring operator / (const char* str )
  1.1009 +    { return superstring( s + "/" + str ); }
  1.1010 +
  1.1011 +  private:
  1.1012 +    string s;
  1.1013 +};
  1.1014 +#endif
  1.1015 +
  1.1016 +void StringTest::te_tmp()
  1.1017 +{
  1.1018 +#if !defined (TE_TMP_TEST_IGNORED)
  1.1019 +  superstring s;
  1.1020 +  string more( "more" );
  1.1021 +  string less( "less" );
  1.1022 +
  1.1023 +  superstring r = s / (more + less);
  1.1024 +#endif
  1.1025 +}
  1.1026 +
  1.1027 +void StringTest::template_wexpression()
  1.1028 +{
  1.1029 +#if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)
  1.1030 +#  if !defined (__CYGWIN__) || defined (STLPORT)
  1.1031 +  wstring one(L"one"), two(L"two"), three(L"three");
  1.1032 +  wstring space(1, L' ');
  1.1033 +
  1.1034 +  {
  1.1035 +    wstring result(one + L' ' + two + L' ' + three);
  1.1036 +    CPPUNIT_CHECK( result == L"one two three" );
  1.1037 +  }
  1.1038 +
  1.1039 +  {
  1.1040 +    wstring result(one + L' ' + two + L' ' + three, 4);
  1.1041 +    CPPUNIT_CHECK( result == L"two three" );
  1.1042 +  }
  1.1043 +
  1.1044 +  {
  1.1045 +    wstring result(one + L' ' + two + L' ' + three, 4, 3);
  1.1046 +    CPPUNIT_CHECK( result == L"two" );
  1.1047 +  }
  1.1048 +
  1.1049 +  //2 members expressions:
  1.1050 +  CPPUNIT_CHECK( (L' ' + one) == L" one" );
  1.1051 +  CPPUNIT_CHECK( (one + L' ') == L"one " );
  1.1052 +  CPPUNIT_CHECK( (one + L" two") == L"one two" );
  1.1053 +  CPPUNIT_CHECK( (L"one " + two) == L"one two" );
  1.1054 +  CPPUNIT_CHECK( (one + space) == L"one " );
  1.1055 +
  1.1056 +  //3 members expressions:
  1.1057 +  CPPUNIT_CHECK( ((one + space) + L"two") == L"one two" );
  1.1058 +  CPPUNIT_CHECK( (L"one" + (space + two)) == L"one two" );
  1.1059 +  CPPUNIT_CHECK( ((one + space) + two) == L"one two" );
  1.1060 +  CPPUNIT_CHECK( (one + (space + two)) == L"one two" );
  1.1061 +  CPPUNIT_CHECK( ((one + space) + L't') == L"one t" );
  1.1062 +  CPPUNIT_CHECK( (L'o' + (space + two)) == L"o two" );
  1.1063 +
  1.1064 +  //4 members expressions:
  1.1065 +  CPPUNIT_CHECK( ((one + space) + (two + space)) == L"one two " );
  1.1066 +
  1.1067 +  //special operators
  1.1068 +  {
  1.1069 +    wstring result;
  1.1070 +    result = one + space + two;
  1.1071 +    CPPUNIT_CHECK( result == L"one two" );
  1.1072 +
  1.1073 +    result += space + three;
  1.1074 +    CPPUNIT_CHECK( result == L"one two three" );
  1.1075 +  }
  1.1076 +
  1.1077 +  //special append method
  1.1078 +  {
  1.1079 +    wstring result;
  1.1080 +    //Use reserve to avoid reallocation and really test auto-referencing problems:
  1.1081 +    result.reserve(64);
  1.1082 +
  1.1083 +    result.append(one + space + two);
  1.1084 +    CPPUNIT_CHECK( result == L"one two" );
  1.1085 +
  1.1086 +    result.append(space + result + space + three);
  1.1087 +    CPPUNIT_CHECK( result == L"one two one two three" );
  1.1088 +
  1.1089 +    result = L"one two";
  1.1090 +    result.append(space + three, 1, 2);
  1.1091 +    CPPUNIT_ASSERT( result == L"one twoth" );
  1.1092 +
  1.1093 +    result.append(space + result);
  1.1094 +    CPPUNIT_CHECK( result == L"one twoth one twoth" );
  1.1095 +  }
  1.1096 +
  1.1097 +  //special assign method
  1.1098 +  {
  1.1099 +    wstring result;
  1.1100 +    //Use reserve to avoid reallocation and really test auto-referencing problems:
  1.1101 +    result.reserve(64);
  1.1102 +
  1.1103 +    result.assign(one + space + two + space + three);
  1.1104 +    CPPUNIT_CHECK( result == L"one two three" );
  1.1105 +
  1.1106 +    result.assign(one + space + two + space + three, 3, 5);
  1.1107 +    CPPUNIT_CHECK( result == L" two " );
  1.1108 +
  1.1109 +    result.assign(one + result + three);
  1.1110 +    CPPUNIT_CHECK( result == L"one two three" );
  1.1111 +  }
  1.1112 +
  1.1113 +  {
  1.1114 +    CPPUNIT_CHECK( !(one + L' ' + two).empty() );
  1.1115 +
  1.1116 +    wchar_t result = (one + L' ' + two)[3];
  1.1117 +    CPPUNIT_CHECK( result == L' ' );
  1.1118 +
  1.1119 +    result = (one + L' ' + two).at(3);
  1.1120 +    CPPUNIT_CHECK( result == L' ' );
  1.1121 +
  1.1122 +#    if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
  1.1123 +    try {
  1.1124 +      result = (one + L' ' + two).at(10);
  1.1125 +      CPPUNIT_ASSERT(false);
  1.1126 +    }
  1.1127 +    catch (out_of_range const&) {
  1.1128 +      CPPUNIT_ASSERT( result == L' ' );
  1.1129 +    }
  1.1130 +    catch (...) {
  1.1131 +      CPPUNIT_ASSERT(false);
  1.1132 +    }
  1.1133 +#    endif
  1.1134 +  }
  1.1135 +#  endif
  1.1136 +#endif
  1.1137 +}
  1.1138 +
  1.1139 +void StringTest::io()
  1.1140 +{
  1.1141 +#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
  1.1142 +  string str("STLport");
  1.1143 +  {
  1.1144 +    ostringstream ostr;
  1.1145 +    ostr << str;
  1.1146 +    CPPUNIT_ASSERT( ostr.good() );
  1.1147 +    CPPUNIT_ASSERT( ostr.str() == str );
  1.1148 +  }
  1.1149 +  {
  1.1150 +    istringstream istr(str);
  1.1151 +    string istr_content;
  1.1152 +    istr >> istr_content;
  1.1153 +    CPPUNIT_ASSERT( !istr.fail() && istr.eof() );
  1.1154 +    CPPUNIT_ASSERT( istr_content == str );
  1.1155 +  }
  1.1156 +  {
  1.1157 +    istringstream istr(str);
  1.1158 +    istr.width(3);
  1.1159 +    string istr_content;
  1.1160 +    istr >> istr_content;
  1.1161 +    CPPUNIT_ASSERT( !istr.fail() && !istr.eof() );
  1.1162 +    CPPUNIT_ASSERT( istr_content == "STL" );
  1.1163 +  }
  1.1164 +#endif
  1.1165 +}
  1.1166 +
  1.1167 +void StringTest::allocator_with_state()
  1.1168 +{
  1.1169 +#if !(defined (STLPORT) && defined (_STLP_NO_CUSTOM_IO)) 
  1.1170 +
  1.1171 +  char buf1[1024];
  1.1172 +  StackAllocator<char> stack1(buf1, buf1 + sizeof(buf1));
  1.1173 +
  1.1174 +  char buf2[1024];
  1.1175 +  StackAllocator<char> stack2(buf2, buf2 + sizeof(buf2));
  1.1176 +
  1.1177 +  typedef basic_string<char, char_traits<char>, StackAllocator<char> > StackString;
  1.1178 +  {
  1.1179 +    StackString str1("string stack1", stack1);
  1.1180 +    StackString str1Cpy(str1);
  1.1181 +
  1.1182 +    StackString str2("string stack2", stack2);
  1.1183 +    StackString str2Cpy(str2);
  1.1184 +
  1.1185 +    str1.swap(str2);
  1.1186 +
  1.1187 +    CPPUNIT_ASSERT( str1.get_allocator().swaped() );
  1.1188 +    CPPUNIT_ASSERT( str2.get_allocator().swaped() );
  1.1189 +
  1.1190 +    CPPUNIT_ASSERT( str1 == str2Cpy );
  1.1191 +    CPPUNIT_ASSERT( str2 == str1Cpy );
  1.1192 +    CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
  1.1193 +    CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
  1.1194 +  }
  1.1195 +  CPPUNIT_ASSERT( stack1.ok() );
  1.1196 +  CPPUNIT_ASSERT( stack2.ok() );
  1.1197 +  stack1.reset(); stack2.reset();
  1.1198 +
  1.1199 +  {
  1.1200 +    StackString str1("longer string from stack1 allocator instance for dynamic allocation", stack1);
  1.1201 +    StackString str1Cpy(str1);
  1.1202 +
  1.1203 +    StackString str2("longer string from stack2 allocator instance for dynamic allocation", stack2);
  1.1204 +    StackString str2Cpy(str2);
  1.1205 +
  1.1206 +    str1.swap(str2);
  1.1207 +
  1.1208 +    CPPUNIT_ASSERT( str1.get_allocator().swaped() );
  1.1209 +    CPPUNIT_ASSERT( str2.get_allocator().swaped() );
  1.1210 +
  1.1211 +    CPPUNIT_ASSERT( str1 == str2Cpy );
  1.1212 +    CPPUNIT_ASSERT( str2 == str1Cpy );
  1.1213 +    CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
  1.1214 +    CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
  1.1215 +  }
  1.1216 +  CPPUNIT_ASSERT( stack1.ok() );
  1.1217 +  CPPUNIT_ASSERT( stack2.ok() );
  1.1218 +  stack1.reset(); stack2.reset();
  1.1219 +
  1.1220 +
  1.1221 +  {
  1.1222 +    StackString str1("string stack1", stack1);
  1.1223 +    StackString str1Cpy(str1);
  1.1224 +
  1.1225 +    StackString str2("longer string from stack2 allocator instance for dynamic allocation", stack2);
  1.1226 +    StackString str2Cpy(str2);
  1.1227 +
  1.1228 +    str1.swap(str2);
  1.1229 +
  1.1230 +    CPPUNIT_ASSERT( str1.get_allocator().swaped() );
  1.1231 +    CPPUNIT_ASSERT( str2.get_allocator().swaped() );
  1.1232 +
  1.1233 +    CPPUNIT_ASSERT( str1 == str2Cpy );
  1.1234 +    CPPUNIT_ASSERT( str2 == str1Cpy );
  1.1235 +    CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
  1.1236 +    CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
  1.1237 +  }
  1.1238 +  CPPUNIT_ASSERT( stack1.ok() );
  1.1239 +  CPPUNIT_ASSERT( stack2.ok() );
  1.1240 +  stack1.reset(); stack2.reset();
  1.1241 +
  1.1242 +
  1.1243 +  {
  1.1244 +    StackString str1("longer string from stack1 allocator instance for dynamic allocation", stack1);
  1.1245 +    StackString str1Cpy(str1);
  1.1246 +
  1.1247 +    StackString str2("string stack2", stack2);
  1.1248 +    StackString str2Cpy(str2);
  1.1249 +
  1.1250 +    str1.swap(str2);
  1.1251 +
  1.1252 +    CPPUNIT_ASSERT( str1.get_allocator().swaped() );
  1.1253 +    CPPUNIT_ASSERT( str2.get_allocator().swaped() );
  1.1254 +
  1.1255 +    CPPUNIT_ASSERT( str1 == str2Cpy );
  1.1256 +    CPPUNIT_ASSERT( str2 == str1Cpy );
  1.1257 +    CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
  1.1258 +    CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
  1.1259 +  }
  1.1260 +  CPPUNIT_ASSERT( stack1.ok() );
  1.1261 +  CPPUNIT_ASSERT( stack2.ok() );
  1.1262 +  stack1.reset(); stack2.reset();
  1.1263 +#endif
  1.1264 +}
  1.1265 +
  1.1266 +void StringTest::capacity()
  1.1267 +{
  1.1268 +  string s;
  1.1269 +
  1.1270 +  CPPUNIT_CHECK( s.capacity() > 0 );
  1.1271 +  CPPUNIT_CHECK( s.capacity() < s.max_size() );
  1.1272 +  CPPUNIT_CHECK( s.capacity() >= s.size() );
  1.1273 +
  1.1274 +#ifndef _STLP_SHORT_STRING_SZ
  1.1275 +#  define _STLP_SHORT_STRING_SZ 16 // see stlport/stl/_string_base.h
  1.1276 +#endif
  1.1277 +
  1.1278 +  for ( int i = 0; i < _STLP_SHORT_STRING_SZ + 2; ++i ) {
  1.1279 +    s += ' ';
  1.1280 +    CPPUNIT_CHECK( s.capacity() > 0 );
  1.1281 +    CPPUNIT_CHECK( s.capacity() < s.max_size() );
  1.1282 +    CPPUNIT_CHECK( s.capacity() >= s.size() );
  1.1283 +  }
  1.1284 +}
  1.1285 +void StringTest::str_cov1()
  1.1286 +	{
  1.1287 +		{
  1.1288 +		string example( "this is an example string" );
  1.1289 +		string::iterator it = example.begin();   
  1.1290 +		example.replace(it+4,example.end()-4,4,'o'); 
  1.1291 +		CPPUNIT_CHECK(example == "thisooooring"  );
  1.1292 +		}
  1.1293 +		{
  1.1294 +		string str4 ( "This perfectly unclear." );
  1.1295 +		basic_string <char>::size_type indexCh4a;
  1.1296 +		string str4a ( "clear" );
  1.1297 +		indexCh4a = str4.rfind ( str4a , 15 );
  1.1298 +		CPPUNIT_CHECK(indexCh4a == -1  );
  1.1299 +		}
  1.1300 +		{
  1.1301 +		string str1f ( "Hello " ), str2f ( "Wide World " );
  1.1302 +		swap(str1f,str2f);
  1.1303 +		CPPUNIT_CHECK(str1f == "Wide World ");	
  1.1304 +		CPPUNIT_CHECK(str2f == "Hello ");	
  1.1305 +		}
  1.1306 +
  1.1307 +	}
  1.1308 +void StringTest::str_cov2()
  1.1309 +	{
  1.1310 +		{
  1.1311 +		string result1a, result1b;
  1.1312 +		string s1o ( "AAAAAAAA" );
  1.1313 +		string s1p ( "BBB" );
  1.1314 +		const char* cs1p = "CCC";
  1.1315 +		result1a = s1o.replace ( 1 , 3 , s1p );
  1.1316 +		CPPUNIT_CHECK(result1a == "ABBBAAAA");
  1.1317 +		result1b = s1o.replace ( 5 , 3 , cs1p );
  1.1318 +		CPPUNIT_CHECK(result1b == "ABBBACCC");
  1.1319 +		string result2a, result2b;
  1.1320 +		string s2o ( "AAAAAAAA" );
  1.1321 +		string s2p ( "BBB" );
  1.1322 +		result2a = s2o.replace ( 1 , 3 , s2p , 1 , 2 );
  1.1323 +		CPPUNIT_CHECK(result2a == "ABBAAAA");
  1.1324 +		string result3a;
  1.1325 +		string s3o ( "AAAAAAAA" );
  1.1326 +		char ch3p = 'C';
  1.1327 +		result3a = s3o.replace ( 1 , 3 , 4 , ch3p );
  1.1328 +		CPPUNIT_CHECK(result3a == "ACCCCAAAA");
  1.1329 +		string s4o ( "AAAAAAAA" );
  1.1330 +		string s4p ( "BBB" );
  1.1331 +		const char* cs4p = "CCC";
  1.1332 +		basic_string<char>::iterator IterF0, IterL0;
  1.1333 +		IterF0 = s4o.begin ( );
  1.1334 +		IterL0 = s4o.begin ( ) + 3;
  1.1335 +		string result4a, result4b;
  1.1336 +		result4a = s4o.replace ( IterF0 , IterL0 , s4p );
  1.1337 +		CPPUNIT_CHECK(result4a == "BBBAAAAA");
  1.1338 +		result4b = s4o.replace ( IterF0 , IterL0 , cs4p );
  1.1339 +		CPPUNIT_CHECK(result4b == "CCCAAAAA");
  1.1340 +		string s5o ( "AAAAAAAF" );
  1.1341 +		const char* cs5p = "CCCBB";
  1.1342 +		basic_string<char>::iterator IterF1, IterL1;
  1.1343 +		IterF1 = s5o.begin ( );
  1.1344 +		IterL1 = s5o.begin ( ) + 4;
  1.1345 +		string result5a;
  1.1346 +		result5a = s5o.replace ( IterF1 , IterL1 , cs5p , 4 );
  1.1347 +		CPPUNIT_CHECK(result5a == "CCCBAAAF");
  1.1348 +		string s6o ( "AAAAAAAG" );
  1.1349 +		char ch6p = 'q';
  1.1350 +		basic_string<char>::iterator IterF2, IterL2;
  1.1351 +		IterF2 = s6o.begin ( );
  1.1352 +		IterL2 = s6o.begin ( ) + 3;
  1.1353 +		string result6a;
  1.1354 +		result6a = s6o.replace ( IterF2 , IterL2 , 4 , ch6p );
  1.1355 +		CPPUNIT_CHECK(result6a == "qqqqAAAAG");
  1.1356 +		}
  1.1357 +	}
  1.1358 +void StringTest::str_cov3()
  1.1359 +	{
  1.1360 +		{
  1.1361 +		string str1 ("This is the sample test string"), str2;
  1.1362 +		basic_string <char>::reverse_iterator str_rIter, str1_rIter, str2_rIter;
  1.1363 +		basic_string <char>::const_reverse_iterator str1_rcIter;
  1.1364 +		str1_rIter = str1.rend ( );
  1.1365 +		str1_rIter--;
  1.1366 +		CPPUNIT_CHECK(*str1_rIter == 'T');
  1.1367 +		str_rIter = str1.rbegin( ); 
  1.1368 +		CPPUNIT_CHECK(*str_rIter == 'g');
  1.1369 +		str1_rcIter = str1.rbegin( );
  1.1370 +		CPPUNIT_CHECK(*str1_rcIter == 'g');
  1.1371 +		str1_rcIter = str1.rend ( );
  1.1372 +		str1_rcIter--;
  1.1373 +		CPPUNIT_CHECK(*str1_rcIter == 'T');
  1.1374 +		}
  1.1375 +		{
  1.1376 +		string str1a ( "Hello " );
  1.1377 +		str1a = "0";
  1.1378 +		CPPUNIT_CHECK(str1a == "0");
  1.1379 +		}
  1.1380 +		{
  1.1381 +		string str1 ("Hello world");
  1.1382 +		CPPUNIT_CHECK(str1.length ( ) == 11);
  1.1383 +		}
  1.1384 +		{
  1.1385 +		int comp5a;
  1.1386 +		string s5o ( "AACAB" );
  1.1387 +		const char* cs5p = "CAB";
  1.1388 +		comp5a = s5o.compare (  2 , 3 , cs5p );
  1.1389 +		CPPUNIT_CHECK(comp5a == 0);		
  1.1390 +		}
  1.1391 +
  1.1392 +	}
  1.1393 +void StringTest::str_cov4()
  1.1394 +	{
  1.1395 +		{
  1.1396 +		string str4 ( "12-ab-12-ab" );
  1.1397 +		basic_string <char>::size_type indexCh4a;
  1.1398 +		string str4a ( "ba3" );
  1.1399 +		indexCh4a = str4.find_last_of  ( str4a , 8 );
  1.1400 +		CPPUNIT_CHECK(indexCh4a == 4);
  1.1401 +		}
  1.1402 +		{
  1.1403 +		string str4 ( "12-ab-12-ab" );
  1.1404 +		basic_string <char>::size_type indexCh4a;
  1.1405 +		string str4a ( "b-a" );
  1.1406 +		indexCh4a = str4.find_last_not_of  ( str4a , 5 );
  1.1407 +		CPPUNIT_CHECK(indexCh4a == 1);
  1.1408 +		}
  1.1409 +		{
  1.1410 +		string str1 ( "abcd-1234-abcd-1234" );
  1.1411 +		basic_string <char>::size_type indexCh1a;
  1.1412 +
  1.1413 +		indexCh1a = str1.find_first_of ( "d" , 5 );
  1.1414 +		CPPUNIT_CHECK(indexCh1a == 13);
  1.1415 +		string str2 ( "12-ab-12-ab" );
  1.1416 +		basic_string <char>::size_type indexCh2a;
  1.1417 +
  1.1418 +		string str2a ( "ba3" );
  1.1419 +		indexCh2a = str2.find_first_of ( str2a , 5 );
  1.1420 +		CPPUNIT_CHECK( indexCh2a == 9 );
  1.1421 +		}
  1.1422 +		{
  1.1423 +		string str4 ( "12-ab-12-ab" );
  1.1424 + 	    basic_string <char>::size_type indexCh4a;
  1.1425 +
  1.1426 +		string str4a ( "ba3" );
  1.1427 +		indexCh4a = str4.find_first_not_of ( str4a , 5 );
  1.1428 +		CPPUNIT_CHECK(indexCh4a == 5 );
  1.1429 +		}
  1.1430 +	}
  1.1431 +void StringTest::str_cov5()
  1.1432 +	{
  1.1433 +		{
  1.1434 +		string str4 ( "clearly this perfectly unclear." );
  1.1435 +		basic_string <char>::size_type indexCh4a;
  1.1436 +
  1.1437 +		string str4a ( "clear" );
  1.1438 +		indexCh4a = str4.find ( str4a , 5 );
  1.1439 +		CPPUNIT_CHECK( indexCh4a != string::npos );
  1.1440 +		}
  1.1441 +		{
  1.1442 +		const char *cstr1a = "Hello Out There.";
  1.1443 +		basic_string <char> str1a ( cstr1a , 5);
  1.1444 +		CPPUNIT_CHECK( str1a == "Hello" );	
  1.1445 +		}
  1.1446 +		{
  1.1447 +		string str1a,str1b;
  1.1448 +		const char *cstr1a = "Out There";
  1.1449 +		str1a.assign ( cstr1a );
  1.1450 +		CPPUNIT_CHECK(str1a == "Out There");	
  1.1451 +		
  1.1452 +		str1b.assign ( cstr1a , 3 );
  1.1453 +		CPPUNIT_CHECK(str1b == "Out");	
  1.1454 +		
  1.1455 +		string str1f ( "Hello " ), str2f ( "Wide World " );
  1.1456 +		str1f.assign ( str2f.begin ( ) + 5 , str2f.end ( ) - 1 );
  1.1457 +		CPPUNIT_CHECK(str1f == "World");	
  1.1458 +		}
  1.1459 +		{
  1.1460 +		string str1f ( "Hello " ), str2f ( "Wide World " );
  1.1461 +		str1f.append ( str2f.begin ( ) + 5 , str2f.end ( ) - 1 );
  1.1462 +		CPPUNIT_CHECK(str1f == "Hello World");	
  1.1463 +		
  1.1464 +		string str1b ( "Hello " );
  1.1465 +		const char *cstr1b = "Out There ";
  1.1466 +		str1b.append ( cstr1b , 3 );
  1.1467 +		CPPUNIT_CHECK(str1b == "Hello Out");	
  1.1468 +		}
  1.1469 +	}
  1.1470 +void StringTest::str_cov6()
  1.1471 +	{
  1.1472 +		{
  1.1473 +		string s1 ( "AACAB" );
  1.1474 +		string s2 ( "BACAB" );
  1.1475 +		const char* s3 = "CAB";
  1.1476 +		
  1.1477 +		bool flag;
  1.1478 +		
  1.1479 +		flag = s2 >= s1;
  1.1480 +		CPPUNIT_CHECK(flag == true);		
  1.1481 +		
  1.1482 +		flag = s3 >= s1;
  1.1483 +		CPPUNIT_CHECK(flag == true);		
  1.1484 +		
  1.1485 +		flag = s1 >= s3;
  1.1486 +		CPPUNIT_CHECK(flag == false);
  1.1487 +		
  1.1488 +		flag = s2 > s1;
  1.1489 +		CPPUNIT_CHECK(flag == true);		
  1.1490 +		
  1.1491 +		flag = s3 > s1;
  1.1492 +		CPPUNIT_CHECK(flag == true);		
  1.1493 +		
  1.1494 +		flag = s1 > s3;
  1.1495 +		CPPUNIT_CHECK(flag == false);
  1.1496 +		
  1.1497 +		flag = s2 <= s1;
  1.1498 +		CPPUNIT_CHECK(flag == false);		
  1.1499 +		
  1.1500 +		flag = s3 <= s1;
  1.1501 +		CPPUNIT_CHECK(flag == false);		
  1.1502 +		
  1.1503 +		flag = s1 <= s3;
  1.1504 +		CPPUNIT_CHECK(flag == true);
  1.1505 +		
  1.1506 +		flag = s3 < s1;
  1.1507 +		CPPUNIT_CHECK(flag == false);		
  1.1508 +		
  1.1509 +		flag = s1 < s3;
  1.1510 +		CPPUNIT_CHECK(flag == true);
  1.1511 +		}
  1.1512 +		{
  1.1513 +		string str1 ( "xddd-1234-abcd" );
  1.1514 +		basic_string <char>::size_type indexCh1a;
  1.1515 +
  1.1516 +		indexCh1a = str1.find_first_not_of ( "d" , 2 );
  1.1517 +		CPPUNIT_CHECK(indexCh1a == 4);	
  1.1518 +		}
  1.1519 +	}
  1.1520 +