⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 money_facets_test.cpp

📁 stl的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      CPPUNIT_ASSERT( str_res[index++] == '9' );      ++fieldIndex;      //space cannot be last:      if ((fieldIndex < 3) &&          dom_fmp.neg_format().field[fieldIndex] == money_base::space) {        CPPUNIT_ASSERT( str_res[index++] == ' ' );        ++fieldIndex;      }      if (fieldIndex == 3) {        //If none is last we should not add anything to the resulting string:        if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {          CPPUNIT_ASSERT( index == str_res.size() );        } else {          CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );          CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );        }      }    }  }  ostr.str("");  // Check value with two decimal digit:  {    CPPUNIT_ASSERT( (has_facet<moneypunct<char, false> >(loc)) );    moneypunct<char, false> const& dom_fmp = use_facet<moneypunct<char, false> >(loc);    string str_res;    // Check money_put    {      ostreambuf_iterator<char, char_traits<char> > res = fmp.put(ostr, false, ostr, ' ', 90);      CPPUNIT_ASSERT( !res.failed() );      str_res = ostr.str();      size_t fieldIndex = 0;      size_t index = 0;      if (dom_fmp.pos_format().field[fieldIndex] == money_base::sign) {        CPPUNIT_ASSERT( str_res.substr(index, dom_fmp.positive_sign().size()) == dom_fmp.positive_sign() );        index += dom_fmp.positive_sign().size();        ++fieldIndex;      }      string::size_type p = strlen( rl.money_prefix );      if (p != 0) {        CPPUNIT_ASSERT( str_res.substr(index, p) == rl.money_prefix );        index += p;        ++fieldIndex;      }      if (dom_fmp.neg_format().field[fieldIndex] == money_base::space ||          dom_fmp.neg_format().field[fieldIndex] == money_base::none) {        CPPUNIT_ASSERT( str_res[index++] == ' ' );        ++fieldIndex;      }      if (dom_fmp.frac_digits() != 0) {        CPPUNIT_ASSERT( str_res[index++] == '0' );        CPPUNIT_ASSERT( str_res[index++] == dom_fmp.decimal_point() );        for ( int fd = 1; fd < dom_fmp.frac_digits() - 1; ++fd ) {          CPPUNIT_ASSERT( str_res[index++] == '0' );        }      }      CPPUNIT_ASSERT( str_res[index++] == '9' );      if (dom_fmp.frac_digits() != 0) {        CPPUNIT_ASSERT( str_res[index++] == '0' );      }      ++fieldIndex;      //space cannot be last:      if ((fieldIndex < 3) &&          dom_fmp.neg_format().field[fieldIndex] == money_base::space) {        CPPUNIT_ASSERT( str_res[index++] == ' ' );        ++fieldIndex;      }      if (fieldIndex == 3) {        //If none is last we should not add anything to the resulting string:        if (dom_fmp.neg_format().field[fieldIndex] == money_base::none) {          CPPUNIT_ASSERT( index == str_res.size() );        } else {          CPPUNIT_ASSERT( dom_fmp.neg_format().field[fieldIndex] == money_base::symbol );          CPPUNIT_ASSERT( str_res.substr(index, strlen(rl.money_suffix)) == rl.money_suffix );        }      }    }  }}typedef void (LocaleTest::*_Test) (const locale&, const ref_monetary*);static void test_supported_locale(LocaleTest& inst, _Test __test) {  size_t n = sizeof(tested_locales) / sizeof(tested_locales[0]);  for (size_t i = 0; i < n; ++i) {    locale loc;#  if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)    try#  endif    {      locale tmp(tested_locales[i].name);      loc = tmp;    }#  if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)    catch (runtime_error const&) {      //This locale is not supported.      continue;    }#  endif    CPPUNIT_MESSAGE( loc.name().c_str() );    (inst.*__test)(loc, tested_locales + i);    {      locale tmp(locale::classic(), tested_locales[i].name, locale::monetary);      loc = tmp;    }    (inst.*__test)(loc, tested_locales + i);    {      locale tmp0(locale::classic(), new moneypunct_byname<char, true>(tested_locales[i].name));      locale tmp1(tmp0, new moneypunct_byname<char, false>(tested_locales[i].name));      loc = tmp1;    }    (inst.*__test)(loc, tested_locales + i);  }}void LocaleTest::money_put_get(){ test_supported_locale(*this, &LocaleTest::_money_put_get); }void LocaleTest::money_put_X_bug(){ test_supported_locale(*this, &LocaleTest::_money_put_X_bug); }void LocaleTest::moneypunct_by_name(){  /*   * Check of the 22.1.1.2.7 standard point. Construction of a locale   * instance from a null pointer or an unknown name should result in   * a runtime_error exception.   */#  if !defined (STLPORT) || defined (_STLP_USE_EXCEPTIONS)#    if defined (STLPORT) || !defined (__GNUC__)  try {    locale loc(locale::classic(), new moneypunct_byname<char, true>(static_cast<char const*>(0)));    CPPUNIT_FAIL;  }  catch (runtime_error const&) {  }  catch (...) {    CPPUNIT_FAIL;  }#    endif  try {    locale loc(locale::classic(), new moneypunct_byname<char, true>("yasli_language"));    CPPUNIT_FAIL;  }  catch (runtime_error const&) {  }  catch (...) {    CPPUNIT_FAIL;  }  try {    string veryLongFacetName("LC_MONETARY=");    veryLongFacetName.append(512, '?');    locale loc(locale::classic(), new moneypunct_byname<char, true>(veryLongFacetName.c_str()));    CPPUNIT_FAIL;  }  catch (runtime_error const& /* e */) {    //CPPUNIT_MESSAGE( e.what() );  }  catch (...) {    CPPUNIT_FAIL;  }#    if defined (STLPORT) || !defined (__GNUC__)  try {    locale loc(locale::classic(), new moneypunct_byname<char, false>(static_cast<char const*>(0)));    CPPUNIT_FAIL;  }  catch (runtime_error const&) {  }  catch (...) {    CPPUNIT_FAIL;  }#    endif  try {    locale loc(locale::classic(), new moneypunct_byname<char, false>("yasli_language"));    CPPUNIT_FAIL;  }  catch (runtime_error const&) {  }  catch (...) {    CPPUNIT_FAIL;  }  try {    string veryLongFacetName("LC_MONETARY=");    veryLongFacetName.append(512, '?');    locale loc(locale::classic(), new moneypunct_byname<char, false>(veryLongFacetName.c_str()));    CPPUNIT_FAIL;  }  catch (runtime_error const& /* e */) {    //CPPUNIT_MESSAGE( e.what() );  }  catch (...) {    CPPUNIT_FAIL;  }  try {    locale loc(locale::classic(), new moneypunct_byname<char, false>("C"));    moneypunct<char, false> const& cfacet_byname = use_facet<moneypunct<char, false> >(loc);    moneypunct<char, false> const& cfacet = use_facet<moneypunct<char, false> >(locale::classic());    money_base::pattern cp = cfacet.pos_format();    money_base::pattern cp_bn = cfacet_byname.pos_format();    CPPUNIT_CHECK( cp_bn.field[0] == cp.field[0] );    CPPUNIT_CHECK( cp_bn.field[1] == cp.field[1] );    CPPUNIT_CHECK( cp_bn.field[2] == cp.field[2] );    CPPUNIT_CHECK( cp_bn.field[3] == cp.field[3] );    CPPUNIT_CHECK( cfacet_byname.frac_digits() == cfacet.frac_digits() );    if (cfacet_byname.frac_digits() != 0)      CPPUNIT_CHECK( cfacet_byname.decimal_point() == cfacet.decimal_point() );    CPPUNIT_CHECK( cfacet_byname.grouping() == cfacet.grouping() );    if (!cfacet_byname.grouping().empty())      CPPUNIT_CHECK( cfacet_byname.thousands_sep() == cfacet.thousands_sep() );    CPPUNIT_CHECK( cfacet_byname.positive_sign() == cfacet.positive_sign() );    CPPUNIT_CHECK( cfacet_byname.negative_sign() == cfacet.negative_sign() );  }  catch (runtime_error const& /* e */) {    /* CPPUNIT_MESSAGE( e.what() ); */    CPPUNIT_FAIL;  }  catch (...) {    CPPUNIT_FAIL;  }  try {    locale loc(locale::classic(), new moneypunct_byname<char, true>("C"));    moneypunct<char, true> const& cfacet_byname = use_facet<moneypunct<char, true> >(loc);    moneypunct<char, true> const& cfacet = use_facet<moneypunct<char, true> >(locale::classic());    money_base::pattern cp = cfacet.pos_format();    money_base::pattern cp_bn = cfacet_byname.pos_format();    CPPUNIT_CHECK( cp_bn.field[0] == cp.field[0] );    CPPUNIT_CHECK( cp_bn.field[1] == cp.field[1] );    CPPUNIT_CHECK( cp_bn.field[2] == cp.field[2] );    CPPUNIT_CHECK( cp_bn.field[3] == cp.field[3] );    CPPUNIT_CHECK( cfacet_byname.frac_digits() == cfacet.frac_digits() );    if (cfacet_byname.frac_digits() != 0)      CPPUNIT_CHECK( cfacet_byname.decimal_point() == cfacet.decimal_point() );    CPPUNIT_CHECK( cfacet_byname.grouping() == cfacet.grouping() );    if (!cfacet_byname.grouping().empty())      CPPUNIT_CHECK( cfacet_byname.thousands_sep() == cfacet.thousands_sep() );    CPPUNIT_CHECK( cfacet_byname.positive_sign() == cfacet.positive_sign() );    CPPUNIT_CHECK( cfacet_byname.negative_sign() == cfacet.negative_sign() );  }  catch (runtime_error const& /* e */) {    /* CPPUNIT_MESSAGE( e.what() ); */    CPPUNIT_FAIL;  }  catch (...) {    CPPUNIT_FAIL;  }  try {    // On platform without real localization support we should rely on the "C" locale facet.    locale loc(locale::classic(), new moneypunct_byname<char, false>(""));  }  catch (runtime_error const& /* e */) {    /* CPPUNIT_MESSAGE( e.what() ); */    CPPUNIT_FAIL;  }  catch (...) {    CPPUNIT_FAIL;  }#    if !defined (STLPORT) || !defined (_STLP_NO_WCHAR_T)#      if defined (STLPORT) || !defined (__GNUC__)  try {    locale loc(locale::classic(), new moneypunct_byname<wchar_t, true>(static_cast<char const*>(0)));    CPPUNIT_FAIL;  }  catch (runtime_error const&) {  }  catch (...) {    CPPUNIT_FAIL;  }#      endif  try {    locale loc(locale::classic(), new moneypunct_byname<wchar_t, true>("yasli_language"));    CPPUNIT_FAIL;  }  catch (runtime_error const&) {  }  catch (...) {    CPPUNIT_FAIL;  }#      if defined (STLPORT) || !defined (__GNUC__)  try {    locale loc(locale::classic(), new moneypunct_byname<wchar_t, false>(static_cast<char const*>(0)));    CPPUNIT_FAIL;  }  catch (runtime_error const&) {  }  catch (...) {    CPPUNIT_FAIL;  }#      endif  try {    locale loc(locale::classic(), new moneypunct_byname<wchar_t, false>("yasli_language"));    CPPUNIT_FAIL;  }  catch (runtime_error const&) {  }  catch (...) {    CPPUNIT_FAIL;  }#    endif#  endif}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -