os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/string_test.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// To make GLib C++ closer to STLport behavior we need this macro:
sl@0
    15
// Only mandatory when building unit tests without STLport, do not change
sl@0
    16
// anything when building with STLport
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
#define _GLIBCXX_FULLY_DYNAMIC_STRING
sl@0
    21
sl@0
    22
//Has to be first for StackAllocator swap overload to be taken
sl@0
    23
//into account (at least using GCC 4.0.1)
sl@0
    24
#include "stack_allocator.h"
sl@0
    25
sl@0
    26
#include <vector>
sl@0
    27
#include <deque>
sl@0
    28
#include <string>
sl@0
    29
#include <algorithm>
sl@0
    30
#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
sl@0
    31
#  include <sstream>
sl@0
    32
#endif
sl@0
    33
sl@0
    34
#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
    35
#  include <stdexcept>
sl@0
    36
#endif
sl@0
    37
sl@0
    38
#if !defined (STLPORT) || defined (_STLP_THREADS)
sl@0
    39
#  if defined (STLPORT) && defined (_STLP_PTHREADS) || \
sl@0
    40
      defined (__GNUC__) && !defined (__MINGW32__)
sl@0
    41
#    define USE_PTHREAD_API
sl@0
    42
#    include <pthread.h>
sl@0
    43
#  endif
sl@0
    44
sl@0
    45
#  if defined (STLPORT) && defined (_STLP_WIN32THREADS) || \
sl@0
    46
      defined (__GNUC__) && defined (__MINGW32__) || \
sl@0
    47
      defined (_MSC_VER)
sl@0
    48
#    define USE_WINDOWS_API
sl@0
    49
#    include <windows.h>
sl@0
    50
#  endif
sl@0
    51
#endif
sl@0
    52
sl@0
    53
#include "stack_allocator.h"
sl@0
    54
#include "cppunit/cppunit_proxy.h"
sl@0
    55
sl@0
    56
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
sl@0
    57
using namespace std;
sl@0
    58
#endif
sl@0
    59
sl@0
    60
//
sl@0
    61
// TestCase class
sl@0
    62
//
sl@0
    63
class StringTest : public CPPUNIT_NS::TestCase
sl@0
    64
{
sl@0
    65
  CPPUNIT_TEST_SUITE(StringTest);
sl@0
    66
  CPPUNIT_TEST(constructor);
sl@0
    67
  CPPUNIT_TEST(reserve);
sl@0
    68
  CPPUNIT_TEST(assign);
sl@0
    69
  CPPUNIT_TEST(erase);
sl@0
    70
  CPPUNIT_TEST(data);
sl@0
    71
  CPPUNIT_TEST(c_str);
sl@0
    72
  CPPUNIT_TEST(null_char);
sl@0
    73
  CPPUNIT_TEST(insert);
sl@0
    74
  CPPUNIT_TEST(replace);
sl@0
    75
  CPPUNIT_TEST(resize);
sl@0
    76
  CPPUNIT_TEST(short_string);
sl@0
    77
  CPPUNIT_TEST(find);
sl@0
    78
  CPPUNIT_TEST(rfind);
sl@0
    79
  CPPUNIT_TEST(find_last_of);
sl@0
    80
  CPPUNIT_TEST(find_last_not_of);
sl@0
    81
  CPPUNIT_TEST(copy);
sl@0
    82
#if !defined (USE_PTHREAD_API) && !defined (USE_WINDOWS_API)
sl@0
    83
  CPPUNIT_IGNORE;
sl@0
    84
#endif
sl@0
    85
  CPPUNIT_TEST(mt);
sl@0
    86
  CPPUNIT_STOP_IGNORE;
sl@0
    87
  CPPUNIT_TEST(short_string_optim_bug);
sl@0
    88
  CPPUNIT_TEST(compare);
sl@0
    89
#if defined (__DMC__)
sl@0
    90
  CPPUNIT_IGNORE;
sl@0
    91
#endif
sl@0
    92
  CPPUNIT_TEST(template_expression);
sl@0
    93
#if defined (STLPORT) && defined (_STLP_MSVC) && (_STLP_MSVC < 1300)
sl@0
    94
#  define TE_TMP_TEST_IGNORED
sl@0
    95
  CPPUNIT_IGNORE;
sl@0
    96
#endif
sl@0
    97
  CPPUNIT_TEST(te_tmp);
sl@0
    98
#if defined (TE_TMP_TEST_IGNORED)
sl@0
    99
  CPPUNIT_STOP_IGNORE;
sl@0
   100
#endif
sl@0
   101
#if defined (STLPORT) && defined (_STLP_NO_WCHAR_T)
sl@0
   102
  CPPUNIT_IGNORE;
sl@0
   103
#endif
sl@0
   104
#if defined (__CYGWIN__) && !defined (STLPORT)
sl@0
   105
  CPPUNIT_IGNORE;
sl@0
   106
#endif
sl@0
   107
  CPPUNIT_TEST(template_wexpression);
sl@0
   108
  CPPUNIT_STOP_IGNORE;
sl@0
   109
#if defined (STLPORT) && defined (_STLP_USE_NO_IOSTREAMS)
sl@0
   110
  CPPUNIT_IGNORE;
sl@0
   111
#endif
sl@0
   112
  CPPUNIT_TEST(io);
sl@0
   113
  CPPUNIT_STOP_IGNORE;
sl@0
   114
#if defined (STLPORT) && defined (_STLP_NO_CUSTOM_IO) 
sl@0
   115
  CPPUNIT_IGNORE;
sl@0
   116
#endif
sl@0
   117
  CPPUNIT_TEST(allocator_with_state);
sl@0
   118
  CPPUNIT_STOP_IGNORE;
sl@0
   119
  CPPUNIT_TEST(capacity);
sl@0
   120
  CPPUNIT_TEST(str_cov1);
sl@0
   121
  CPPUNIT_TEST(str_cov2);
sl@0
   122
  CPPUNIT_TEST(str_cov3);
sl@0
   123
  CPPUNIT_TEST(str_cov4);
sl@0
   124
  CPPUNIT_TEST(str_cov5);
sl@0
   125
  CPPUNIT_TEST(str_cov6);
sl@0
   126
  CPPUNIT_TEST_SUITE_END();
sl@0
   127
sl@0
   128
protected:
sl@0
   129
  void constructor();
sl@0
   130
  void reserve();
sl@0
   131
  void erase();
sl@0
   132
  void data();
sl@0
   133
  void c_str();
sl@0
   134
  void null_char();
sl@0
   135
  void insert();
sl@0
   136
  void replace();
sl@0
   137
  void resize();
sl@0
   138
  void short_string();
sl@0
   139
  void find();
sl@0
   140
  void rfind();
sl@0
   141
  void find_last_of();
sl@0
   142
  void find_last_not_of();
sl@0
   143
  void copy();
sl@0
   144
  void assign();
sl@0
   145
  void mt();
sl@0
   146
  void short_string_optim_bug();
sl@0
   147
  void compare();
sl@0
   148
  void template_expression();
sl@0
   149
  void te_tmp();
sl@0
   150
  void template_wexpression();
sl@0
   151
  void io();
sl@0
   152
  void allocator_with_state();
sl@0
   153
  void capacity();
sl@0
   154
  void str_cov1();
sl@0
   155
  void str_cov2();
sl@0
   156
  void str_cov3();
sl@0
   157
  void str_cov4();
sl@0
   158
  void str_cov5();
sl@0
   159
  void str_cov6();
sl@0
   160
  static string func(const string& par) {
sl@0
   161
    string tmp( par );
sl@0
   162
    return tmp;
sl@0
   163
  }
sl@0
   164
sl@0
   165
#if defined (USE_PTHREAD_API) || defined (USE_WINDOWS_API)
sl@0
   166
#  if defined (USE_PTHREAD_API)
sl@0
   167
  static void* f(void*)
sl@0
   168
#  else
sl@0
   169
  static DWORD __stdcall f(void*)
sl@0
   170
#  endif
sl@0
   171
  {
sl@0
   172
    string s( "qyweyuewunfkHBUKGYUGL,wehbYGUW^(@T@H!BALWD:h^&@#*@(#:JKHWJ:CND" );
sl@0
   173
sl@0
   174
    for ( int i = 0; i < 2000000; ++i ) {
sl@0
   175
      string sx = func( s );
sl@0
   176
    }
sl@0
   177
sl@0
   178
    return 0;
sl@0
   179
  }
sl@0
   180
#endif
sl@0
   181
sl@0
   182
};
sl@0
   183
sl@0
   184
CPPUNIT_TEST_SUITE_REGISTRATION(StringTest);
sl@0
   185
sl@0
   186
//
sl@0
   187
// tests implementation
sl@0
   188
//
sl@0
   189
void StringTest::constructor()
sl@0
   190
{
sl@0
   191
#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
   192
  try {
sl@0
   193
    string s((size_t)-1, 'a');
sl@0
   194
    CPPUNIT_ASSERT( false );
sl@0
   195
  }
sl@0
   196
  catch (length_error const&) {
sl@0
   197
  }
sl@0
   198
  catch (...) {
sl@0
   199
    //Expected exception is length_error:
sl@0
   200
    CPPUNIT_ASSERT( false );
sl@0
   201
  }
sl@0
   202
#endif
sl@0
   203
}
sl@0
   204
sl@0
   205
void StringTest::reserve()
sl@0
   206
{
sl@0
   207
  string s;
sl@0
   208
#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
   209
  try {
sl@0
   210
    s.reserve(s.max_size() + 1);
sl@0
   211
    CPPUNIT_ASSERT( false );
sl@0
   212
  }
sl@0
   213
  catch (length_error const&) {
sl@0
   214
  }
sl@0
   215
  catch (...) {
sl@0
   216
    //Expected exception is length_error:
sl@0
   217
    CPPUNIT_ASSERT( false );
sl@0
   218
  }
sl@0
   219
#endif
sl@0
   220
}
sl@0
   221
sl@0
   222
