os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/locale_test.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
 */
sl@0
     5
#include <string>
sl@0
     6
sl@0
     7
#if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
sl@0
     8
#  include <sstream>
sl@0
     9
#  include <locale>
sl@0
    10
#  include <stdexcept>
sl@0
    11
#  include <memory>
sl@0
    12
#  include <algorithm>
sl@0
    13
//#  include <iostream>
sl@0
    14
sl@0
    15
#  include "cppunit/cppunit_proxy.h"
sl@0
    16
sl@0
    17
#  if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
sl@0
    18
using namespace std;
sl@0
    19
#  endif
sl@0
    20
sl@0
    21
struct ref_locale {
sl@0
    22
  const char *name;
sl@0
    23
  const char *decimal_point;
sl@0
    24
  const char *thousands_sep;
sl@0
    25
  const char *money_int_prefix;
sl@0
    26
  const char *money_int_prefix_old;
sl@0
    27
  const char *money_prefix;
sl@0
    28
  const char *money_suffix;
sl@0
    29
  const char *money_decimal_point;
sl@0
    30
  const char *money_thousands_sep;
sl@0
    31
};
sl@0
    32
sl@0
    33
// Pls, don't write #ifdef _STLP_REAL_LOCALE_IMPLEMENTED here!
sl@0
    34
// It undefined in any case!!!!!
sl@0
    35
sl@0
    36
static const ref_locale tested_locales[] = {
sl@0
    37
//{  name,         decimal_point, thousands_sep, money_int_prefix, money_int_prefix_old, money_prefix, money_suffix, money_decimal_point, money_thousands_sep},
sl@0
    38
  { "fr_FR",       ",",           "\xa0",        "EUR ",           "FRF ",               "",           "",           ",",
sl@0
    39
#  if defined (WIN32) || defined (_WIN32)
sl@0
    40
                                                                                                                                          "\xa0" },
sl@0
    41
#  else
sl@0
    42
                                                                                                                                          " " },
sl@0
    43
#  endif
sl@0
    44
  { "ru_RU.koi8r", ",",           ".",           "RUB ",           "RUR ",               "",           "\xd2\xd5\xc2", ".",               " " },
sl@0
    45
  { "en_GB",       ".",           ",",           "GBP ",           "",                   "\xa3",       "",           ".",                 "," },
sl@0
    46
  { "en_US",       ".",           ",",           "USD ",           "",                   "$",          "",           ".",                 "," },
sl@0
    47
  { "C",           ".",           ",",           "",               "",                   "",           "",           " ",                 " " },
sl@0
    48
};
sl@0
    49
sl@0
    50
sl@0
    51
//
sl@0
    52
// TestCase class
sl@0
    53
//
sl@0
    54
class LocaleTest : public CPPUNIT_NS::TestCase
sl@0
    55
{
sl@0
    56
  CPPUNIT_TEST_SUITE(LocaleTest);
sl@0
    57
#  if defined (STLPORT) && !defined (_STLP_USE_EXCEPTIONS)
sl@0
    58
  CPPUNIT_IGNORE;
sl@0
    59
#  endif
sl@0
    60
  CPPUNIT_TEST(locale_by_name);
sl@0
    61
  CPPUNIT_STOP_IGNORE;
sl@0
    62
  CPPUNIT_TEST(loc_has_facet);
sl@0
    63
  CPPUNIT_TEST(num_put_get);
sl@0
    64
  CPPUNIT_TEST(money_put_get);
sl@0
    65
  CPPUNIT_TEST(money_put_X_bug);
sl@0
    66
  CPPUNIT_TEST(time_put_get);
sl@0
    67
#  if defined (__DMC__) && defined (_DLL)
sl@0
    68
  CPPUNIT_IGNORE;
sl@0
    69
#  endif
sl@0
    70
  CPPUNIT_TEST(collate_facet);
sl@0
    71
  CPPUNIT_TEST(ctype_facet);
sl@0
    72
#  if defined (STLPORT) && defined (_STLP_NO_MEMBER_TEMPLATES)
sl@0
    73
  CPPUNIT_IGNORE;
sl@0
    74
#  endif
sl@0
    75
  CPPUNIT_TEST(locale_init_problem);
sl@0
    76
  CPPUNIT_STOP_IGNORE;
sl@0
    77
  CPPUNIT_TEST(default_locale);
sl@0
    78
#  if !defined (STLPORT)
sl@0
    79
  CPPUNIT_IGNORE;
sl@0
    80
#  endif
sl@0
    81
  CPPUNIT_TEST(facet_id);
sl@0
    82
  CPPUNIT_STOP_IGNORE;
sl@0
    83
#  if defined (STLPORT) && \
sl@0
    84
     (!defined (_STLP_USE_EXCEPTIONS) || defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS))
sl@0
    85
  CPPUNIT_IGNORE;
sl@0
    86
#  endif
sl@0
    87
  CPPUNIT_TEST(combine);
sl@0
    88
  CPPUNIT_TEST_SUITE_END();
sl@0
    89
sl@0
    90
public:
sl@0
    91
  void locale_by_name();
sl@0
    92
  void loc_has_facet();
sl@0
    93
  void num_put_get();
sl@0
    94
  void money_put_get();
sl@0
    95
  void time_put_get();
sl@0
    96
  void collate_facet();
sl@0
    97
  void ctype_facet();
sl@0
    98
  void locale_init_problem();
sl@0
    99
  void money_put_X_bug();
sl@0
   100
  void default_locale();
sl@0
   101
  void facet_id();
sl@0
   102
  void combine();
sl@0
   103
private:
sl@0
   104
  void _loc_has_facet( const locale&, const ref_locale& );
sl@0
   105
  void _num_put_get( const locale&, const ref_locale& );
sl@0
   106
  void _money_put_get( const locale&, const ref_locale& );
sl@0
   107
  void _money_put_get2( const locale& loc, const locale& streamLoc, const ref_locale& );
sl@0
   108
  void _time_put_get( const locale&, const ref_locale& );
sl@0
   109
  void _ctype_facet( const locale&, const ref_locale& );
sl@0
   110
  void _locale_init_problem( const locale&, const ref_locale& );
sl@0
   111
  void _money_put_X_bug( const locale&, const ref_locale& );
sl@0
   112
};
sl@0
   113
sl@0
   114
CPPUNIT_TEST_SUITE_REGISTRATION(LocaleTest);
sl@0
   115
sl@0
   116
//
sl@0
   117
// tests implementation
sl@0
   118
//
sl@0
   119
void LocaleTest::_num_put_get( const locale& loc, const ref_locale& rl ) {
sl@0
   120
  CPPUNIT_ASSERT( has_facet<numpunct<char> >(loc) );
sl@0
   121
  numpunct<char> const& npct = use_facet<numpunct<char> >(loc);
sl@0
   122
  CPPUNIT_ASSERT( npct.decimal_point() == *rl.decimal_point );
sl@0
   123
sl@0
   124
  float val = 1234.56f;
sl@0
   125
  ostringstream fostr;
sl@0
   126
  fostr.imbue(loc);
sl@0
   127
  fostr << val;
sl@0
   128
sl@0
   129
  string ref = "1";
sl@0
   130
  if (!npct.grouping().empty()) {
sl@0
   131
    ref += npct.thousands_sep();
sl@0
   132
  }
sl@0
   133
  ref += "234";
sl@0
   134
  ref += npct.decimal_point();
sl@0
   135
  ref += "56";
sl@0
   136
  //cout << "In " << loc.name() << " 1234.56 is written: " << fostr.str() << endl;
sl@0
   137
  CPPUNIT_ASSERT( fostr.str() == ref );
sl@0
   138
sl@0
   139
  val = 12345678.9f;
sl@0
   140
  ref = "1";
sl@0
   141
  ref += npct.decimal_point();
sl@0
   142
  ref += "23457e+07";
sl@0
   143
  fostr.str("");
sl@0
   144
  fostr << val;
sl@0
   145
  CPPUNIT_ASSERT( fostr.str() == ref );
sl@0
   146
sl@0
   147
  val = 1000000000.0f;
sl@0
   148
  fostr.str("");
sl@0
   149
  fostr << val;
sl@0
   150
  CPPUNIT_ASSERT( fostr.str() == "1e+09" );
sl@0
   151
sl@0
   152
  val = 1234.0f;
sl@0
   153
  ref = "1";
sl@0
   154
  if (!npct.grouping().empty()) {
sl@0
   155
    ref += npct.thousands_sep();
sl@0
   156
  }
sl@0
   157
  ref += "234";
sl@0
   158
  fostr.str("");
sl@0
   159
  fostr << val;
sl@0
   160
  CPPUNIT_ASSERT( fostr.str() == ref );
sl@0
   161
sl@0
   162
  val = 10000001.0f;
sl@0
   163
  fostr.str("");
sl@0
   164
  fostr << val;
sl@0
   165
  CPPUNIT_ASSERT( fostr.str() == "1e+07" );
sl@0
   166
}
sl@0
   167
sl@0
   168
void LocaleTest::_money_put_get( const locale& loc, const ref_locale& rl )
sl@0
   169
{
sl@0
   170
  _money_put_get2(loc, loc, rl);
sl@0
   171
}
sl@0
   172
sl@0
   173
