os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/codecvt_test.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
//
sl@0
    15
sl@0
    16
#include <string>
sl@0
    17
#include <sstream>
sl@0
    18
#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
sl@0
    19
#  include <fstream>
sl@0
    20
#  include <locale>
sl@0
    21
sl@0
    22
#  include "cppunit/cppunit_proxy.h"
sl@0
    23
sl@0
    24
#  if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
sl@0
    25
using namespace std;
sl@0
    26
#  endif
sl@0
    27
sl@0
    28
//
sl@0
    29
// TestCase class
sl@0
    30
//
sl@0
    31
class CodecvtTest : public CPPUNIT_NS::TestCase
sl@0
    32
{
sl@0
    33
  CPPUNIT_TEST_SUITE(CodecvtTest);
sl@0
    34
#if defined (STLPORT) && defined (_STLP_NO_MEMBER_TEMPLATES)
sl@0
    35
  CPPUNIT_IGNORE;
sl@0
    36
#endif
sl@0
    37
  CPPUNIT_TEST(variable_encoding);
sl@0
    38
  CPPUNIT_TEST(locale_cov1);
sl@0
    39
  CPPUNIT_TEST(locale_cov2);
sl@0
    40
  CPPUNIT_TEST(locale_cov3);
sl@0
    41
  CPPUNIT_TEST(locale_cov4);
sl@0
    42
  CPPUNIT_TEST(locale_cov5);
sl@0
    43
  CPPUNIT_TEST(locale_cov6);
sl@0
    44
  CPPUNIT_TEST(locale_cov7);
sl@0
    45
  CPPUNIT_TEST_SUITE_END();
sl@0
    46
sl@0
    47
protected:
sl@0
    48
  void variable_encoding();
sl@0
    49
  void locale_cov1();
sl@0
    50
  void locale_cov2();
sl@0
    51
  void locale_cov3();
sl@0
    52
  void locale_cov4();
sl@0
    53
  void locale_cov5();
sl@0
    54
  void locale_cov6();
sl@0
    55
  void locale_cov7();
sl@0
    56
};
sl@0
    57
sl@0
    58
CPPUNIT_TEST_SUITE_REGISTRATION(CodecvtTest);
sl@0
    59
sl@0
    60
#if defined (STLPORT)
sl@0
    61
#  define __NO_THROW _STLP_NOTHROW
sl@0
    62
#else
sl@0
    63
#  define __NO_THROW throw()
sl@0
    64
#endif
sl@0
    65
sl@0
    66
sl@0
    67
/* Codecvt facet eating some characters from the external buffer.
sl@0
    68
 * Transform '01' in 'a'
sl@0
    69
 */
sl@0
    70