void StringTest::mt()
sl@0
   223
{
sl@0
   224
#if defined (USE_PTHREAD_API) || defined (USE_WINDOWS_API)
sl@0
   225
  const int nth = 2;
sl@0
   226
#  if defined (USE_PTHREAD_API)
sl@0
   227
  pthread_t t[nth];
sl@0
   228
sl@0
   229
  for ( int i = 0; i < nth; ++i ) {
sl@0
   230
    pthread_create( &t[i], 0, f, 0 );
sl@0
   231
  }
sl@0
   232
sl@0
   233
  for ( int i = 0; i < nth; ++i ) {
sl@0
   234
    pthread_join( t[i], 0 );
sl@0
   235
  }
sl@0
   236
#  endif // PTHREAD
sl@0
   237
sl@0
   238
#  if defined (USE_WINDOWS_API)
sl@0
   239
  //DWORD start = GetTickCount();
sl@0
   240
sl@0
   241
  HANDLE t[nth];
sl@0
   242
sl@0
   243
  int i; // VC6 not support in-loop scope of cycle var
sl@0
   244
  for ( i = 0; i < nth; ++i ) {
sl@0
   245
    t[i] = CreateThread(NULL, 0, f, 0, 0, NULL);
sl@0
   246
  }
sl@0
   247
sl@0
   248
  if (WaitForMultipleObjects(nth, t, TRUE, INFINITE) == WAIT_FAILED) {
sl@0
   249
    // On some platforms (evc3/evc4) WaitForMultipleObjects() with fWaitAll == TRUE
sl@0
   250
    // is not supported. We then wait with a loop on each thread:
sl@0
   251
    for ( i = 0; i < nth; ++i ) {
sl@0
   252
      WaitForSingleObject(t[i], INFINITE);
sl@0
   253
    }
sl@0
   254
  }
sl@0
   255
sl@0
   256
  /*
sl@0
   257
  DWORD duration = GetTickCount() - start;
sl@0
   258
  ostringstream ostr;
sl@0
   259
  ostr << "Duration: " << duration << endl;
sl@0
   260
  CPPUNIT_MESSAGE(ostr.str().c_str());
sl@0
   261
  */
sl@0
   262
#  endif
sl@0
   263
#endif
sl@0
   264
}
sl@0
   265
sl@0
   266
void StringTest::short_string()
sl@0
   267
{
sl@0
   268
  string const ref_short_str1("str1"), ref_short_str2("str2");
sl@0
   269
  string short_str1(ref_short_str1), short_str2(ref_short_str2);
sl@0
   270
  string const ref_long_str1("str                                                  1");
sl@0
   271
  string const ref_long_str2("str                                                  2");
sl@0
   272
  string long_str1(ref_long_str1), long_str2(ref_long_str2);
sl@0
   273
sl@0
   274
  CPPUNIT_ASSERT(short_str1 == ref_short_str1);
sl@0
   275
  CPPUNIT_ASSERT(long_str1 == ref_long_str1);
sl@0
   276
sl@0
   277
  {
sl@0
   278
    string str1(short_str1);
sl@0
   279
    str1 = long_str1;
sl@0
   280
    CPPUNIT_ASSERT(str1 == ref_long_str1);
sl@0
   281
  }
sl@0
   282
sl@0
   283
  {
sl@0
   284
    string str1(long_str1);
sl@0
   285
    str1 = short_str1;
sl@0
   286
    CPPUNIT_ASSERT(str1 == ref_short_str1);
sl@0
   287
  }
sl@0
   288
sl@0
   289
  {
sl@0
   290
    short_str1.swap(short_str2);
sl@0
   291
    CPPUNIT_ASSERT((short_str1 == ref_short_str2) && (short_str2 == ref_short_str1));
sl@0
   292
    short_str1.swap(short_str2);
sl@0
   293
  }
sl@0
   294
sl@0
   295
  {
sl@0
   296
    long_str1.swap(long_str2);
sl@0
   297
    CPPUNIT_ASSERT((long_str1 == ref_long_str2) && (long_str2 == ref_long_str1));
sl@0
   298
    long_str1.swap(long_str2);
sl@0
   299
  }
sl@0
   300
sl@0
   301
  {
sl@0
   302
    short_str1.swap(long_str1);
sl@0
   303
    CPPUNIT_ASSERT((short_str1 == ref_long_str1) && (long_str1 == ref_short_str1));
sl@0
   304
    short_str1.swap(long_str1);
sl@0
   305
  }
sl@0
   306
sl@0
   307
  {
sl@0
   308
    long_str1.swap(short_str1);
sl@0
   309
    CPPUNIT_ASSERT((short_str1 == ref_long_str1) && (long_str1 == ref_short_str1));
sl@0
   310
    long_str1.swap(short_str1);
sl@0
   311
  }
sl@0
   312
sl@0
   313
  {
sl@0
   314
    //This is to test move constructor
sl@0
   315
    vector<string> str_vect;
sl@0
   316
    str_vect.push_back(short_str1);
sl@0
   317
    str_vect.push_back(long_str1);
sl@0
   318
    str_vect.push_back(short_str2);
sl@0
   319
    str_vect.push_back(long_str2);
sl@0
   320
    CPPUNIT_ASSERT((str_vect[0] == ref_short_str1) &&
sl@0
   321
                   (str_vect[1] == ref_long_str1) &&
sl@0
   322
                   (str_vect[2] == ref_short_str2) &&
sl@0
   323
                   (str_vect[3] == ref_long_str2));
sl@0
   324
  }
sl@0
   325
}
sl@0
   326
sl@0
   327
void StringTest::erase()
sl@0
   328
{
sl@0
   329
  char const* c_str = "Hello, World!";
sl@0
   330
  string str(c_str);
sl@0
   331
  CPPUNIT_ASSERT( str == c_str );
sl@0
   332
sl@0
   333
  str.erase(str.begin() + 1, str.end() - 1); // Erase all but first and last.
sl@0
   334
sl@0
   335
  size_t i;
sl@0
   336
  for (i = 0; i < str.size(); ++i) {
sl@0
   337
    switch ( i ) {
sl@0
   338
      case 0:
sl@0
   339
        CPPUNIT_ASSERT( str[i] == 'H' );
sl@0
   340
        break;
sl@0
   341
      case 1:
sl@0
   342
        CPPUNIT_ASSERT( str[i] == '!' );
sl@0
   343
        break;
sl@0
   344
      default:
sl@0
   345
        CPPUNIT_ASSERT( false );
sl@0
   346
    }
sl@0
   347
  }
sl@0
   348
sl@0
   349
  str.insert(1, c_str);
sl@0
   350
  str.erase(str.begin()); // Erase first element.
sl@0
   351
  str.erase(str.end() - 1); // Erase last element.
sl@0
   352
  CPPUNIT_ASSERT( str == c_str );
sl@0
   353
  str.clear(); // Erase all.
sl@0
   354
  CPPUNIT_ASSERT( str.empty() );
sl@0
   355
sl@0
   356
  str = c_str;
sl@0
   357
  CPPUNIT_ASSERT( str == c_str );
sl@0
   358
sl@0
   359
  str.erase(1, str.size() - 1); // Erase all but first and last.
sl@0
   360
  for (i = 0; i < str.size(); i++) {
sl@0
   361
    switch ( i ) {
sl@0
   362
      case 0:
sl@0
   363
        CPPUNIT_ASSERT( str[i] == 'H' );
sl@0
   364
        break;
sl@0
   365
      case 1:
sl@0
   366
        CPPUNIT_ASSERT( str[i] == '!' );
sl@0
   367
        break;
sl@0
   368
      default:
sl@0
   369
        CPPUNIT_ASSERT( false );
sl@0
   370
    }
sl@0
   371
  }
sl@0
   372
sl@0
   373
  str.erase(1);
sl@0
   374
  CPPUNIT_ASSERT( str == "H" );
sl@0
   375
}
sl@0
   376
sl@0
   377
void StringTest::data()
sl@0
   378
{
sl@0
   379
  string xx;
sl@0
   380
sl@0
   381
  CPPUNIT_ASSERT( xx.data() != 0 );  // ISO-IEC-14882:1998(E), 21.3.6, paragraph 3
sl@0
   382
#if 0
sl@0
   383
  /* This test really not required: in ISO-IEC-14882:1998(E) paragraph 3 stated:
sl@0
   384
   * '... and can have zero added to it', again: 'CAN', but not 'MUST'.
sl@0
   385
   * That's why I am comment this test. But I don't remove it due to I had
sl@0
   386
   * unevident problem with misinterpretation of data() return (i.e. data()
sl@0
   387
   * and c_str() provide different functionality!) and expect that this is
sl@0
   388
   * more-or-less common pitfall.
sl@0
   389
   *    - ptr
sl@0
   390
   */
sl@0
   391
  string low( "2004-01-01" );
sl@0
   392
  // Blocks A and B should follow each other.
sl@0
   393
  // Block A:
sl@0
   394
  xx = "123456";
sl@0
   395
  xx += low;
sl@0
   396
  if ( strcmp( xx.data(), "1234562004-01-01" ) != 0 ) {
sl@0
   397
    return -1;
sl@0
   398
  }
sl@0
   399
  // End of block A
sl@0
   400
sl@0
   401
  // Block B:
sl@0
   402
  xx = "1234";
sl@0
   403
  xx += ";";
sl@0
   404
sl@0
   405
  if ( strcmp( xx.data(), "1234;" ) != 0 ) {
sl@0
   406
    return -1;
sl@0
   407
  }
sl@0
   408
  // End of block B
sl@0
   409
#endif
sl@0
   410
}
sl@0
   411
sl@0
   412