void LocaleTest::_money_put_get2( const locale& loc, const locale& streamLoc, const ref_locale& rl )
sl@0
   174
{
sl@0
   175
  CPPUNIT_ASSERT( has_facet<money_put<char> >(loc) );
sl@0
   176
  money_put<char> const& fmp = use_facet<money_put<char> >(loc);
sl@0
   177
  CPPUNIT_ASSERT( has_facet<money_get<char> >(loc) );
sl@0
   178
  money_get<char> const& fmg = use_facet<money_get<char> >(loc);
sl@0
   179
sl@0
   180
  ostringstream ostr;
sl@0
   181
  ostr.imbue(streamLoc);
sl@0
   182
  ostr << showbase;
sl@0
   183
sl@0
   184
  //Check a positive value (international format)
sl@0
   185
  {
sl@0
   186
    string str_res;
sl@0
   187
    //money_put
sl@0
   188
    {
sl@0
   189
      CPPUNIT_ASSERT( (has_facet<moneypunct<char, true> >(loc)) );
sl@0
   190
      moneypunct<char, true> const& intl_fmp = use_facet<moneypunct<char, true> >(loc);
sl@0
   191
sl@0
   192
      ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, true, ostr, ' ', 123456);
sl@0
   193
sl@0
   194
      CPPUNIT_ASSERT( !res.failed() );
sl@0
   195
      str_res = ostr.str();
sl@0
   196
sl@0
   197
      size_t fieldIndex = 0;
sl@0
   198
      size_t index = 0;
sl@0
   199
sl@0
   200
      //On a positive value we skip the sign field if exists:
sl@0
   201
      if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) {
sl@0
   202
        ++fieldIndex;
sl@0
   203
      }
sl@0
   204
      // international currency abbreviation, if it is before value
sl@0
   205
sl@0
   206
      /*
sl@0
   207
       * int_curr_symbol
sl@0
   208
       *
sl@0
   209
       *   The international currency symbol. The operand is a four-character
sl@0
   210
       *   string, with the first three characters containing the alphabetic
sl@0
   211
       *   international currency symbol in accordance with those specified
sl@0
   212
       *   in the ISO 4217 specification. The fourth character is the character used
sl@0
   213
       *   to separate the international currency symbol from the monetary quantity.
sl@0
   214
       *
sl@0
   215
       * (http://www.opengroup.org/onlinepubs/7990989775/xbd/locale.html)
sl@0
   216
       */
sl@0
   217
      string::size_type p = strlen( rl.money_int_prefix );
sl@0
   218
      if (p != 0) {
sl@0
   219
        CPPUNIT_ASSERT( intl_fmp.pos_format().field[fieldIndex] == money_base::symbol );
sl@0
   220
        string::size_type p_old = strlen( rl.money_int_prefix_old );
sl@0
   221
        CPPUNIT_ASSERT( (str_res.substr(index, p) == rl.money_int_prefix) ||
sl@0
   222
                        ((p_old != 0) && (str_res.substr(index, p_old) ==  rl.money_int_prefix_old)) );
sl@0
   223
        if ( str_res.substr(index, p) == rl.money_int_prefix ) {
sl@0
   224
          index += p;
sl@0
   225
        } else {
sl@0
   226
          index += p_old;
sl@0
   227
        }
sl@0
   228
        ++fieldIndex;
sl@0
   229
      }
sl@0
   230
sl@0
   231
      // space after currency
sl@0
   232
      if (intl_fmp.pos_format().field[fieldIndex] == money_base::space ||
sl@0
   233
          intl_fmp.pos_format().field[fieldIndex] == money_base::none) {
sl@0
   234
        // iternational currency symobol has four chars, one of these chars
sl@0
   235
        // is separator, so if format has space on this place, it should
sl@0
   236
        // be skipped.
sl@0
   237
        ++fieldIndex;
sl@0
   238
      }
sl@0
   239
sl@0
   240
      // sign
sl@0
   241
      if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) {
sl@0
   242
        ++fieldIndex;
sl@0
   243
      }
sl@0
   244
sl@0
   245
      // value
sl@0
   246
      CPPUNIT_ASSERT( str_res[index++] == '1' );
sl@0
   247
      if (!intl_fmp.grouping().empty()) {
sl@0
   248
        CPPUNIT_ASSERT( str_res[index++] == /* intl_fmp.thousands_sep() */ *rl.money_thousands_sep );
sl@0
   249
      }
sl@0
   250
      CPPUNIT_ASSERT( str_res[index++] == '2' );
sl@0
   251
      CPPUNIT_ASSERT( str_res[index++] == '3' );
sl@0
   252
      CPPUNIT_ASSERT( str_res[index++] == '4' );
sl@0
   253
      if (intl_fmp.frac_digits() != 0) {
sl@0
   254
        CPPUNIT_ASSERT( str_res[index++] == /* intl_fmp.decimal_point() */ *rl.money_decimal_point );
sl@0
   255
      }
sl@0
   256
      CPPUNIT_ASSERT( str_res[index++] == '5' );
sl@0
   257
      CPPUNIT_ASSERT( str_res[index++] == '6' );
sl@0
   258
      ++fieldIndex;
sl@0
   259
sl@0
   260
      // sign
sl@0
   261
      if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) {
sl@0
   262
        ++fieldIndex;
sl@0
   263
      }
sl@0
   264
sl@0
   265
      // space
sl@0
   266
      if (intl_fmp.pos_format().field[fieldIndex] == money_base::space ) {
sl@0
   267
        CPPUNIT_ASSERT( str_res[index++] == ' ' );
sl@0
   268
        ++fieldIndex;
sl@0
   269
      }
sl@0
   270
sl@0
   271
      // sign
sl@0
   272
      if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) {
sl@0
   273
        ++fieldIndex;
sl@0
   274
      }
sl@0
   275
sl@0
   276
      //as space cannot be last the only left format can be none:
sl@0
   277
      while ( fieldIndex < 3 ) {
sl@0
   278
        CPPUNIT_ASSERT( intl_fmp.pos_format().field[fieldIndex] == money_base::none );
sl@0
   279
        ++fieldIndex;
sl@0
   280
      }
sl@0
   281
    }
sl@0
   282
sl@0
   283
    //money_get
sl@0
   284
    {
sl@0
   285
      ios_base::iostate err = ios_base::goodbit;
sl@0
   286
      string digits;
sl@0
   287
sl@0
   288
      istringstream istr(str_res);
sl@0
   289
      ostr.str( "" );
sl@0
   290
      ostr.clear();
sl@0
   291
      fmg.get(istr, istreambuf_iterator<char, char_traits<char> >(), true, ostr, err, digits);
sl@0
   292
      CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 );
sl@0
   293
      CPPUNIT_ASSERT( digits == "123456" );
sl@0
   294
    }
sl@0
   295
  }
sl@0
   296
sl@0
   297
  ostr.str("");
sl@0
   298
  //Check a negative value (national format)
sl@0
   299
  {
sl@0
   300
    CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) );
sl@0
   301
    moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc);
sl@0
   302
    string str_res;
sl@0
   303
    //Check money_put
sl@0
   304
    {
sl@0
   305
      ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', -123456);
sl@0
   306
sl@0
   307
      CPPUNIT_ASSERT( !res.failed() );
sl@0
   308
      str_res = ostr.str();
sl@0
   309
sl@0
   310
      size_t fieldIndex = 0;
sl@0
   311
      size_t index = 0;
sl@0
   312
sl@0
   313
      if (dom_fmp.neg_format().field[fieldIndex] == money_base::sign) {
sl@0
   314
        CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.negative_sign().size()) == dom_fmp.negative_sign() );
sl@0
   315
        index += dom_fmp.negative_sign().size();
sl@0
   316
        ++fieldIndex;
sl@0
   317
      }
sl@0
   318
sl@0
   319
      string::size_type p = strlen( rl.money_prefix );
sl@0
   320
      if (p != 0) {
sl@0
   321
        CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix );
sl@0
   322
        index += p;
sl@0
   323
        ++fieldIndex;
sl@0
   324
      }
sl@0
   325
      if (dom_fmp.neg_format().field[fieldIndex] == money_base::space ||
sl@0
   326
          dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
sl@0
   327
        CPPUNIT_ASSERT( str_res[index++] == ' ' );
sl@0
   328
        ++fieldIndex;
sl@0
   329
      }
sl@0
   330
sl@0
   331
      CPPUNIT_ASSERT( str_res[index++] == '1' );
sl@0
   332
      if (!dom_fmp.grouping().empty()) {
sl@0
   333
        CPPUNIT_ASSERT( str_res[index++] == dom_fmp.thousands_sep() );
sl@0
   334
      }
sl@0
   335
      CPPUNIT_ASSERT( str_res[index++] == '2' );
sl@0
   336
      CPPUNIT_ASSERT( str_res[index++] == '3' );
sl@0
   337
      CPPUNIT_ASSERT( str_res[index++] == '4' );
sl@0
   338
      if (dom_fmp.frac_digits() != 0) {
sl@0
   339
        CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() );
sl@0
   340
      }
sl@0
   341
      CPPUNIT_ASSERT( str_res[index++] == '5' );
sl@0
   342
      CPPUNIT_ASSERT( str_res[index++] == '6' );
sl@0
   343
      ++fieldIndex;
sl@0
   344
sl@0
   345
      //space cannot be last:
sl@0
   346
      if ((fieldIndex < 3) &&
sl@0
   347
          dom_fmp.neg_format().field[fieldIndex] == money_base::space) {
sl@0
   348
        CPPUNIT_ASSERT( str_res[index++] == ' ' );
sl@0
   349
        ++fieldIndex;
sl@0
   350
      }
sl@0
   351
sl@0
   352
      if (fieldIndex == 3) {
sl@0
   353
        //If none is last we should not add anything to the resulting string:
sl@0
   354
        if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
sl@0
   355
          CPPUNIT_ASSERT( index == str_res.size() );
sl@0
   356
        } else {
sl@0
   357
          CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );
sl@0
   358
          CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );
sl@0
   359
        }
sl@0
   360
      }
sl@0
   361
    }
sl@0
   362
sl@0
   363
    //money_get
sl@0
   364
    {
sl@0
   365
      ios_base::iostate err = ios_base::goodbit;
sl@0
   366
#  if defined (STLPORT)
sl@0
   367
      _STLP_LONGEST_FLOAT_TYPE val;
sl@0
   368
#  else
sl@0
   369
      long double val;
sl@0
   370
#  endif
sl@0
   371
sl@0
   372
      istringstream istr(str_res);
sl@0
   373
      fmg.get(istr, istreambuf_iterator<char, char_traits<char> >(), false, ostr, err, val);
sl@0
   374
      CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 );
sl@0
   375
      if (dom_fmp.negative_sign().empty()) {
sl@0
   376
        //Without negative sign there is no way to guess the resulting amount sign ("C" locale):
sl@0
   377
        CPPUNIT_ASSERT( val == 123456 );
sl@0
   378
      }
sl@0
   379
      else {
sl@0
   380
        CPPUNIT_ASSERT( val == -123456 );
sl@0
   381
      }
sl@0
   382
    }
sl@0
   383
  }
sl@0
   384
  ostr.str("");
sl@0
   385
  //Check a negative value (national format)
sl@0
   386
  {
sl@0
   387
    CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) );