struct eater_codecvt : public codecvt<char, char, mbstate_t> {
sl@0
    71
  typedef codecvt<char,char,mbstate_t> base;
sl@0
    72
sl@0
    73
  explicit eater_codecvt(size_t refs = 0) : base(refs) {}
sl@0
    74
sl@0
    75
  // primitive conversion
sl@0
    76
  virtual base::result
sl@0
    77
  do_in(mbstate_t& mb,
sl@0
    78
        const char* ebegin, const char* eend, const char*& ecur,
sl@0
    79
        char* ibegin, char* iend, char*& icur) const __NO_THROW {
sl@0
    80
      char *state = (char*)&mb;
sl@0
    81
      ecur = ebegin;
sl@0
    82
      icur = ibegin;
sl@0
    83
sl@0
    84
      while (ecur != eend) {
sl@0
    85
          if (icur == iend)
sl@0
    86
              return partial;
sl@0
    87
          if (*ecur == '0' || *state == 1) {
sl@0
    88
            if (*state != 1) {
sl@0
    89
              ++ecur;
sl@0
    90
            }
sl@0
    91
            if (ecur == eend) {
sl@0
    92
              *state = 1;
sl@0
    93
              return ok;
sl@0
    94
            }
sl@0
    95
sl@0
    96
            if (*ecur == '1') {
sl@0
    97
              *icur = 'a';
sl@0
    98
            }
sl@0
    99
            else {
sl@0
   100
              *(icur++) = '0';
sl@0
   101
              if (icur == iend) {
sl@0
   102
                if (*state != 1) {
sl@0
   103
                  --ecur;
sl@0
   104
                }
sl@0
   105
                return partial;
sl@0
   106
              }
sl@0
   107
              *icur = *ecur;
sl@0
   108
            }
sl@0
   109
          }
sl@0
   110
          else {
sl@0
   111
            *icur = *ecur;
sl@0
   112
          }
sl@0
   113
sl@0
   114
          *state = 0;
sl@0
   115
          ++icur;
sl@0
   116
          ++ecur;
sl@0
   117
      }
sl@0
   118
sl@0
   119
      return ok;
sl@0
   120
  }
sl@0
   121
sl@0
   122
  // claim it's not a null-conversion
sl@0
   123
  virtual bool do_always_noconv() const __NO_THROW
sl@0
   124
  { return false; }
sl@0
   125
sl@0
   126
  // claim it doesn't have a fixed-length encoding
sl@0
   127
  virtual int do_encoding() const __NO_THROW
sl@0
   128
  { return 0; }
sl@0
   129
sl@0
   130
  // implemented for consistency with do_in overload
sl@0
   131
  virtual int do_length(const mbstate_t &state,
sl@0
   132
                        const char *efrom, const char *eend, size_t m) const {
sl@0
   133
    char *ibegin = new char[m];
sl@0
   134
    const char *ecur = efrom;
sl@0
   135
    char *icur = ibegin;
sl@0
   136
    mbstate_t tmp = state;
sl@0
   137
    do_in(tmp, efrom, eend, ecur, ibegin, ibegin + m, icur);
sl@0
   138
    delete[] ibegin;
sl@0
   139
    return ecur - efrom;
sl@0
   140
  }
sl@0
   141
sl@0
   142
  virtual int do_max_length() const __NO_THROW
sl@0
   143
  { return 2; }
sl@0
   144
};
sl@0
   145
sl@0
   146
/* Codecvt facet generating more characters than the ones read from the
sl@0
   147
 * external buffer, transform '01' in 'abc'
sl@0
   148
 * This kind of facet do not allow systematical positionning in the external
sl@0
   149
 * buffer (tellg -> -1), when you just read a 'a' you are at an undefined
sl@0
   150
 * external buffer position.
sl@0
   151
 */
sl@0
   152