void StringTest::c_str()
sl@0
   413
{
sl@0
   414
  string low( "2004-01-01" );
sl@0
   415
  string xx;
sl@0
   416
  string yy;
sl@0
   417
sl@0
   418
  CPPUNIT_ASSERT( *(yy.c_str()) == '\0' ); // ISO-IEC-14882:1998(E), 21.3.6, paragraph 1
sl@0
   419
sl@0
   420
  // Blocks A and B should follow each other.
sl@0
   421
  // Block A:
sl@0
   422
  xx = "123456";
sl@0
   423
  xx += low;
sl@0
   424
  CPPUNIT_ASSERT( strcmp( xx.c_str(), "1234562004-01-01" ) == 0 );
sl@0
   425
  // End of block A
sl@0
   426
sl@0
   427
  // Block B:
sl@0
   428
  xx = "1234";
sl@0
   429
  xx += ";";
sl@0
   430
  CPPUNIT_ASSERT( strcmp( xx.c_str(), "1234;" ) == 0 );
sl@0
   431
  // End of block B
sl@0
   432
}
sl@0
   433
sl@0
   434
void StringTest::null_char()
sl@0
   435
{
sl@0
   436
  // ISO/IEC 14882:1998(E), ISO/IEC 14882:2003(E), 21.3.4 ('... the const version')
sl@0
   437
  const string s( "123456" );
sl@0
   438
sl@0
   439
  CPPUNIT_CHECK( s[s.size()] == '\0' );
sl@0
   440
sl@0
   441
#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
   442
  try {
sl@0
   443
    //Check is only here to avoid warning about value of expression not used
sl@0
   444
    CPPUNIT_CHECK( s.at(s.size()) == '\0' );
sl@0
   445
    CPPUNIT_ASSERT( false );
sl@0
   446
  }
sl@0
   447
  catch (out_of_range const&) {
sl@0
   448
    CPPUNIT_ASSERT( true );
sl@0
   449
  }
sl@0
   450
  catch ( ... ) {
sl@0
   451
    CPPUNIT_ASSERT( false );
sl@0
   452
  }
sl@0
   453
#endif
sl@0
   454
}
sl@0
   455
sl@0
   456
void StringTest::insert()
sl@0
   457
{
sl@0
   458
  string strorg = "This is test string for string calls";
sl@0
   459
  string str;
sl@0
   460
  /*
sl@0
   461
   * In case of reallocation there is no auto reference problem
sl@0
   462
   * so we reserve a big enough string to be sure to test this
sl@0
   463
   * particular point.
sl@0
   464
   */
sl@0
   465
  str.reserve(100);
sl@0
   466
  str = strorg;
sl@0
   467
sl@0
   468
  //test self insertion:
sl@0
   469
  str.insert(10, str.c_str() + 5, 15);
sl@0
   470
  CPPUNIT_ASSERT( str == "This is teis test string st string for string calls" );
sl@0
   471
sl@0
   472
  str = strorg;
sl@0
   473
  str.insert(15, str.c_str() + 5, 25);
sl@0
   474
  CPPUNIT_ASSERT( str == "This is test stis test string for stringring for string calls" );
sl@0
   475
sl@0
   476
  str = strorg;
sl@0
   477
  str.insert(0, str.c_str() + str.size() - 4, 4);
sl@0
   478
  CPPUNIT_ASSERT( str == "allsThis is test string for string calls" );
sl@0
   479
sl@0
   480
  str = strorg;
sl@0
   481
  str.insert(0, str.c_str() + str.size() / 2 - 1, str.size() / 2 + 1);
sl@0
   482
  CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" );
sl@0
   483
sl@0
   484
  str = strorg;
sl@0
   485
  string::iterator b = str.begin();
sl@0
   486
  string::const_iterator s = str.begin() + str.size() / 2 - 1;
sl@0
   487
  string::const_iterator e = str.end();
sl@0
   488
  str.insert( b, s, e );
sl@0
   489
  CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" );
sl@0
   490
sl@0
   491
  str = strorg;
sl@0
   492
  str.insert(str.begin(), str.begin() + str.size() / 2 - 1, str.end());
sl@0
   493
  CPPUNIT_ASSERT( str == "ng for string callsThis is test string for string calls" );
sl@0
   494
sl@0
   495
#ifdef _STLP_MEMBER_TEMPLATES
sl@0
   496
  vector<int> int_vect;
sl@0
   497
  //Just a compile time test:
sl@0
   498
  str.insert(str.end(), int_vect.begin(), int_vect.end());
sl@0
   499
#endif
sl@0
   500
sl@0
   501
  string str0;
sl@0
   502
  str0.insert(str0.begin(), 5, '0');
sl@0
   503
  CPPUNIT_ASSERT( str0 == "00000" );
sl@0
   504
sl@0
   505
  string str1;
sl@0
   506
  {
sl@0
   507
    string::size_type pos = 0, nb = 2;
sl@0
   508
    str1.insert(pos, nb, '1');
sl@0
   509
  }
sl@0
   510
  CPPUNIT_ASSERT( str1 == "11" );
sl@0
   511
sl@0
   512
  str0.insert(0, str1);
sl@0
   513
  CPPUNIT_ASSERT( str0 == "1100000" );
sl@0
   514
sl@0
   515
  string str2("2345");
sl@0
   516
  str0.insert(str0.size(), str2, 1, 2);
sl@0
   517
  CPPUNIT_ASSERT( str0 == "110000034" );
sl@0
   518
sl@0
   519
  str1.insert(str1.begin() + 1, 2, '2');
sl@0
   520
  CPPUNIT_ASSERT( str1 == "1221" );
sl@0
   521
sl@0
   522
  str1.insert(2, "333333", 3);
sl@0
   523
  CPPUNIT_ASSERT( str1 == "1233321" );
sl@0
   524
sl@0
   525
  str1.insert(4, "4444");
sl@0
   526
  CPPUNIT_ASSERT( str1 == "12334444321" );
sl@0
   527
sl@0
   528
  str1.insert(str1.begin() + 6, '5');
sl@0
   529
  CPPUNIT_ASSERT( str1 == "123344544321" );
sl@0
   530
}
sl@0
   531
sl@0
   532
void StringTest::replace()
sl@0
   533
{
sl@0
   534
  /*
sl@0
   535
   * This test case is for the non template basic_string::replace method,
sl@0
   536
   * this is why we play with the const iterators and reference to guaranty
sl@0
   537
   * that the right method is called.
sl@0
   538
   */
sl@0
   539
  const string v( "78" );
sl@0
   540
  string s( "123456" );
sl@0
   541
  string const& cs = s;
sl@0
   542
sl@0
   543
  string::iterator i = s.begin() + 1;
sl@0
   544
  s.replace(i, i + 3, v.begin(), v.end());
sl@0
   545
  CPPUNIT_ASSERT( s == "17856" );
sl@0
   546
sl@0
   547
  s = "123456";
sl@0
   548
  i = s.begin() + 1;
sl@0
   549
  s.replace(i, i + 1, v.begin(), v.end());
sl@0
   550
  CPPUNIT_ASSERT( s == "1783456" );
sl@0
   551
sl@0
   552
  s = "123456";
sl@0
   553
  i = s.begin() + 1;
sl@0
   554
  string::const_iterator ci = s.begin() + 1;
sl@0
   555
  s.replace(i, i + 3, ci + 3, cs.end());
sl@0
   556
  CPPUNIT_ASSERT( s == "15656" );
sl@0
   557
sl@0
   558
  s = "123456";
sl@0
   559
  i = s.begin() + 1;
sl@0
   560
  ci = s.begin() + 1;
sl@0
   561
  s.replace(i, i + 3, ci, ci + 2);
sl@0
   562
  CPPUNIT_ASSERT( s == "12356" );
sl@0
   563
sl@0
   564
  s = "123456";
sl@0
   565
  i = s.begin() + 1;
sl@0
   566
  ci = s.begin() + 1;
sl@0
   567
  s.replace(i, i + 3, ci + 1, cs.end());
sl@0
   568
  CPPUNIT_ASSERT( s == "1345656" );
sl@0
   569
sl@0
   570
  s = "123456";
sl@0
   571
  s.replace(s.begin() + 4, s.end(), cs.begin(), cs.end());
sl@0
   572
  CPPUNIT_ASSERT( s == "1234123456" );
sl@0
   573
sl@0
   574
  /*
sl@0
   575
   * This is the test for the template replace method.
sl@0
   576
   */
sl@0
   577
  s = "123456";
sl@0
   578
  string::iterator b = s.begin() + 4;
sl@0
   579
  string::iterator e = s.end();
sl@0
   580
  string::const_iterator rb = s.begin();
sl@0
   581
  string::const_iterator re = s.end();
sl@0
   582
  s.replace(b, e, rb, re);
sl@0
   583
  CPPUNIT_ASSERT( s == "1234123456" );
sl@0
   584
sl@0
   585
  s = "123456";
sl@0
   586
  s.replace(s.begin() + 4, s.end(), s.begin(), s.end());
sl@0
   587
  CPPUNIT_ASSERT( s == "1234123456" );
sl@0
   588
sl@0
   589
  string strorg("This is test string for string calls");
sl@0
   590
  string str = strorg;
sl@0
   591
  str.replace(5, 15, str.c_str(), 10);
sl@0
   592
  CPPUNIT_ASSERT( str == "This This is tefor string calls" );
sl@0
   593
sl@0
   594
  str = strorg;
sl@0
   595
  str.replace(5, 5, str.c_str(), 10);
sl@0
   596
  CPPUNIT_ASSERT( str == "This This is test string for string calls" );
sl@0
   597
sl@0
   598
#if !defined (STLPORT) || defined (_STLP_MEMBER_TEMPLATES)
sl@0
   599
  deque<char> cdeque;
sl@0
   600
  cdeque.push_back('I');
sl@0
   601
  str.replace(str.begin(), str.begin() + 11, cdeque.begin(), cdeque.end());
sl@0
   602
  CPPUNIT_ASSERT( str == "Is test string for string calls" );
sl@0
   603
#endif
sl@0
   604
}
sl@0
   605
sl@0
   606