sl@0
   388
    moneypunct<char, true> const& dom_fmp = use_facet<moneypunct<char, true> >(loc);
sl@0
   389
    string str_res;
sl@0
   390
    //Check money_put
sl@0
   391
    {
sl@0
   392
      ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, true, ostr, ' ', -123456);
sl@0
   393
sl@0
   394
      CPPUNIT_ASSERT( !res.failed() );
sl@0
   395
      str_res = ostr.str();
sl@0
   396
sl@0
   397
      size_t fieldIndex = 0;
sl@0
   398
      size_t index = 0;
sl@0
   399
sl@0
   400
      if (dom_fmp.neg_format().field[fieldIndex] == money_base::sign) {
sl@0
   401
        CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.negative_sign().size()) == dom_fmp.negative_sign() );
sl@0
   402
        index += dom_fmp.negative_sign().size();
sl@0
   403
        ++fieldIndex;
sl@0
   404
      }
sl@0
   405
sl@0
   406
      string::size_type p = strlen( rl.money_prefix );
sl@0
   407
      if (p != 0) {
sl@0
   408
        CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix );
sl@0
   409
        index += p;
sl@0
   410
        ++fieldIndex;
sl@0
   411
      }
sl@0
   412
      if (dom_fmp.neg_format().field[fieldIndex] == money_base::space ||
sl@0
   413
          dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
sl@0
   414
        CPPUNIT_ASSERT( str_res[index++] == ' ' );
sl@0
   415
        ++fieldIndex;
sl@0
   416
      }
sl@0
   417
sl@0
   418
      CPPUNIT_ASSERT( str_res[index++] == '1' );
sl@0
   419
      if (!dom_fmp.grouping().empty()) {
sl@0
   420
        CPPUNIT_ASSERT( str_res[index++] == dom_fmp.thousands_sep() );
sl@0
   421
      }
sl@0
   422
      CPPUNIT_ASSERT( str_res[index++] == '2' );
sl@0
   423
      CPPUNIT_ASSERT( str_res[index++] == '3' );
sl@0
   424
      CPPUNIT_ASSERT( str_res[index++] == '4' );
sl@0
   425
      if (dom_fmp.frac_digits() != 0) {
sl@0
   426
        CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() );
sl@0
   427
      }
sl@0
   428
      CPPUNIT_ASSERT( str_res[index++] == '5' );
sl@0
   429
      CPPUNIT_ASSERT( str_res[index++] == '6' );
sl@0
   430
      ++fieldIndex;
sl@0
   431
sl@0
   432
      //space cannot be last:
sl@0
   433
      if ((fieldIndex < 3) &&
sl@0
   434
          dom_fmp.neg_format().field[fieldIndex] == money_base::space) {
sl@0
   435
        CPPUNIT_ASSERT( str_res[index++] == ' ' );
sl@0
   436
        ++fieldIndex;
sl@0
   437
      }
sl@0
   438
sl@0
   439
      if (fieldIndex == 3) {
sl@0
   440
        //If none is last we should not add anything to the resulting string:
sl@0
   441
        if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
sl@0
   442
          CPPUNIT_ASSERT( index == str_res.size() );
sl@0
   443
        } else {
sl@0
   444
          CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );
sl@0
   445
          CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );
sl@0
   446
        }
sl@0
   447
      }
sl@0
   448
    }
sl@0
   449
sl@0
   450
    //money_get
sl@0
   451
    {
sl@0
   452
      ios_base::iostate err = ios_base::goodbit;
sl@0
   453
#  if defined (STLPORT)
sl@0
   454
      _STLP_LONGEST_FLOAT_TYPE val;
sl@0
   455
#  else
sl@0
   456
      long double val;
sl@0
   457
#  endif
sl@0
   458
sl@0
   459
      istringstream istr(str_res);
sl@0
   460
      fmg.get(istr, istreambuf_iterator<char, char_traits<char> >(), false, ostr, err, val);
sl@0
   461
      CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 );
sl@0
   462
      if (dom_fmp.negative_sign().empty()) {
sl@0
   463
        //Without negative sign there is no way to guess the resulting amount sign ("C" locale):
sl@0
   464
        CPPUNIT_ASSERT( val == 123456 );
sl@0
   465
      }
sl@0
   466
      else {
sl@0
   467
        CPPUNIT_ASSERT( val == -123456 );
sl@0
   468
      }
sl@0
   469
    }
sl@0
   470
  }
sl@0
   471
}
sl@0
   472
sl@0
   473
sl@0
   474
// Test for bug in case when number of digits in value less then number
sl@0
   475
// of digits in fraction. I.e. '9' should be printed as '0.09',
sl@0
   476
// if x.frac_digits() == 2.
sl@0
   477
sl@0
   478
void LocaleTest::_money_put_X_bug( const locale& loc, const ref_locale& rl )
sl@0
   479
{
sl@0
   480
  CPPUNIT_ASSERT( has_facet<money_put<char> >(loc) );
sl@0
   481
  money_put<char> const& fmp = use_facet<money_put<char> >(loc);
sl@0
   482
sl@0
   483
  ostringstream ostr;
sl@0
   484
  ostr.imbue(loc);
sl@0
   485
  ostr << showbase;
sl@0
   486
sl@0
   487
  // ostr.str("");
sl@0
   488
  // Check value with one decimal digit:
sl@0
   489
  {
sl@0
   490
    CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) );
sl@0
   491
    moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc);
sl@0
   492
    string str_res;
sl@0
   493
    // Check money_put
sl@0
   494
    {
sl@0
   495
      ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', 9);
sl@0
   496
sl@0
   497
      CPPUNIT_ASSERT( !res.failed() );
sl@0
   498
      str_res = ostr.str();
sl@0
   499
sl@0
   500
      size_t fieldIndex = 0;
sl@0
   501
      size_t index = 0;
sl@0
   502
sl@0
   503
      if (dom_fmp.pos_format().field[fieldIndex] == money_base::sign) {
sl@0
   504
        CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.positive_sign().size()) == dom_fmp.positive_sign() );
sl@0
   505
        index += dom_fmp.positive_sign().size();
sl@0
   506
        ++fieldIndex;
sl@0
   507
      }
sl@0
   508
sl@0
   509
      string::size_type p = strlen( rl.money_prefix );
sl@0
   510
      if (p != 0) {
sl@0
   511
        CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix );
sl@0
   512
        index += p;
sl@0
   513
        ++fieldIndex;
sl@0
   514
      }
sl@0
   515
      if (dom_fmp.neg_format().field[fieldIndex] == money_base::space ||
sl@0
   516
          dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
sl@0
   517
        CPPUNIT_ASSERT( str_res[index++] == ' ' );
sl@0
   518
        ++fieldIndex;
sl@0
   519
      }
sl@0
   520
      if (dom_fmp.frac_digits() != 0) {
sl@0
   521
        CPPUNIT_ASSERT( str_res[index++] == '0' );
sl@0
   522
        CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() );
sl@0
   523
        for ( int fd = 1; fd < dom_fmp.frac_digits(); ++fd ) {
sl@0
   524
          CPPUNIT_ASSERT( str_res[index++] == '0' );
sl@0
   525
        }
sl@0
   526
      }
sl@0
   527
      CPPUNIT_ASSERT( str_res[index++] == '9' );
sl@0
   528
      ++fieldIndex;
sl@0
   529
sl@0
   530
      //space cannot be last:
sl@0
   531
      if ((fieldIndex < 3) &&
sl@0
   532
          dom_fmp.neg_format().field[fieldIndex] == money_base::space) {
sl@0
   533
        CPPUNIT_ASSERT( str_res[index++] == ' ' );
sl@0
   534
        ++fieldIndex;
sl@0
   535
      }
sl@0
   536
sl@0
   537
      if (fieldIndex == 3) {
sl@0
   538
        //If none is last we should not add anything to the resulting string:
sl@0
   539
        if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
sl@0
   540
          CPPUNIT_ASSERT( index == str_res.size() );
sl@0
   541
        } else {
sl@0
   542
          CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );
sl@0
   543
          CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );
sl@0
   544
        }
sl@0
   545
      }
sl@0
   546
    }
sl@0
   547
  }
sl@0
   548
sl@0
   549
  ostr.str("");
sl@0
   550
  // Check value with two decimal digit:
sl@0
   551
  {
sl@0
   552
    CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) );
sl@0
   553
    moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc);
sl@0
   554
    string str_res;
sl@0
   555
    // Check money_put
sl@0
   556
    {
sl@0
   557
      ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', 90);
sl@0
   558
sl@0
   559
      CPPUNIT_ASSERT( !res.failed() );
sl@0
   560
      str_res = ostr.str();
sl@0
   561
sl@0
   562
      size_t fieldIndex = 0;
sl@0
   563
      size_t index = 0;
sl@0
   564
sl@0
   565
      if (dom_fmp.pos_format().field[fieldIndex] == money_base::sign) {
sl@0
   566
        CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.positive_sign().size()) == dom_fmp.positive_sign() );
sl@0
   567
        index += dom_fmp.positive_sign().size();
sl@0
   568
        ++fieldIndex;
sl@0
   569
      }
sl@0
   570
sl@0
   571
      string::size_type p = strlen( rl.money_prefix );
sl@0
   572
      if (p != 0) {
sl@0
   573
        CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix );
sl@0
   574
        index += p;
sl@0
   575
        ++fieldIndex;
sl@0
   576
      }
sl@0
   577
      if (dom_fmp.neg_format().field[fieldIndex] == money_base::space ||
sl@0
   578
          dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
sl@0
   579
        CPPUNIT_ASSERT( str_res[index++] == ' ' );
sl@0
   580
        ++fieldIndex;
sl@0
   581
      }
sl@0
   582
      if (dom_fmp.frac_digits() != 0) {
sl@0
   583
        CPPUNIT_ASSERT( str_res[index++] == '0' );
sl@0
   584
        CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() );
sl@0
   585
        for ( int fd = 1; fd < dom_fmp.frac_digits() - 1; ++fd ) {
sl@0
   586
          CPPUNIT_ASSERT( str_res[index++] == '0' );
sl@0
   587
        }
sl@0
   588
      }
sl@0
   589
      CPPUNIT_ASSERT( str_res[index++] == '9' );
