sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: */ sl@0: #include sl@0: sl@0: #if !defined (STLPORT) || !defined (_STLP_USE_NO_IOSTREAMS) sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: //# include sl@0: sl@0: # include "cppunit/cppunit_proxy.h" sl@0: sl@0: # if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) sl@0: using namespace std; sl@0: # endif sl@0: sl@0: struct ref_locale { sl@0: const char *name; sl@0: const char *decimal_point; sl@0: const char *thousands_sep; sl@0: const char *money_int_prefix; sl@0: const char *money_int_prefix_old; sl@0: const char *money_prefix; sl@0: const char *money_suffix; sl@0: const char *money_decimal_point; sl@0: const char *money_thousands_sep; sl@0: }; sl@0: sl@0: // Pls, don't write #ifdef _STLP_REAL_LOCALE_IMPLEMENTED here! sl@0: // It undefined in any case!!!!! sl@0: sl@0: static const ref_locale tested_locales[] = { sl@0: //{ name, decimal_point, thousands_sep, money_int_prefix, money_int_prefix_old, money_prefix, money_suffix, money_decimal_point, money_thousands_sep}, sl@0: { "fr_FR", ",", "\xa0", "EUR ", "FRF ", "", "", ",", sl@0: # if defined (WIN32) || defined (_WIN32) sl@0: "\xa0" }, sl@0: # else sl@0: " " }, sl@0: # endif sl@0: { "ru_RU.koi8r", ",", ".", "RUB ", "RUR ", "", "\xd2\xd5\xc2", ".", " " }, sl@0: { "en_GB", ".", ",", "GBP ", "", "\xa3", "", ".", "," }, sl@0: { "en_US", ".", ",", "USD ", "", "$", "", ".", "," }, sl@0: { "C", ".", ",", "", "", "", "", " ", " " }, sl@0: }; sl@0: sl@0: sl@0: // sl@0: // TestCase class sl@0: // sl@0: class LocaleTest : public CPPUNIT_NS::TestCase sl@0: { sl@0: CPPUNIT_TEST_SUITE(LocaleTest); sl@0: # if defined (STLPORT) && !defined (_STLP_USE_EXCEPTIONS) sl@0: CPPUNIT_IGNORE; sl@0: # endif sl@0: CPPUNIT_TEST(locale_by_name); sl@0: CPPUNIT_STOP_IGNORE; sl@0: CPPUNIT_TEST(loc_has_facet); sl@0: CPPUNIT_TEST(num_put_get); sl@0: CPPUNIT_TEST(money_put_get); sl@0: CPPUNIT_TEST(money_put_X_bug); sl@0: CPPUNIT_TEST(time_put_get); sl@0: # if defined (__DMC__) && defined (_DLL) sl@0: CPPUNIT_IGNORE; sl@0: # endif sl@0: CPPUNIT_TEST(collate_facet); sl@0: CPPUNIT_TEST(ctype_facet); sl@0: # if defined (STLPORT) && defined (_STLP_NO_MEMBER_TEMPLATES) sl@0: CPPUNIT_IGNORE; sl@0: # endif sl@0: CPPUNIT_TEST(locale_init_problem); sl@0: CPPUNIT_STOP_IGNORE; sl@0: CPPUNIT_TEST(default_locale); sl@0: # if !defined (STLPORT) sl@0: CPPUNIT_IGNORE; sl@0: # endif sl@0: CPPUNIT_TEST(facet_id); sl@0: CPPUNIT_STOP_IGNORE; sl@0: # if defined (STLPORT) && \ sl@0: (!defined (_STLP_USE_EXCEPTIONS) || defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)) sl@0: CPPUNIT_IGNORE; sl@0: # endif sl@0: CPPUNIT_TEST(combine); sl@0: CPPUNIT_TEST_SUITE_END(); sl@0: sl@0: public: sl@0: void locale_by_name(); sl@0: void loc_has_facet(); sl@0: void num_put_get(); sl@0: void money_put_get(); sl@0: void time_put_get(); sl@0: void collate_facet(); sl@0: void ctype_facet(); sl@0: void locale_init_problem(); sl@0: void money_put_X_bug(); sl@0: void default_locale(); sl@0: void facet_id(); sl@0: void combine(); sl@0: private: sl@0: void _loc_has_facet( const locale&, const ref_locale& ); sl@0: void _num_put_get( const locale&, const ref_locale& ); sl@0: void _money_put_get( const locale&, const ref_locale& ); sl@0: void _money_put_get2( const locale& loc, const locale& streamLoc, const ref_locale& ); sl@0: void _time_put_get( const locale&, const ref_locale& ); sl@0: void _ctype_facet( const locale&, const ref_locale& ); sl@0: void _locale_init_problem( const locale&, const ref_locale& ); sl@0: void _money_put_X_bug( const locale&, const ref_locale& ); sl@0: }; sl@0: sl@0: CPPUNIT_TEST_SUITE_REGISTRATION(LocaleTest); sl@0: sl@0: // sl@0: // tests implementation sl@0: // sl@0: void LocaleTest::_num_put_get( const locale& loc, const ref_locale& rl ) { sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: numpunct const& npct = use_facet >(loc); sl@0: CPPUNIT_ASSERT( npct.decimal_point() == *rl.decimal_point ); sl@0: sl@0: float val = 1234.56f; sl@0: ostringstream fostr; sl@0: fostr.imbue(loc); sl@0: fostr << val; sl@0: sl@0: string ref = "1"; sl@0: if (!npct.grouping().empty()) { sl@0: ref += npct.thousands_sep(); sl@0: } sl@0: ref += "234"; sl@0: ref += npct.decimal_point(); sl@0: ref += "56"; sl@0: //cout << "In " << loc.name() << " 1234.56 is written: " << fostr.str() << endl; sl@0: CPPUNIT_ASSERT( fostr.str() == ref ); sl@0: sl@0: val = 12345678.9f; sl@0: ref = "1"; sl@0: ref += npct.decimal_point(); sl@0: ref += "23457e+07"; sl@0: fostr.str(""); sl@0: fostr << val; sl@0: CPPUNIT_ASSERT( fostr.str() == ref ); sl@0: sl@0: val = 1000000000.0f; sl@0: fostr.str(""); sl@0: fostr << val; sl@0: CPPUNIT_ASSERT( fostr.str() == "1e+09" ); sl@0: sl@0: val = 1234.0f; sl@0: ref = "1"; sl@0: if (!npct.grouping().empty()) { sl@0: ref += npct.thousands_sep(); sl@0: } sl@0: ref += "234"; sl@0: fostr.str(""); sl@0: fostr << val; sl@0: CPPUNIT_ASSERT( fostr.str() == ref ); sl@0: sl@0: val = 10000001.0f; sl@0: fostr.str(""); sl@0: fostr << val; sl@0: CPPUNIT_ASSERT( fostr.str() == "1e+07" ); sl@0: } sl@0: sl@0: void LocaleTest::_money_put_get( const locale& loc, const ref_locale& rl ) sl@0: { sl@0: _money_put_get2(loc, loc, rl); sl@0: } sl@0: sl@0: void LocaleTest::_money_put_get2( const locale& loc, const locale& streamLoc, const ref_locale& rl ) sl@0: { sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: money_put const& fmp = use_facet >(loc); sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: money_get const& fmg = use_facet >(loc); sl@0: sl@0: ostringstream ostr; sl@0: ostr.imbue(streamLoc); sl@0: ostr << showbase; sl@0: sl@0: //Check a positive value (international format) sl@0: { sl@0: string str_res; sl@0: //money_put sl@0: { sl@0: CPPUNIT_ASSERT( (has_facet >(loc)) ); sl@0: moneypunct const& intl_fmp = use_facet >(loc); sl@0: sl@0: ostreambuf_iterator > res = fmp.put(ostr, true, ostr, ' ', 123456); sl@0: sl@0: CPPUNIT_ASSERT( !res.failed() ); sl@0: str_res = ostr.str(); sl@0: sl@0: size_t fieldIndex = 0; sl@0: size_t index = 0; sl@0: sl@0: //On a positive value we skip the sign field if exists: sl@0: if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) { sl@0: ++fieldIndex; sl@0: } sl@0: // international currency abbreviation, if it is before value sl@0: sl@0: /* sl@0: * int_curr_symbol sl@0: * sl@0: * The international currency symbol. The operand is a four-character sl@0: * string, with the first three characters containing the alphabetic sl@0: * international currency symbol in accordance with those specified sl@0: * in the ISO 4217 specification. The fourth character is the character used sl@0: * to separate the international currency symbol from the monetary quantity. sl@0: * sl@0: * (http://www.opengroup.org/onlinepubs/7990989775/xbd/locale.html) sl@0: */ sl@0: string::size_type p = strlen( rl.money_int_prefix ); sl@0: if (p != 0) { sl@0: CPPUNIT_ASSERT( intl_fmp.pos_format().field[fieldIndex] == money_base::symbol ); sl@0: string::size_type p_old = strlen( rl.money_int_prefix_old ); sl@0: CPPUNIT_ASSERT( (str_res.substr(index, p) == rl.money_int_prefix) || sl@0: ((p_old != 0) && (str_res.substr(index, p_old) == rl.money_int_prefix_old)) ); sl@0: if ( str_res.substr(index, p) == rl.money_int_prefix ) { sl@0: index += p; sl@0: } else { sl@0: index += p_old; sl@0: } sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: // space after currency sl@0: if (intl_fmp.pos_format().field[fieldIndex] == money_base::space || sl@0: intl_fmp.pos_format().field[fieldIndex] == money_base::none) { sl@0: // iternational currency symobol has four chars, one of these chars sl@0: // is separator, so if format has space on this place, it should sl@0: // be skipped. sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: // sign sl@0: if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) { sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: // value sl@0: CPPUNIT_ASSERT( str_res[index++] == '1' ); sl@0: if (!intl_fmp.grouping().empty()) { sl@0: CPPUNIT_ASSERT( str_res[index++] == /* intl_fmp.thousands_sep() */ *rl.money_thousands_sep ); sl@0: } sl@0: CPPUNIT_ASSERT( str_res[index++] == '2' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == '3' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == '4' ); sl@0: if (intl_fmp.frac_digits() != 0) { sl@0: CPPUNIT_ASSERT( str_res[index++] == /* intl_fmp.decimal_point() */ *rl.money_decimal_point ); sl@0: } sl@0: CPPUNIT_ASSERT( str_res[index++] == '5' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == '6' ); sl@0: ++fieldIndex; sl@0: sl@0: // sign sl@0: if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) { sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: // space sl@0: if (intl_fmp.pos_format().field[fieldIndex] == money_base::space ) { sl@0: CPPUNIT_ASSERT( str_res[index++] == ' ' ); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: // sign sl@0: if (intl_fmp.pos_format().field[fieldIndex] == money_base::sign) { sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: //as space cannot be last the only left format can be none: sl@0: while ( fieldIndex < 3 ) { sl@0: CPPUNIT_ASSERT( intl_fmp.pos_format().field[fieldIndex] == money_base::none ); sl@0: ++fieldIndex; sl@0: } sl@0: } sl@0: sl@0: //money_get sl@0: { sl@0: ios_base::iostate err = ios_base::goodbit; sl@0: string digits; sl@0: sl@0: istringstream istr(str_res); sl@0: ostr.str( "" ); sl@0: ostr.clear(); sl@0: fmg.get(istr, istreambuf_iterator >(), true, ostr, err, digits); sl@0: CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 ); sl@0: CPPUNIT_ASSERT( digits == "123456" ); sl@0: } sl@0: } sl@0: sl@0: ostr.str(""); sl@0: //Check a negative value (national format) sl@0: { sl@0: CPPUNIT_ASSERT( (has_facet >(loc)) ); sl@0: moneypunct const& dom_fmp = use_facet >(loc); sl@0: string str_res; sl@0: //Check money_put sl@0: { sl@0: ostreambuf_iterator > res = fmp.put(ostr, false, ostr, ' ', -123456); sl@0: sl@0: CPPUNIT_ASSERT( !res.failed() ); sl@0: str_res = ostr.str(); sl@0: sl@0: size_t fieldIndex = 0; sl@0: size_t index = 0; sl@0: sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::sign) { sl@0: CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.negative_sign().size()) == dom_fmp.negative_sign() ); sl@0: index += dom_fmp.negative_sign().size(); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: string::size_type p = strlen( rl.money_prefix ); sl@0: if (p != 0) { sl@0: CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix ); sl@0: index += p; sl@0: ++fieldIndex; sl@0: } sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::space || sl@0: dom_fmp.neg_format().field[fieldIndex] == money_base::none) { sl@0: CPPUNIT_ASSERT( str_res[index++] == ' ' ); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: CPPUNIT_ASSERT( str_res[index++] == '1' ); sl@0: if (!dom_fmp.grouping().empty()) { sl@0: CPPUNIT_ASSERT( str_res[index++] == dom_fmp.thousands_sep() ); sl@0: } sl@0: CPPUNIT_ASSERT( str_res[index++] == '2' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == '3' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == '4' ); sl@0: if (dom_fmp.frac_digits() != 0) { sl@0: CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() ); sl@0: } sl@0: CPPUNIT_ASSERT( str_res[index++] == '5' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == '6' ); sl@0: ++fieldIndex; sl@0: sl@0: //space cannot be last: sl@0: if ((fieldIndex < 3) && sl@0: dom_fmp.neg_format().field[fieldIndex] == money_base::space) { sl@0: CPPUNIT_ASSERT( str_res[index++] == ' ' ); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: if (fieldIndex == 3) { sl@0: //If none is last we should not add anything to the resulting string: sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) { sl@0: CPPUNIT_ASSERT( index == str_res.size() ); sl@0: } else { sl@0: CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol ); sl@0: CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix ); sl@0: } sl@0: } sl@0: } sl@0: sl@0: //money_get sl@0: { sl@0: ios_base::iostate err = ios_base::goodbit; sl@0: # if defined (STLPORT) sl@0: _STLP_LONGEST_FLOAT_TYPE val; sl@0: # else sl@0: long double val; sl@0: # endif sl@0: sl@0: istringstream istr(str_res); sl@0: fmg.get(istr, istreambuf_iterator >(), false, ostr, err, val); sl@0: CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 ); sl@0: if (dom_fmp.negative_sign().empty()) { sl@0: //Without negative sign there is no way to guess the resulting amount sign ("C" locale): sl@0: CPPUNIT_ASSERT( val == 123456 ); sl@0: } sl@0: else { sl@0: CPPUNIT_ASSERT( val == -123456 ); sl@0: } sl@0: } sl@0: } sl@0: ostr.str(""); sl@0: //Check a negative value (national format) sl@0: { sl@0: CPPUNIT_ASSERT( (has_facet >(loc)) ); sl@0: moneypunct const& dom_fmp = use_facet >(loc); sl@0: string str_res; sl@0: //Check money_put sl@0: { sl@0: ostreambuf_iterator > res = fmp.put(ostr, true, ostr, ' ', -123456); sl@0: sl@0: CPPUNIT_ASSERT( !res.failed() ); sl@0: str_res = ostr.str(); sl@0: sl@0: size_t fieldIndex = 0; sl@0: size_t index = 0; sl@0: sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::sign) { sl@0: CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.negative_sign().size()) == dom_fmp.negative_sign() ); sl@0: index += dom_fmp.negative_sign().size(); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: string::size_type p = strlen( rl.money_prefix ); sl@0: if (p != 0) { sl@0: CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix ); sl@0: index += p; sl@0: ++fieldIndex; sl@0: } sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::space || sl@0: dom_fmp.neg_format().field[fieldIndex] == money_base::none) { sl@0: CPPUNIT_ASSERT( str_res[index++] == ' ' ); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: CPPUNIT_ASSERT( str_res[index++] == '1' ); sl@0: if (!dom_fmp.grouping().empty()) { sl@0: CPPUNIT_ASSERT( str_res[index++] == dom_fmp.thousands_sep() ); sl@0: } sl@0: CPPUNIT_ASSERT( str_res[index++] == '2' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == '3' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == '4' ); sl@0: if (dom_fmp.frac_digits() != 0) { sl@0: CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() ); sl@0: } sl@0: CPPUNIT_ASSERT( str_res[index++] == '5' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == '6' ); sl@0: ++fieldIndex; sl@0: sl@0: //space cannot be last: sl@0: if ((fieldIndex < 3) && sl@0: dom_fmp.neg_format().field[fieldIndex] == money_base::space) { sl@0: CPPUNIT_ASSERT( str_res[index++] == ' ' ); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: if (fieldIndex == 3) { sl@0: //If none is last we should not add anything to the resulting string: sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) { sl@0: CPPUNIT_ASSERT( index == str_res.size() ); sl@0: } else { sl@0: CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol ); sl@0: CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix ); sl@0: } sl@0: } sl@0: } sl@0: sl@0: //money_get sl@0: { sl@0: ios_base::iostate err = ios_base::goodbit; sl@0: # if defined (STLPORT) sl@0: _STLP_LONGEST_FLOAT_TYPE val; sl@0: # else sl@0: long double val; sl@0: # endif sl@0: sl@0: istringstream istr(str_res); sl@0: fmg.get(istr, istreambuf_iterator >(), false, ostr, err, val); sl@0: CPPUNIT_ASSERT( (err & (ios_base::failbit | ios_base::badbit)) == 0 ); sl@0: if (dom_fmp.negative_sign().empty()) { sl@0: //Without negative sign there is no way to guess the resulting amount sign ("C" locale): sl@0: CPPUNIT_ASSERT( val == 123456 ); sl@0: } sl@0: else { sl@0: CPPUNIT_ASSERT( val == -123456 ); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: // Test for bug in case when number of digits in value less then number sl@0: // of digits in fraction. I.e. '9' should be printed as '0.09', sl@0: // if x.frac_digits() == 2. sl@0: sl@0: void LocaleTest::_money_put_X_bug( const locale& loc, const ref_locale& rl ) sl@0: { sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: money_put const& fmp = use_facet >(loc); sl@0: sl@0: ostringstream ostr; sl@0: ostr.imbue(loc); sl@0: ostr << showbase; sl@0: sl@0: // ostr.str(""); sl@0: // Check value with one decimal digit: sl@0: { sl@0: CPPUNIT_ASSERT( (has_facet >(loc)) ); sl@0: moneypunct const& dom_fmp = use_facet >(loc); sl@0: string str_res; sl@0: // Check money_put sl@0: { sl@0: ostreambuf_iterator > res = fmp.put(ostr, false, ostr, ' ', 9); sl@0: sl@0: CPPUNIT_ASSERT( !res.failed() ); sl@0: str_res = ostr.str(); sl@0: sl@0: size_t fieldIndex = 0; sl@0: size_t index = 0; sl@0: sl@0: if (dom_fmp.pos_format().field[fieldIndex] == money_base::sign) { sl@0: CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.positive_sign().size()) == dom_fmp.positive_sign() ); sl@0: index += dom_fmp.positive_sign().size(); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: string::size_type p = strlen( rl.money_prefix ); sl@0: if (p != 0) { sl@0: CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix ); sl@0: index += p; sl@0: ++fieldIndex; sl@0: } sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::space || sl@0: dom_fmp.neg_format().field[fieldIndex] == money_base::none) { sl@0: CPPUNIT_ASSERT( str_res[index++] == ' ' ); sl@0: ++fieldIndex; sl@0: } sl@0: if (dom_fmp.frac_digits() != 0) { sl@0: CPPUNIT_ASSERT( str_res[index++] == '0' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() ); sl@0: for ( int fd = 1; fd < dom_fmp.frac_digits(); ++fd ) { sl@0: CPPUNIT_ASSERT( str_res[index++] == '0' ); sl@0: } sl@0: } sl@0: CPPUNIT_ASSERT( str_res[index++] == '9' ); sl@0: ++fieldIndex; sl@0: sl@0: //space cannot be last: sl@0: if ((fieldIndex < 3) && sl@0: dom_fmp.neg_format().field[fieldIndex] == money_base::space) { sl@0: CPPUNIT_ASSERT( str_res[index++] == ' ' ); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: if (fieldIndex == 3) { sl@0: //If none is last we should not add anything to the resulting string: sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) { sl@0: CPPUNIT_ASSERT( index == str_res.size() ); sl@0: } else { sl@0: CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol ); sl@0: CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix ); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: ostr.str(""); sl@0: // Check value with two decimal digit: sl@0: { sl@0: CPPUNIT_ASSERT( (has_facet >(loc)) ); sl@0: moneypunct const& dom_fmp = use_facet >(loc); sl@0: string str_res; sl@0: // Check money_put sl@0: { sl@0: ostreambuf_iterator > res = fmp.put(ostr, false, ostr, ' ', 90); sl@0: sl@0: CPPUNIT_ASSERT( !res.failed() ); sl@0: str_res = ostr.str(); sl@0: sl@0: size_t fieldIndex = 0; sl@0: size_t index = 0; sl@0: sl@0: if (dom_fmp.pos_format().field[fieldIndex] == money_base::sign) { sl@0: CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.positive_sign().size()) == dom_fmp.positive_sign() ); sl@0: index += dom_fmp.positive_sign().size(); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: string::size_type p = strlen( rl.money_prefix ); sl@0: if (p != 0) { sl@0: CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix ); sl@0: index += p; sl@0: ++fieldIndex; sl@0: } sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::space || sl@0: dom_fmp.neg_format().field[fieldIndex] == money_base::none) { sl@0: CPPUNIT_ASSERT( str_res[index++] == ' ' ); sl@0: ++fieldIndex; sl@0: } sl@0: if (dom_fmp.frac_digits() != 0) { sl@0: CPPUNIT_ASSERT( str_res[index++] == '0' ); sl@0: CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() ); sl@0: for ( int fd = 1; fd < dom_fmp.frac_digits() - 1; ++fd ) { sl@0: CPPUNIT_ASSERT( str_res[index++] == '0' ); sl@0: } sl@0: } sl@0: CPPUNIT_ASSERT( str_res[index++] == '9' ); sl@0: if (dom_fmp.frac_digits() != 0) { sl@0: CPPUNIT_ASSERT( str_res[index++] == '0' ); sl@0: } sl@0: ++fieldIndex; sl@0: sl@0: //space cannot be last: sl@0: if ((fieldIndex < 3) && sl@0: dom_fmp.neg_format().field[fieldIndex] == money_base::space) { sl@0: CPPUNIT_ASSERT( str_res[index++] == ' ' ); sl@0: ++fieldIndex; sl@0: } sl@0: sl@0: if (fieldIndex == 3) { sl@0: //If none is last we should not add anything to the resulting string: sl@0: if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) { sl@0: CPPUNIT_ASSERT( index == str_res.size() ); sl@0: } else { sl@0: CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol ); sl@0: CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix ); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void LocaleTest::_time_put_get( const locale& loc, const ref_locale&) sl@0: { sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: const time_put& tmp = use_facet >(loc); sl@0: sl@0: struct tm xmas = { 0, 0, 12, 25, 11, 93 }; sl@0: ostringstream ostr; sl@0: ostr.imbue(loc); sl@0: string format = "%B %d %Y"; sl@0: sl@0: time_put::iter_type ret = tmp.put(ostr, ostr, ' ', &xmas, format.data(), format.data() + format.size()); sl@0: CPPUNIT_ASSERT( !ret.failed() ); sl@0: sl@0: /* sl@0: * In other words, user conformation is required for reliable parsing sl@0: * of user-entered dates and times, but machine-generated formats can be sl@0: * parsed reliably. This allows parsers to be aggressive about interpreting sl@0: * user variations on standard format. sl@0: * sl@0: * ISO/IEC 14882, 22.2.5.1 sl@0: */ sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: const time_get& tmg = use_facet >(loc); sl@0: basic_ios io(0); sl@0: io.imbue(loc); sl@0: sl@0: istringstream istr( ostr.str() ); sl@0: istreambuf_iterator > i( istr ); sl@0: istreambuf_iterator > e; sl@0: ios_base::iostate err = ios_base::goodbit; sl@0: struct tm other = { 15, 20, 9, 14, 7, 105 }; sl@0: sl@0: i = tmg.get_monthname( i, e, io, err, &other ); sl@0: CPPUNIT_ASSERT( err == ios_base::goodbit ); sl@0: CPPUNIT_ASSERT( other.tm_mon == xmas.tm_mon ); sl@0: sl@0: ++i; ++i; ++i; ++i; // skip day of month and spaces around it sl@0: i = tmg.get_year( i, e, io, err, &other ); sl@0: sl@0: CPPUNIT_ASSERT( err == ios_base::eofbit ); sl@0: CPPUNIT_ASSERT( other.tm_year == xmas.tm_year ); sl@0: sl@0: ostringstream ostrX; sl@0: ostrX.imbue(loc); sl@0: format = "%x %X"; sl@0: sl@0: ret = tmp.put(ostrX, ostrX, ' ', &xmas, format.data(), format.data() + format.size()); sl@0: CPPUNIT_ASSERT( !ret.failed() ); sl@0: sl@0: istringstream istrX( ostrX.str() ); sl@0: istreambuf_iterator > j( istrX ); sl@0: sl@0: err = ios_base::goodbit; sl@0: sl@0: struct tm yet_more = { 15, 20, 9, 14, 7, 105 }; sl@0: sl@0: j = tmg.get_date( j, e, io, err, &yet_more ); sl@0: sl@0: CPPUNIT_ASSERT( err == ios_base::goodbit ); sl@0: sl@0: CPPUNIT_ASSERT( yet_more.tm_sec != xmas.tm_sec ); sl@0: CPPUNIT_ASSERT( yet_more.tm_min != xmas.tm_min ); sl@0: CPPUNIT_ASSERT( yet_more.tm_hour != xmas.tm_hour ); sl@0: CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday ); sl@0: CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon ); sl@0: CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year ); sl@0: sl@0: ++j; // skip space sl@0: sl@0: j = tmg.get_time( j, e, io, err, &yet_more ); sl@0: sl@0: CPPUNIT_ASSERT( err == ios_base::eofbit || err == ios_base::goodbit ); sl@0: sl@0: CPPUNIT_ASSERT( yet_more.tm_sec == xmas.tm_sec ); sl@0: CPPUNIT_ASSERT( yet_more.tm_min == xmas.tm_min ); sl@0: CPPUNIT_ASSERT( yet_more.tm_hour == xmas.tm_hour ); sl@0: CPPUNIT_ASSERT( yet_more.tm_mday == xmas.tm_mday ); sl@0: CPPUNIT_ASSERT( yet_more.tm_mon == xmas.tm_mon ); sl@0: CPPUNIT_ASSERT( yet_more.tm_year == xmas.tm_year ); sl@0: } sl@0: sl@0: void LocaleTest::_ctype_facet( const locale& loc, const ref_locale&) sl@0: { sl@0: # if !(defined (__DMC__) && defined (_DLL)) sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: ctype const& ct = use_facet >(loc); sl@0: sl@0: //is sl@0: { sl@0: CPPUNIT_ASSERT( ct.is(ctype_base::digit, '0') ); sl@0: CPPUNIT_ASSERT( ct.is(ctype_base::upper, 'A') ); sl@0: CPPUNIT_ASSERT( ct.is(ctype_base::lower, 'a') ); sl@0: CPPUNIT_ASSERT( ct.is(ctype_base::alpha, 'A') ); sl@0: CPPUNIT_ASSERT( ct.is(ctype_base::space, ' ') ); sl@0: CPPUNIT_ASSERT( !ct.is(ctype_base::space, '2') ); sl@0: CPPUNIT_ASSERT( ct.is(ctype_base::punct, '.') ); sl@0: CPPUNIT_ASSERT( ct.is(ctype_base::xdigit, 'a') ); sl@0: } sl@0: sl@0: //is range sl@0: { sl@0: char values[] = "0Aa ."; sl@0: ctype_base::mask res[sizeof(values)]; sl@0: ct.is(values, values + sizeof(values), res); sl@0: // '0' sl@0: CPPUNIT_ASSERT( (res[0] & ctype_base::print) != 0 ); sl@0: CPPUNIT_ASSERT( (res[0] & ctype_base::digit) != 0 ); sl@0: CPPUNIT_ASSERT( (res[0] & ctype_base::xdigit) != 0 ); sl@0: // 'A' sl@0: CPPUNIT_ASSERT( (res[1] & ctype_base::print) != 0 ); sl@0: CPPUNIT_ASSERT( (res[1] & ctype_base::alpha) != 0 ); sl@0: CPPUNIT_ASSERT( (res[1] & ctype_base::xdigit) != 0 ); sl@0: CPPUNIT_ASSERT( (res[1] & ctype_base::upper) != 0 ); sl@0: // 'a' sl@0: CPPUNIT_ASSERT( (res[2] & ctype_base::print) != 0 ); sl@0: CPPUNIT_ASSERT( (res[2] & ctype_base::alpha) != 0 ); sl@0: CPPUNIT_ASSERT( (res[2] & ctype_base::xdigit) != 0 ); sl@0: CPPUNIT_ASSERT( (res[2] & ctype_base::lower) != 0 ); sl@0: CPPUNIT_ASSERT( (res[2] & ctype_base::space) == 0 ); sl@0: // ' ' sl@0: CPPUNIT_ASSERT( (res[3] & ctype_base::print) != 0 ); sl@0: CPPUNIT_ASSERT( (res[3] & ctype_base::space) != 0 ); sl@0: CPPUNIT_ASSERT( (res[3] & ctype_base::digit) == 0 ); sl@0: // '.' sl@0: CPPUNIT_ASSERT( (res[4] & ctype_base::print) != 0 ); sl@0: CPPUNIT_ASSERT( (res[4] & ctype_base::punct) != 0 ); sl@0: CPPUNIT_ASSERT( (res[4] & ctype_base::digit) == 0 ); sl@0: } sl@0: sl@0: //scan_is sl@0: { sl@0: char range[] = "abAc123 ."; sl@0: const char *rbeg = range; sl@0: const char *rend = range + sizeof(range); sl@0: sl@0: const char *res; sl@0: res = ct.scan_is((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend); sl@0: CPPUNIT_ASSERT( res != rend ); sl@0: CPPUNIT_ASSERT( *res == 'a' ); sl@0: sl@0: res = ct.scan_is(ctype_base::upper, rbeg, rend); sl@0: CPPUNIT_ASSERT( res != rend ); sl@0: CPPUNIT_ASSERT( *res == 'A' ); sl@0: sl@0: res = ct.scan_is(ctype_base::punct, rbeg, rend); sl@0: CPPUNIT_ASSERT( res != rend ); sl@0: CPPUNIT_ASSERT( *res == '.' ); sl@0: } sl@0: sl@0: //scan_not sl@0: { sl@0: char range[] = "abAc123 ."; sl@0: const char *rbeg = range; sl@0: const char *rend = range + sizeof(range); sl@0: sl@0: const char *res; sl@0: res = ct.scan_not((ctype_base::mask)(ctype_base::alpha | ctype_base::lower), rbeg, rend); sl@0: CPPUNIT_ASSERT( res != rend ); sl@0: CPPUNIT_ASSERT( *res == '1' ); sl@0: sl@0: res = ct.scan_not(ctype_base::alpha, rbeg, rend); sl@0: CPPUNIT_ASSERT( res != rend ); sl@0: CPPUNIT_ASSERT( *res == '1' ); sl@0: sl@0: res = ct.scan_not(ctype_base::punct, rbeg, rend); sl@0: CPPUNIT_ASSERT( res != rend ); sl@0: CPPUNIT_ASSERT( *res == 'a' ); sl@0: } sl@0: sl@0: //toupper sl@0: { sl@0: CPPUNIT_ASSERT( ct.toupper('a') == 'A' ); sl@0: CPPUNIT_ASSERT( ct.toupper('A') == 'A' ); sl@0: CPPUNIT_ASSERT( ct.toupper('1') == '1' ); sl@0: } sl@0: sl@0: //toupper range sl@0: { sl@0: char range[] = "abAc1"; sl@0: char expected_range[] = "ABAC1"; sl@0: ct.toupper(range, range + sizeof(range)); sl@0: CPPUNIT_ASSERT( equal(range, range + sizeof(range), expected_range) ); sl@0: } sl@0: sl@0: //tolower sl@0: { sl@0: CPPUNIT_ASSERT( ct.tolower('A') == 'a' ); sl@0: CPPUNIT_ASSERT( ct.tolower('a') == 'a' ); sl@0: CPPUNIT_ASSERT( ct.tolower('1') == '1' ); sl@0: } sl@0: sl@0: //tolower range sl@0: { sl@0: char range[] = "ABaC1"; sl@0: char expected_range[] = "abac1"; sl@0: ct.tolower(range, range + sizeof(range)); sl@0: CPPUNIT_ASSERT( equal(range, range + sizeof(range), expected_range) ); sl@0: } sl@0: sl@0: //widen sl@0: { sl@0: CPPUNIT_ASSERT( ct.widen('a') == 'a' ); sl@0: } sl@0: sl@0: //widen range sl@0: { sl@0: char range[] = "ABaC1"; sl@0: char res[sizeof(range)]; sl@0: ct.widen(range, range + sizeof(range), res); sl@0: CPPUNIT_ASSERT( equal(range, range + sizeof(range), res) ); sl@0: } sl@0: sl@0: //narrow sl@0: { sl@0: CPPUNIT_ASSERT( ct.narrow('a', 'b') == 'a' ); sl@0: } sl@0: sl@0: //narrow range sl@0: { sl@0: char range[] = "ABaC1"; sl@0: char res[sizeof(range)]; sl@0: ct.narrow(range, range + sizeof(range), 'b', res); sl@0: CPPUNIT_ASSERT( equal(range, range + sizeof(range), res) ); sl@0: } sl@0: # endif /* __DMC__ */ sl@0: } sl@0: sl@0: template sl@0: void test_supported_locale(LocaleTest inst, _Tp __test) { sl@0: size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]); sl@0: for (size_t i = 0; i < n; ++i) { sl@0: auto_ptr loc; sl@0: # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) sl@0: try { sl@0: loc.reset(new locale(tested_locales[i].name)); sl@0: } sl@0: catch (runtime_error const&) { sl@0: //This locale is not supported. sl@0: continue; sl@0: } sl@0: # else sl@0: //Without exception support we only test C locale. sl@0: if (tested_locales[i].name[0] != 'C' || sl@0: tested_locales[i].name[1] != 0) sl@0: continue; sl@0: loc.reset(new locale(tested_locales[i].name)); sl@0: # endif sl@0: CPPUNIT_MESSAGE( loc->name().c_str() ); sl@0: (inst.*__test)(*loc, tested_locales[i]); sl@0: } sl@0: } sl@0: sl@0: void LocaleTest::locale_by_name() { sl@0: # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) sl@0: /* sl@0: * Check of the 22.1.1.2.7 standard point. Construction of a locale sl@0: * instance from a null pointer or an unknown name should result in sl@0: * a runtime_error exception. sl@0: */ sl@0: try { sl@0: locale loc(static_cast(0)); sl@0: CPPUNIT_ASSERT( false ); sl@0: } sl@0: catch (runtime_error const&) { sl@0: } sl@0: catch (...) { sl@0: CPPUNIT_ASSERT( false ); sl@0: } sl@0: sl@0: try { sl@0: locale loc("yasli_language"); sl@0: CPPUNIT_ASSERT( false ); sl@0: } sl@0: catch (runtime_error const&) { sl@0: } sl@0: catch (...) { sl@0: CPPUNIT_ASSERT( false ); sl@0: } sl@0: # endif sl@0: } sl@0: sl@0: void LocaleTest::loc_has_facet() { sl@0: locale loc("C"); sl@0: typedef numpunct implemented_facet; sl@0: CPPUNIT_ASSERT( has_facet(loc) ); sl@0: /* sl@0: typedef num_put > not_implemented_facet; sl@0: CPPUNIT_ASSERT( !has_facet(loc) ); sl@0: */ sl@0: } sl@0: sl@0: void LocaleTest::num_put_get() sl@0: { test_supported_locale(*this, &LocaleTest::_num_put_get); } sl@0: sl@0: void LocaleTest::money_put_get() sl@0: { test_supported_locale(*this, &LocaleTest::_money_put_get); } sl@0: sl@0: void LocaleTest::money_put_X_bug() sl@0: { test_supported_locale(*this, &LocaleTest::_money_put_X_bug); } sl@0: sl@0: void LocaleTest::time_put_get() sl@0: { test_supported_locale(*this, &LocaleTest::_time_put_get); } sl@0: sl@0: void LocaleTest::collate_facet() sl@0: { sl@0: { sl@0: CPPUNIT_ASSERT( has_facet >(locale::classic()) ); sl@0: collate const& col = use_facet >(locale::classic()); sl@0: sl@0: char const str1[] = "abcdef1"; sl@0: char const str2[] = "abcdef2"; sl@0: const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1; sl@0: const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1; sl@0: sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 ); sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 ); sl@0: sl@0: //Smallest string should be before largest one: sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 ); sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 ); sl@0: } sl@0: sl@0: # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) sl@0: try { sl@0: locale loc("fr_FR.ISO-8859-1"); sl@0: { sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: collate const& col = use_facet >(loc); sl@0: sl@0: char const str1[] = "abcdef1"; sl@0: char const str2[] = "abcdef2"; sl@0: const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1; sl@0: const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1; sl@0: sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 ); sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 ); sl@0: sl@0: //Smallest string should be before largest one: sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 ); sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 ); sl@0: } sl@0: { sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: collate const& col = use_facet >(loc); sl@0: sl@0: string strs[] = {"abdd", "abçd", "abbd", "abcd"}; sl@0: sl@0: string transformed[4]; sl@0: for (size_t i = 0; i < 4; ++i) { sl@0: transformed[i] = col.transform(strs[i].data(), strs[i].data() + strs[i].size()); sl@0: } sl@0: sl@0: sort(strs, strs + 4, loc); sl@0: // c and ç are considered same when strxfrm() is done on the string sl@0: CPPUNIT_ASSERT( strs[0] == "abbd" ); sl@0: CPPUNIT_ASSERT( strs[1] == "abçd" ); sl@0: CPPUNIT_ASSERT( strs[2] == "abcd" ); sl@0: CPPUNIT_ASSERT( strs[3] == "abdd" ); sl@0: sl@0: sort(transformed, transformed + 4); sl@0: sl@0: CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + strs[0].size()) == transformed[0] ); sl@0: CPPUNIT_ASSERT( col.transform(strs[1].data(), strs[1].data() + strs[1].size()) == transformed[1] ); sl@0: CPPUNIT_ASSERT( col.transform(strs[2].data(), strs[2].data() + strs[2].size()) == transformed[2] ); sl@0: CPPUNIT_ASSERT( col.transform(strs[3].data(), strs[3].data() + strs[3].size()) == transformed[3] ); sl@0: sl@0: // Check empty string result in empty key. sl@0: CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data()).empty() ); sl@0: sl@0: // Check that only characters that matter are taken into accout to build the key. sl@0: CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + 2) == col.transform(strs[1].data(), strs[1].data() + 2) ); sl@0: } sl@0: # if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T) sl@0: { sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: collate const& col = use_facet >(loc); sl@0: sl@0: wchar_t const str1[] = L"abcdef1"; sl@0: wchar_t const str2[] = L"abcdef2"; sl@0: const size_t size1 = sizeof(str1) / sizeof(str1[0]) - 1; sl@0: const size_t size2 = sizeof(str2) / sizeof(str2[0]) - 1; sl@0: sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 1) == 0 ); sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1, str2, str2 + size2) == -1 ); sl@0: sl@0: //Smallest string should be before largest one: sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 2, str2, str2 + size2 - 1) == -1 ); sl@0: CPPUNIT_ASSERT( col.compare(str1, str1 + size1 - 1, str2, str2 + size2 - 2) == 1 ); sl@0: } sl@0: { sl@0: size_t i; sl@0: CPPUNIT_ASSERT( has_facet >(loc) ); sl@0: collate const& col = use_facet >(loc); sl@0: sl@0: // Here we would like to use L"abçd" but it looks like all compilers sl@0: // do not support storage of unicode characters in exe resulting in sl@0: // compilation error. We avoid this test for the moment. sl@0: wstring strs[] = {L"abdd", L"abcd", L"abbd", L"abcd"}; sl@0: sl@0: wstring transformed[4]; sl@0: for (i = 0; i < 4; ++i) { sl@0: transformed[i] = col.transform(strs[i].data(), strs[i].data() + strs[i].size()); sl@0: } sl@0: sl@0: sort(strs, strs + 4, loc); sl@0: CPPUNIT_ASSERT( strs[0] == L"abbd" ); sl@0: CPPUNIT_ASSERT( strs[1] == L"abcd" ); sl@0: CPPUNIT_ASSERT( strs[2] == L"abcd" ); sl@0: CPPUNIT_ASSERT( strs[3] == L"abdd" ); sl@0: sl@0: sort(transformed, transformed + 4); sl@0: sl@0: CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + strs[0].size()) == transformed[0] ); sl@0: CPPUNIT_ASSERT( col.transform(strs[1].data(), strs[1].data() + strs[1].size()) == transformed[1] ); sl@0: CPPUNIT_ASSERT( col.transform(strs[2].data(), strs[2].data() + strs[2].size()) == transformed[2] ); sl@0: CPPUNIT_ASSERT( col.transform(strs[3].data(), strs[3].data() + strs[3].size()) == transformed[3] ); sl@0: sl@0: CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data()).empty() ); sl@0: sl@0: CPPUNIT_ASSERT( col.transform(strs[0].data(), strs[0].data() + 2) == col.transform(strs[1].data(), strs[1].data() + 2) ); sl@0: } sl@0: # endif sl@0: } sl@0: catch (runtime_error const&) { sl@0: CPPUNIT_MESSAGE("No french locale to check collate facet"); sl@0: } sl@0: # endif sl@0: } sl@0: sl@0: void LocaleTest::ctype_facet() sl@0: { test_supported_locale(*this, &LocaleTest::_ctype_facet); } sl@0: sl@0: void LocaleTest::locale_init_problem() { sl@0: # if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) sl@0: test_supported_locale(*this, &LocaleTest::_locale_init_problem); sl@0: # endif sl@0: } sl@0: sl@0: sl@0: /* sl@0: * Creation of a locale instance imply initialization of some STLport internal sl@0: * static objects first. We use a static instance of locale to check that this sl@0: * initialization is done correctly. sl@0: */ sl@0: static locale global_loc; sl@0: static locale other_loc(""); sl@0: sl@0: # if !defined (STLPORT) || !defined (_STLP_NO_MEMBER_TEMPLATES) sl@0: void LocaleTest::_locale_init_problem( const locale& loc, const ref_locale&) sl@0: { sl@0: # if !defined (__APPLE__) && !defined (__FreeBSD__) || \ sl@0: !defined(__GNUC__) || ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__> 3))) sl@0: typedef codecvt my_facet; sl@0: # else sl@0: // std::mbstate_t required for gcc 3.3.2 on FreeBSD... sl@0: // I am not sure what key here---FreeBSD or 3.3.2... sl@0: // - ptr 2005-04-04 sl@0: typedef codecvt my_facet; sl@0: # endif sl@0: sl@0: # if !(defined (__DMC__) && defined (_DLL)) sl@0: locale loc_ref(global_loc); sl@0: { sl@0: locale gloc( loc_ref, new my_facet() ); sl@0: CPPUNIT_ASSERT( has_facet( gloc ) ); sl@0: //The following code is just here to try to confuse the reference counting underlying mecanism: sl@0: locale::global( locale::classic() ); sl@0: locale::global( gloc ); sl@0: } sl@0: sl@0: # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) sl@0: try { sl@0: # endif sl@0: ostringstream os("test") ; sl@0: locale loc2( loc, new my_facet() ); sl@0: CPPUNIT_ASSERT( has_facet( loc2 ) ); sl@0: os.imbue( loc2 ); sl@0: # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) sl@0: } sl@0: catch ( runtime_error& ) { sl@0: CPPUNIT_ASSERT( false ); sl@0: } sl@0: catch ( ... ) { sl@0: CPPUNIT_ASSERT( false ); sl@0: } sl@0: # endif sl@0: sl@0: # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) sl@0: try { sl@0: # endif sl@0: ostringstream os2("test2"); sl@0: # if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS) sl@0: } sl@0: catch ( runtime_error& ) { sl@0: CPPUNIT_ASSERT( false ); sl@0: } sl@0: catch ( ... ) { sl@0: CPPUNIT_ASSERT( false ); sl@0: } sl@0: # endif sl@0: # endif /* __DMC__ */ sl@0: } sl@0: # endif sl@0: sl@0: void LocaleTest::default_locale() sl@0: { sl@0: locale loc( "" ); sl@0: } sl@0: sl@0: void LocaleTest::facet_id() sl@0: { sl@0: #if defined (__SYMBIAN32__NO_STATIC_IMPORTS__) || defined (__SYMBIAN32__WSD__) sl@0: # if defined (STLPORT) sl@0: locale::id _id_01 = collate::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_01._M_index == 1 ); sl@0: sl@0: locale::id _id_02 = ctype::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_02._M_index == 2 ); sl@0: sl@0: # ifndef _STLP_NO_MBSTATE_T sl@0: locale::id _id_03 = codecvt::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_03._M_index == 3 ); sl@0: # endif sl@0: sl@0: locale::id _id_04 = moneypunct::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_04._M_index == 4 ); sl@0: sl@0: locale::id _id_05 = moneypunct::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_05._M_index == 5 ); sl@0: sl@0: locale::id _id_06 = numpunct::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_06._M_index == 6 ); sl@0: sl@0: locale::id _id_07 = messages::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_07._M_index == 7 ); sl@0: sl@0: locale::id _id_08 = money_get > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_08._M_index == 8 ); sl@0: sl@0: /* sl@0: locale::id _id_09 = money_get::id; sl@0: CPPUNIT_CHECK( _id_09._M_index == 9 ); sl@0: */ sl@0: sl@0: locale::id _id_10 = money_put > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_10._M_index == 10 ); sl@0: sl@0: /* sl@0: locale::id _id_11 = money_put::id; sl@0: CPPUNIT_CHECK( _id_11._M_index == 11 ); sl@0: */ sl@0: sl@0: locale::id _id_12 = num_get > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_12._M_index == 12 ); sl@0: sl@0: /* sl@0: locale::id _id_13 = num_get::id; sl@0: CPPUNIT_CHECK( _id_13._M_index == 13 ); sl@0: */ sl@0: sl@0: locale::id _id_14 = num_put > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_14._M_index == 14 ); sl@0: sl@0: /* sl@0: locale::id _id_15 = num_put::id; sl@0: CPPUNIT_CHECK( _id_15._M_index == 15 ); sl@0: */ sl@0: sl@0: locale::id _id_16 = time_get > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_16._M_index == 16 ); sl@0: sl@0: /* sl@0: locale::id _id_17 = time_get::id; sl@0: CPPUNIT_CHECK( _id_17._M_index == 17 ); sl@0: */ sl@0: sl@0: locale::id _id_18 = time_put > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_18._M_index == 18 ); sl@0: sl@0: /* sl@0: locale::id _id_19 = time_put::id; sl@0: CPPUNIT_CHECK( _id_19._M_index == 19 ); sl@0: */ sl@0: sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: locale::id _id_20 = collate::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_20._M_index == 20 ); sl@0: sl@0: locale::id _id_21 = ctype::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_21._M_index == 21 ); sl@0: sl@0: # ifndef _STLP_NO_MBSTATE_T sl@0: locale::id _id_22 = codecvt::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_22._M_index == 22 ); sl@0: # endif sl@0: locale::id _id_23 = moneypunct::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_23._M_index == 23 ); sl@0: sl@0: locale::id _id_24 = moneypunct::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_24._M_index == 24 ); sl@0: sl@0: locale::id _id_25 = numpunct::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_25._M_index == 25 ); sl@0: sl@0: locale::id _id_26 = messages::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_26._M_index == 26 ); sl@0: sl@0: locale::id _id_27 = money_get > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_27._M_index == 27 ); sl@0: sl@0: /* sl@0: locale::id _id_28 = money_get::id; sl@0: CPPUNIT_CHECK( _id_28._M_index == 28 ); sl@0: */ sl@0: sl@0: locale::id _id_29 = money_put > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_29._M_index == 29 ); sl@0: sl@0: /* sl@0: locale::id _id_30 = money_put::id; sl@0: CPPUNIT_CHECK( _id_30._M_index == 30 ); sl@0: */ sl@0: sl@0: locale::id _id_31 = num_get > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_31._M_index == 31 ); sl@0: sl@0: /* sl@0: locale::id _id_32 = num_get::id; sl@0: CPPUNIT_CHECK( _id_32._M_index == 32 ); sl@0: */ sl@0: sl@0: locale::id _id_33 = num_put > > ::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_33._M_index == 33 ); sl@0: sl@0: /* sl@0: locale::id _id_34 = num_put::id; sl@0: CPPUNIT_CHECK( _id_34._M_index == 34 ); sl@0: */ sl@0: sl@0: locale::id _id_35 = time_get > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_35._M_index == 35 ); sl@0: sl@0: /* sl@0: locale::id _id_36 = time_get::id; sl@0: CPPUNIT_CHECK( _id_36._M_index == 36 ); sl@0: */ sl@0: sl@0: locale::id _id_37 = time_put > >::GetFacetLocaleId(); sl@0: CPPUNIT_CHECK( _id_37._M_index == 37 ); sl@0: sl@0: /* sl@0: locale::id _id_38 = time_put::id; sl@0: CPPUNIT_CHECK( _id_38._M_index == 38 ); sl@0: */ sl@0: # endif sl@0: # endif sl@0: sl@0: #else sl@0: sl@0: # if defined (STLPORT) sl@0: locale::id _id_01 = collate::id; sl@0: CPPUNIT_CHECK( _id_01._M_index == 1 ); sl@0: sl@0: locale::id _id_02 = ctype::id; sl@0: CPPUNIT_CHECK( _id_02._M_index == 2 ); sl@0: sl@0: # ifndef _STLP_NO_MBSTATE_T sl@0: locale::id _id_03 = codecvt::id; sl@0: CPPUNIT_CHECK( _id_03._M_index == 3 ); sl@0: # endif sl@0: sl@0: locale::id _id_04 = moneypunct::id; sl@0: CPPUNIT_CHECK( _id_04._M_index == 4 ); sl@0: sl@0: locale::id _id_05 = moneypunct::id; sl@0: CPPUNIT_CHECK( _id_05._M_index == 5 ); sl@0: sl@0: locale::id _id_06 = numpunct::id; sl@0: CPPUNIT_CHECK( _id_06._M_index == 6 ); sl@0: sl@0: locale::id _id_07 = messages::id; sl@0: CPPUNIT_CHECK( _id_07._M_index == 7 ); sl@0: sl@0: locale::id _id_08 = money_get > >::id; sl@0: CPPUNIT_CHECK( _id_08._M_index == 8 ); sl@0: sl@0: /* sl@0: locale::id _id_09 = money_get::id; sl@0: CPPUNIT_CHECK( _id_09._M_index == 9 ); sl@0: */ sl@0: sl@0: locale::id _id_10 = money_put > >::id; sl@0: CPPUNIT_CHECK( _id_10._M_index == 10 ); sl@0: sl@0: /* sl@0: locale::id _id_11 = money_put::id; sl@0: CPPUNIT_CHECK( _id_11._M_index == 11 ); sl@0: */ sl@0: sl@0: locale::id _id_12 = num_get > >::id; sl@0: CPPUNIT_CHECK( _id_12._M_index == 12 ); sl@0: sl@0: /* sl@0: locale::id _id_13 = num_get::id; sl@0: CPPUNIT_CHECK( _id_13._M_index == 13 ); sl@0: */ sl@0: sl@0: locale::id _id_14 = num_put > >::id; sl@0: CPPUNIT_CHECK( _id_14._M_index == 14 ); sl@0: sl@0: /* sl@0: locale::id _id_15 = num_put::id; sl@0: CPPUNIT_CHECK( _id_15._M_index == 15 ); sl@0: */ sl@0: sl@0: locale::id _id_16 = time_get > >::id; sl@0: CPPUNIT_CHECK( _id_16._M_index == 16 ); sl@0: sl@0: /* sl@0: locale::id _id_17 = time_get::id; sl@0: CPPUNIT_CHECK( _id_17._M_index == 17 ); sl@0: */ sl@0: sl@0: locale::id _id_18 = time_put > >::id; sl@0: CPPUNIT_CHECK( _id_18._M_index == 18 ); sl@0: sl@0: /* sl@0: locale::id _id_19 = time_put::id; sl@0: CPPUNIT_CHECK( _id_19._M_index == 19 ); sl@0: */ sl@0: sl@0: # ifndef _STLP_NO_WCHAR_T sl@0: locale::id _id_20 = collate::id; sl@0: CPPUNIT_CHECK( _id_20._M_index == 20 ); sl@0: sl@0: locale::id _id_21 = ctype::id; sl@0: CPPUNIT_CHECK( _id_21._M_index == 21 ); sl@0: sl@0: # ifndef _STLP_NO_MBSTATE_T sl@0: locale::id _id_22 = codecvt::id; sl@0: CPPUNIT_CHECK( _id_22._M_index == 22 ); sl@0: # endif sl@0: locale::id _id_23 = moneypunct::id; sl@0: CPPUNIT_CHECK( _id_23._M_index == 23 ); sl@0: sl@0: locale::id _id_24 = moneypunct::id; sl@0: CPPUNIT_CHECK( _id_24._M_index == 24 ); sl@0: sl@0: locale::id _id_25 = numpunct::id; sl@0: CPPUNIT_CHECK( _id_25._M_index == 25 ); sl@0: sl@0: locale::id _id_26 = messages::id; sl@0: CPPUNIT_CHECK( _id_26._M_index == 26 ); sl@0: sl@0: locale::id _id_27 = money_get > >::id; sl@0: CPPUNIT_CHECK( _id_27._M_index == 27 ); sl@0: sl@0: /* sl@0: locale::id _id_28 = money_get::id; sl@0: CPPUNIT_CHECK( _id_28._M_index == 28 ); sl@0: */ sl@0: sl@0: locale::id _id_29 = money_put > >::id; sl@0: CPPUNIT_CHECK( _id_29._M_index == 29 ); sl@0: sl@0: /* sl@0: locale::id _id_30 = money_put::id; sl@0: CPPUNIT_CHECK( _id_30._M_index == 30 ); sl@0: */ sl@0: sl@0: locale::id _id_31 = num_get > >::id; sl@0: CPPUNIT_CHECK( _id_31._M_index == 31 ); sl@0: sl@0: /* sl@0: locale::id _id_32 = num_get::id; sl@0: CPPUNIT_CHECK( _id_32._M_index == 32 ); sl@0: */ sl@0: sl@0: locale::id _id_33 = num_put > > ::id; sl@0: CPPUNIT_CHECK( _id_33._M_index == 33 ); sl@0: sl@0: /* sl@0: locale::id _id_34 = num_put::id; sl@0: CPPUNIT_CHECK( _id_34._M_index == 34 ); sl@0: */ sl@0: sl@0: locale::id _id_35 = time_get > >::id; sl@0: CPPUNIT_CHECK( _id_35._M_index == 35 ); sl@0: sl@0: /* sl@0: locale::id _id_36 = time_get::id; sl@0: CPPUNIT_CHECK( _id_36._M_index == 36 ); sl@0: */ sl@0: sl@0: locale::id _id_37 = time_put > >::id; sl@0: CPPUNIT_CHECK( _id_37._M_index == 37 ); sl@0: sl@0: /* sl@0: locale::id _id_38 = time_put::id; sl@0: CPPUNIT_CHECK( _id_38._M_index == 38 ); sl@0: */ sl@0: # endif sl@0: # endif sl@0: # endif //__WINSCW__ sl@0: } sl@0: sl@0: void LocaleTest::combine() sl@0: { sl@0: # if (!defined (STLPORT) || \ sl@0: (defined (_STLP_USE_EXCEPTIONS) && !defined (_STLP_NO_MEMBER_TEMPLATES) && !defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS))) sl@0: auto_ptr loc1, loc2; sl@0: size_t loc1_index = 0; sl@0: size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]); sl@0: for (size_t i = 0; i < n; ++i) { sl@0: try { sl@0: locale *ploc = new locale(tested_locales[i].name); sl@0: if (loc1.get() == 0) sl@0: { sl@0: loc1.reset(ploc); sl@0: loc1_index = i; sl@0: continue; sl@0: } sl@0: else sl@0: { sl@0: loc2.reset(ploc); sl@0: } sl@0: sl@0: //We can start the test sl@0: ostringstream ostr; sl@0: ostr << "combining '" << loc2->name() << "' money facets with '" << loc1->name() << "'"; sl@0: CPPUNIT_MESSAGE( ostr.str().c_str() ); sl@0: sl@0: //We are going to combine money facets as all formats are different. sl@0: { sl@0: //We check that resulting locale has correctly acquire loc2 facets. sl@0: locale loc = loc1->combine >(*loc2); sl@0: loc = loc.combine >(*loc2); sl@0: loc = loc.combine >(*loc2); sl@0: loc = loc.combine >(*loc2); sl@0: sl@0: //Check loc has the correct facets: sl@0: _money_put_get2(*loc2, loc, tested_locales[i]); sl@0: sl@0: //Check loc1 has not been impacted: sl@0: _money_put_get2(*loc1, *loc1, tested_locales[loc1_index]); sl@0: sl@0: //Check loc2 has not been impacted: sl@0: _money_put_get2(*loc2, *loc2, tested_locales[i]); sl@0: } sl@0: { sl@0: //We check that resulting locale has not wrongly acquire loc1 facets that hasn't been combine: sl@0: locale loc = loc2->combine >(*loc1); sl@0: loc = loc.combine >(*loc1); sl@0: loc = loc.combine >(*loc1); sl@0: sl@0: //Check loc has the correct facets: sl@0: _money_put_get2(*loc2, loc, tested_locales[i]); sl@0: sl@0: //Check loc1 has not been impacted: sl@0: _money_put_get2(*loc1, *loc1, tested_locales[loc1_index]); sl@0: sl@0: //Check loc2 has not been impacted: sl@0: _money_put_get2(*loc2, *loc2, tested_locales[i]); sl@0: } sl@0: sl@0: { sl@0: // Check auto combination do not result in weird reference counting behavior sl@0: // (might generate a crash). sl@0: loc1->combine >(*loc1); sl@0: } sl@0: sl@0: loc1.reset(loc2.release()); sl@0: loc1_index = i; sl@0: } sl@0: catch (runtime_error const&) { sl@0: //This locale is not supported. sl@0: continue; sl@0: } sl@0: } sl@0: # endif sl@0: } sl@0: sl@0: #endif