struct generator_codecvt : public codecvt<char, char, mbstate_t> {
sl@0
   153
  typedef codecvt<char,char,mbstate_t> base;
sl@0
   154
sl@0
   155
  explicit generator_codecvt(size_t refs = 0) : base(refs) {}
sl@0
   156
sl@0
   157
  // primitive conversion
sl@0
   158
  virtual base::result
sl@0
   159
  do_in(mbstate_t& mb,
sl@0
   160
        const char* ebegin, const char* eend, const char*& ecur,
sl@0
   161
        char* ibegin, char* iend, char*& icur) const __NO_THROW {
sl@0
   162
      //Access the mbstate information in a portable way:
sl@0
   163
      char *state = (char*)&mb;
sl@0
   164
      ecur = ebegin;
sl@0
   165
      icur = ibegin;
sl@0
   166
sl@0
   167
      if (icur == iend) return ok;
sl@0
   168
sl@0
   169
      if (*state == 2) {
sl@0
   170
        *(icur++) = 'b';
sl@0
   171
        if (icur == iend) {
sl@0
   172
          *state = 3;
sl@0
   173
          return ok;
sl@0
   174
        }
sl@0
   175
        *(icur++) = 'c';
sl@0
   176
        *state = 0;
sl@0
   177
      }
sl@0
   178
      else if (*state == 3) {
sl@0
   179
        *(icur++) = 'c';
sl@0
   180
        *state = 0;
sl@0
   181
      }
sl@0
   182
sl@0
   183
      while (ecur != eend) {
sl@0
   184
          if (icur == iend)
sl@0
   185
              return ok;
sl@0
   186
          if (*ecur == '0' || *state == 1) {
sl@0
   187
            if (*state != 1) {
sl@0
   188
              ++ecur;
sl@0
   189
            }
sl@0
   190
            if (ecur == eend) {
sl@0
   191
              *state = 1;
sl@0
   192
              return partial;
sl@0
   193
            }
sl@0
   194
sl@0
   195
            if (*ecur == '1') {
sl@0
   196
              *(icur++) = 'a';
sl@0
   197
              if (icur == iend) {
sl@0
   198
                *state = 2;
sl@0
   199
                return ok;
sl@0
   200
              }
sl@0
   201
              *(icur++) = 'b';
sl@0
   202
              if (icur == iend) {
sl@0
   203
                *state = 3;
sl@0
   204
                return ok;
sl@0
   205
              }
sl@0
   206
              *icur = 'c';
sl@0
   207
            }
sl@0
   208
            else {
sl@0
   209
              *(icur++) = '0';
sl@0
   210
              if (icur == iend) {
sl@0
   211
                if (*state != 1) {
sl@0
   212
                  --ecur;
sl@0
   213
                }
sl@0
   214
                return ok;
sl@0
   215
              }
sl@0
   216
              *icur = *ecur;
sl@0
   217
            }
sl@0
   218
          }
sl@0
   219
          else {
sl@0
   220
            *icur = *ecur;
sl@0
   221
          }
sl@0
   222
sl@0
   223
          *state = 0;
sl@0
   224
          ++icur;
sl@0
   225
          ++ecur;
sl@0
   226
      }
sl@0
   227
sl@0
   228
      return ok;
sl@0
   229
  }
sl@0
   230
sl@0
   231
  // claim it's not a null-conversion
sl@0
   232
  virtual bool do_always_noconv() const __NO_THROW
sl@0
   233
  { return false; }
sl@0
   234
sl@0
   235
  // claim it doesn't have a fixed-length encoding
sl@0
   236
  virtual int do_encoding() const __NO_THROW
sl@0
   237
  { return 0; }
sl@0
   238
sl@0
   239
  // implemented for consistency with do_in overload
sl@0
   240
  virtual int do_length(const mbstate_t &mb,
sl@0
   241
                        const char *efrom, const char *eend, size_t m) const {
sl@0
   242
    const char *state = (const char*)&mb;
sl@0
   243
    int offset = 0;
sl@0
   244
    if (*state == 2)
sl@0
   245
      offset = 2;
sl@0
   246
    else if (*state == 3)
sl@0
   247
      offset = 1;
sl@0
   248
sl@0
   249
    char *ibegin = new char[m + offset];
sl@0
   250
    const char *ecur = efrom;
sl@0
   251
    char *icur = ibegin;
sl@0
   252
    mbstate_t tmpState = mb;
sl@0
   253
    do_in(tmpState, efrom, eend, ecur, ibegin, ibegin + m + offset, icur);
sl@0
   254
    /*
sl@0
   255
    char *state = (char*)&tmpState;
sl@0
   256
    if (*state != 0) {
sl@0
   257
      if (*state == 1)
sl@0
   258
        --ecur;
sl@0
   259
      else if (*state == 2 || *state == 3) {
sl@0
   260
        //Undefined position, we return -1:
sl@0
   261
        ecur = efrom - 1;
sl@0
   262
      }
sl@0
   263
    }
sl@0
   264
    else {
sl@0
   265
      if (*((char*)&mb) != 0) {
sl@0
   266
        //We take into account the character that hasn't been counted yet in
sl@0
   267
        //the previous decoding step:
sl@0
   268
        ecur++;
sl@0
   269
      }
sl@0
   270
    }
sl@0
   271
    */
sl@0
   272
    delete[] ibegin;
sl@0
   273
    return (int)min((size_t)(ecur - efrom), m);
sl@0
   274
  }
sl@0
   275
sl@0
   276
  virtual int do_max_length() const __NO_THROW
sl@0
   277
  { return 0; }
sl@0
   278
};
sl@0
   279
sl@0
   280
//
sl@0
   281
// tests implementation
sl@0
   282
//
sl@0
   283