sl@0
   590
      if (dom_fmp.frac_digits() != 0) {
sl@0
   591
        CPPUNIT_ASSERT( str_res[index++] == '0' );
sl@0
   592
      }
sl@0
   593
      ++fieldIndex;
sl@0
   594
sl@0
   595
      //space cannot be last:
sl@0
   596
      if ((fieldIndex < 3) &&
sl@0
   597
          dom_fmp.neg_format().field[fieldIndex] == money_base::space) {
sl@0
   598
        CPPUNIT_ASSERT( str_res[index++] == ' ' );
sl@0
   599
        ++fieldIndex;
sl@0
   600
      }
sl@0
   601
sl@0
   602
      if (fieldIndex == 3) {
sl@0
   603
        //If none is last we should not add anything to the resulting string:
sl@0
   604
        if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
sl@0
   605
          CPPUNIT_ASSERT( index == str_res.size() );
sl@0
   606
        } else {
sl@0
   607
          CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );
sl@0
   608
          CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );
sl@0
   609
        }
sl@0
   610
      }
sl@0
   611
    }
sl@0
   612
  }
sl@0
   613
}
sl@0
   614
sl@0
   615
void LocaleTest::_time_put_get( const locale& loc, const ref_locale&)
sl@0
   616
{
sl@0
   617
  CPPUNIT_ASSERT( has_facet<time_put<char> >(loc) );
sl@0
   618
  const time_put<char>& tmp = use_facet<time_put<char> >(loc);
sl@0
   619
sl@0
   620
  struct tm xmas = { 0, 0, 12, 25, 11, 93 };
sl@0
   621
  ostringstream ostr;
sl@0
   622
  ostr.imbue(loc);
sl@0
   623
  string format = "%B %d %Y";
sl@0
   624
sl@0
   625
  time_put<char>::iter_type ret = tmp.put(ostr, ostr, ' ', &xmas, format.data(), format.data() + format.size());
sl@0
   626
  CPPUNIT_ASSERT( !ret.failed() );
sl@0
   627
sl@0
   628
  /*
sl@0
   629
   * In other words, user conformation is required for reliable parsing
sl@0
   630
   * of user-entered dates and times, but machine-generated formats can be
sl@0
   631
   * parsed reliably. This allows parsers to be aggressive about interpreting
sl@0
   632
   * user variations on standard format.
sl@0
   633
   *
sl@0
   634
   *                                             ISO/IEC 14882, 22.2.5.1
sl@0
   635
   */
sl@0
   636
  CPPUNIT_ASSERT( has_facet<time_get<char> >(loc) );
sl@0
   637
  const time_get<char>& tmg = use_facet<time_get<char> >(loc);
sl@0
   638
  basic_ios<char> io(0);
sl@0
   639
  io.imbue(loc);
sl@0
   640
sl@0
   641
  istringstream istr( ostr.str() );
sl@0
   642
  istreambuf_iterator<char, char_traits<char> > i( istr );
sl@0
   643
  istreambuf_iterator<char, char_traits<char> > e;
sl@0
   644
  ios_base::iostate err = ios_base::goodbit;
sl@0
   645
  struct tm other = { 15, 20, 9, 14, 7, 105 };
sl@0
   646
sl@0
   647
  i = tmg.get_monthname( i, e, io, err, &other );
sl@0
   648
  CPPUNIT_ASSERT( err == ios_base::goodbit );
sl@0
   649
  CPPUNIT_ASSERT( other.tm_mon == xmas.tm_mon );
sl@0
   650
sl@0
   651
  ++i; ++i; ++i; ++i; // skip day of month and spaces around it
sl@0
   652
  i = tmg.get_year( i, e, io, err, &other );
sl@0
   653
sl@0
   654
  CPPUNIT_ASSERT( err == ios_base::eofbit );
sl@0
   655
  CPPUNIT_ASSERT( other.tm_year == xmas.tm_year );
sl@0
   656
sl@0
   657
  ostringstream ostrX;
sl@0
   658
  ostrX.imbue(loc);
sl@0
   659
  format = "%x %X";
sl@0
   660
sl@0
   661
  ret = tmp.put(ostrX, ostrX, ' ', &xmas, format.data(), format.data() + format.size());
sl@0
   662
  CPPUNIT_ASSERT( !ret.failed() );
sl@0
   663
sl@0
   664
  istringstream istrX( ostrX.str() );
sl@0
   665
  istreambuf_iterator<char, char_traits<char> > j( istrX );
sl@0
   666
sl@0
   667
  err = ios_base::goodbit;
sl@0
   668
sl@0
   669
  struct tm yet_more = { 15, 20, 9, 14, 7, 105 };
sl@0
   670
sl@0
   671
  j = tmg.get_date( j, e, io, err, &yet_more );
sl@0
   672
sl@0
   673
  CPPUNIT_ASSERT( err == ios_base::goodbit );
sl@0
   674
sl@0
   675
  CPPUNIT_ASSERT( yet_more.tm_sec != xmas.tm_sec );
sl@0
   676
  CPPUNIT_ASSERT( yet_more.tm_min != xmas.tm_min );
sl@0
   677
  CPPUNIT_ASSERT( yet_more.tm_hour != xmas.tm_hour );
sl@0
   678
  CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday );
sl@0
   679
  CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon );
sl@0
   680
  CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year );
sl@0
   681
sl@0
   682
  ++j; // skip space
sl@0
   683
sl@0
   684
  j = tmg.get_time( j, e, io, err, &yet_more );
sl@0
   685
sl@0
   686
  CPPUNIT_ASSERT( err == ios_base::eofbit || err == ios_base::goodbit );
sl@0
   687
sl@0
   688
  CPPUNIT_ASSERT( yet_more.tm_sec == xmas.tm_sec );
sl@0
   689
  CPPUNIT_ASSERT( yet_more.tm_min == xmas.tm_min );
sl@0
   690
  CPPUNIT_ASSERT( yet_more.tm_hour == xmas.tm_hour );
sl@0
   691
  CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday );
sl@0
   692
  CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon );
sl@0
   693
  CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year );
sl@0
   694
}
sl@0
   695
sl@0
   696