void StringTest::resize()
sl@0
   607
{
sl@0
   608
  string s;
sl@0
   609
sl@0
   610
  s.resize(0);
sl@0
   611
sl@0
   612
  CPPUNIT_ASSERT( *s.c_str() == 0 );
sl@0
   613
sl@0
   614
  s = "1234567";
sl@0
   615
sl@0
   616
  s.resize(0);
sl@0
   617
  CPPUNIT_ASSERT( *s.c_str() == 0 );
sl@0
   618
sl@0
   619
  s = "1234567";
sl@0
   620
  s.resize(1);
sl@0
   621
  CPPUNIT_ASSERT( s.size() == 1 );
sl@0
   622
  CPPUNIT_ASSERT( *s.c_str() == '1' );
sl@0
   623
  CPPUNIT_ASSERT( *(s.c_str() + 1) == 0 );
sl@0
   624
sl@0
   625
  s = "1234567";
sl@0
   626
  s.resize(10);
sl@0
   627
  CPPUNIT_ASSERT( s.size() == 10 );
sl@0
   628
  CPPUNIT_ASSERT( s[6] == '7' );
sl@0
   629
  CPPUNIT_ASSERT( s[7] == 0 );
sl@0
   630
  CPPUNIT_ASSERT( s[8] == 0 );
sl@0
   631
  CPPUNIT_ASSERT( s[9] == 0 );
sl@0
   632
}
sl@0
   633
sl@0
   634
void StringTest::find()
sl@0
   635
{
sl@0
   636
  string s("one two three one two three");
sl@0
   637
  CPPUNIT_ASSERT( s.find("one") == 0 );
sl@0
   638
  CPPUNIT_ASSERT( s.find('t') == 4 );
sl@0
   639
  CPPUNIT_ASSERT( s.find('t', 5) == 8 );
sl@0
   640
  //We are trying to get a const reference to the npos string static member to
sl@0
   641
  //force the compiler to allocate memory for this variable. It used to reveal
sl@0
   642
  //a bug of STLport which was simply declaring npos without instanciating it.
sl@0
   643
#if !defined (STLPORT) || !defined (_STLP_STATIC_CONST_INIT_BUG)
sl@0
   644
  string::size_type const& npos_local = string::npos;
sl@0
   645
#else
sl@0
   646
#  define npos_local string::npos
sl@0
   647
#endif
sl@0
   648
  CPPUNIT_ASSERT( s.find("four") == npos_local );
sl@0
   649
  CPPUNIT_ASSERT( s.find("one", string::npos) == npos_local );
sl@0
   650
sl@0
   651
  CPPUNIT_ASSERT( s.find_first_of("abcde") == 2 );
sl@0
   652
sl@0
   653
  CPPUNIT_ASSERT( s.find_first_not_of("enotw ") == 9 );
sl@0
   654
}
sl@0
   655
sl@0
   656
void StringTest::rfind()
sl@0
   657
{
sl@0
   658
  // 21.3.6.2
sl@0
   659
  string s("one two three one two three");
sl@0
   660
sl@0
   661
  CPPUNIT_ASSERT( s.rfind("two") == 18 );
sl@0
   662
  CPPUNIT_ASSERT( s.rfind("two", 0) == string::npos );
sl@0
   663
  CPPUNIT_ASSERT( s.rfind("two", 11) == 4 );
sl@0
   664
  CPPUNIT_ASSERT( s.rfind('w') == 19 );
sl@0
   665
sl@0
   666
  string test( "aba" );
sl@0
   667
sl@0
   668
  CPPUNIT_CHECK( test.rfind( "a", 2, 1 ) == 2 );
sl@0
   669
  CPPUNIT_CHECK( test.rfind( "a", 1, 1 ) == 0 );
sl@0
   670
  CPPUNIT_CHECK( test.rfind( "a", 0, 1 ) == 0 );
sl@0
   671
sl@0
   672
  CPPUNIT_CHECK( test.rfind( 'a', 2 ) == 2 );
sl@0
   673
  CPPUNIT_CHECK( test.rfind( 'a', 1 ) == 0 );
sl@0
   674
  CPPUNIT_CHECK( test.rfind( 'a', 0 ) == 0 );
sl@0
   675
}
sl@0
   676
sl@0
   677
void StringTest::find_last_of()
sl@0
   678
{
sl@0
   679
  // 21.3.6.4
sl@0
   680
  string s("one two three one two three");
sl@0
   681
sl@0
   682
  CPPUNIT_ASSERT( s.find_last_of("abcde") == 26 );
sl@0
   683
sl@0
   684
  string test( "aba" );
sl@0
   685
sl@0
   686
  CPPUNIT_CHECK( test.find_last_of( "a", 2, 1 ) == 2 );
sl@0
   687
  CPPUNIT_CHECK( test.find_last_of( "a", 1, 1 ) == 0 );
sl@0
   688
  CPPUNIT_CHECK( test.find_last_of( "a", 0, 1 ) == 0 );
sl@0
   689
sl@0
   690
  CPPUNIT_CHECK( test.find_last_of( 'a', 2 ) == 2 );
sl@0
   691
  CPPUNIT_CHECK( test.find_last_of( 'a', 1 ) == 0 );
sl@0
   692
  CPPUNIT_CHECK( test.find_last_of( 'a', 0 ) == 0 );
sl@0
   693
}
sl@0
   694
sl@0
   695
void StringTest::find_last_not_of()
sl@0
   696
{
sl@0
   697
  // 21.3.6.6
sl@0
   698
  string s("one two three one two three");
sl@0
   699
sl@0
   700
  CPPUNIT_ASSERT( s.find_last_not_of("ehortw ") == 15 );
sl@0
   701
sl@0
   702
  string test( "aba" );
sl@0
   703
sl@0
   704
  CPPUNIT_CHECK( test.find_last_not_of( "a", 2, 1 ) == 1 );
sl@0
   705
  CPPUNIT_CHECK( test.find_last_not_of( "b", 2, 1 ) == 2 );
sl@0
   706
  CPPUNIT_CHECK( test.find_last_not_of( "a", 1, 1 ) == 1 );
sl@0
   707
  CPPUNIT_CHECK( test.find_last_not_of( "b", 1, 1 ) == 0 );
sl@0
   708
  CPPUNIT_CHECK( test.find_last_not_of( "a", 0, 1 ) == string::npos );
sl@0
   709
  CPPUNIT_CHECK( test.find_last_not_of( "b", 0, 1 ) == 0 );
sl@0
   710
sl@0
   711
  CPPUNIT_CHECK( test.find_last_not_of( 'a', 2 ) == 1 );
sl@0
   712
  CPPUNIT_CHECK( test.find_last_not_of( 'b', 2 ) == 2 );
sl@0
   713
  CPPUNIT_CHECK( test.find_last_not_of( 'a', 1 ) == 1 );
sl@0
   714
  CPPUNIT_CHECK( test.find_last_not_of( 'b', 1 ) == 0 );
sl@0
   715
  CPPUNIT_CHECK( test.find_last_not_of( 'a', 0 ) == string::npos );
sl@0
   716
  CPPUNIT_CHECK( test.find_last_not_of( 'b', 0 ) == 0 );
sl@0
   717
}
sl@0
   718
sl@0
   719
void StringTest::copy()
sl@0
   720
{
sl@0
   721
  string s("foo");
sl@0
   722
  char dest[4];
sl@0
   723
  dest[0] = dest[1] = dest[2] = dest[3] = 1;
sl@0
   724
  s.copy(dest, 4);
sl@0
   725
  int pos = 0;
sl@0
   726
  CPPUNIT_ASSERT( dest[pos++] == 'f' );
sl@0
   727
  CPPUNIT_ASSERT( dest[pos++] == 'o' );
sl@0
   728
  CPPUNIT_ASSERT( dest[pos++] == 'o' );
sl@0
   729
  CPPUNIT_ASSERT( dest[pos++] == 1 );
sl@0
   730
sl@0
   731
  dest[0] = dest[1] = dest[2] = dest[3] = 1;
sl@0
   732
  s.copy(dest, 4, 2);
sl@0
   733
  pos = 0;
sl@0
   734
  CPPUNIT_ASSERT( dest[pos++] == 'o' );
sl@0
   735
  CPPUNIT_ASSERT( dest[pos++] == 1 );
sl@0
   736
sl@0
   737
#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
   738
  try {
sl@0
   739
    s.copy(dest, 4, 5);
sl@0
   740
    CPPUNIT_ASSERT( false );
sl@0
   741
  }
sl@0
   742
  catch (out_of_range const&) {
sl@0
   743
    CPPUNIT_ASSERT( true );
sl@0
   744
  }
sl@0
   745
  catch ( ... ) {
sl@0
   746
    CPPUNIT_ASSERT( false );
sl@0
   747
  }
sl@0
   748
#endif
sl@0
   749
}
sl@0
   750
sl@0
   751
void StringTest::assign()
sl@0
   752
{
sl@0
   753
  string s;
sl@0
   754
  char const* cstr = "test string for assign";
sl@0
   755
sl@0
   756
  s.assign(cstr, cstr + 22);
sl@0
   757
  CPPUNIT_ASSERT( s == "test string for assign" );
sl@0
   758
sl@0
   759
  string s2("other test string");
sl@0
   760
  s.assign(s2);
sl@0
   761
  CPPUNIT_ASSERT( s == s2 );
sl@0
   762
sl@0
   763
  static string str1;
sl@0
   764
  static string str2;
sl@0
   765
sl@0
   766
  // short string optim:
sl@0
   767
  str1 = "123456";
sl@0
   768
  // longer than short string:
sl@0
   769
  str2 = "1234567890123456789012345678901234567890";
sl@0
   770
sl@0
   771
  CPPUNIT_ASSERT(str1[5] == '6');
sl@0
   772
  CPPUNIT_ASSERT(str2[29] == '0');
sl@0
   773
}
sl@0
   774
sl@0
   775