void CodecvtTest::variable_encoding()
sl@0
   284
{
sl@0
   285
#if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)
sl@0
   286
  //We first generate the file used for test:
sl@0
   287
  const char* fileName = "c:\\test_file.txt";
sl@0
   288
  {
sl@0
   289
    ofstream ostr(fileName);
sl@0
   290
    //Maybe we simply do not have write access to repository
sl@0
   291
    CPPUNIT_ASSERT( ostr.good() );
sl@0
   292
    for (int i = 0; i < 2048; ++i) {
sl@0
   293
      ostr << "0123456789";
sl@0
   294
    }
sl@0
   295
    CPPUNIT_ASSERT( ostr.good() );
sl@0
   296
  }
sl@0
   297
sl@0
   298
  {
sl@0
   299
    ifstream istr(fileName);
sl@0
   300
    CPPUNIT_ASSERT( istr.good() );
sl@0
   301
    CPPUNIT_ASSERT( !istr.eof() );
sl@0
   302
sl@0
   303
    eater_codecvt codec(1);
sl@0
   304
    locale loc(locale::classic(), &codec);
sl@0
   305
sl@0
   306
    istr.imbue(loc);
sl@0
   307
    CPPUNIT_ASSERT( istr.good() );
sl@0
   308
    CPPUNIT_ASSERT( (int)istr.tellg() == 0 );
sl@0
   309
sl@0
   310
    int theoricalPos = 0;
sl@0
   311
    do {
sl@0
   312
      signed char c = (signed char)istr.get();
sl@0
   313
      if (c == char_traits<char>::eof()) {
sl@0
   314
        break;
sl@0
   315
      }
sl@0
   316
      ++theoricalPos;
sl@0
   317
      if (c == 'a') {
sl@0
   318
        ++theoricalPos;
sl@0
   319
      }
sl@0
   320
     CPPUNIT_ASSERT( (int)istr.tellg() == theoricalPos );
sl@0
   321
    }
sl@0
   322
    while (!istr.eof());
sl@0
   323
sl@0
   324
    CPPUNIT_ASSERT( istr.eof() );
sl@0
   325
  }
sl@0
   326
sl@0
   327
#  if 0
sl@0
   328
  /* This test is broken, not sure if it is really possible to get a position in
sl@0
   329
   * a locale having a codecvt such as generator_codecvt. Maybe generator_codecvt
sl@0
   330
   * is not a valid theorical example of codecvt implementation. */
sl@0
   331
  {
sl@0
   332
    ifstream istr(fileName);
sl@0
   333
    CPPUNIT_ASSERT( istr.good() );
sl@0
   334
    CPPUNIT_ASSERT( !istr.eof() );
sl@0
   335
sl@0
   336
    generator_codecvt codec(1);
sl@0
   337
    locale loc(locale::classic(), &codec);
sl@0
   338
sl@0
   339
    istr.imbue(loc);
sl@0
   340
    CPPUNIT_ASSERT( istr.good() );
sl@0
   341
    CPPUNIT_ASSERT( (int)istr.tellg() == 0 );
sl@0
   342
sl@0
   343
    int theoricalPos = 0;
sl@0
   344
    int theoricalTellg;
sl@0
   345
    do {
sl@0
   346
      char c = istr.get();
sl@0
   347
      if (c == char_traits<char>::eof()) {
sl@0
   348
        break;
sl@0
   349
      }
sl@0
   350
      switch (c) {
sl@0
   351
        case 'a':
sl@0
   352
        case 'b':
sl@0
   353
          theoricalTellg = -1;
sl@0
   354
          break;
sl@0
   355
        case 'c':
sl@0
   356
          ++theoricalPos;
sl@0
   357
        default:
sl@0
   358
          ++theoricalPos;
sl@0
   359
          theoricalTellg = theoricalPos;
sl@0
   360
          break;
sl@0
   361
      }
sl@0
   362
sl@0
   363
      if ((int)istr.tellg() != theoricalTellg) {
sl@0
   364
        CPPUNIT_ASSERT( (int)istr.tellg() == theoricalTellg );
sl@0
   365
      }
sl@0
   366
    }
sl@0
   367
    while (!istr.eof());
sl@0
   368
sl@0
   369
    CPPUNIT_ASSERT( istr.eof() );
sl@0
   370
  }
sl@0
   371
#  endif
sl@0
   372
#endif
sl@0
   373
}
sl@0
   374