void LocaleTest::_ctype_facet( const locale& loc, const ref_locale&)
sl@0
   697
{
sl@0
   698
#  if !(defined (__DMC__) && defined (_DLL))
sl@0
   699
  CPPUNIT_ASSERT( has_facet<ctype<char> >(loc) );
sl@0
   700
  ctype<char> const& ct = use_facet<ctype<char> >(loc);
sl@0
   701
sl@0
   702
  //is
sl@0
   703
  {
sl@0
   704
    CPPUNIT_ASSERT( ct.is(ctype_base::digit, '0') );
sl@0
   705
    CPPUNIT_ASSERT( ct.is(ctype_base::upper, 'A') );
sl@0
   706
    CPPUNIT_ASSERT( ct.is(ctype_base::lower, 'a') );
sl@0
   707
    CPPUNIT_ASSERT( ct.is(ctype_base::alpha, 'A') );
sl@0
   708
    CPPUNIT_ASSERT( ct.is(ctype_base::space, ' ') );
sl@0
   709
    CPPUNIT_ASSERT( !ct.is(ctype_base::space, '2') );
sl@0
   710
    CPPUNIT_ASSERT( ct.is(ctype_base::punct, '.') );
sl@0
   711
    CPPUNIT_ASSERT( ct.is(ctype_base::xdigit, 'a') );
sl@0
   712
  }
sl@0
   713
sl@0
   714
  //is range
sl@0
   715
  {
sl@0
   716
    char values[] = "0Aa .";
sl@0
   717
    ctype_base::mask res[sizeof(values)];
sl@0
   718
    ct.is(values, values + sizeof(values), res);
sl@0
   719
    // '0'
sl@0
   720
    CPPUNIT_ASSERT( (res[0] & ctype_base::print) != 0 );
sl@0
   721
    CPPUNIT_ASSERT( (res[0] & ctype_base::digit) != 0 );
sl@0
   722
    CPPUNIT_ASSERT( (res[0] & ctype_base::xdigit) != 0 );
sl@0
   723
    // 'A'
sl@0
   724
    CPPUNIT_ASSERT( (res[1] & ctype_base::print) != 0 );
sl@0
   725
    CPPUNIT_ASSERT( (res[1] & ctype_base::alpha) != 0 );
sl@0
   726
    CPPUNIT_ASSERT( (res[1] & ctype_base::xdigit) != 0 );
sl@0
   727
    CPPUNIT_ASSERT( (res[1] & ctype_base::upper) != 0 );
sl@0
   728
    // 'a'
sl@0
   729
    CPPUNIT_ASSERT( (res[2] & ctype_base::print) != 0 );
sl@0
   730
    CPPUNIT_ASSERT( (res[2] & ctype_base::alpha) != 0 );
sl@0
   731
    CPPUNIT_ASSERT( (res[2] & ctype_base::xdigit) != 0 );
sl@0
   732
    CPPUNIT_ASSERT( (res[2] & ctype_base::lower) != 0 );
sl@0
   733
    CPPUNIT_ASSERT( (res[2] & ctype_base::space) == 0 );
sl@0
   734
    // ' '
sl@0
   735
    CPPUNIT_ASSERT( (res[3] & ctype_base::print) != 0 );
sl@0
   736
    CPPUNIT_ASSERT( (res[3] & ctype_base::space) != 0 );
sl@0
   737
    CPPUNIT_ASSERT( (res[3] & ctype_base::digit) == 0 );
sl@0
   738
    // '.'
sl@0
   739
    CPPUNIT_ASSERT( (res[4] & ctype_base::print) != 0 );
sl@0
   740
    CPPUNIT_ASSERT( (res[4] & ctype_base::punct) != 0 );
sl@0
   741
    CPPUNIT_ASSERT( (res[4] & ctype_base::digit) == 0 );
sl@0
   742
  }
sl@0
   743
sl@0
   744
  //scan_is
sl@0
   745
  {
sl@0
   746
    char range[] = "abAc123 .";
sl@0
   747
    const char *rbeg = range;
sl@0
   748
    const char *rend = range + sizeof(range);
sl@0
   749
sl@0
   750
    const char *res;
sl@0
   751
    res = ct.scan_is((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend);
sl@0
   752
    CPPUNIT_ASSERT( res != rend );
sl@0
   753
    CPPUNIT_ASSERT( *res == 'a' );
sl@0
   754
sl@0
   755
    res = ct.scan_is(ctype_base::upper, rbeg, rend);
sl@0
   756
    CPPUNIT_ASSERT( res != rend );
sl@0
   757
    CPPUNIT_ASSERT( *res == 'A' );
sl@0
   758
sl@0
   759
    res = ct.scan_is(ctype_base::punct, rbeg, rend);
sl@0
   760
    CPPUNIT_ASSERT( res != rend );
sl@0
   761
    CPPUNIT_ASSERT( *res == '.' );
sl@0
   762
  }
sl@0
   763
sl@0
   764
  //scan_not
sl@0
   765
  {
sl@0
   766
    char range[] = "abAc123 .";
sl@0
   767
    const char *rbeg = range;
sl@0
   768
    const char *rend = range + sizeof(range);
sl@0
   769
sl@0
   770
    const char *res;
sl@0
   771
    res = ct.scan_not((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend);
sl@0
   772
    CPPUNIT_ASSERT( res != rend );
sl@0
   773
    CPPUNIT_ASSERT( *res == '1' );
sl@0
   774
sl@0
   775
    res = ct.scan_not(ctype_base::alpha, rbeg, rend);
sl@0
   776
    CPPUNIT_ASSERT( res != rend );
sl@0
   777
    CPPUNIT_ASSERT( *res == '1' );
sl@0
   778
sl@0
   779
    res = ct.scan_not(ctype_base::punct, rbeg, rend);
sl@0
   780
    CPPUNIT_ASSERT( res != rend );
sl@0
   781
    CPPUNIT_ASSERT( *res == 'a' );
sl@0
   782
  }
sl@0
   783
sl@0
   784
  //toupper
sl@0
   785
  {
sl@0
   786
    CPPUNIT_ASSERT( ct.toupper('a') == 'A' );
sl@0
   787
    CPPUNIT_ASSERT( ct.toupper('A') == 'A' );
sl@0
   788
    CPPUNIT_ASSERT( ct.toupper('1') == '1' );
sl@0
   789
  }
sl@0
   790
sl@0
   791
  //toupper range
sl@0
   792
  {
sl@0
   793
    char range[] = "abAc1";
sl@0
   794
    char expected_range[] = "ABAC1";
sl@0
   795
    ct.toupper(range, range + sizeof(range));
sl@0
   796
    CPPUNIT_ASSERT( equal(range, range + sizeof(range), expected_range) );
sl@0
   797
  }
sl@0
   798
sl@0
   799
  //tolower
sl@0
   800
  {
sl@0
   801
    CPPUNIT_ASSERT( ct.tolower('A') == 'a' );
sl@0
   802
    CPPUNIT_ASSERT( ct.tolower('a') == 'a' );
sl@0
   803
    CPPUNIT_ASSERT( ct.tolower('1') == '1' );
sl@0
   804
  }
sl@0
   805
sl@0
   806
  //tolower range
sl@0
   807
  {
sl@0
   808
    char range[] = "ABaC1";
sl@0
   809
    char expected_range[] = "abac1";
sl@0
   810
    ct.tolower(range, range + sizeof(range));
sl@0
   811
    CPPUNIT_ASSERT( equal(range, range + sizeof(range), expected_range) );
sl@0
   812
  }
sl@0
   813
sl@0
   814
  //widen
sl@0
   815
  {
sl@0
   816
    CPPUNIT_ASSERT( ct.widen('a') == 'a' );
sl@0
   817
  }
sl@0
   818
sl@0
   819
  //widen range
sl@0
   820
  {
sl@0
   821
    char range[] = "ABaC1";
sl@0
   822
    char res[sizeof(range)];
sl@0
   823
    ct.widen(range, range + sizeof(range), res);
sl@0
   824
    CPPUNIT_ASSERT( equal(range, range + sizeof(range), res) );
sl@0
   825
  }
sl@0
   826
sl@0
   827
  //narrow
sl@0
   828
  {
sl@0
   829
    CPPUNIT_ASSERT( ct.narrow('a', 'b') == 'a' );
sl@0
   830
  }
sl@0
   831
sl@0
   832
  //narrow range
sl@0
   833
  {
sl@0
   834
    char range[] = "ABaC1";
sl@0
   835
    char res[sizeof(range)];
sl@0
   836
    ct.narrow(range, range + sizeof(range), 'b', res);
sl@0
   837
    CPPUNIT_ASSERT( equal(range, range + sizeof(range), res) );
sl@0
   838
  }
sl@0
   839
#  endif /* __DMC__ */
sl@0
   840
}
sl@0
   841
sl@0
   842
template <class _Tp>
sl@0
   843
void test_supported_locale(LocaleTest inst, _Tp __test) {
sl@0
   844
  size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]);
sl@0
   845
  for (size_t i = 0; i < n; ++i) {
sl@0
   846
    auto_ptr<locale> loc;
sl@0
   847
#  if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
   848
    try {
sl@0
   849
      loc.reset(new locale(tested_locales[i].name));
sl@0
   850
    }
sl@0
   851
    catch (runtime_error const&) {
sl@0
   852
      //This locale is not supported.
sl@0
   853
      continue;
sl@0
   854
    }
sl@0
   855
#  else
sl@0
   856
    //Without exception support we only test C locale.
sl@0
   857
    if (tested_locales[i].name[0] != 'C' ||
sl@0
   858
        tested_locales[i].name[1] != 0)
sl@0
   859
      continue;
sl@0
   860
    loc.reset(new locale(tested_locales[i].name));
sl@0
   861
#  endif
sl@0
   862
    CPPUNIT_MESSAGE( loc->name().c_str() );
sl@0
   863
    (inst.*__test)(*loc, tested_locales[i]);
sl@0
   864
  }
sl@0
   865
}
sl@0
   866
sl@0
   867
void LocaleTest::locale_by_name() {
sl@0
   868
#  if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
   869
  /*
sl@0
   870
   * Check of the 22.1.1.2.7 standard point. Construction of a locale
sl@0
   871
   * instance from a null pointer or an unknown name should result in
sl@0
   872
   * a runtime_error exception.
sl@0
   873
   */
sl@0
   874
  try {
sl@0
   875
    locale loc(static_cast<char const*>(0));
sl@0
   876
    CPPUNIT_ASSERT( false );
sl@0
   877
  }
sl@0
   878
  catch (runtime_error const&) {
sl@0
   879
  }
sl@0
   880
  catch (...) {
sl@0
   881
    CPPUNIT_ASSERT( false );
sl@0
   882
  }
sl@0
   883
sl@0
   884
  try {
sl@0
   885
    locale loc("yasli_language");
sl@0
   886
    CPPUNIT_ASSERT( false );
sl@0
   887
  }
sl@0
   888
  catch (runtime_error const&) {
sl@0
   889
  }
sl@0
   890
  catch (...) {
sl@0
   891
    CPPUNIT_ASSERT( false );
sl@0
   892
  }
sl@0
   893
#  endif
sl@0
   894
}
sl@0
   895
sl@0
   896
void LocaleTest::loc_has_facet() {
sl@0
   897
  locale loc("C");
sl@0
   898
  typedef numpunct<char> implemented_facet;
sl@0
   899
  CPPUNIT_ASSERT( has_facet<implemented_facet>(loc) );
sl@0
   900
  /*
sl@0
   901
  typedef num_put<char, back_insert_iterator<string> > not_implemented_facet;
sl@0
   902
  CPPUNIT_ASSERT( !has_facet<not_implemented_facet>(loc) );
sl@0
   903
  */
sl@0
   904
}
sl@0
   905
sl@0
   906
void LocaleTest::num_put_get()
sl@0
   907
{ test_supported_locale(*this, &LocaleTest::_num_put_get); }
sl@0
   908
sl@0
   909
void LocaleTest::money_put_get()
sl@0
   910
{ test_supported_locale(*this, &LocaleTest::_money_put_get); }
sl@0
   911
sl@0
   912
void LocaleTest::money_put_X_bug()
sl@0
   913
{ test_supported_locale(*this, &LocaleTest::_money_put_X_bug); }
sl@0
   914
sl@0
   915
void LocaleTest::time_put_get()
sl@0
   916
{ test_supported_locale(*this, &LocaleTest::_time_put_get); }
sl@0
   917
sl@0
   918
void LocaleTest::collate_facet()
sl@0
   919
{
sl@0
   920
  {
sl@0
   921
    CPPUNIT_ASSERT( has_facet<collate<char> >(locale::classic()) );
sl@0
   922
    collate<char> const& col = use_facet<collate<char> >(locale::classic());
sl@0
   923
sl@0
   924
    char const str1[] = "abcdef1";
sl@0
   925
    char const str2[] = "abcdef2";
sl@0
   926
    const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1;
sl@0
   927
    const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1;
sl@0
   928
sl@0
   929
    CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 );
sl@0
   930
    CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 );
sl@0
   931
sl@0
   932
    //Smallest string should be before largest one:
sl@0
   933
    CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 );
sl@0
   934
    CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 );
sl@0
   935
  }
sl@0
   936
sl@0
   937
#  if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
   938
  try {
sl@0
   939
    locale loc("fr_FR.ISO-8859-1");
sl@0
   940
    {
sl@0
   941
      CPPUNIT_ASSERT( has_facet<collate<char> >(loc) );
sl@0
   942
      collate<char> const& col = use_facet<collate<char> >(loc);
sl@0
   943
sl@0
   944
      char const str1[] = "abcdef1";
sl@0
   945
      char const str2[] = "abcdef2";
sl@0
   946
      const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1;
sl@0
   947
      const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1;
sl@0
   948
sl@0
   949
      CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 );
sl@0
   950
      CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 );
sl@0
   951
sl@0
   952
      //Smallest string should be before largest one:
sl@0
   953
      CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 );
sl@0
   954
      CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 );
sl@0
   955
    }