/* This test is to check if std::string properly supports the short string
sl@0
   776
 * optimization. It has been found out that eMbedded Visual C++ 3.0 and .NET
sl@0
   777
 * compilers for the ARM platform fail to pass structs and classes of certain
sl@0
   778
 * size per value. This seems to be a known compiler bug. For other processors
sl@0
   779
 * (e.g. x86) the error doesn't occur.
sl@0
   780
 * (The ARM compiler creates a temporary object from teststr on the stack, to
sl@0
   781
 * pass it to the helper function. It uses the copy constructor for this.
sl@0
   782
 * After this the temporary object is copied to another place on the stack.
sl@0
   783
 * The result is that the _M_finish pointer then points to the wrong buffer
sl@0
   784
 * end and the size of the short string is incorrectly calculated.)
sl@0
   785
 */
sl@0
   786
void StringTest::short_string_optim_bug()
sl@0
   787
{
sl@0
   788
   string teststr("shortest");
sl@0
   789
sl@0
   790
   bool short_string_optim_bug_helper(string teststr);
sl@0
   791
sl@0
   792
   CPPUNIT_ASSERT(true == short_string_optim_bug_helper(teststr));
sl@0
   793
}
sl@0
   794
sl@0
   795
bool short_string_optim_bug_helper(string teststr)
sl@0
   796
{
sl@0
   797
   size_t ss = teststr.size();
sl@0
   798
   return (ss == 8);
sl@0
   799
}
sl@0
   800
sl@0
   801
void StringTest::compare()
sl@0
   802
{
sl@0
   803
  string str1("abcdef");
sl@0
   804
  string str2;
sl@0
   805
sl@0
   806
  str2 = "abcdef";
sl@0
   807
  CPPUNIT_ASSERT( str1.compare(str2) == 0 );
sl@0
   808
  str2 = "abcde";
sl@0
   809
  CPPUNIT_ASSERT( str1.compare(str2) > 0 );
sl@0
   810
  str2 = "abcdefg";
sl@0
   811
  CPPUNIT_ASSERT( str1.compare(str2) < 0 );
sl@0
   812
sl@0
   813
  CPPUNIT_ASSERT( str1.compare("abcdef") == 0 );
sl@0
   814
  CPPUNIT_ASSERT( str1.compare("abcde") > 0 );
sl@0
   815
  CPPUNIT_ASSERT( str1.compare("abcdefg") < 0 );
sl@0
   816
sl@0
   817
  str2 = "cde";
sl@0
   818
  CPPUNIT_ASSERT( str1.compare(2, 3, str2) == 0 );
sl@0
   819
  str2 = "cd";
sl@0
   820
  CPPUNIT_ASSERT( str1.compare(2, 3, str2) > 0 );
sl@0
   821
  str2 = "cdef";
sl@0
   822
  CPPUNIT_ASSERT( str1.compare(2, 3, str2) < 0 );
sl@0
   823
sl@0
   824
  str2 = "abcdef";
sl@0
   825
  CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 3) == 0 );
sl@0
   826
  CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 2) > 0 );
sl@0
   827
  CPPUNIT_ASSERT( str1.compare(2, 3, str2, 2, 4) < 0 );
sl@0
   828
sl@0
   829
  CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 3) == 0 );
sl@0
   830
  CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 2) > 0 );
sl@0
   831
  CPPUNIT_ASSERT( str1.compare(2, 3, "cdefgh", 4) < 0 );
sl@0
   832
}
sl@0
   833
sl@0
   834
/*
sl@0
   835
class mystring : public string {
sl@0
   836
public:
sl@0
   837
  mystring() {}
sl@0
   838
  mystring(string const& s) : string(s) {}
sl@0
   839
sl@0
   840
  mystring& operator = (string const& s) {
sl@0
   841
    string::operator = (s);
sl@0
   842
    return *this;
sl@0
   843
  };
sl@0
   844
};
sl@0
   845
*/
sl@0
   846
sl@0
   847
void StringTest::template_expression()
sl@0
   848
{
sl@0
   849
  string one("one"), two("two"), three("three");
sl@0
   850
  string space(1, ' ');
sl@0
   851
sl@0
   852
  // check availability of [un]equality operators
sl@0
   853
  {
sl@0
   854
      // string-string
sl@0
   855
      one == two;
sl@0
   856
      one != two;
sl@0
   857
      // string-literal
sl@0
   858
      one == "two";
sl@0
   859
      one != "two";
sl@0
   860
      // literal-string
sl@0
   861
      "one" == two;
sl@0
   862
      "one" != two;
sl@0
   863
      // strsum-string
sl@0
   864
      (one + two) == three;
sl@0
   865
      (one + two) != three;
sl@0
   866
      // string-strsum
sl@0
   867
      one == (two + three);
sl@0
   868
      one != (two + three);
sl@0
   869
      // strsum-literal
sl@0
   870
      (one + two) == "three";
sl@0
   871
      (one + two) != "three";
sl@0
   872
      // literal-strsum
sl@0
   873
      "one" == (two + three);
sl@0
   874
      "one" != (two + three);
sl@0
   875
      // strsum-strsum
sl@0
   876
      (one + two) == (two + three);
sl@0
   877
      (one + two) != (two + three);
sl@0
   878
  }
sl@0
   879
sl@0
   880
  {
sl@0
   881
    string result(one + ' ' + two + ' ' + three);
sl@0
   882
    CPPUNIT_CHECK( result == "one two three" );
sl@0
   883
  }
sl@0
   884
sl@0
   885
  {
sl@0
   886
    string result(one + ' ' + two + ' ' + three, 4);
sl@0
   887
    CPPUNIT_CHECK( result == "two three" );
sl@0
   888
  }
sl@0
   889
sl@0
   890
  {
sl@0
   891
    string result(one + ' ' + two + ' ' + three, 4, 3);
sl@0
   892
    CPPUNIT_CHECK( result == "two" );
sl@0
   893
  }
sl@0
   894
sl@0
   895
  //2 members expressions:
sl@0
   896
  CPPUNIT_CHECK( (' ' + one) == " one" );
sl@0
   897
  CPPUNIT_CHECK( (one + ' ') == "one " );
sl@0
   898
  CPPUNIT_CHECK( (one + " two") == "one two" );
sl@0
   899
  CPPUNIT_CHECK( ("one " + two) == "one two" );
sl@0
   900
  CPPUNIT_CHECK( (one + space) == "one " );
sl@0
   901
sl@0
   902
  //3 members expressions:
sl@0
   903
  CPPUNIT_CHECK( ((one + space) + "two") == "one two" );
sl@0
   904
  CPPUNIT_CHECK( ("one" + (space + two)) == "one two" );
sl@0
   905
  CPPUNIT_CHECK( ((one + space) + two) == "one two" );
sl@0
   906
  CPPUNIT_CHECK( (one + (space + two)) == "one two" );
sl@0
   907
  CPPUNIT_CHECK( ((one + space) + 't') == "one t" );
sl@0
   908
  CPPUNIT_CHECK( ('o' + (space + two)) == "o two" );
sl@0
   909
sl@0
   910
  //4 members expressions:
sl@0
   911
  CPPUNIT_CHECK( ((one + space) + (two + space)) == "one two " );
sl@0
   912
sl@0
   913
  //special operators
sl@0
   914
  {
sl@0
   915
    string result;
sl@0
   916
    result = one + space + two;
sl@0
   917
    CPPUNIT_CHECK( result == "one two" );
sl@0
   918
sl@0
   919
    result += space + three;
sl@0
   920
    CPPUNIT_CHECK( result == "one two three" );
sl@0
   921
  }
sl@0
   922
sl@0
   923
  //special append method
sl@0
   924
  {
sl@0
   925
    string result;
sl@0
   926
    //Use reserve to avoid reallocation and really test auto-referencing problems:
sl@0
   927
    result.reserve(64);
sl@0
   928
sl@0
   929
    result.append(one + space + two);
sl@0
   930
    CPPUNIT_CHECK( result == "one two" );
sl@0
   931
sl@0
   932
    result.append(space + result + space + three);
sl@0
   933
    CPPUNIT_CHECK( result == "one two one two three" );
sl@0
   934
sl@0
   935
    result = "one two";
sl@0
   936
    result.append(space + three, 1, 2);
sl@0
   937
    CPPUNIT_ASSERT( result == "one twoth" );
sl@0
   938
sl@0
   939
    result.append(space + result);
sl@0
   940
    CPPUNIT_CHECK( result == "one twoth one twoth" );
sl@0
   941
  }
sl@0
   942
sl@0
   943
  //special assign method
sl@0
   944
  {
sl@0
   945
    string result;
sl@0
   946
    //Use reserve to avoid reallocation and really test auto-referencing problems:
sl@0
   947
    result.reserve(64);
sl@0
   948
sl@0
   949
    result.assign(one + space + two + space + three);
sl@0
   950
    CPPUNIT_CHECK( result == "one two three" );
sl@0
   951
sl@0
   952
    result.assign(one + space + two + space + three, 3, 5);
sl@0
   953
    CPPUNIT_CHECK( result == " two " );
sl@0
   954
sl@0
   955
    result.assign(one + result + three);
sl@0
   956
    CPPUNIT_CHECK( result == "one two three" );
sl@0
   957
  }
sl@0
   958
sl@0
   959
  {
sl@0
   960
    CPPUNIT_CHECK( !(one + ' ' + two).empty() );
sl@0
   961
sl@0
   962
    char result = (one + ' ' + two)[3];
sl@0
   963
    CPPUNIT_CHECK( result == ' ' );
sl@0
   964
sl@0
   965
    result = (one + ' ' + two).at(3);
sl@0
   966
    CPPUNIT_CHECK( result == ' ' );
sl@0
   967
sl@0
   968
#if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
   969
    try {
sl@0
   970
      result = (one + ' ' + two).at(10);
sl@0
   971
      CPPUNIT_ASSERT(false);
sl@0
   972
    }
sl@0
   973
    catch (out_of_range const&) {
sl@0
   974
      CPPUNIT_ASSERT( result == ' ' );
sl@0
   975
    }
sl@0
   976
    catch (...) {
sl@0
   977
      CPPUNIT_ASSERT(false);
sl@0
   978
    }
sl@0
   979
#endif
sl@0
   980
  }
sl@0
   981
sl@0
   982
  /*
sl@0
   983
  mystring a("ing");
sl@0
   984
  //gcc failed to compile following expression when template expressions are activated.
sl@0
   985
  //MSVC sees no problem. gcc limitation or MSVC is too cool ??
sl@0
   986
  mystring b = "str" + a;
sl@0
   987
  */
sl@0
   988
}
sl@0
   989
sl@0
   990
#if !defined (TE_TMP_TEST_IGNORED)
sl@0
   991
class superstring
sl@0
   992
{
sl@0
   993
  public:
sl@0
   994
    superstring() :
sl@0
   995
      s("super")
sl@0
   996
    {}
sl@0
   997
sl@0
   998
    superstring( const string& str ) :
sl@0
   999
      s( str )
sl@0
  1000
    {}
sl@0
  1001
sl@0
  1002
  superstring operator / (const string& str )
sl@0
  1003
    { return superstring( s + "/" + str ); }
sl@0
  1004
sl@0
  1005
  superstring operator / (const char* str )
sl@0
  1006
    { return superstring( s + "/" + str ); }
sl@0
  1007
sl@0
  1008
  private:
sl@0
  1009
    string s;
sl@0
  1010
};
sl@0
  1011
#endif
sl@0
  1012
sl@0
  1013
void StringTest::te_tmp()
sl@0
  1014
{
sl@0
  1015
#if !defined (TE_TMP_TEST_IGNORED)
sl@0
  1016
  superstring s;
sl@0
  1017
  string more( "more" );
sl@0
  1018
  string less( "less" );
sl@0
  1019
sl@0
  1020
  superstring r = s / (more + less);
sl@0
  1021
#endif
sl@0
  1022
}
sl@0
  1023
sl@0
  1024
void StringTest::template_wexpression()
sl@0
  1025
{
sl@0
  1026
#if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)
sl@0
  1027
#  if !defined (__CYGWIN__) || defined (STLPORT)
sl@0
  1028
  wstring one(L"one"), two(L"two"), three(L"three");
sl@0
  1029
  wstring space(1, L' ');
sl@0
  1030
sl@0
  1031
  {
sl@0
  1032
    wstring result(one + L' ' + two + L' ' + three);
sl@0
  1033
    CPPUNIT_CHECK( result == L"one two three" );
sl@0
  1034
  }
sl@0
  1035
sl@0
  1036
  {
sl@0
  1037
    wstring result(one + L' ' + two + L' ' + three, 4);
sl@0
  1038
    CPPUNIT_CHECK( result == L"two three" );
sl@0
  1039
  }
sl@0
  1040
sl@0
  1041
  {
sl@0
  1042
    wstring result(one + L' ' + two + L' ' + three, 4, 3);
sl@0
  1043
    CPPUNIT_CHECK( result == L"two" );
sl@0
  1044
  }
sl@0
  1045
sl@0
  1046
  //2 members expressions:
sl@0
  1047
  CPPUNIT_CHECK( (L' ' + one) == L" one" );
sl@0
  1048
  CPPUNIT_CHECK( (one + L' ') == L"one " );
sl@0
  1049
  CPPUNIT_CHECK( (one + L" two") == L"one two" );
sl@0
  1050
  CPPUNIT_CHECK( (L"one " + two) == L"one two" );
sl@0
  1051
  CPPUNIT_CHECK( (one + space) == L"one " );
sl@0
  1052
sl@0
  1053
  //3 members expressions:
sl@0
  1054
  CPPUNIT_CHECK( ((one + space) + L"two") == L"one two" );
sl@0
  1055
  CPPUNIT_CHECK( (L"one" + (space + two)) == L"one two" );
sl@0
  1056
  CPPUNIT_CHECK( ((one + space) + two) == L"one two" );
sl@0
  1057
  CPPUNIT_CHECK( (one + (space + two)) == L"one two" );
sl@0
  1058
  CPPUNIT_CHECK( ((one + space) + L't') == L"one t" );
sl@0
  1059
  CPPUNIT_CHECK( (L'o' + (space + two)) == L"o two" );
sl@0
  1060
sl@0
  1061
  //4 members expressions:
sl@0
  1062
  CPPUNIT_CHECK( ((one + space) + (two + space)) == L"one two " );
sl@0
  1063
sl@0
  1064
  //special operators
sl@0
  1065
  {
sl@0
  1066
    wstring result;
sl@0
  1067
    result = one + space + two;
sl@0
  1068
    CPPUNIT_CHECK( result == L"one two" );
sl@0
  1069
sl@0
  1070
    result += space + three;
sl@0
  1071
    CPPUNIT_CHECK( result == L"one two three" );
sl@0
  1072
  }
sl@0
  1073
sl@0
  1074
  //special append method
sl@0
  1075
  {
sl@0
  1076
    wstring result;
sl@0
  1077
    //Use reserve to avoid reallocation and really test auto-referencing problems:
sl@0
  1078
    result.reserve(64);
sl@0
  1079
sl@0
  1080
    result.append(one + space + two);
sl@0
  1081
    CPPUNIT_CHECK( result == L"one two" );
sl@0
  1082
sl@0
  1083
    result.append(space + result + space + three);
sl@0
  1084
    CPPUNIT_CHECK( result == L"one two one two three" );
sl@0
  1085
sl@0
  1086
    result = L"one two";
sl@0
  1087
    result.append(space + three, 1, 2);
sl@0
  1088
    CPPUNIT_ASSERT( result == L"one twoth" );
sl@0
  1089
sl@0
  1090
    result.append(space + result);
sl@0
  1091
    CPPUNIT_CHECK( result == L"one twoth one twoth" );
sl@0
  1092
  }
sl@0
  1093
sl@0
  1094
  //special assign method
sl@0
  1095
  {
sl@0
  1096
    wstring result;
sl@0
  1097
    //Use reserve to avoid reallocation and really test auto-referencing problems:
sl@0
  1098
    result.reserve(64);
sl@0
  1099
sl@0
  1100
    result.assign(one + space + two + space + three);
sl@0
  1101
    CPPUNIT_CHECK( result == L"one two three" );
sl@0
  1102
sl@0
  1103
    result.assign(one + space + two + space + three, 3, 5);
sl@0
  1104
    CPPUNIT_CHECK( result == L" two " );
sl@0
  1105
sl@0
  1106
    result.assign(one + result + three);
sl@0
  1107
    CPPUNIT_CHECK( result == L"one two three" );
sl@0
  1108
  }
sl@0
  1109
sl@0
  1110
  {
sl@0
  1111
    CPPUNIT_CHECK( !(one + L' ' + two).empty() );
sl@0
  1112
sl@0
  1113
    wchar_t result = (one + L' ' + two)[3];
sl@0
  1114
    CPPUNIT_CHECK( result == L' ' );
sl@0
  1115
sl@0
  1116
    result = (one + L' ' + two).at(3);
sl@0
  1117
    CPPUNIT_CHECK( result == L' ' );
sl@0
  1118
sl@0
  1119
#    if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
  1120
    try {
sl@0
  1121
      result = (one + L' ' + two).at(10);
sl@0
  1122
      CPPUNIT_ASSERT(false);
sl@0
  1123
    }
sl@0
  1124
    catch (out_of_range const&) {
sl@0
  1125
      CPPUNIT_ASSERT( result == L' ' );
sl@0
  1126
    }
sl@0
  1127
    catch (...) {
sl@0
  1128
      CPPUNIT_ASSERT(false);
sl@0
  1129
    }
sl@0
  1130
#    endif
sl@0
  1131
  }
sl@0
  1132
#  endif
sl@0
  1133
#endif
sl@0
  1134
}
sl@0
  1135
sl@0
  1136
void StringTest::io()
sl@0
  1137
{
sl@0
  1138
#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
sl@0
  1139
  string str("STLport");
sl@0
  1140
  {
sl@0
  1141
    ostringstream ostr;
sl@0
  1142
    ostr << str;
sl@0
  1143
    CPPUNIT_ASSERT( ostr.good() );
sl@0
  1144
    CPPUNIT_ASSERT( ostr.str() == str );
sl@0
  1145
  }
sl@0
  1146
  {
sl@0
  1147
    istringstream istr(str);
sl@0
  1148
    string istr_content;
sl@0
  1149
    istr >> istr_content;
sl@0
  1150
    CPPUNIT_ASSERT( !istr.fail() && istr.eof() );
sl@0
  1151
    CPPUNIT_ASSERT( istr_content == str );
sl@0
  1152
  }
sl@0
  1153
  {
sl@0
  1154
    istringstream istr(str);
sl@0
  1155
    istr.width(3);
sl@0
  1156
    string istr_content;
sl@0
  1157
    istr >> istr_content;
sl@0
  1158
    CPPUNIT_ASSERT( !istr.fail() && !istr.eof() );
sl@0
  1159
    CPPUNIT_ASSERT( istr_content == "STL" );
sl@0
  1160
  }
sl@0
  1161
#endif
sl@0
  1162
}
sl@0
  1163
sl@0
  1164
void StringTest::allocator_with_state()
sl@0
  1165
{
sl@0
  1166
#if !(defined (STLPORT) && defined (_STLP_NO_CUSTOM_IO)) 
sl@0
  1167
sl@0
  1168
  char buf1[1024];
sl@0
  1169
  StackAllocator<char> stack1(buf1, buf1 + sizeof(buf1));
sl@0
  1170
sl@0
  1171
  char buf2[1024];
sl@0
  1172
  StackAllocator<char> stack2(buf2, buf2 + sizeof(buf2));
sl@0
  1173
sl@0
  1174
  typedef basic_string<char, char_traits<char>, StackAllocator<char> > StackString;
sl@0
  1175
  {
sl@0
  1176
    StackString str1("string stack1", stack1);
sl@0
  1177
    StackString str1Cpy(str1);
sl@0
  1178
sl@0
  1179
    StackString str2("string stack2", stack2);
sl@0
  1180
    StackString str2Cpy(str2);
sl@0
  1181
sl@0
  1182
    str1.swap(str2);
sl@0
  1183
sl@0
  1184
    CPPUNIT_ASSERT( str1.get_allocator().swaped() );
sl@0
  1185
    CPPUNIT_ASSERT( str2.get_allocator().swaped() );
sl@0
  1186
sl@0
  1187
    CPPUNIT_ASSERT( str1 == str2Cpy );
sl@0
  1188
    CPPUNIT_ASSERT( str2 == str1Cpy );
sl@0
  1189
    CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
sl@0
  1190
    CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
sl@0
  1191
  }
sl@0
  1192
  CPPUNIT_ASSERT( stack1.ok() );
sl@0
  1193
  CPPUNIT_ASSERT( stack2.ok() );
sl@0
  1194
  stack1.reset(); stack2.reset();
sl@0
  1195
sl@0
  1196
  {
sl@0
  1197
    StackString str1("longer string from stack1 allocator instance for dynamic allocation", stack1);
sl@0
  1198
    StackString str1Cpy(str1);
sl@0
  1199
sl@0
  1200
    StackString str2("longer string from stack2 allocator instance for dynamic allocation", stack2);
sl@0
  1201
    StackString str2Cpy(str2);
sl@0
  1202
sl@0
  1203
    str1.swap(str2);
sl@0
  1204
sl@0
  1205
    CPPUNIT_ASSERT( str1.get_allocator().swaped() );
sl@0
  1206
    CPPUNIT_ASSERT( str2.get_allocator().swaped() );
sl@0
  1207
sl@0
  1208
    CPPUNIT_ASSERT( str1 == str2Cpy );
sl@0
  1209
    CPPUNIT_ASSERT( str2 == str1Cpy );
sl@0
  1210
    CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
sl@0
  1211
    CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
sl@0
  1212
  }
sl@0
  1213
  CPPUNIT_ASSERT( stack1.ok() );
sl@0
  1214
  CPPUNIT_ASSERT( stack2.ok() );
sl@0
  1215
  stack1.reset(); stack2.reset();
sl@0
  1216
sl@0
  1217
sl@0
  1218
  {
sl@0
  1219
    StackString str1("string stack1", stack1);
sl@0
  1220
    StackString str1Cpy(str1);
sl@0
  1221
sl@0
  1222
    StackString str2("longer string from stack2 allocator instance for dynamic allocation", stack2);
sl@0
  1223
    StackString str2Cpy(str2);
sl@0
  1224
sl@0
  1225
    str1.swap(str2);
sl@0
  1226
sl@0
  1227
    CPPUNIT_ASSERT( str1.get_allocator().swaped() );
sl@0
  1228
    CPPUNIT_ASSERT( str2.get_allocator().swaped() );
sl@0
  1229
sl@0
  1230
    CPPUNIT_ASSERT( str1 == str2Cpy );
sl@0
  1231
    CPPUNIT_ASSERT( str2 == str1Cpy );
sl@0
  1232
    CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
sl@0
  1233
    CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
sl@0
  1234
  }
sl@0
  1235
  CPPUNIT_ASSERT( stack1.ok() );
sl@0
  1236
  CPPUNIT_ASSERT( stack2.ok() );
sl@0
  1237
  stack1.reset(); stack2.reset();
sl@0
  1238
sl@0
  1239
sl@0
  1240
  {
sl@0
  1241
    StackString str1("longer string from stack1 allocator instance for dynamic allocation", stack1);
sl@0
  1242
    StackString str1Cpy(str1);
sl@0
  1243
sl@0
  1244
    StackString str2("string stack2", stack2);
sl@0
  1245
    StackString str2Cpy(str2);
sl@0
  1246
sl@0
  1247
    str1.swap(str2);
sl@0
  1248
sl@0
  1249
    CPPUNIT_ASSERT( str1.get_allocator().swaped() );
sl@0
  1250
    CPPUNIT_ASSERT( str2.get_allocator().swaped() );
sl@0
  1251
sl@0
  1252
    CPPUNIT_ASSERT( str1 == str2Cpy );
sl@0
  1253
    CPPUNIT_ASSERT( str2 == str1Cpy );
sl@0
  1254
    CPPUNIT_ASSERT( str1.get_allocator() == stack2 );
sl@0
  1255
    CPPUNIT_ASSERT( str2.get_allocator() == stack1 );
sl@0
  1256
  }
sl@0
  1257
  CPPUNIT_ASSERT( stack1.ok() );
sl@0
  1258
  CPPUNIT_ASSERT( stack2.ok() );
sl@0
  1259
  stack1.reset(); stack2.reset();
sl@0
  1260
#endif
sl@0
  1261
}
sl@0
  1262
sl@0
  1263
void StringTest::capacity()
sl@0
  1264
{
sl@0
  1265
  string s;
sl@0
  1266
sl@0
  1267
  CPPUNIT_CHECK( s.capacity() > 0 );
sl@0
  1268
  CPPUNIT_CHECK( s.capacity() < s.max_size() );
sl@0
  1269
  CPPUNIT_CHECK( s.capacity() >= s.size() );
sl@0
  1270
sl@0
  1271
#ifndef _STLP_SHORT_STRING_SZ
sl@0
  1272
#  define _STLP_SHORT_STRING_SZ 16 // see stlport/stl/_string_base.h
sl@0
  1273
#endif
sl@0
  1274
sl@0
  1275
  for ( int i = 0; i < _STLP_SHORT_STRING_SZ + 2; ++i ) {
sl@0
  1276
    s += ' ';
sl@0
  1277
    CPPUNIT_CHECK( s.capacity() > 0 );
sl@0
  1278
    CPPUNIT_CHECK( s.capacity() < s.max_size() );
sl@0
  1279
    CPPUNIT_CHECK( s.capacity() >= s.size() );
sl@0
  1280
  }
sl@0
  1281
}
sl@0
  1282
void StringTest::str_cov1()
sl@0
  1283
	{
sl@0
  1284
		{
sl@0
  1285
		string example( "this is an example string" );
sl@0
  1286
		string::iterator it = example.begin();   
sl@0
  1287
		example.replace(it+4,example.end()-4,4,'o'); 
sl@0
  1288
		CPPUNIT_CHECK(example == "thisooooring"  );
sl@0
  1289
		}
sl@0
  1290
		{
sl@0
  1291
		string str4 ( "This perfectly unclear." );
sl@0
  1292
		basic_string <char>::size_type indexCh4a;
sl@0
  1293
		string str4a ( "clear" );
sl@0
  1294
		indexCh4a = str4.rfind ( str4a , 15 );
sl@0
  1295
		CPPUNIT_CHECK(indexCh4a == -1  );
sl@0
  1296
		}
sl@0
  1297
		{
sl@0
  1298
		string str1f ( "Hello " ), str2f ( "Wide World " );
sl@0
  1299
		swap(str1f,str2f);
sl@0
  1300
		CPPUNIT_CHECK(str1f == "Wide World ");	
sl@0
  1301
		CPPUNIT_CHECK(str2f == "Hello ");	
sl@0
  1302
		}
sl@0
  1303
sl@0
  1304
	}
sl@0
  1305
void StringTest::str_cov2()
sl@0
  1306
	{
sl@0
  1307
		{
sl@0
  1308
		string result1a, result1b;
sl@0
  1309
		string s1o ( "AAAAAAAA" );
sl@0
  1310
		string s1p ( "BBB" );
sl@0
  1311
		const char* cs1p = "CCC";
sl@0
  1312
		result1a = s1o.replace ( 1 , 3 , s1p );
sl@0
  1313
		CPPUNIT_CHECK(result1a == "ABBBAAAA");
sl@0
  1314
		result1b = s1o.replace ( 5 , 3 , cs1p );
sl@0
  1315
		CPPUNIT_CHECK(result1b == "ABBBACCC");
sl@0
  1316
		string result2a, result2b;
sl@0
  1317
		string s2o ( "AAAAAAAA" );
sl@0
  1318
		string s2p ( "BBB" );
sl@0
  1319
		result2a = s2o.replace ( 1 , 3 , s2p , 1 , 2 );
sl@0
  1320
		CPPUNIT_CHECK(result2a == "ABBAAAA");
sl@0
  1321
		string result3a;
sl@0
  1322
		string s3o ( "AAAAAAAA" );
sl@0
  1323
		char ch3p = 'C';
sl@0
  1324
		result3a = s3o.replace ( 1 , 3 , 4 , ch3p );
sl@0
  1325
		CPPUNIT_CHECK(result3a == "ACCCCAAAA");
sl@0
  1326
		string s4o ( "AAAAAAAA" );
sl@0
  1327
		string s4p ( "BBB" );
sl@0
  1328
		const char* cs4p = "CCC";
sl@0
  1329
		basic_string<char>::iterator IterF0, IterL0;
sl@0
  1330
		IterF0 = s4o.begin ( );
sl@0
  1331
		IterL0 = s4o.begin ( ) + 3;
sl@0
  1332
		string result4a, result4b;
sl@0
  1333
		result4a = s4o.replace ( IterF0 , IterL0 , s4p );
sl@0
  1334
		CPPUNIT_CHECK(result4a == "BBBAAAAA");
sl@0
  1335
		result4b = s4o.replace ( IterF0 , IterL0 , cs4p );
sl@0
  1336
		CPPUNIT_CHECK(result4b == "CCCAAAAA");
sl@0
  1337
		string s5o ( "AAAAAAAF" );
sl@0
  1338
		const char* cs5p = "CCCBB";
sl@0
  1339
		basic_string<char>::iterator IterF1, IterL1;
sl@0
  1340
		IterF1 = s5o.begin ( );
sl@0
  1341
		IterL1 = s5o.begin ( ) + 4;
sl@0
  1342
		string result5a;
sl@0
  1343
		result5a = s5o.replace ( IterF1 , IterL1 , cs5p , 4 );
sl@0
  1344
		CPPUNIT_CHECK(result5a == "CCCBAAAF");
sl@0
  1345
		string s6o ( "AAAAAAAG" );
sl@0
  1346
		char ch6p = 'q';
sl@0
  1347
		basic_string<char>::iterator IterF2, IterL2;
sl@0
  1348
		IterF2 = s6o.begin ( );
sl@0
  1349
		IterL2 = s6o.begin ( ) + 3;
sl@0
  1350
		string result6a;
sl@0
  1351
		result6a = s6o.replace ( IterF2 , IterL2 , 4 , ch6p );
sl@0
  1352
		CPPUNIT_CHECK(result6a == "qqqqAAAAG");
sl@0
  1353
		}
sl@0
  1354
	}