sl@0
   375
void CodecvtTest::locale_cov1()
sl@0
   376
	{
sl@0
   377
	locale loc ( "fr_FR.ISO-8859-1" );
sl@0
   378
	locale loc1 ( "en_US.ISO-8859-1" );
sl@0
   379
	bool result1,result2;
sl@0
   380
		{
sl@0
   381
	    result1 = isalnum ( 'L', loc);
sl@0
   382
		result2 = isalnum ( '@', loc);
sl@0
   383
		CPPUNIT_ASSERT( result1 == true );
sl@0
   384
		CPPUNIT_ASSERT( result2 == false);
sl@0
   385
		
sl@0
   386
		result1 = isalnum ( 'L', loc1);
sl@0
   387
		result2 = isalnum ( '@', loc1);
sl@0
   388
		CPPUNIT_ASSERT( result1 == true );
sl@0
   389
		CPPUNIT_ASSERT( result2 == false);
sl@0
   390
		}
sl@0
   391
		{
sl@0
   392
	    result1 = isalpha ( 'L', loc);
sl@0
   393
		result2 = isalpha ( '@', loc);
sl@0
   394
		CPPUNIT_ASSERT( result1 == true );
sl@0
   395
		CPPUNIT_ASSERT( result2 == false);
sl@0
   396
		
sl@0
   397
		result1 = isalpha ( 'L', loc1);
sl@0
   398
		result2 = isalpha ( '@', loc1);
sl@0
   399
		CPPUNIT_ASSERT( result1 == true );
sl@0
   400
		CPPUNIT_ASSERT( result2 == false);
sl@0
   401
		}
sl@0
   402
		{
sl@0
   403
	    result1 = iscntrl ( 'L', loc);
sl@0
   404
		result2 = iscntrl ( '\n', loc);
sl@0
   405
		CPPUNIT_ASSERT( result1 == false);
sl@0
   406
		CPPUNIT_ASSERT( result2 == true );
sl@0
   407
		
sl@0
   408
		result1 = iscntrl ( 'L', loc1);
sl@0
   409
		result2 = iscntrl ( '\n', loc1);
sl@0
   410
		CPPUNIT_ASSERT( result1 == false);
sl@0
   411
		CPPUNIT_ASSERT( result2 == true );
sl@0
   412
		}
sl@0
   413
		{
sl@0
   414
	    result1 = isdigit ( 'L', loc);
sl@0
   415
		result2 = isdigit ( '3', loc);
sl@0
   416
		CPPUNIT_ASSERT( result1 == false);
sl@0
   417
		CPPUNIT_ASSERT( result2 == true );
sl@0
   418
		
sl@0
   419
	    result1 = isdigit ( 'L', loc1);
sl@0
   420
		result2 = isdigit ( '3', loc1);
sl@0
   421
		CPPUNIT_ASSERT( result1 == false);
sl@0
   422
		CPPUNIT_ASSERT( result2 == true );
sl@0
   423
		}
sl@0
   424
	}
sl@0
   425