sl@0
   956
    {
sl@0
   957
      CPPUNIT_ASSERT( has_facet<collate<char> >(loc) );
sl@0
   958
      collate<char> const& col = use_facet<collate<char> >(loc);
sl@0
   959
sl@0
   960
      string strs[] = {"abdd", "abçd", "abbd", "abcd"};
sl@0
   961
sl@0
   962
      string transformed[4];
sl@0
   963
      for (size_t i = 0; i < 4; ++i) {
sl@0
   964
        transformed[i] = col.transform(strs[i].data(), strs[i].data() + strs[i].size());
sl@0
   965
      }
sl@0
   966
sl@0
   967
      sort(strs, strs + 4, loc);
sl@0
   968
      // c and ç are considered same when strxfrm() is done on the string
sl@0
   969
      CPPUNIT_ASSERT( strs[0] == "abbd" );
sl@0
   970
      CPPUNIT_ASSERT( strs[1] == "abçd" );
sl@0
   971
      CPPUNIT_ASSERT( strs[2] == "abcd" );
sl@0
   972
      CPPUNIT_ASSERT( strs[3] == "abdd" );
sl@0
   973
sl@0
   974
      sort(transformed, transformed + 4);
sl@0
   975
sl@0
   976
      CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + strs[0].size()) == transformed[0] );
sl@0
   977
      CPPUNIT_ASSERT( col.transform(strs[1].data(), strs[1].data() + strs[1].size()) == transformed[1] );
sl@0
   978
      CPPUNIT_ASSERT( col.transform(strs[2].data(), strs[2].data() + strs[2].size()) == transformed[2] );
sl@0
   979
      CPPUNIT_ASSERT( col.transform(strs[3].data(), strs[3].data() + strs[3].size()) == transformed[3] );
sl@0
   980
sl@0
   981
      // Check empty string result in empty key.
sl@0
   982
      CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data()).empty() );
sl@0
   983
sl@0
   984
      // Check that only characters that matter are taken into accout to build the key.
sl@0
   985
      CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + 2) == col.transform(strs[1].data(), strs[1].data() + 2) );
sl@0
   986
    }
sl@0
   987
#    if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)
sl@0
   988
    {
sl@0
   989
      CPPUNIT_ASSERT( has_facet<collate<wchar_t> >(loc) );
sl@0
   990
      collate<wchar_t> const& col = use_facet<collate<wchar_t> >(loc);
sl@0
   991
sl@0
   992
      wchar_t const str1[] = L"abcdef1";
sl@0
   993
      wchar_t const str2[] = L"abcdef2";
sl@0
   994
      const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1;
sl@0
   995
      const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1;
sl@0
   996
sl@0
   997
      CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 );
sl@0
   998
      CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 );
sl@0
   999
sl@0
  1000
      //Smallest string should be before largest one:
sl@0
  1001
      CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 );
sl@0
  1002
      CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 );
sl@0
  1003
    }
sl@0
  1004
    {
sl@0
  1005
      size_t i;
sl@0
  1006
      CPPUNIT_ASSERT( has_facet<collate<wchar_t> >(loc) );
sl@0
  1007
      collate<wchar_t> const& col = use_facet<collate<wchar_t> >(loc);
sl@0
  1008
sl@0
  1009
      // Here we would like to use L"abçd" but it looks like all compilers
sl@0
  1010
      // do not support storage of unicode characters in exe resulting in
sl@0
  1011
      // compilation error. We avoid this test for the moment.
sl@0
  1012
      wstring strs[] = {L"abdd", L"abcd", L"abbd", L"abcd"};
sl@0
  1013
sl@0
  1014
      wstring transformed[4];
sl@0
  1015
      for (i = 0; i < 4; ++i) {
sl@0
  1016
        transformed[i] = col.transform(strs[i].data(), strs[i].data() + strs[i].size());
sl@0
  1017
      }
sl@0
  1018
sl@0
  1019
      sort(strs, strs + 4, loc);
sl@0
  1020
      CPPUNIT_ASSERT( strs[0] == L"abbd" );
sl@0
  1021
      CPPUNIT_ASSERT( strs[1] == L"abcd" );
sl@0
  1022
      CPPUNIT_ASSERT( strs[2] == L"abcd" );
sl@0
  1023
      CPPUNIT_ASSERT( strs[3] == L"abdd" );
sl@0
  1024
sl@0
  1025
      sort(transformed, transformed + 4);
sl@0
  1026
sl@0
  1027
      CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + strs[0].size()) == transformed[0] );
sl@0
  1028
      CPPUNIT_ASSERT( col.transform(strs[1].data(), strs[1].data() + strs[1].size()) == transformed[1] );
sl@0
  1029
      CPPUNIT_ASSERT( col.transform(strs[2].data(), strs[2].data() + strs[2].size()) == transformed[2] );
sl@0
  1030
      CPPUNIT_ASSERT( col.transform(strs[3].data(), strs[3].data() + strs[3].size()) == transformed[3] );
sl@0
  1031
sl@0
  1032
      CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data()).empty() );
sl@0
  1033
sl@0
  1034
      CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + 2) == col.transform(strs[1].data(), strs[1].data() + 2) );
sl@0
  1035
    }
sl@0
  1036
#    endif
sl@0
  1037
  }
sl@0
  1038
  catch (runtime_error const&) {
sl@0
  1039
    CPPUNIT_MESSAGE("No french locale to check collate facet");
sl@0
  1040
  }
sl@0
  1041
#  endif
sl@0
  1042
}
sl@0
  1043
sl@0
  1044
void LocaleTest::ctype_facet()
sl@0
  1045
{ test_supported_locale(*this, &LocaleTest::_ctype_facet); }
sl@0
  1046
sl@0
  1047
void LocaleTest::locale_init_problem() {
sl@0
  1048
#  if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)
sl@0
  1049
  test_supported_locale(*this, &LocaleTest::_locale_init_problem);
sl@0
  1050
#  endif
sl@0
  1051
}
sl@0
  1052
sl@0
  1053
sl@0
  1054
/*
sl@0
  1055
 * Creation of a locale instance imply initialization of some STLport internal
sl@0
  1056
 * static objects first. We use a static instance of locale to check that this
sl@0
  1057
 * initialization is done correctly.
sl@0
  1058
 */
sl@0
  1059
static locale global_loc;
sl@0
  1060
static locale other_loc("");
sl@0
  1061
sl@0
  1062
#  if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)
sl@0
  1063
void LocaleTest::_locale_init_problem( const locale& loc, const ref_locale&)
sl@0
  1064
{
sl@0
  1065
#    if !defined (__APPLE__) && !defined (__FreeBSD__) || \
sl@0
  1066
        !defined(__GNUC__) || ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__> 3)))
sl@0
  1067
  typedef codecvt<char,char,mbstate_t> my_facet;
sl@0
  1068
#    else
sl@0
  1069
// std::mbstate_t required for gcc 3.3.2 on FreeBSD...
sl@0
  1070
// I am not sure what key here---FreeBSD or 3.3.2...
sl@0
  1071
//      - ptr 2005-04-04
sl@0
  1072
  typedef codecvt<char,char,std::mbstate_t> my_facet;
sl@0
  1073
#    endif
sl@0
  1074
sl@0
  1075
#    if !(defined (__DMC__) && defined (_DLL))
sl@0
  1076
  locale loc_ref(global_loc);
sl@0
  1077
  {
sl@0
  1078
    locale gloc( loc_ref, new my_facet() );
sl@0
  1079
    CPPUNIT_ASSERT( has_facet<my_facet>( gloc ) );
sl@0
  1080
    //The following code is just here to try to confuse the reference counting underlying mecanism:
sl@0
  1081
    locale::global( locale::classic() );
sl@0
  1082
    locale::global( gloc );
sl@0
  1083
  }
sl@0
  1084
sl@0
  1085
#      if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
  1086
  try {
sl@0
  1087
#      endif
sl@0
  1088
    ostringstream os("test") ;
sl@0
  1089
    locale loc2( loc, new my_facet() );
sl@0
  1090
    CPPUNIT_ASSERT( has_facet<my_facet>( loc2 ) );
sl@0
  1091
    os.imbue( loc2 );
sl@0
  1092
#      if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
  1093
  }
sl@0
  1094
  catch ( runtime_error& ) {
sl@0
  1095
    CPPUNIT_ASSERT( false );
sl@0
  1096
  }
sl@0
  1097
  catch ( ... ) {
sl@0
  1098
   CPPUNIT_ASSERT( false );
sl@0
  1099
  }
sl@0
  1100
#      endif
sl@0
  1101
sl@0
  1102
#      if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
  1103
  try {
sl@0
  1104
#      endif
sl@0
  1105
    ostringstream os2("test2");
sl@0
  1106
#      if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
sl@0
  1107
  }
sl@0
  1108
  catch ( runtime_error& ) {
sl@0
  1109
    CPPUNIT_ASSERT( false );
sl@0
  1110
  }
sl@0
  1111
  catch ( ... ) {
sl@0
  1112
    CPPUNIT_ASSERT( false );
sl@0
  1113
  }
sl@0
  1114
#      endif
sl@0
  1115
#    endif /* __DMC__ */
sl@0
  1116
}
sl@0
  1117
#  endif
sl@0
  1118
sl@0
  1119
void LocaleTest::default_locale()
sl@0
  1120
{
sl@0
  1121
  locale loc( "" );
sl@0
  1122
}
sl@0
  1123
sl@0
  1124