sl@0
  1355
void StringTest::str_cov3()
sl@0
  1356
	{
sl@0
  1357
		{
sl@0
  1358
		string str1 ("This is the sample test string"), str2;
sl@0
  1359
		basic_string <char>::reverse_iterator str_rIter, str1_rIter, str2_rIter;
sl@0
  1360
		basic_string <char>::const_reverse_iterator str1_rcIter;
sl@0
  1361
		str1_rIter = str1.rend ( );
sl@0
  1362
		str1_rIter--;
sl@0
  1363
		CPPUNIT_CHECK(*str1_rIter == 'T');
sl@0
  1364
		str_rIter = str1.rbegin( ); 
sl@0
  1365
		CPPUNIT_CHECK(*str_rIter == 'g');
sl@0
  1366
		str1_rcIter = str1.rbegin( );
sl@0
  1367
		CPPUNIT_CHECK(*str1_rcIter == 'g');
sl@0
  1368
		str1_rcIter = str1.rend ( );
sl@0
  1369
		str1_rcIter--;
sl@0
  1370
		CPPUNIT_CHECK(*str1_rcIter == 'T');
sl@0
  1371
		}
sl@0
  1372
		{
sl@0
  1373
		string str1a ( "Hello " );
sl@0
  1374
		str1a = "0";
sl@0
  1375
		CPPUNIT_CHECK(str1a == "0");
sl@0
  1376
		}
sl@0
  1377
		{
sl@0
  1378
		string str1 ("Hello world");
sl@0
  1379
		CPPUNIT_CHECK(str1.length ( ) == 11);
sl@0
  1380
		}
sl@0
  1381
		{
sl@0
  1382
		int comp5a;
sl@0
  1383
		string s5o ( "AACAB" );
sl@0
  1384
		const char* cs5p = "CAB";
sl@0
  1385
		comp5a = s5o.compare (  2 , 3 , cs5p );
sl@0
  1386
		CPPUNIT_CHECK(comp5a == 0);		
sl@0
  1387
		}
sl@0
  1388
sl@0
  1389
	}
sl@0
  1390
void StringTest::str_cov4()
sl@0
  1391
	{
sl@0
  1392
		{
sl@0
  1393
		string str4 ( "12-ab-12-ab" );
sl@0
  1394
		basic_string <char>::size_type indexCh4a;
sl@0
  1395
		string str4a ( "ba3" );
sl@0
  1396
		indexCh4a = str4.find_last_of  ( str4a , 8 );
sl@0
  1397
		CPPUNIT_CHECK(indexCh4a == 4);
sl@0
  1398
		}
sl@0
  1399
		{
sl@0
  1400
		string str4 ( "12-ab-12-ab" );
sl@0
  1401
		basic_string <char>::size_type indexCh4a;
sl@0
  1402
		string str4a ( "b-a" );
sl@0
  1403
		indexCh4a = str4.find_last_not_of  ( str4a , 5 );
sl@0
  1404
		CPPUNIT_CHECK(indexCh4a == 1);
sl@0
  1405
		}
sl@0
  1406
		{
sl@0
  1407
		string str1 ( "abcd-1234-abcd-1234" );
sl@0
  1408
		basic_string <char>::size_type indexCh1a;
sl@0
  1409
sl@0
  1410
		indexCh1a = str1.find_first_of ( "d" , 5 );
sl@0
  1411
		CPPUNIT_CHECK(indexCh1a == 13);
sl@0
  1412
		string str2 ( "12-ab-12-ab" );
sl@0
  1413
		basic_string <char>::size_type indexCh2a;
sl@0
  1414
sl@0
  1415
		string str2a ( "ba3" );
sl@0
  1416
		indexCh2a = str2.find_first_of ( str2a , 5 );
sl@0
  1417
		CPPUNIT_CHECK( indexCh2a == 9 );
sl@0
  1418
		}
sl@0
  1419
		{
sl@0
  1420
		string str4 ( "12-ab-12-ab" );
sl@0
  1421
 	    basic_string <char>::size_type indexCh4a;
sl@0
  1422
sl@0
  1423
		string str4a ( "ba3" );
sl@0
  1424
		indexCh4a = str4.find_first_not_of ( str4a , 5 );
sl@0
  1425
		CPPUNIT_CHECK(indexCh4a == 5 );
sl@0
  1426
		}
sl@0
  1427
	}
sl@0
  1428
void StringTest::str_cov5()
sl@0
  1429
	{
sl@0
  1430
		{
sl@0
  1431
		string str4 ( "clearly this perfectly unclear." );
sl@0
  1432
		basic_string <char>::size_type indexCh4a;
sl@0
  1433
sl@0
  1434
		string str4a ( "clear" );
sl@0
  1435
		indexCh4a = str4.find ( str4a , 5 );
sl@0
  1436
		CPPUNIT_CHECK( indexCh4a != string::npos );
sl@0
  1437
		}
sl@0
  1438
		{
sl@0
  1439
		const char *cstr1a = "Hello Out There.";
sl@0
  1440
		basic_string <char> str1a ( cstr1a , 5);
sl@0
  1441
		CPPUNIT_CHECK( str1a == "Hello" );	
sl@0
  1442
		}
sl@0
  1443
		{
sl@0
  1444
		string str1a,str1b;
sl@0
  1445
		const char *cstr1a = "Out There";
sl@0
  1446
		str1a.assign ( cstr1a );
sl@0
  1447
		CPPUNIT_CHECK(str1a == "Out There");	
sl@0
  1448
		
sl@0
  1449
		str1b.assign ( cstr1a , 3 );
sl@0
  1450
		CPPUNIT_CHECK(str1b == "Out");	
sl@0
  1451
		
sl@0
  1452
		string str1f ( "Hello " ), str2f ( "Wide World " );
sl@0
  1453
		str1f.assign ( str2f.begin ( ) + 5 , str2f.end ( ) - 1 );
sl@0
  1454
		CPPUNIT_CHECK(str1f == "World");	
sl@0
  1455
		}
sl@0
  1456
		{
sl@0
  1457
		string str1f ( "Hello " ), str2f ( "Wide World " );
sl@0
  1458
		str1f.append ( str2f.begin ( ) + 5 , str2f.end ( ) - 1 );
sl@0
  1459
		CPPUNIT_CHECK(str1f == "Hello World");	
sl@0
  1460
		
sl@0
  1461
		string str1b ( "Hello " );
sl@0
  1462
		const char *cstr1b = "Out There ";
sl@0
  1463
		str1b.append ( cstr1b , 3 );
sl@0
  1464
		CPPUNIT_CHECK(str1b == "Hello Out");	
sl@0
  1465
		}
sl@0
  1466
	}
sl@0
  1467
void StringTest::str_cov6()
sl@0
  1468
	{
sl@0
  1469
		{
sl@0
  1470
		string s1 ( "AACAB" );
sl@0
  1471
		string s2 ( "BACAB" );
sl@0
  1472
		const char* s3 = "CAB";
sl@0
  1473
		
sl@0
  1474
		bool flag;
sl@0
  1475
		
sl@0
  1476
		flag = s2 >= s1;
sl@0
  1477
		CPPUNIT_CHECK(flag == true);		
sl@0
  1478
		
sl@0
  1479
		flag = s3 >= s1;
sl@0
  1480
		CPPUNIT_CHECK(flag == true);		
sl@0
  1481
		
sl@0
  1482
		flag = s1 >= s3;
sl@0
  1483
		CPPUNIT_CHECK(flag == false);
sl@0
  1484
		
sl@0
  1485
		flag = s2 > s1;
sl@0
  1486
		CPPUNIT_CHECK(flag == true);		
sl@0
  1487
		
sl@0
  1488
		flag = s3 > s1;
sl@0
  1489
		CPPUNIT_CHECK(flag == true);		
sl@0
  1490
		
sl@0
  1491
		flag = s1 > s3;
sl@0
  1492
		CPPUNIT_CHECK(flag == false);
sl@0
  1493
		
sl@0
  1494
		flag = s2 <= s1;
sl@0
  1495
		CPPUNIT_CHECK(flag == false);		
sl@0
  1496
		
sl@0
  1497
		flag = s3 <= s1;
sl@0
  1498
		CPPUNIT_CHECK(flag == false);		
sl@0
  1499
		
sl@0
  1500
		flag = s1 <= s3;
sl@0
  1501
		CPPUNIT_CHECK(flag == true);
sl@0
  1502
		
sl@0
  1503
		flag = s3 < s1;
sl@0
  1504
		CPPUNIT_CHECK(flag == false);		
sl@0
  1505
		
sl@0
  1506
		flag = s1 < s3;
sl@0
  1507
		CPPUNIT_CHECK(flag == true);
sl@0
  1508
		}
sl@0
  1509
		{
sl@0
  1510
		string str1 ( "xddd-1234-abcd" );
sl@0
  1511
		basic_string <char>::size_type indexCh1a;
sl@0
  1512
sl@0
  1513
		indexCh1a = str1.find_first_not_of ( "d" , 2 );
sl@0
  1514
		CPPUNIT_CHECK(indexCh1a == 4);	
sl@0
  1515
		}
sl@0
  1516
	}
sl@0
  1517