void CodecvtTest::locale_cov2()
sl@0
   426
	{
sl@0
   427
	locale loc ( "fr_FR.ISO-8859-1" );
sl@0
   428
	locale loc1 ( "en_US.ISO-8859-1" );
sl@0
   429
	bool result1,result2;
sl@0
   430
		{
sl@0
   431
	    result1 = isgraph ( ' ', loc);
sl@0
   432
		result2 = isgraph ( '.', loc);
sl@0
   433
		CPPUNIT_ASSERT( result1 == false);
sl@0
   434
		CPPUNIT_ASSERT( result2 == true );
sl@0
   435
		
sl@0
   436
		result1 = isgraph ( ' ', loc1);
sl@0
   437
		result2 = isgraph ( '.', loc1);
sl@0
   438
		CPPUNIT_ASSERT( result1 == false);
sl@0
   439
		CPPUNIT_ASSERT( result2 == true );
sl@0
   440
		}
sl@0
   441
		{
sl@0
   442
	    result1 = islower ( 'L', loc);
sl@0
   443
		result2 = islower ( 'v', loc);
sl@0
   444
		CPPUNIT_ASSERT( result1 == false);
sl@0
   445
		CPPUNIT_ASSERT( result2 == true );
sl@0
   446
		
sl@0
   447
		result1 = islower ( 'L', loc1);
sl@0
   448
		result2 = islower ( 'v', loc1);
sl@0
   449
		CPPUNIT_ASSERT( result1 == false);
sl@0
   450
		CPPUNIT_ASSERT( result2 == true );
sl@0
   451
		}
sl@0
   452
		{
sl@0
   453
	    result1 = isprint ( '\n', loc);
sl@0
   454
		result2 = isprint ( 't', loc);
sl@0
   455
		CPPUNIT_ASSERT( result1 == false);
sl@0
   456
		CPPUNIT_ASSERT( result2 == true );
sl@0
   457
		
sl@0
   458
		result1 = isprint ( '\n', loc1);
sl@0
   459
		result2 = isprint ( 't', loc1);
sl@0
   460
		CPPUNIT_ASSERT( result1 == false);
sl@0
   461
		CPPUNIT_ASSERT( result2 == true );
sl@0
   462
		}
sl@0
   463
		{
sl@0
   464
	    result1 = ispunct ( 'L', loc);
sl@0
   465
		result2 = ispunct ( ';', loc);
sl@0
   466
		CPPUNIT_ASSERT( result1 == false);
sl@0
   467
		CPPUNIT_ASSERT( result2 == true );
sl@0
   468
		
sl@0
   469
		result1 = ispunct ( 'L', loc1);
sl@0
   470
		result2 = ispunct ( ';', loc1);
sl@0
   471
		CPPUNIT_ASSERT( result1 == false);
sl@0
   472
		CPPUNIT_ASSERT( result2 == true );
sl@0
   473
		}
sl@0
   474
	}
sl@0
   475
void CodecvtTest::locale_cov3()
sl@0
   476
	{
sl@0
   477
	locale loc ( "fr_FR.ISO-8859-1" );
sl@0
   478
	locale loc1 ( "en_US.ISO-8859-1" );
sl@0
   479
	bool result1,result2,result3;
sl@0
   480
		{
sl@0
   481
		result2 = isspace ( '\n', loc);
sl@0
   482
		result3 = isspace ( 'x', loc);
sl@0
   483
		CPPUNIT_ASSERT( result2 == true );
sl@0
   484
		CPPUNIT_ASSERT( result3 == false );
sl@0
   485
		
sl@0
   486
		result2 = isspace ( '\n', loc1);
sl@0
   487
		result3 = isspace ( 'x', loc1);
sl@0
   488
		CPPUNIT_ASSERT( result2 == true );
sl@0
   489
		CPPUNIT_ASSERT( result3 == false );
sl@0
   490
		}
sl@0
   491
		{
sl@0
   492
	    result1 = isupper ( 'L', loc);
sl@0
   493
		result2 = isupper ( ';', loc);
sl@0
   494
		CPPUNIT_ASSERT( result1 == true );
sl@0
   495
		CPPUNIT_ASSERT( result2 == false );
sl@0
   496
		
sl@0
   497
		result1 = isupper ( 'L', loc1);
sl@0
   498
		result2 = isupper ( ';', loc1);
sl@0
   499
		CPPUNIT_ASSERT( result1 == true );
sl@0
   500
		CPPUNIT_ASSERT( result2 == false );
sl@0
   501
		}
sl@0
   502
		{
sl@0
   503
	    result1 = isxdigit ( 'f', loc);
sl@0
   504
		result2 = isxdigit ( 'd', loc);
sl@0
   505
		result3 = isxdigit ( 'q', loc);
sl@0
   506
		CPPUNIT_ASSERT( result1 == true );
sl@0
   507
		CPPUNIT_ASSERT( result2 == true );
sl@0
   508
		CPPUNIT_ASSERT( result3 == false );
sl@0
   509
		
sl@0
   510
		result1 = isxdigit ( 'f', loc1);
sl@0
   511
		result2 = isxdigit ( 'd', loc1);
sl@0
   512
		result3 = isxdigit ( 'q', loc1);
sl@0
   513
		CPPUNIT_ASSERT( result1 == true );
sl@0
   514
		CPPUNIT_ASSERT( result2 == true );
sl@0
   515
		CPPUNIT_ASSERT( result3 == false );
sl@0
   516
		}
sl@0
   517
	}
