First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
7 #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS)
13 //# include <iostream>
15 # include "cppunit/cppunit_proxy.h"
17 # if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
23 const char *decimal_point;
24 const char *thousands_sep;
25 const char *money_int_prefix;
26 const char *money_int_prefix_old;
27 const char *money_prefix;
28 const char *money_suffix;
29 const char *money_decimal_point;
30 const char *money_thousands_sep;
33 // Pls, don't write #ifdef _STLP_REAL_LOCALE_IMPLEMENTED here!
34 // It undefined in any case!!!!!
36 static const ref_locale tested_locales[] = {
37 //{ name, decimal_point, thousands_sep, money_int_prefix, money_int_prefix_old, money_prefix, money_suffix, money_decimal_point, money_thousands_sep},
38 { "fr_FR", ",", "\xa0", "EUR ", "FRF ", "", "", ",",
39 # if defined (WIN32) || defined (_WIN32)
44 { "ru_RU.koi8r", ",", ".", "RUB ", "RUR ", "", "\xd2\xd5\xc2", ".", " " },
45 { "en_GB", ".", ",", "GBP ", "", "\xa3", "", ".", "," },
46 { "en_US", ".", ",", "USD ", "", "$", "", ".", "," },
47 { "C", ".", ",", "", "", "", "", " ", " " },
54 class LocaleTest : public CPPUNIT_NS::TestCase
56 CPPUNIT_TEST_SUITE(LocaleTest);
57 # if defined (STLPORT) && !defined (_STLP_USE_EXCEPTIONS)
60 CPPUNIT_TEST(locale_by_name);
62 CPPUNIT_TEST(loc_has_facet);
63 CPPUNIT_TEST(num_put_get);
64 CPPUNIT_TEST(money_put_get);
65 CPPUNIT_TEST(money_put_X_bug);
66 CPPUNIT_TEST(time_put_get);
67 # if defined (__DMC__) && defined (_DLL)
70 CPPUNIT_TEST(collate_facet);
71 CPPUNIT_TEST(ctype_facet);
72 # if defined (STLPORT) && defined (_STLP_NO_MEMBER_TEMPLATES)
75 CPPUNIT_TEST(locale_init_problem);
77 CPPUNIT_TEST(default_locale);
78 # if !defined (STLPORT)
81 CPPUNIT_TEST(facet_id);
83 # if defined (STLPORT) && \
84 (!defined (_STLP_USE_EXCEPTIONS) || defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS))
87 CPPUNIT_TEST(combine);
88 CPPUNIT_TEST_SUITE_END();
91 void locale_by_name();
98 void locale_init_problem();
99 void money_put_X_bug();
100 void default_locale();
104 void _loc_has_facet( const locale&, const ref_locale& );
105 void _num_put_get( const locale&, const ref_locale& );
106 void _money_put_get( const locale&, const ref_locale& );
107 void _money_put_get2( const locale& loc, const locale& streamLoc, const ref_locale& );
108 void _time_put_get( const locale&, const ref_locale& );
109 void _ctype_facet( const locale&, const ref_locale& );
110 void _locale_init_problem( const locale&, const ref_locale& );
111 void _money_put_X_bug( const locale&, const ref_locale& );
114 CPPUNIT_TEST_SUITE_REGISTRATION(LocaleTest);
117 // tests implementation
119 void LocaleTest::_num_put_get( const locale& loc, const ref_locale& rl ) {
120 CPPUNIT_ASSERT( has_facet<numpunct<char> >(loc) );
121 numpunct<char> const& npct = use_facet<numpunct<char> >(loc);
122 CPPUNIT_ASSERT( npct.decimal_point() == *rl.decimal_point );
124 float val = 1234.56f;
130 if (!npct.grouping().empty()) {
131 ref += npct.thousands_sep();
134 ref += npct.decimal_point();
136 //cout << "In " << loc.name() << " 1234.56 is written: " << fostr.str() << endl;
137 CPPUNIT_ASSERT( fostr.str() == ref );
141 ref += npct.decimal_point();
145 CPPUNIT_ASSERT( fostr.str() == ref );
150 CPPUNIT_ASSERT( fostr.str() == "1e+09" );
154 if (!npct.grouping().empty()) {
155 ref += npct.thousands_sep();
160 CPPUNIT_ASSERT( fostr.str() == ref );
165 CPPUNIT_ASSERT( fostr.str() == "1e+07" );
168 void LocaleTest::_money_put_get( const locale& loc, const ref_locale& rl )
170 _money_put_get2(loc, loc, rl);
173 void LocaleTest::_money_put_get2( const locale& loc, const locale& streamLoc, const ref_locale& rl )
175 CPPUNIT_ASSERT( has_facet<money_put<char> >(loc) );
176 money_put<char> const& fmp = use_facet<money_put<char> >(loc);
177 CPPUNIT_ASSERT( has_facet<money_get<char> >(loc) );
178 money_get<char> const& fmg = use_facet<money_get<char> >(loc);
181 ostr.imbue(streamLoc);
184 //Check a positive value (international format)
189 CPPUNIT_ASSERT( (has_facet<moneypunct<char, true> >(loc)) );
190 moneypunct<char, true> const& intl_fmp = use_facet<moneypunct<char, true> >(loc);
192 ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, true, ostr, ' ', 123456);
194 CPPUNIT_ASSERT( !res.failed() );
195 str_res = ostr.str();
197 size_t fieldIndex = 0;
200 //On a positive value we skip the sign field if exists:
201 if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) {
204 // international currency abbreviation, if it is before value
209 * The international currency symbol. The operand is a four-character
210 * string, with the first three characters containing the alphabetic
211 * international currency symbol in accordance with those specified
212 * in the ISO 4217 specification. The fourth character is the character used
213 * to separate the international currency symbol from the monetary quantity.
215 * (http://www.opengroup.org/onlinepubs/7990989775/xbd/locale.html)
217 string::size_type p = strlen( rl.money_int_prefix );
219 CPPUNIT_ASSERT( intl_fmp.pos_format().field[fieldIndex] == money_base::symbol );
220 string::size_type p_old = strlen( rl.money_int_prefix_old );
221 CPPUNIT_ASSERT( (str_res.substr(index, p) == rl.money_int_prefix) ||
222 ((p_old != 0) && (str_res.substr(index, p_old) == rl.money_int_prefix_old)) );
223 if ( str_res.substr(index, p) == rl.money_int_prefix ) {
231 // space after currency
232 if (intl_fmp.pos_format().field[fieldIndex] == money_base::space ||
233 intl_fmp.pos_format().field[fieldIndex] == money_base::none) {
234 // iternational currency symobol has four chars, one of these chars
235 // is separator, so if format has space on this place, it should
241 if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) {
246 CPPUNIT_ASSERT( str_res[index++] == '1' );
247 if (!intl_fmp.grouping().empty()) {
248 CPPUNIT_ASSERT( str_res[index++] == /* intl_fmp.thousands_sep() */ *rl.money_thousands_sep );
250 CPPUNIT_ASSERT( str_res[index++] == '2' );
251 CPPUNIT_ASSERT( str_res[index++] == '3' );
252 CPPUNIT_ASSERT( str_res[index++] == '4' );
253 if (intl_fmp.frac_digits() != 0) {
254 CPPUNIT_ASSERT( str_res[index++] == /* intl_fmp.decimal_point() */ *rl.money_decimal_point );
256 CPPUNIT_ASSERT( str_res[index++] == '5' );
257 CPPUNIT_ASSERT( str_res[index++] == '6' );
261 if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) {
266 if (intl_fmp.pos_format().field[fieldIndex] == money_base::space ) {
267 CPPUNIT_ASSERT( str_res[index++] == ' ' );
272 if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) {
276 //as space cannot be last the only left format can be none:
277 while ( fieldIndex < 3 ) {
278 CPPUNIT_ASSERT( intl_fmp.pos_format().field[fieldIndex] == money_base::none );
285 ios_base::iostate err = ios_base::goodbit;
288 istringstream istr(str_res);
291 fmg.get(istr, istreambuf_iterator<char, char_traits<char> >(), true, ostr, err, digits);
292 CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 );
293 CPPUNIT_ASSERT( digits == "123456" );
298 //Check a negative value (national format)
300 CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) );
301 moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc);
305 ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', -123456);
307 CPPUNIT_ASSERT( !res.failed() );
308 str_res = ostr.str();
310 size_t fieldIndex = 0;
313 if (dom_fmp.neg_format().field[fieldIndex] == money_base::sign) {
314 CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.negative_sign().size()) == dom_fmp.negative_sign() );
315 index += dom_fmp.negative_sign().size();
319 string::size_type p = strlen( rl.money_prefix );
321 CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix );
325 if (dom_fmp.neg_format().field[fieldIndex] == money_base::space ||
326 dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
327 CPPUNIT_ASSERT( str_res[index++] == ' ' );
331 CPPUNIT_ASSERT( str_res[index++] == '1' );
332 if (!dom_fmp.grouping().empty()) {
333 CPPUNIT_ASSERT( str_res[index++] == dom_fmp.thousands_sep() );
335 CPPUNIT_ASSERT( str_res[index++] == '2' );
336 CPPUNIT_ASSERT( str_res[index++] == '3' );
337 CPPUNIT_ASSERT( str_res[index++] == '4' );
338 if (dom_fmp.frac_digits() != 0) {
339 CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() );
341 CPPUNIT_ASSERT( str_res[index++] == '5' );
342 CPPUNIT_ASSERT( str_res[index++] == '6' );
345 //space cannot be last:
346 if ((fieldIndex < 3) &&
347 dom_fmp.neg_format().field[fieldIndex] == money_base::space) {
348 CPPUNIT_ASSERT( str_res[index++] == ' ' );
352 if (fieldIndex == 3) {
353 //If none is last we should not add anything to the resulting string:
354 if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
355 CPPUNIT_ASSERT( index == str_res.size() );
357 CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );
358 CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );
365 ios_base::iostate err = ios_base::goodbit;
366 # if defined (STLPORT)
367 _STLP_LONGEST_FLOAT_TYPE val;
372 istringstream istr(str_res);
373 fmg.get(istr, istreambuf_iterator<char, char_traits<char> >(), false, ostr, err, val);
374 CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 );
375 if (dom_fmp.negative_sign().empty()) {
376 //Without negative sign there is no way to guess the resulting amount sign ("C" locale):
377 CPPUNIT_ASSERT( val == 123456 );
380 CPPUNIT_ASSERT( val == -123456 );
385 //Check a negative value (national format)
387 CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) );
388 moneypunct<char, true> const& dom_fmp = use_facet<moneypunct<char, true> >(loc);
392 ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, true, ostr, ' ', -123456);
394 CPPUNIT_ASSERT( !res.failed() );
395 str_res = ostr.str();
397 size_t fieldIndex = 0;
400 if (dom_fmp.neg_format().field[fieldIndex] == money_base::sign) {
401 CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.negative_sign().size()) == dom_fmp.negative_sign() );
402 index += dom_fmp.negative_sign().size();
406 string::size_type p = strlen( rl.money_prefix );
408 CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix );
412 if (dom_fmp.neg_format().field[fieldIndex] == money_base::space ||
413 dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
414 CPPUNIT_ASSERT( str_res[index++] == ' ' );
418 CPPUNIT_ASSERT( str_res[index++] == '1' );
419 if (!dom_fmp.grouping().empty()) {
420 CPPUNIT_ASSERT( str_res[index++] == dom_fmp.thousands_sep() );
422 CPPUNIT_ASSERT( str_res[index++] == '2' );
423 CPPUNIT_ASSERT( str_res[index++] == '3' );
424 CPPUNIT_ASSERT( str_res[index++] == '4' );
425 if (dom_fmp.frac_digits() != 0) {
426 CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() );
428 CPPUNIT_ASSERT( str_res[index++] == '5' );
429 CPPUNIT_ASSERT( str_res[index++] == '6' );
432 //space cannot be last:
433 if ((fieldIndex < 3) &&
434 dom_fmp.neg_format().field[fieldIndex] == money_base::space) {
435 CPPUNIT_ASSERT( str_res[index++] == ' ' );
439 if (fieldIndex == 3) {
440 //If none is last we should not add anything to the resulting string:
441 if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
442 CPPUNIT_ASSERT( index == str_res.size() );
444 CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );
445 CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );
452 ios_base::iostate err = ios_base::goodbit;
453 # if defined (STLPORT)
454 _STLP_LONGEST_FLOAT_TYPE val;
459 istringstream istr(str_res);
460 fmg.get(istr, istreambuf_iterator<char, char_traits<char> >(), false, ostr, err, val);
461 CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 );
462 if (dom_fmp.negative_sign().empty()) {
463 //Without negative sign there is no way to guess the resulting amount sign ("C" locale):
464 CPPUNIT_ASSERT( val == 123456 );
467 CPPUNIT_ASSERT( val == -123456 );
474 // Test for bug in case when number of digits in value less then number
475 // of digits in fraction. I.e. '9' should be printed as '0.09',
476 // if x.frac_digits() == 2.
478 void LocaleTest::_money_put_X_bug( const locale& loc, const ref_locale& rl )
480 CPPUNIT_ASSERT( has_facet<money_put<char> >(loc) );
481 money_put<char> const& fmp = use_facet<money_put<char> >(loc);
488 // Check value with one decimal digit:
490 CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) );
491 moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc);
495 ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', 9);
497 CPPUNIT_ASSERT( !res.failed() );
498 str_res = ostr.str();
500 size_t fieldIndex = 0;
503 if (dom_fmp.pos_format().field[fieldIndex] == money_base::sign) {
504 CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.positive_sign().size()) == dom_fmp.positive_sign() );
505 index += dom_fmp.positive_sign().size();
509 string::size_type p = strlen( rl.money_prefix );
511 CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix );
515 if (dom_fmp.neg_format().field[fieldIndex] == money_base::space ||
516 dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
517 CPPUNIT_ASSERT( str_res[index++] == ' ' );
520 if (dom_fmp.frac_digits() != 0) {
521 CPPUNIT_ASSERT( str_res[index++] == '0' );
522 CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() );
523 for ( int fd = 1; fd < dom_fmp.frac_digits(); ++fd ) {
524 CPPUNIT_ASSERT( str_res[index++] == '0' );
527 CPPUNIT_ASSERT( str_res[index++] == '9' );
530 //space cannot be last:
531 if ((fieldIndex < 3) &&
532 dom_fmp.neg_format().field[fieldIndex] == money_base::space) {
533 CPPUNIT_ASSERT( str_res[index++] == ' ' );
537 if (fieldIndex == 3) {
538 //If none is last we should not add anything to the resulting string:
539 if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
540 CPPUNIT_ASSERT( index == str_res.size() );
542 CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );
543 CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );
550 // Check value with two decimal digit:
552 CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) );
553 moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc);
557 ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', 90);
559 CPPUNIT_ASSERT( !res.failed() );
560 str_res = ostr.str();
562 size_t fieldIndex = 0;
565 if (dom_fmp.pos_format().field[fieldIndex] == money_base::sign) {
566 CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.positive_sign().size()) == dom_fmp.positive_sign() );
567 index += dom_fmp.positive_sign().size();
571 string::size_type p = strlen( rl.money_prefix );
573 CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix );
577 if (dom_fmp.neg_format().field[fieldIndex] == money_base::space ||
578 dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
579 CPPUNIT_ASSERT( str_res[index++] == ' ' );
582 if (dom_fmp.frac_digits() != 0) {
583 CPPUNIT_ASSERT( str_res[index++] == '0' );
584 CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() );
585 for ( int fd = 1; fd < dom_fmp.frac_digits() - 1; ++fd ) {
586 CPPUNIT_ASSERT( str_res[index++] == '0' );
589 CPPUNIT_ASSERT( str_res[index++] == '9' );
590 if (dom_fmp.frac_digits() != 0) {
591 CPPUNIT_ASSERT( str_res[index++] == '0' );
595 //space cannot be last:
596 if ((fieldIndex < 3) &&
597 dom_fmp.neg_format().field[fieldIndex] == money_base::space) {
598 CPPUNIT_ASSERT( str_res[index++] == ' ' );
602 if (fieldIndex == 3) {
603 //If none is last we should not add anything to the resulting string:
604 if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {
605 CPPUNIT_ASSERT( index == str_res.size() );
607 CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );
608 CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );
615 void LocaleTest::_time_put_get( const locale& loc, const ref_locale&)
617 CPPUNIT_ASSERT( has_facet<time_put<char> >(loc) );
618 const time_put<char>& tmp = use_facet<time_put<char> >(loc);
620 struct tm xmas = { 0, 0, 12, 25, 11, 93 };
623 string format = "%B %d %Y";
625 time_put<char>::iter_type ret = tmp.put(ostr, ostr, ' ', &xmas, format.data(), format.data() + format.size());
626 CPPUNIT_ASSERT( !ret.failed() );
629 * In other words, user conformation is required for reliable parsing
630 * of user-entered dates and times, but machine-generated formats can be
631 * parsed reliably. This allows parsers to be aggressive about interpreting
632 * user variations on standard format.
634 * ISO/IEC 14882, 22.2.5.1
636 CPPUNIT_ASSERT( has_facet<time_get<char> >(loc) );
637 const time_get<char>& tmg = use_facet<time_get<char> >(loc);
638 basic_ios<char> io(0);
641 istringstream istr( ostr.str() );
642 istreambuf_iterator<char, char_traits<char> > i( istr );
643 istreambuf_iterator<char, char_traits<char> > e;
644 ios_base::iostate err = ios_base::goodbit;
645 struct tm other = { 15, 20, 9, 14, 7, 105 };
647 i = tmg.get_monthname( i, e, io, err, &other );
648 CPPUNIT_ASSERT( err == ios_base::goodbit );
649 CPPUNIT_ASSERT( other.tm_mon == xmas.tm_mon );
651 ++i; ++i; ++i; ++i; // skip day of month and spaces around it
652 i = tmg.get_year( i, e, io, err, &other );
654 CPPUNIT_ASSERT( err == ios_base::eofbit );
655 CPPUNIT_ASSERT( other.tm_year == xmas.tm_year );
661 ret = tmp.put(ostrX, ostrX, ' ', &xmas, format.data(), format.data() + format.size());
662 CPPUNIT_ASSERT( !ret.failed() );
664 istringstream istrX( ostrX.str() );
665 istreambuf_iterator<char, char_traits<char> > j( istrX );
667 err = ios_base::goodbit;
669 struct tm yet_more = { 15, 20, 9, 14, 7, 105 };
671 j = tmg.get_date( j, e, io, err, &yet_more );
673 CPPUNIT_ASSERT( err == ios_base::goodbit );
675 CPPUNIT_ASSERT( yet_more.tm_sec != xmas.tm_sec );
676 CPPUNIT_ASSERT( yet_more.tm_min != xmas.tm_min );
677 CPPUNIT_ASSERT( yet_more.tm_hour != xmas.tm_hour );
678 CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday );
679 CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon );
680 CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year );
684 j = tmg.get_time( j, e, io, err, &yet_more );
686 CPPUNIT_ASSERT( err == ios_base::eofbit || err == ios_base::goodbit );
688 CPPUNIT_ASSERT( yet_more.tm_sec == xmas.tm_sec );
689 CPPUNIT_ASSERT( yet_more.tm_min == xmas.tm_min );
690 CPPUNIT_ASSERT( yet_more.tm_hour == xmas.tm_hour );
691 CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday );
692 CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon );
693 CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year );
696 void LocaleTest::_ctype_facet( const locale& loc, const ref_locale&)
698 # if !(defined (__DMC__) && defined (_DLL))
699 CPPUNIT_ASSERT( has_facet<ctype<char> >(loc) );
700 ctype<char> const& ct = use_facet<ctype<char> >(loc);
704 CPPUNIT_ASSERT( ct.is(ctype_base::digit, '0') );
705 CPPUNIT_ASSERT( ct.is(ctype_base::upper, 'A') );
706 CPPUNIT_ASSERT( ct.is(ctype_base::lower, 'a') );
707 CPPUNIT_ASSERT( ct.is(ctype_base::alpha, 'A') );
708 CPPUNIT_ASSERT( ct.is(ctype_base::space, ' ') );
709 CPPUNIT_ASSERT( !ct.is(ctype_base::space, '2') );
710 CPPUNIT_ASSERT( ct.is(ctype_base::punct, '.') );
711 CPPUNIT_ASSERT( ct.is(ctype_base::xdigit, 'a') );
716 char values[] = "0Aa .";
717 ctype_base::mask res[sizeof(values)];
718 ct.is(values, values + sizeof(values), res);
720 CPPUNIT_ASSERT( (res[0] & ctype_base::print) != 0 );
721 CPPUNIT_ASSERT( (res[0] & ctype_base::digit) != 0 );
722 CPPUNIT_ASSERT( (res[0] & ctype_base::xdigit) != 0 );
724 CPPUNIT_ASSERT( (res[1] & ctype_base::print) != 0 );
725 CPPUNIT_ASSERT( (res[1] & ctype_base::alpha) != 0 );
726 CPPUNIT_ASSERT( (res[1] & ctype_base::xdigit) != 0 );
727 CPPUNIT_ASSERT( (res[1] & ctype_base::upper) != 0 );
729 CPPUNIT_ASSERT( (res[2] & ctype_base::print) != 0 );
730 CPPUNIT_ASSERT( (res[2] & ctype_base::alpha) != 0 );
731 CPPUNIT_ASSERT( (res[2] & ctype_base::xdigit) != 0 );
732 CPPUNIT_ASSERT( (res[2] & ctype_base::lower) != 0 );
733 CPPUNIT_ASSERT( (res[2] & ctype_base::space) == 0 );
735 CPPUNIT_ASSERT( (res[3] & ctype_base::print) != 0 );
736 CPPUNIT_ASSERT( (res[3] & ctype_base::space) != 0 );
737 CPPUNIT_ASSERT( (res[3] & ctype_base::digit) == 0 );
739 CPPUNIT_ASSERT( (res[4] & ctype_base::print) != 0 );
740 CPPUNIT_ASSERT( (res[4] & ctype_base::punct) != 0 );
741 CPPUNIT_ASSERT( (res[4] & ctype_base::digit) == 0 );
746 char range[] = "abAc123 .";
747 const char *rbeg = range;
748 const char *rend = range + sizeof(range);
751 res = ct.scan_is((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend);
752 CPPUNIT_ASSERT( res != rend );
753 CPPUNIT_ASSERT( *res == 'a' );
755 res = ct.scan_is(ctype_base::upper, rbeg, rend);
756 CPPUNIT_ASSERT( res != rend );
757 CPPUNIT_ASSERT( *res == 'A' );
759 res = ct.scan_is(ctype_base::punct, rbeg, rend);
760 CPPUNIT_ASSERT( res != rend );
761 CPPUNIT_ASSERT( *res == '.' );
766 char range[] = "abAc123 .";
767 const char *rbeg = range;
768 const char *rend = range + sizeof(range);
771 res = ct.scan_not((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend);
772 CPPUNIT_ASSERT( res != rend );
773 CPPUNIT_ASSERT( *res == '1' );
775 res = ct.scan_not(ctype_base::alpha, rbeg, rend);
776 CPPUNIT_ASSERT( res != rend );
777 CPPUNIT_ASSERT( *res == '1' );
779 res = ct.scan_not(ctype_base::punct, rbeg, rend);
780 CPPUNIT_ASSERT( res != rend );
781 CPPUNIT_ASSERT( *res == 'a' );
786 CPPUNIT_ASSERT( ct.toupper('a') == 'A' );
787 CPPUNIT_ASSERT( ct.toupper('A') == 'A' );
788 CPPUNIT_ASSERT( ct.toupper('1') == '1' );
793 char range[] = "abAc1";
794 char expected_range[] = "ABAC1";
795 ct.toupper(range, range + sizeof(range));
796 CPPUNIT_ASSERT( equal(range, range + sizeof(range), expected_range) );
801 CPPUNIT_ASSERT( ct.tolower('A') == 'a' );
802 CPPUNIT_ASSERT( ct.tolower('a') == 'a' );
803 CPPUNIT_ASSERT( ct.tolower('1') == '1' );
808 char range[] = "ABaC1";
809 char expected_range[] = "abac1";
810 ct.tolower(range, range + sizeof(range));
811 CPPUNIT_ASSERT( equal(range, range + sizeof(range), expected_range) );
816 CPPUNIT_ASSERT( ct.widen('a') == 'a' );
821 char range[] = "ABaC1";
822 char res[sizeof(range)];
823 ct.widen(range, range + sizeof(range), res);
824 CPPUNIT_ASSERT( equal(range, range + sizeof(range), res) );
829 CPPUNIT_ASSERT( ct.narrow('a', 'b') == 'a' );
834 char range[] = "ABaC1";
835 char res[sizeof(range)];
836 ct.narrow(range, range + sizeof(range), 'b', res);
837 CPPUNIT_ASSERT( equal(range, range + sizeof(range), res) );
839 # endif /* __DMC__ */
843 void test_supported_locale(LocaleTest inst, _Tp __test) {
844 size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]);
845 for (size_t i = 0; i < n; ++i) {
846 auto_ptr<locale> loc;
847 # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
849 loc.reset(new locale(tested_locales[i].name));
851 catch (runtime_error const&) {
852 //This locale is not supported.
856 //Without exception support we only test C locale.
857 if (tested_locales[i].name[0] != 'C' ||
858 tested_locales[i].name[1] != 0)
860 loc.reset(new locale(tested_locales[i].name));
862 CPPUNIT_MESSAGE( loc->name().c_str() );
863 (inst.*__test)(*loc, tested_locales[i]);
867 void LocaleTest::locale_by_name() {
868 # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
870 * Check of the 22.1.1.2.7 standard point. Construction of a locale
871 * instance from a null pointer or an unknown name should result in
872 * a runtime_error exception.
875 locale loc(static_cast<char const*>(0));
876 CPPUNIT_ASSERT( false );
878 catch (runtime_error const&) {
881 CPPUNIT_ASSERT( false );
885 locale loc("yasli_language");
886 CPPUNIT_ASSERT( false );
888 catch (runtime_error const&) {
891 CPPUNIT_ASSERT( false );
896 void LocaleTest::loc_has_facet() {
898 typedef numpunct<char> implemented_facet;
899 CPPUNIT_ASSERT( has_facet<implemented_facet>(loc) );
901 typedef num_put<char, back_insert_iterator<string> > not_implemented_facet;
902 CPPUNIT_ASSERT( !has_facet<not_implemented_facet>(loc) );
906 void LocaleTest::num_put_get()
907 { test_supported_locale(*this, &LocaleTest::_num_put_get); }
909 void LocaleTest::money_put_get()
910 { test_supported_locale(*this, &LocaleTest::_money_put_get); }
912 void LocaleTest::money_put_X_bug()
913 { test_supported_locale(*this, &LocaleTest::_money_put_X_bug); }
915 void LocaleTest::time_put_get()
916 { test_supported_locale(*this, &LocaleTest::_time_put_get); }
918 void LocaleTest::collate_facet()
921 CPPUNIT_ASSERT( has_facet<collate<char> >(locale::classic()) );
922 collate<char> const& col = use_facet<collate<char> >(locale::classic());
924 char const str1[] = "abcdef1";
925 char const str2[] = "abcdef2";
926 const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1;
927 const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1;
929 CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 );
930 CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 );
932 //Smallest string should be before largest one:
933 CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 );
934 CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 );
937 # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
939 locale loc("fr_FR.ISO-8859-1");
941 CPPUNIT_ASSERT( has_facet<collate<char> >(loc) );
942 collate<char> const& col = use_facet<collate<char> >(loc);
944 char const str1[] = "abcdef1";
945 char const str2[] = "abcdef2";
946 const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1;
947 const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1;
949 CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 );
950 CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 );
952 //Smallest string should be before largest one:
953 CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 );
954 CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 );
957 CPPUNIT_ASSERT( has_facet<collate<char> >(loc) );
958 collate<char> const& col = use_facet<collate<char> >(loc);
960 string strs[] = {"abdd", "abçd", "abbd", "abcd"};
962 string transformed[4];
963 for (size_t i = 0; i < 4; ++i) {
964 transformed[i] = col.transform(strs[i].data(), strs[i].data() + strs[i].size());
967 sort(strs, strs + 4, loc);
968 // c and ç are considered same when strxfrm() is done on the string
969 CPPUNIT_ASSERT( strs[0] == "abbd" );
970 CPPUNIT_ASSERT( strs[1] == "abçd" );
971 CPPUNIT_ASSERT( strs[2] == "abcd" );
972 CPPUNIT_ASSERT( strs[3] == "abdd" );
974 sort(transformed, transformed + 4);
976 CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + strs[0].size()) == transformed[0] );
977 CPPUNIT_ASSERT( col.transform(strs[1].data(), strs[1].data() + strs[1].size()) == transformed[1] );
978 CPPUNIT_ASSERT( col.transform(strs[2].data(), strs[2].data() + strs[2].size()) == transformed[2] );
979 CPPUNIT_ASSERT( col.transform(strs[3].data(), strs[3].data() + strs[3].size()) == transformed[3] );
981 // Check empty string result in empty key.
982 CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data()).empty() );
984 // Check that only characters that matter are taken into accout to build the key.
985 CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + 2) == col.transform(strs[1].data(), strs[1].data() + 2) );
987 # if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)
989 CPPUNIT_ASSERT( has_facet<collate<wchar_t> >(loc) );
990 collate<wchar_t> const& col = use_facet<collate<wchar_t> >(loc);
992 wchar_t const str1[] = L"abcdef1";
993 wchar_t const str2[] = L"abcdef2";
994 const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1;
995 const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1;
997 CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 );
998 CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 );
1000 //Smallest string should be before largest one:
1001 CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 );
1002 CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 );
1006 CPPUNIT_ASSERT( has_facet<collate<wchar_t> >(loc) );
1007 collate<wchar_t> const& col = use_facet<collate<wchar_t> >(loc);
1009 // Here we would like to use L"abçd" but it looks like all compilers
1010 // do not support storage of unicode characters in exe resulting in
1011 // compilation error. We avoid this test for the moment.
1012 wstring strs[] = {L"abdd", L"abcd", L"abbd", L"abcd"};
1014 wstring transformed[4];
1015 for (i = 0; i < 4; ++i) {
1016 transformed[i] = col.transform(strs[i].data(), strs[i].data() + strs[i].size());
1019 sort(strs, strs + 4, loc);
1020 CPPUNIT_ASSERT( strs[0] == L"abbd" );
1021 CPPUNIT_ASSERT( strs[1] == L"abcd" );
1022 CPPUNIT_ASSERT( strs[2] == L"abcd" );
1023 CPPUNIT_ASSERT( strs[3] == L"abdd" );
1025 sort(transformed, transformed + 4);
1027 CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + strs[0].size()) == transformed[0] );
1028 CPPUNIT_ASSERT( col.transform(strs[1].data(), strs[1].data() + strs[1].size()) == transformed[1] );
1029 CPPUNIT_ASSERT( col.transform(strs[2].data(), strs[2].data() + strs[2].size()) == transformed[2] );
1030 CPPUNIT_ASSERT( col.transform(strs[3].data(), strs[3].data() + strs[3].size()) == transformed[3] );
1032 CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data()).empty() );
1034 CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + 2) == col.transform(strs[1].data(), strs[1].data() + 2) );
1038 catch (runtime_error const&) {
1039 CPPUNIT_MESSAGE("No french locale to check collate facet");
1044 void LocaleTest::ctype_facet()
1045 { test_supported_locale(*this, &LocaleTest::_ctype_facet); }
1047 void LocaleTest::locale_init_problem() {
1048 # if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)
1049 test_supported_locale(*this, &LocaleTest::_locale_init_problem);
1055 * Creation of a locale instance imply initialization of some STLport internal
1056 * static objects first. We use a static instance of locale to check that this
1057 * initialization is done correctly.
1059 static locale global_loc;
1060 static locale other_loc("");
1062 # if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES)
1063 void LocaleTest::_locale_init_problem( const locale& loc, const ref_locale&)
1065 # if !defined (__APPLE__) && !defined (__FreeBSD__) || \
1066 !defined(__GNUC__) || ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__> 3)))
1067 typedef codecvt<char,char,mbstate_t> my_facet;
1069 // std::mbstate_t required for gcc 3.3.2 on FreeBSD...
1070 // I am not sure what key here---FreeBSD or 3.3.2...
1072 typedef codecvt<char,char,std::mbstate_t> my_facet;
1075 # if !(defined (__DMC__) && defined (_DLL))
1076 locale loc_ref(global_loc);
1078 locale gloc( loc_ref, new my_facet() );
1079 CPPUNIT_ASSERT( has_facet<my_facet>( gloc ) );
1080 //The following code is just here to try to confuse the reference counting underlying mecanism:
1081 locale::global( locale::classic() );
1082 locale::global( gloc );
1085 # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
1088 ostringstream os("test") ;
1089 locale loc2( loc, new my_facet() );
1090 CPPUNIT_ASSERT( has_facet<my_facet>( loc2 ) );
1092 # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
1094 catch ( runtime_error& ) {
1095 CPPUNIT_ASSERT( false );
1098 CPPUNIT_ASSERT( false );
1102 # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
1105 ostringstream os2("test2");
1106 # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)
1108 catch ( runtime_error& ) {
1109 CPPUNIT_ASSERT( false );
1112 CPPUNIT_ASSERT( false );
1115 # endif /* __DMC__ */
1119 void LocaleTest::default_locale()
1124 void LocaleTest::facet_id()
1126 #if defined (__SYMBIAN32__NO_STATIC_IMPORTS__) || defined (__SYMBIAN32__WSD__)
1127 # if defined (STLPORT)
1128 locale::id _id_01 = collate<char>::GetFacetLocaleId();
1129 CPPUNIT_CHECK( _id_01._M_index == 1 );
1131 locale::id _id_02 = ctype<char>::GetFacetLocaleId();
1132 CPPUNIT_CHECK( _id_02._M_index == 2 );
1134 # ifndef _STLP_NO_MBSTATE_T
1135 locale::id _id_03 = codecvt<char, char, mbstate_t>::GetFacetLocaleId();
1136 CPPUNIT_CHECK( _id_03._M_index == 3 );
1139 locale::id _id_04 = moneypunct<char, true>::GetFacetLocaleId();
1140 CPPUNIT_CHECK( _id_04._M_index == 4 );
1142 locale::id _id_05 = moneypunct<char, false>::GetFacetLocaleId();
1143 CPPUNIT_CHECK( _id_05._M_index == 5 );
1145 locale::id _id_06 = numpunct<char>::GetFacetLocaleId();
1146 CPPUNIT_CHECK( _id_06._M_index == 6 );
1148 locale::id _id_07 = messages<char>::GetFacetLocaleId();
1149 CPPUNIT_CHECK( _id_07._M_index == 7 );
1151 locale::id _id_08 = money_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
1152 CPPUNIT_CHECK( _id_08._M_index == 8 );
1155 locale::id _id_09 = money_get<char, const char*>::id;
1156 CPPUNIT_CHECK( _id_09._M_index == 9 );
1159 locale::id _id_10 = money_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
1160 CPPUNIT_CHECK( _id_10._M_index == 10 );
1163 locale::id _id_11 = money_put<char, char*>::id;
1164 CPPUNIT_CHECK( _id_11._M_index == 11 );
1167 locale::id _id_12 = num_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
1168 CPPUNIT_CHECK( _id_12._M_index == 12 );
1171 locale::id _id_13 = num_get<char, const char*>::id;
1172 CPPUNIT_CHECK( _id_13._M_index == 13 );
1175 locale::id _id_14 = num_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
1176 CPPUNIT_CHECK( _id_14._M_index == 14 );
1179 locale::id _id_15 = num_put<char, char*>::id;
1180 CPPUNIT_CHECK( _id_15._M_index == 15 );
1183 locale::id _id_16 = time_get<char, istreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
1184 CPPUNIT_CHECK( _id_16._M_index == 16 );
1187 locale::id _id_17 = time_get<char, const char*>::id;
1188 CPPUNIT_CHECK( _id_17._M_index == 17 );
1191 locale::id _id_18 = time_put<char, ostreambuf_iterator<char, char_traits<char> > >::GetFacetLocaleId();
1192 CPPUNIT_CHECK( _id_18._M_index == 18 );
1195 locale::id _id_19 = time_put<char, char*>::id;
1196 CPPUNIT_CHECK( _id_19._M_index == 19 );
1199 # ifndef _STLP_NO_WCHAR_T
1200 locale::id _id_20 = collate<wchar_t>::GetFacetLocaleId();
1201 CPPUNIT_CHECK( _id_20._M_index == 20 );
1203 locale::id _id_21 = ctype<wchar_t>::GetFacetLocaleId();
1204 CPPUNIT_CHECK( _id_21._M_index == 21 );
1206 # ifndef _STLP_NO_MBSTATE_T
1207 locale::id _id_22 = codecvt<wchar_t, char, mbstate_t>::GetFacetLocaleId();
1208 CPPUNIT_CHECK( _id_22._M_index == 22 );
1210 locale::id _id_23 = moneypunct<wchar_t, true>::GetFacetLocaleId();
1211 CPPUNIT_CHECK( _id_23._M_index == 23 );
1213 locale::id _id_24 = moneypunct<wchar_t, false>::GetFacetLocaleId();
1214 CPPUNIT_CHECK( _id_24._M_index == 24 );
1216 locale::id _id_25 = numpunct<wchar_t>::GetFacetLocaleId();
1217 CPPUNIT_CHECK( _id_25._M_index == 25 );
1219 locale::id _id_26 = messages<wchar_t>::GetFacetLocaleId();
1220 CPPUNIT_CHECK( _id_26._M_index == 26 );
1222 locale::id _id_27 = money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
1223 CPPUNIT_CHECK( _id_27._M_index == 27 );
1226 locale::id _id_28 = money_get<wchar_t, const wchar_t*>::id;
1227 CPPUNIT_CHECK( _id_28._M_index == 28 );
1230 locale::id _id_29 = money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
1231 CPPUNIT_CHECK( _id_29._M_index == 29 );
1234 locale::id _id_30 = money_put<wchar_t, wchar_t*>::id;
1235 CPPUNIT_CHECK( _id_30._M_index == 30 );
1238 locale::id _id_31 = num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
1239 CPPUNIT_CHECK( _id_31._M_index == 31 );
1242 locale::id _id_32 = num_get<wchar_t, const wchar_t*>::id;
1243 CPPUNIT_CHECK( _id_32._M_index == 32 );
1246 locale::id _id_33 = num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::GetFacetLocaleId();
1247 CPPUNIT_CHECK( _id_33._M_index == 33 );
1250 locale::id _id_34 = num_put<wchar_t, wchar_t*>::id;
1251 CPPUNIT_CHECK( _id_34._M_index == 34 );
1254 locale::id _id_35 = time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
1255 CPPUNIT_CHECK( _id_35._M_index == 35 );
1258 locale::id _id_36 = time_get<wchar_t, const wchar_t*>::id;
1259 CPPUNIT_CHECK( _id_36._M_index == 36 );
1262 locale::id _id_37 = time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::GetFacetLocaleId();
1263 CPPUNIT_CHECK( _id_37._M_index == 37 );
1266 locale::id _id_38 = time_put<wchar_t, wchar_t*>::id;
1267 CPPUNIT_CHECK( _id_38._M_index == 38 );
1274 # if defined (STLPORT)
1275 locale::id _id_01 = collate<char>::id;
1276 CPPUNIT_CHECK( _id_01._M_index == 1 );
1278 locale::id _id_02 = ctype<char>::id;
1279 CPPUNIT_CHECK( _id_02._M_index == 2 );
1281 # ifndef _STLP_NO_MBSTATE_T
1282 locale::id _id_03 = codecvt<char, char, mbstate_t>::id;
1283 CPPUNIT_CHECK( _id_03._M_index == 3 );
1286 locale::id _id_04 = moneypunct<char, true>::id;
1287 CPPUNIT_CHECK( _id_04._M_index == 4 );
1289 locale::id _id_05 = moneypunct<char, false>::id;
1290 CPPUNIT_CHECK( _id_05._M_index == 5 );
1292 locale::id _id_06 = numpunct<char>::id;
1293 CPPUNIT_CHECK( _id_06._M_index == 6 );
1295 locale::id _id_07 = messages<char>::id;
1296 CPPUNIT_CHECK( _id_07._M_index == 7 );
1298 locale::id _id_08 = money_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
1299 CPPUNIT_CHECK( _id_08._M_index == 8 );
1302 locale::id _id_09 = money_get<char, const char*>::id;
1303 CPPUNIT_CHECK( _id_09._M_index == 9 );
1306 locale::id _id_10 = money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
1307 CPPUNIT_CHECK( _id_10._M_index == 10 );
1310 locale::id _id_11 = money_put<char, char*>::id;
1311 CPPUNIT_CHECK( _id_11._M_index == 11 );
1314 locale::id _id_12 = num_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
1315 CPPUNIT_CHECK( _id_12._M_index == 12 );
1318 locale::id _id_13 = num_get<char, const char*>::id;
1319 CPPUNIT_CHECK( _id_13._M_index == 13 );
1322 locale::id _id_14 = num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
1323 CPPUNIT_CHECK( _id_14._M_index == 14 );
1326 locale::id _id_15 = num_put<char, char*>::id;
1327 CPPUNIT_CHECK( _id_15._M_index == 15 );
1330 locale::id _id_16 = time_get<char, istreambuf_iterator<char, char_traits<char> > >::id;
1331 CPPUNIT_CHECK( _id_16._M_index == 16 );
1334 locale::id _id_17 = time_get<char, const char*>::id;
1335 CPPUNIT_CHECK( _id_17._M_index == 17 );
1338 locale::id _id_18 = time_put<char, ostreambuf_iterator<char, char_traits<char> > >::id;
1339 CPPUNIT_CHECK( _id_18._M_index == 18 );
1342 locale::id _id_19 = time_put<char, char*>::id;
1343 CPPUNIT_CHECK( _id_19._M_index == 19 );
1346 # ifndef _STLP_NO_WCHAR_T
1347 locale::id _id_20 = collate<wchar_t>::id;
1348 CPPUNIT_CHECK( _id_20._M_index == 20 );
1350 locale::id _id_21 = ctype<wchar_t>::id;
1351 CPPUNIT_CHECK( _id_21._M_index == 21 );
1353 # ifndef _STLP_NO_MBSTATE_T
1354 locale::id _id_22 = codecvt<wchar_t, char, mbstate_t>::id;
1355 CPPUNIT_CHECK( _id_22._M_index == 22 );
1357 locale::id _id_23 = moneypunct<wchar_t, true>::id;
1358 CPPUNIT_CHECK( _id_23._M_index == 23 );
1360 locale::id _id_24 = moneypunct<wchar_t, false>::id;
1361 CPPUNIT_CHECK( _id_24._M_index == 24 );
1363 locale::id _id_25 = numpunct<wchar_t>::id;
1364 CPPUNIT_CHECK( _id_25._M_index == 25 );
1366 locale::id _id_26 = messages<wchar_t>::id;
1367 CPPUNIT_CHECK( _id_26._M_index == 26 );
1369 locale::id _id_27 = money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
1370 CPPUNIT_CHECK( _id_27._M_index == 27 );
1373 locale::id _id_28 = money_get<wchar_t, const wchar_t*>::id;
1374 CPPUNIT_CHECK( _id_28._M_index == 28 );
1377 locale::id _id_29 = money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
1378 CPPUNIT_CHECK( _id_29._M_index == 29 );
1381 locale::id _id_30 = money_put<wchar_t, wchar_t*>::id;
1382 CPPUNIT_CHECK( _id_30._M_index == 30 );
1385 locale::id _id_31 = num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
1386 CPPUNIT_CHECK( _id_31._M_index == 31 );
1389 locale::id _id_32 = num_get<wchar_t, const wchar_t*>::id;
1390 CPPUNIT_CHECK( _id_32._M_index == 32 );
1393 locale::id _id_33 = num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id;
1394 CPPUNIT_CHECK( _id_33._M_index == 33 );
1397 locale::id _id_34 = num_put<wchar_t, wchar_t*>::id;
1398 CPPUNIT_CHECK( _id_34._M_index == 34 );
1401 locale::id _id_35 = time_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
1402 CPPUNIT_CHECK( _id_35._M_index == 35 );
1405 locale::id _id_36 = time_get<wchar_t, const wchar_t*>::id;
1406 CPPUNIT_CHECK( _id_36._M_index == 36 );
1409 locale::id _id_37 = time_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id;
1410 CPPUNIT_CHECK( _id_37._M_index == 37 );
1413 locale::id _id_38 = time_put<wchar_t, wchar_t*>::id;
1414 CPPUNIT_CHECK( _id_38._M_index == 38 );
1418 # endif //__WINSCW__
1421 void LocaleTest::combine()
1423 # if (!defined (STLPORT) || \
1424 (defined (_STLP_USE_EXCEPTIONS) && !defined (_STLP_NO_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)))
1425 auto_ptr<locale> loc1, loc2;
1426 size_t loc1_index = 0;
1427 size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]);
1428 for (size_t i = 0; i < n; ++i) {
1430 locale *ploc = new locale(tested_locales[i].name);
1431 if (loc1.get() == 0)
1442 //We can start the test
1444 ostr << "combining '" << loc2->name() << "' money facets with '" << loc1->name() << "'";
1445 CPPUNIT_MESSAGE( ostr.str().c_str() );
1447 //We are going to combine money facets as all formats are different.
1449 //We check that resulting locale has correctly acquire loc2 facets.
1450 locale loc = loc1->combine<moneypunct<char, true> >(*loc2);
1451 loc = loc.combine<moneypunct<char, false> >(*loc2);
1452 loc = loc.combine<money_put<char> >(*loc2);
1453 loc = loc.combine<money_get<char> >(*loc2);
1455 //Check loc has the correct facets:
1456 _money_put_get2(*loc2, loc, tested_locales[i]);
1458 //Check loc1 has not been impacted:
1459 _money_put_get2(*loc1, *loc1, tested_locales[loc1_index]);
1461 //Check loc2 has not been impacted:
1462 _money_put_get2(*loc2, *loc2, tested_locales[i]);
1465 //We check that resulting locale has not wrongly acquire loc1 facets that hasn't been combine:
1466 locale loc = loc2->combine<numpunct<char> >(*loc1);
1467 loc = loc.combine<time_put<char> >(*loc1);
1468 loc = loc.combine<time_get<char> >(*loc1);
1470 //Check loc has the correct facets:
1471 _money_put_get2(*loc2, loc, tested_locales[i]);
1473 //Check loc1 has not been impacted:
1474 _money_put_get2(*loc1, *loc1, tested_locales[loc1_index]);
1476 //Check loc2 has not been impacted:
1477 _money_put_get2(*loc2, *loc2, tested_locales[i]);
1481 // Check auto combination do not result in weird reference counting behavior
1482 // (might generate a crash).
1483 loc1->combine<numpunct<char> >(*loc1);
1486 loc1.reset(loc2.release());
1489 catch (runtime_error const&) {
1490 //This locale is not supported.