void LocaleTest::facet_id()
sl@0
  1125
{
sl@0
  1126
#if defined (__SYMBIAN32__NO_STATIC_IMPORTS__) || defined (__SYMBIAN32__WSD__)
sl@0
  1127
#  if defined (STLPORT)
sl@0
  1128
  locale::id _id_01 = collate<char>::GetFacetLocaleId();
sl@0
  1129
  CPPUNIT_CHECK( _id_01._M_index == 1 );
sl@0
  1130
sl@0
  1131
  locale::id _id_02 = ctype<char>::GetFacetLocaleId();
sl@0
  1132
  CPPUNIT_CHECK( _id_02._M_index == 2 );
sl@0
  1133
sl@0
  1134
#    ifndef _STLP_NO_MBSTATE_T
sl@0
  1135
  locale::id _id_03 = codecvt<char, char, mbstate_t>::GetFacetLocaleId();
sl@0
  1136
  CPPUNIT_CHECK( _id_03._M_index == 3 );
sl@0
  1137
#    endif
sl@0
  1138
sl@0
  1139
  locale::id _id_04 = moneypunct<char, true>::GetFacetLocaleId();
sl@0
  1140
  CPPUNIT_CHECK( _id_04._M_index == 4 );
sl@0
  1141
sl@0
  1142
  locale::id _id_05 = moneypunct<char, false>::GetFacetLocaleId();
sl@0
  1143
  CPPUNIT_CHECK( _id_05._M_index == 5 );
sl@0
  1144
sl@0
  1145
  locale::id _id_06 = numpunct<char>::GetFacetLocaleId();
sl@0
  1146
  CPPUNIT_CHECK( _id_06._M_index == 6 );
sl@0
  1147
sl@0
  1148
  locale::id _id_07 = messages<char>::GetFacetLocaleId();
sl@0
  1149
  CPPUNIT_CHECK( _id_07._M_index == 7 );
sl@0
  1150
sl@0
  1151
  locale::id _id_08 = money_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
sl@0
  1152
  CPPUNIT_CHECK( _id_08._M_index == 8 );
sl@0
  1153
sl@0
  1154
  /*
sl@0
  1155
  locale::id _id_09 = money_get<char, const char*>::id;
sl@0
  1156
  CPPUNIT_CHECK( _id_09._M_index == 9 );
sl@0
  1157
  */
sl@0
  1158
sl@0
  1159
  locale::id _id_10 = money_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
sl@0
  1160
  CPPUNIT_CHECK( _id_10._M_index == 10 );
sl@0
  1161
sl@0
  1162
  /*
sl@0
  1163
  locale::id _id_11 = money_put<char, char*>::id;
sl@0
  1164
  CPPUNIT_CHECK( _id_11._M_index == 11 );
sl@0
  1165
  */
sl@0
  1166
sl@0
  1167
  locale::id _id_12 = num_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
sl@0
  1168
  CPPUNIT_CHECK( _id_12._M_index == 12 );
sl@0
  1169
sl@0
  1170
  /*
sl@0
  1171
  locale::id _id_13 = num_get<char, const char*>::id;
sl@0
  1172
  CPPUNIT_CHECK( _id_13._M_index == 13 );
sl@0
  1173
  */
sl@0
  1174
sl@0
  1175
  locale::id _id_14 = num_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
sl@0
  1176
  CPPUNIT_CHECK( _id_14._M_index == 14 );
sl@0
  1177
sl@0
  1178
  /*
sl@0
  1179
  locale::id _id_15 = num_put<char, char*>::id;
sl@0
  1180
  CPPUNIT_CHECK( _id_15._M_index == 15 );
sl@0
  1181
  */
sl@0
  1182
sl@0
  1183
  locale::id _id_16 = time_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
sl@0
  1184
  CPPUNIT_CHECK( _id_16._M_index == 16 );
sl@0
  1185
sl@0
  1186
  /*
sl@0
  1187
  locale::id _id_17 = time_get<char, const char*>::id;
sl@0
  1188
  CPPUNIT_CHECK( _id_17._M_index == 17 );
sl@0
  1189
  */
sl@0
  1190
sl@0
  1191
  locale::id _id_18 = time_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
sl@0
  1192
  CPPUNIT_CHECK( _id_18._M_index == 18 );
sl@0
  1193
sl@0
  1194
  /*
sl@0
  1195
  locale::id _id_19 = time_put<char, char*>::id;
sl@0
  1196
  CPPUNIT_CHECK( _id_19._M_index == 19 );
sl@0
  1197
  */
sl@0
  1198
sl@0
  1199
#    ifndef _STLP_NO_WCHAR_T
sl@0
  1200
  locale::id _id_20 = collate<wchar_t>::GetFacetLocaleId();
sl@0
  1201
  CPPUNIT_CHECK( _id_20._M_index == 20 );
sl@0
  1202
sl@0
  1203
  locale::id _id_21 = ctype<wchar_t>::GetFacetLocaleId();
sl@0
  1204
  CPPUNIT_CHECK( _id_21._M_index == 21 );
sl@0
  1205
sl@0
  1206
#      ifndef _STLP_NO_MBSTATE_T
sl@0
  1207
  locale::id _id_22 = codecvt<wchar_t, char, mbstate_t>::GetFacetLocaleId();
sl@0
  1208
  CPPUNIT_CHECK( _id_22._M_index == 22 );
sl@0
  1209
#      endif
sl@0
  1210
  locale::id _id_23 = moneypunct<wchar_t, true>::GetFacetLocaleId();
sl@0
  1211
  CPPUNIT_CHECK( _id_23._M_index == 23 );
sl@0
  1212
sl@0
  1213
  locale::id _id_24 = moneypunct<wchar_t, false>::GetFacetLocaleId();
sl@0
  1214
  CPPUNIT_CHECK( _id_24._M_index == 24 );
sl@0
  1215
sl@0
  1216
  locale::id _id_25 = numpunct<wchar_t>::GetFacetLocaleId();
sl@0
  1217
  CPPUNIT_CHECK( _id_25._M_index == 25 );
sl@0
  1218
sl@0
  1219
  locale::id _id_26 = messages<wchar_t>::GetFacetLocaleId();
sl@0
  1220
  CPPUNIT_CHECK( _id_26._M_index == 26 );
sl@0
  1221
sl@0
  1222
  locale::id _id_27 = money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
sl@0
  1223
  CPPUNIT_CHECK( _id_27._M_index == 27 );
sl@0
  1224
sl@0
  1225
  /*
sl@0
  1226
  locale::id _id_28 = money_get<wchar_t, const wchar_t*>::id;
sl@0
  1227
  CPPUNIT_CHECK( _id_28._M_index == 28 );
sl@0
  1228
  */
sl@0
  1229
sl@0
  1230
  locale::id _id_29 = money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
sl@0
  1231
  CPPUNIT_CHECK( _id_29._M_index == 29 );
sl@0
  1232
sl@0
  1233
  /*
sl@0
  1234
  locale::id _id_30 = money_put<wchar_t, wchar_t*>::id;
sl@0
  1235
  CPPUNIT_CHECK( _id_30._M_index == 30 );
sl@0
  1236
  */
sl@0
  1237
sl@0
  1238
  locale::id _id_31 = num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
sl@0
  1239
  CPPUNIT_CHECK( _id_31._M_index == 31 );
sl@0
  1240
sl@0
  1241
  /*
sl@0
  1242
  locale::id _id_32 = num_get<wchar_t, const wchar_t*>::id;
sl@0
  1243
  CPPUNIT_CHECK( _id_32._M_index == 32 );
sl@0
  1244
  */
sl@0
  1245
sl@0
  1246
  locale::id _id_33 = num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::GetFacetLocaleId();
sl@0
  1247
  CPPUNIT_CHECK( _id_33._M_index == 33 );
sl@0
  1248
sl@0
  1249
  /*
sl@0
  1250
  locale::id _id_34 = num_put<wchar_t, wchar_t*>::id;
sl@0
  1251
  CPPUNIT_CHECK( _id_34._M_index == 34 );
sl@0
  1252
  */
sl@0
  1253
sl@0
  1254
  locale::id _id_35 = time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
sl@0
  1255
  CPPUNIT_CHECK( _id_35._M_index == 35 );
sl@0
  1256
sl@0
  1257
  /*
sl@0
  1258
  locale::id _id_36 = time_get<wchar_t, const wchar_t*>::id;
sl@0
  1259
  CPPUNIT_CHECK( _id_36._M_index == 36 );
sl@0
  1260
  */
sl@0
  1261
sl@0
  1262
  locale::id _id_37 = time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
sl@0
  1263
  CPPUNIT_CHECK( _id_37._M_index == 37 );
sl@0
  1264
sl@0
  1265
  /*
sl@0
  1266
  locale::id _id_38 = time_put<wchar_t, wchar_t*>::id;
sl@0
  1267
  CPPUNIT_CHECK( _id_38._M_index == 38 );
sl@0
  1268
  */
sl@0
  1269
#    endif
sl@0
  1270
#  endif
sl@0
  1271
sl@0
  1272
#else
sl@0
  1273
sl@0
  1274
#  if defined (STLPORT)
sl@0
  1275
  locale::id _id_01 = collate<char>::id;
sl@0
  1276
  CPPUNIT_CHECK( _id_01._M_index == 1 );
sl@0
  1277
sl@0
  1278
  locale::id _id_02 = ctype<char>::id;
sl@0
  1279
  CPPUNIT_CHECK( _id_02._M_index == 2 );
sl@0
  1280
sl@0
  1281
#    ifndef _STLP_NO_MBSTATE_T
sl@0
  1282
  locale::id _id_03 = codecvt<char, char, mbstate_t>::id;
sl@0
  1283
  CPPUNIT_CHECK( _id_03._M_index == 3 );
sl@0
  1284
#    endif
sl@0
  1285
sl@0
  1286
  locale::id _id_04 = moneypunct<char, true>::id;
sl@0
  1287
  CPPUNIT_CHECK( _id_04._M_index == 4 );
sl@0
  1288
sl@0
  1289
  locale::id _id_05 = moneypunct<char, false>::id;
sl@0
  1290
  CPPUNIT_CHECK( _id_05._M_index == 5 );
sl@0
  1291
sl@0
  1292
  locale::id _id_06 = numpunct<char>::id;
sl@0
  1293
  CPPUNIT_CHECK( _id_06._M_index == 6 );
sl@0
  1294
sl@0
  1295
  locale::id _id_07 = messages<char>::id;
sl@0
  1296
  CPPUNIT_CHECK( _id_07._M_index == 7 );
sl@0
  1297
sl@0
  1298
  locale::id _id_08 = money_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
sl@0
  1299
  CPPUNIT_CHECK( _id_08._M_index == 8 );
sl@0
  1300
sl@0
  1301
  /*
sl@0
  1302
  locale::id _id_09 = money_get<char, const char*>::id;
sl@0
  1303
  CPPUNIT_CHECK( _id_09._M_index == 9 );
sl@0
  1304
  */
sl@0
  1305
sl@0
  1306
  locale::id _id_10 = money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
sl@0
  1307
  CPPUNIT_CHECK( _id_10._M_index == 10 );
sl@0
  1308
sl@0
  1309
  /*
sl@0
  1310
  locale::id _id_11 = money_put<char, char*>::id;
sl@0
  1311
  CPPUNIT_CHECK( _id_11._M_index == 11 );
sl@0
  1312
  */
sl@0
  1313
sl@0
  1314
  locale::id _id_12 = num_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
sl@0
  1315
  CPPUNIT_CHECK( _id_12._M_index == 12 );
sl@0
  1316
sl@0
  1317
  /*
sl@0
  1318
  locale::id _id_13 = num_get<char, const char*>::id;
sl@0
  1319
  CPPUNIT_CHECK( _id_13._M_index == 13 );
sl@0
  1320
  */
sl@0
  1321
sl@0
  1322
  locale::id _id_14 = num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
sl@0
  1323
  CPPUNIT_CHECK( _id_14._M_index == 14 );
sl@0
  1324
sl@0
  1325
  /*
sl@0
  1326
  locale::id _id_15 = num_put<char, char*>::id;
sl@0
  1327
  CPPUNIT_CHECK( _id_15._M_index == 15 );
sl@0
  1328
  */
sl@0
  1329
sl@0
  1330
  locale::id _id_16 = time_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
sl@0
  1331
  CPPUNIT_CHECK( _id_16._M_index == 16 );
sl@0
  1332
sl@0
  1333
  /*
sl@0
  1334
  locale::id _id_17 = time_get<char, const char*>::id;
sl@0
  1335
  CPPUNIT_CHECK( _id_17._M_index == 17 );
sl@0
  1336
  */
sl@0
  1337
sl@0
  1338
  locale::id _id_18 = time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
sl@0
  1339
  CPPUNIT_CHECK( _id_18._M_index == 18 );
sl@0
  1340
sl@0
  1341
  /*
sl@0
  1342
  locale::id _id_19 = time_put<char, char*>::id;
sl@0
  1343
  CPPUNIT_CHECK( _id_19._M_index == 19 );
sl@0
  1344
  */
sl@0
  1345
sl@0
  1346
#    ifndef _STLP_NO_WCHAR_T
sl@0
  1347
  locale::id _id_20 = collate<wchar_t>::id;
sl@0
  1348
  CPPUNIT_CHECK( _id_20._M_index == 20 );
sl@0
  1349
sl@0
  1350
  locale::id _id_21 = ctype<wchar_t>::id;
sl@0
  1351
  CPPUNIT_CHECK( _id_21._M_index == 21 );
sl@0
  1352
sl@0
  1353
#      ifndef _STLP_NO_MBSTATE_T
sl@0
  1354
  locale::id _id_22 = codecvt<wchar_t, char, mbstate_t>::id;
sl@0
  1355
  CPPUNIT_CHECK( _id_22._M_index == 22 );
sl@0
  1356
#      endif
sl@0
  1357
  locale::id _id_23 = moneypunct<wchar_t, true>::id;
sl@0
  1358
  CPPUNIT_CHECK( _id_23._M_index == 23 );
sl@0
  1359
sl@0
  1360
  locale::id _id_24 = moneypunct<wchar_t, false>::id;
sl@0
  1361
  CPPUNIT_CHECK( _id_24._M_index == 24 );
sl@0
  1362
sl@0
  1363
  locale::id _id_25 = numpunct<wchar_t>::id;
sl@0
  1364
  CPPUNIT_CHECK( _id_25._M_index == 25 );
sl@0
  1365
sl@0
  1366
  locale::id _id_26 = messages<wchar_t>::id;
sl@0
  1367
  CPPUNIT_CHECK( _id_26._M_index == 26 );
sl@0
  1368
sl@0
  1369
  locale::id _id_27 = money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
sl@0
  1370
  CPPUNIT_CHECK( _id_27._M_index == 27 );
sl@0
  1371
sl@0
  1372
  /*
sl@0
  1373
  locale::id _id_28 = money_get<wchar_t, const wchar_t*>::id;
sl@0
  1374
  CPPUNIT_CHECK( _id_28._M_index == 28 );
sl@0
  1375
  */
sl@0
  1376
sl@0
  1377
  locale::id _id_29 = money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
sl@0
  1378
  CPPUNIT_CHECK( _id_29._M_index == 29 );
sl@0
  1379
sl@0
  1380
  /*
sl@0
  1381
  locale::id _id_30 = money_put<wchar_t, wchar_t*>::id;
sl@0
  1382
  CPPUNIT_CHECK( _id_30._M_index == 30 );
sl@0
  1383
  */
sl@0
  1384
sl@0
  1385
  locale::id _id_31 = num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
sl@0
  1386
  CPPUNIT_CHECK( _id_31._M_index == 31 );
sl@0
  1387
sl@0
  1388
  /*
sl@0
  1389
  locale::id _id_32 = num_get<wchar_t, const wchar_t*>::id;
sl@0
  1390
  CPPUNIT_CHECK( _id_32._M_index == 32 );
sl@0
  1391
  */
sl@0
  1392
sl@0
  1393
  locale::id _id_33 = num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id;
sl@0
  1394
  CPPUNIT_CHECK( _id_33._M_index == 33 );
sl@0
  1395
sl@0
  1396
  /*
sl@0
  1397
  locale::id _id_34 = num_put<wchar_t, wchar_t*>::id;
sl@0
  1398
  CPPUNIT_CHECK( _id_34._M_index == 34 );
sl@0
  1399
  */
sl@0
  1400
sl@0
  1401
  locale::id _id_35 = time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
sl@0
  1402
  CPPUNIT_CHECK( _id_35._M_index == 35 );
sl@0
  1403
sl@0
  1404
  /*
sl@0
  1405
  locale::id _id_36 = time_get<wchar_t, const wchar_t*>::id;
sl@0
  1406
  CPPUNIT_CHECK( _id_36._M_index == 36 );
sl@0
  1407
  */
sl@0
  1408
sl@0
  1409
  locale::id _id_37 = time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
sl@0
  1410
  CPPUNIT_CHECK( _id_37._M_index == 37 );
sl@0
  1411
sl@0
  1412
  /*
sl@0
  1413
  locale::id _id_38 = time_put<wchar_t, wchar_t*>::id;
sl@0
  1414
  CPPUNIT_CHECK( _id_38._M_index == 38 );
sl@0
  1415
  */
sl@0
  1416
#    endif
sl@0
  1417
#  endif
sl@0
  1418
#  endif //__WINSCW__
sl@0
  1419
}
sl@0
  1420