sl@0
   518
void CodecvtTest::locale_cov4()
sl@0
   519
	{
sl@0
   520
	locale loc ( "fr_FR.ISO-8859-1" );
sl@0
   521
	locale loc1 ( "en_US.ISO-8859-1" );
sl@0
   522
	char cresult1;
sl@0
   523
		{
sl@0
   524
		cresult1 = tolower ( 'H', loc );
sl@0
   525
		CPPUNIT_ASSERT( cresult1 == 'h' );
sl@0
   526
		cresult1 = tolower ( 'h', loc );
sl@0
   527
		CPPUNIT_ASSERT( cresult1 == 'h' );
sl@0
   528
		cresult1 = tolower ( '$', loc );
sl@0
   529
		CPPUNIT_ASSERT( cresult1 == '$' );
sl@0
   530
		
sl@0
   531
		cresult1 = tolower ( 'H', loc1 );
sl@0
   532
		CPPUNIT_ASSERT( cresult1 == 'h' );
sl@0
   533
		cresult1 = tolower ( 'h', loc1 );
sl@0
   534
		CPPUNIT_ASSERT( cresult1 == 'h' );
sl@0
   535
		cresult1 = tolower ( '$', loc1 );
sl@0
   536
		CPPUNIT_ASSERT( cresult1 == '$' );
sl@0
   537
		}
sl@0
   538
		{
sl@0
   539
		cresult1 = toupper ( 'H', loc );
sl@0
   540
		CPPUNIT_ASSERT( cresult1 == 'H' );
sl@0
   541
		cresult1 = toupper ( 'h', loc );
sl@0
   542
		CPPUNIT_ASSERT( cresult1 == 'H' );
sl@0
   543
		cresult1 = toupper ( '$', loc );
sl@0
   544
		CPPUNIT_ASSERT( cresult1 == '$' );
sl@0
   545
		
sl@0
   546
		cresult1 = toupper ( 'H', loc1 );
sl@0
   547
		CPPUNIT_ASSERT( cresult1 == 'H' );
sl@0
   548
		cresult1 = toupper ( 'h', loc1 );
sl@0
   549
		CPPUNIT_ASSERT( cresult1 == 'H' );
sl@0
   550
		cresult1 = toupper ( '$', loc1 );
sl@0
   551
		CPPUNIT_ASSERT( cresult1 == '$' );
sl@0
   552
		}
sl@0
   553
	}
sl@0
   554
void CodecvtTest::locale_cov5()
sl@0
   555
	{
sl@0
   556
		{
sl@0
   557
		char* str = "stdcpp with pips";
sl@0
   558
		mbstate_t state = {0};
sl@0
   559
		locale loc("C");
sl@0
   560
		int res = use_facet<codecvt<wchar_t, char, mbstate_t> > ( loc ).length( state,str, &str[strlen(str)], 50 );
sl@0
   561
		CPPUNIT_ASSERT( res == 16 );
sl@0
   562
		res = use_facet<codecvt<char, char, mbstate_t> >( loc ).max_length( );
sl@0
   563
		}
sl@0
   564
		{
sl@0
   565
		char* str = "stdcpp with pips";
sl@0
   566
		wchar_t wstr [50];
sl@0
   567
		memset(&wstr[0], 0, (sizeof(wchar_t))*(50));
sl@0
   568
		const char* pszNext;
sl@0
   569
		wchar_t* pwszNext;
sl@0
   570
		mbstate_t state = {0};
sl@0
   571
		locale loc("C");
sl@0
   572
		int res = use_facet<codecvt<wchar_t, char, mbstate_t> >( loc ).in( state,str, &str[strlen(str)], pszNext,wstr, &wstr[strlen(str)], pwszNext );
sl@0
   573
		wstr[strlen(str)] = 0; 
sl@0
   574
		CPPUNIT_ASSERT(res!=codecvt_base::error);
sl@0
   575
		}
sl@0
   576
		{
sl@0
   577
		locale loc ( "fr_FR.ISO-8859-1" );
sl@0
   578
		int result1 = use_facet<codecvt<char, char, mbstate_t> > ( loc ).encoding ( );
sl@0
   579
		CPPUNIT_ASSERT(result1 == 1);
sl@0
   580
		bool result2 = use_facet<codecvt<char, char, mbstate_t> >( loc ).always_noconv( );
sl@0
   581
		CPPUNIT_ASSERT(result2 == true);
sl@0
   582
		result2 = use_facet<codecvt<wchar_t, char, mbstate_t> >( loc ).always_noconv( );
sl@0
   583
		CPPUNIT_ASSERT(result2 == false);
sl@0
   584
		}
sl@0
   585
	}