sl@0
  1421
void LocaleTest::combine()
sl@0
  1422
{
sl@0
  1423
#  if (!defined (STLPORT) || \
sl@0
  1424
       (defined (_STLP_USE_EXCEPTIONS) && !defined (_STLP_NO_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)))
sl@0
  1425
  auto_ptr<locale> loc1, loc2;
sl@0
  1426
  size_t loc1_index = 0;
sl@0
  1427
  size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]);
sl@0
  1428
  for (size_t i = 0; i < n; ++i) {
sl@0
  1429
    try {
sl@0
  1430
      locale *ploc = new locale(tested_locales[i].name);
sl@0
  1431
      if (loc1.get() == 0)
sl@0
  1432
      {
sl@0
  1433
        loc1.reset(ploc);
sl@0
  1434
        loc1_index = i;
sl@0
  1435
        continue;
sl@0
  1436
      }
sl@0
  1437
      else
sl@0
  1438
      {
sl@0
  1439
        loc2.reset(ploc);
sl@0
  1440
      }
sl@0
  1441
sl@0
  1442
      //We can start the test
sl@0
  1443
      ostringstream ostr;
sl@0
  1444
      ostr << "combining '" << loc2->name() << "' money facets with '" << loc1->name() << "'";
sl@0
  1445
      CPPUNIT_MESSAGE( ostr.str().c_str() );
sl@0
  1446
sl@0
  1447
      //We are going to combine money facets as all formats are different.
sl@0
  1448
      {
sl@0
  1449
        //We check that resulting locale has correctly acquire loc2 facets.
sl@0
  1450
        locale loc = loc1->combine<moneypunct<char, true> >(*loc2);
sl@0
  1451
        loc = loc.combine<moneypunct<char, false> >(*loc2);
sl@0
  1452
        loc = loc.combine<money_put<char> >(*loc2);
sl@0
  1453
        loc = loc.combine<money_get<char> >(*loc2);
sl@0
  1454
sl@0
  1455
        //Check loc has the correct facets:
sl@0
  1456
        _money_put_get2(*loc2, loc, tested_locales[i]);
sl@0
  1457
sl@0
  1458
        //Check loc1 has not been impacted:
sl@0
  1459
        _money_put_get2(*loc1, *loc1, tested_locales[loc1_index]);
sl@0
  1460
sl@0
  1461
        //Check loc2 has not been impacted:
sl@0
  1462
        _money_put_get2(*loc2, *loc2, tested_locales[i]);
sl@0
  1463
      }
sl@0
  1464
      {
sl@0
  1465
        //We check that resulting locale has not wrongly acquire loc1 facets that hasn't been combine:
sl@0
  1466
        locale loc = loc2->combine<numpunct<char> >(*loc1);
sl@0
  1467
        loc = loc.combine<time_put<char> >(*loc1);
sl@0
  1468
        loc = loc.combine<time_get<char> >(*loc1);
sl@0
  1469
sl@0
  1470
        //Check loc has the correct facets:
sl@0
  1471
        _money_put_get2(*loc2, loc, tested_locales[i]);
sl@0
  1472
sl@0
  1473
        //Check loc1 has not been impacted:
sl@0
  1474
        _money_put_get2(*loc1, *loc1, tested_locales[loc1_index]);
sl@0
  1475
sl@0
  1476
        //Check loc2 has not been impacted:
sl@0
  1477
        _money_put_get2(*loc2, *loc2, tested_locales[i]);
sl@0
  1478
      }
sl@0
  1479
sl@0
  1480
      {
sl@0
  1481
        // Check auto combination do not result in weird reference counting behavior 
sl@0
  1482
        // (might generate a crash).
sl@0
  1483
        loc1->combine<numpunct<char> >(*loc1);
sl@0
  1484
      }
sl@0
  1485
sl@0
  1486
      loc1.reset(loc2.release());
sl@0
  1487
      loc1_index = i;
sl@0
  1488
    }
sl@0
  1489
    catch (runtime_error const&) {
sl@0
  1490
      //This locale is not supported.
sl@0
  1491
      continue;
sl@0
  1492
    }
sl@0
  1493
  }
sl@0
  1494
#  endif
sl@0
  1495
}
sl@0
  1496
sl@0
  1497
#endif