sl@0
   586
void CodecvtTest::locale_cov6()
sl@0
   587
	{
sl@0
   588
		{
sl@0
   589
		locale loc( "en_US.ISO-8859-1" );
sl@0
   590
		const numpunct < char> &npunct = use_facet <numpunct <char> >( loc );
sl@0
   591
		string str = npunct.truename();
sl@0
   592
		CPPUNIT_ASSERT(str == "true");
sl@0
   593
		str = npunct.falsename();
sl@0
   594
		CPPUNIT_ASSERT(str == "false");
sl@0
   595
		CPPUNIT_ASSERT(npunct.thousands_sep( ) == ',');
sl@0
   596
		
sl@0
   597
		const numpunct < wchar_t> &npunct1 = use_facet <numpunct <wchar_t> >( loc );
sl@0
   598
		wstring str1 = npunct1.truename();
sl@0
   599
		CPPUNIT_ASSERT(str1 == L"true");
sl@0
   600
		str1 = npunct1.falsename();
sl@0
   601
		CPPUNIT_ASSERT(str1 == L"false");
sl@0
   602
		CPPUNIT_ASSERT(npunct1.thousands_sep( ) == L',');
sl@0
   603
		CPPUNIT_ASSERT(npunct1.decimal_point( ) == L'.');
sl@0
   604
		}
sl@0
   605
	}
sl@0
   606
void CodecvtTest::locale_cov7()
sl@0
   607
	{
sl@0
   608
		{
sl@0
   609
		locale loc( "en_US.ISO-8859-1" );
sl@0
   610
		const moneypunct <char, true> &mpunct = use_facet <moneypunct <char, true > >(loc);
sl@0
   611
		CPPUNIT_ASSERT(mpunct.thousands_sep( ) == ',');
sl@0
   612
		string str = mpunct.positive_sign( );
sl@0
   613
		str = mpunct.negative_sign( );
sl@0
   614
		char x = mpunct.neg_format().field[0];
sl@0
   615
		x = mpunct.neg_format().field[1];
sl@0
   616
		x = mpunct.neg_format().field[2];
sl@0
   617
		x = mpunct.neg_format().field[3];
sl@0
   618
		CPPUNIT_ASSERT(mpunct.decimal_point( ) == '.');
sl@0
   619
		str = mpunct.curr_symbol( );
sl@0
   620
		
sl@0
   621
		const moneypunct <char, false> &mpunct2 = use_facet <moneypunct <char, false> >(loc);
sl@0
   622
		CPPUNIT_ASSERT(mpunct2.thousands_sep( ) == ',');
sl@0
   623
		str = mpunct2.positive_sign( );
sl@0
   624
		str = mpunct2.negative_sign( );
sl@0
   625
		x = mpunct2.neg_format().field[0];
sl@0
   626
		x = mpunct2.neg_format().field[1];
sl@0
   627
		x = mpunct2.neg_format().field[2];
sl@0
   628
		x = mpunct2.neg_format().field[3];
sl@0
   629
		CPPUNIT_ASSERT(mpunct2.decimal_point( ) == '.');
sl@0
   630
		str = mpunct2.curr_symbol( );
sl@0
   631
		}
sl@0
   632
	}
sl@0
   633
#endif