diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/22_locale/money_get | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/22_locale/money_get')
54 files changed, 4059 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/22_locale/money_get/cons/3.cc b/libstdc++-v3/testsuite/22_locale/money_get/cons/3.cc new file mode 100644 index 000000000..3611c7e44 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/cons/3.cc @@ -0,0 +1,40 @@ +// 2005-04-29 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1 Template class money_get + +// { dg-do compile } + +#include <locale> +#include <testsuite_character.h> + +class gnu_money_get: public std::money_get<__gnu_test::pod_uint> +{ }; + +// libstdc++/21238 +void test01() +{ + gnu_money_get facet01; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/1.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/1.cc new file mode 100644 index 000000000..e76e07694 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/1.cc @@ -0,0 +1,125 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// test string version +void test01() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + // sanity check the data is correct. + const string empty; + + // total EPA budget FY 2002 + const string digits1("720000000000"); + + iterator_type end; + istringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + iss.str("7.200.000.000,00 "); + iterator_type is_it01(iss); + string result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); // xxx + VERIFY( result1 == digits1 ); + VERIFY( err01 == ios_base::eofbit ); + + iss.str("7.200.000.000,00 "); + iterator_type is_it02(iss); + string result2; + ios_base::iostate err02 = ios_base::goodbit; + mon_get.get(is_it02, end, true, iss, err02, result2); + VERIFY( result2 == digits1 ); + VERIFY( err02 == ios_base::eofbit ); + + iss.str("7.200.000.000,00 a"); + iterator_type is_it03(iss); + string result3; + ios_base::iostate err03 = ios_base::goodbit; + mon_get.get(is_it03, end, true, iss, err03, result3); + VERIFY( result3 == digits1 ); + VERIFY( err03 == ios_base::goodbit ); + + iss.str(""); + iterator_type is_it04(iss); + string result4; + ios_base::iostate err04 = ios_base::goodbit; + mon_get.get(is_it04, end, true, iss, err04, result4); + VERIFY( result4 == empty ); + VERIFY( err04 == (ios_base::failbit | ios_base::eofbit) ); + + iss.str("working for enlightenment and peace in a mad world"); + iterator_type is_it05(iss); + string result5; + ios_base::iostate err05 = ios_base::goodbit; + mon_get.get(is_it05, end, true, iss, err05, result5); + VERIFY( result5 == empty ); + VERIFY( err05 == ios_base::failbit ); + + // now try with showbase, to get currency symbol in format + iss.setf(ios_base::showbase); + + iss.str("7.200.000.000,00 EUR "); + iterator_type is_it06(iss); + string result6; + ios_base::iostate err06 = ios_base::goodbit; + mon_get.get(is_it06, end, true, iss, err06, result6); + VERIFY( result6 == digits1 ); + VERIFY( err06 == ios_base::eofbit ); + + iss.str("7.200.000.000,00 EUR "); // Extra space. + iterator_type is_it07(iss); + string result7; + ios_base::iostate err07 = ios_base::goodbit; + mon_get.get(is_it07, end, true, iss, err07, result7); + VERIFY( result7 == digits1 ); + VERIFY( err07 == ios_base::goodbit ); + + iss.str("7.200.000.000,00 \244"); + iterator_type is_it08(iss); + string result8; + ios_base::iostate err08 = ios_base::goodbit; + mon_get.get(is_it08, end, false, iss, err08, result8); + VERIFY( result8 == digits1 ); + VERIFY( err08 == ios_base::eofbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc new file mode 100644 index 000000000..5b4309d09 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/10.cc @@ -0,0 +1,64 @@ +// { dg-require-namedlocale "en_US" } + +// 2003-10-23 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + locale loc_us = locale("en_US"); + + iterator_type end; + istringstream iss; + iss.imbue(loc_us); + + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + iss.str("-$0 "); + iterator_type is_it(iss); + string extracted_amount; + ios_base::iostate err = ios_base::goodbit; + mon_get.get(is_it, end, false, iss, err, extracted_amount); + VERIFY( extracted_amount == "0" ); + VERIFY( err == ios_base::goodbit ); + + iss.str("-$ "); + iterator_type is_it_2(iss); + extracted_amount.clear(); + err = ios_base::goodbit; + mon_get.get(is_it_2, end, false, iss, err, extracted_amount); + VERIFY( extracted_amount.empty() ); + VERIFY( err == ios_base::failbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/11.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/11.cc new file mode 100644 index 000000000..e447e7780 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/11.cc @@ -0,0 +1,64 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2003-10-24 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_de = locale("de_DE@euro"); + + iterator_type end; + istringstream iss; + iss.imbue(loc_de); + + // cache the money_get facet + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + // A _very_ big amount. + string str = "1"; + for (int i = 0; i < 2 * numeric_limits<long double>::digits10; ++i) + str += ".000"; + str += ",00 "; + + iss.str(str); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); + VERIFY( err01 == ios_base::eofbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/11528.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/11528.cc new file mode 100644 index 000000000..5354cda9f --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/11528.cc @@ -0,0 +1,54 @@ +// { dg-require-namedlocale "en_US" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + locale loc_us = locale("en_US"); + + iterator_type end; + istringstream iss; + iss.imbue(loc_us); + + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + iss.str("$.00 "); + iterator_type is_it(iss); + string extracted_amount; + ios_base::iostate err = ios_base::goodbit; + mon_get.get(is_it, end, false, iss, err, extracted_amount); + VERIFY( extracted_amount == "0" ); + VERIFY( err == ios_base::goodbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/12.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/12.cc new file mode 100644 index 000000000..a50393e2a --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/12.cc @@ -0,0 +1,71 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2004-02-05 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// Same as 3.cc but no thousands-sep in input: they are always optional. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<char> iterator_type; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + // total EPA budget FY 2002 + const long double digits1 = 720000000000.0; + + iterator_type end; + istringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + iss.str("7200000000,00 "); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); + VERIFY( result1 == digits1 ); + VERIFY( err01 == ios_base::eofbit ); + + iss.str("7200000000,00 "); + iterator_type is_it02(iss); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + mon_get.get(is_it02, end, false, iss, err02, result2); + VERIFY( result2 == digits1 ); + VERIFY( err02 == ios_base::eofbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/13.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/13.cc new file mode 100644 index 000000000..361e357ce --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/13.cc @@ -0,0 +1,68 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2004-02-05 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// No thousands-sep allowed after the decimal-point. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<char> iterator_type; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + iterator_type end01, end02; + istringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + iss.str("500,1.0 "); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get.get(is_it01, end01, true, iss, err01, result1); + VERIFY( err01 == ios_base::failbit ); + VERIFY( *end01 == '.' ); + + iss.str("500,1.0 "); + iterator_type is_it02(iss); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get.get(is_it02, end02, false, iss, err02, result2); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == '.' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/14.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/14.cc new file mode 100644 index 000000000..f5311cd64 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/14.cc @@ -0,0 +1,61 @@ +// 2004-02-21 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money : public std::moneypunct<char, false> +{ + std::string do_positive_sign() const { return "+"; } + std::string do_negative_sign() const { return ""; } +}; + +void test01() +{ + using namespace std; + typedef istreambuf_iterator<char> InIt; + + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new My_money); + + string buffer("69"); + + InIt iend; + ios_base::iostate err; + string val; + + const money_get<char, InIt>& mg = + use_facet<money_get<char, InIt> >(loc); + + istringstream fmt(buffer); + fmt.imbue(loc); + InIt ibeg(fmt); + mg.get(ibeg, iend, false, fmt, err, val); + VERIFY( val == "-69" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/15.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/15.cc new file mode 100644 index 000000000..1d10cfd84 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/15.cc @@ -0,0 +1,69 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2004-03-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// The grammar doesn't allow thousands separator at the beginning of a +// string, neither two consecutive thousands separators. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<char> iterator_type; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + iterator_type end01, end02; + istringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + iss.str(".100"); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get.get(is_it01, end01, true, iss, err01, result1); + VERIFY( err01 == ios_base::failbit ); + VERIFY( *end01 == '.' ); + + iss.str("30..0"); + iterator_type is_it02(iss); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get.get(is_it02, end02, false, iss, err02, result2); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == '.' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/16.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/16.cc new file mode 100644 index 000000000..54c0934b0 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/16.cc @@ -0,0 +1,77 @@ +// { dg-require-namedlocale "de_DE@euro" } +// { dg-require-namedlocale "en_HK" } + +// 2004-03-02 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// Fail as soon as value digits are not present. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<char> iterator_type; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + locale loc_hk = locale("en_HK"); + VERIFY( loc_hk != loc_de ); + VERIFY( loc_c != loc_hk ); + + iterator_type end01, end02; + istringstream iss01, iss02; + iss01.imbue(loc_de); + iss02.imbue(loc_hk); + + // cache the money_get facet + const money_get<char>& mon_get_01 = + use_facet<money_get<char> >(iss01.getloc()); + const money_get<char>& mon_get_02 = + use_facet<money_get<char> >(iss02.getloc()); + + iss01.setf(ios_base::showbase); + iss01.str("EUR "); + iterator_type is_it01(iss01); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get_01.get(is_it01, end01, true, iss01, err01, result1); + VERIFY( err01 == ios_base::failbit ); + VERIFY( *end01 == 'E' ); + + iss02.str("(HKD )"); + iterator_type is_it02(iss02); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get_02.get(is_it02, end02, true, iss02, err02, result2); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == ')' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/17.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/17.cc new file mode 100644 index 000000000..530999e06 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/17.cc @@ -0,0 +1,72 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2004-03-08 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// 22.2.6.3, p2: "The value _space_ indicates that at least one space +// is required at that position." +void test01() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + iterator_type end, end02; + istringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<char>& mon_get = + use_facet<money_get<char> >(iss.getloc()); + + iss.str("7.200.000.000,00"); + iterator_type is_it01(iss); + string result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); + VERIFY( err01 == (ios_base::failbit | ios_base::eofbit) ); + + // now try with showbase, to get currency symbol in format + iss.setf(ios_base::showbase); + + iss.str("7.200.000.000,00EUR "); + iterator_type is_it02(iss); + string result2; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get.get(is_it02, end, true, iss, err02, result2); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == 'E' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/18.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/18.cc new file mode 100644 index 000000000..f903a7596 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/18.cc @@ -0,0 +1,70 @@ +// { dg-require-namedlocale "en_HK" } + +// 2004-03-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// If (str.flags() & str.showbase) is false, the currency symbol is optional, +// but, if found, must be consumed entirely. +void test01() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_hk = locale("en_HK"); + VERIFY( loc_c != loc_hk ); + + iterator_type end, end01, end02; + istringstream iss; + iss.imbue(loc_hk); + // cache the money_get facet + const money_get<char>& mon_get = + use_facet<money_get<char> >(iss.getloc()); + + iss.str("HK7,200,000,000.00"); + iterator_type is_it01(iss); + string result01; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get.get(is_it01, end, false, iss, err01, result01); + VERIFY( err01 == ios_base::failbit ); + VERIFY( *end01 == '7' ); + + iss.str("(HK100,000,000,000.00)"); + iterator_type is_it02(iss); + string result02; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get.get(is_it02, end, true, iss, err02, result02); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == '1' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/19.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/19.cc new file mode 100644 index 000000000..5ecc131d4 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/19.cc @@ -0,0 +1,124 @@ +// 2004-03-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money_io_01 : public std::moneypunct<char, false> +{ + std::string do_curr_symbol() const { return "$"; } + std::string do_positive_sign() const { return ""; } + std::string do_negative_sign() const { return ""; } + + pattern do_neg_format() const + { + pattern pat = { { value, symbol, none, sign } }; + return pat; + } +}; + +struct My_money_io_02 : public std::moneypunct<char, false> +{ + std::string do_curr_symbol() const { return "%"; } + std::string do_positive_sign() const { return ""; } + std::string do_negative_sign() const { return "-"; } + + pattern do_neg_format() const + { + pattern pat = { { value, symbol, sign, none } }; + return pat; + } +}; + +struct My_money_io_03 : public std::moneypunct<char, false> +{ + std::string do_curr_symbol() const { return "&"; } + std::string do_positive_sign() const { return ""; } + std::string do_negative_sign() const { return ""; } + + pattern do_neg_format() const + { + pattern pat = { { value, space, symbol, sign } }; + return pat; + } +}; + +// When both do_positive_sign and do_negative_sign return an empty +// string, patterns of the forms { value, symbol, none, sign }, +// { value, symbol, sign, none } and { X, Y, symbol, sign } imply +// that the symbol is not consumed since no other characters are +// needed to complete the format. +void test01() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_01(locale::classic(), new My_money_io_01); + locale loc_02(locale::classic(), new My_money_io_02); + locale loc_03(locale::classic(), new My_money_io_03); + + iterator_type end, end01, end02, end03; + istringstream iss_01, iss_02, iss_03; + iss_01.imbue(loc_01); + iss_02.imbue(loc_02); + iss_03.imbue(loc_03); + // cache the money_get facet + const money_get<char>& mon_get_01 = + use_facet<money_get<char> >(iss_01.getloc()); + const money_get<char>& mon_get_02 = + use_facet<money_get<char> >(iss_02.getloc()); + const money_get<char>& mon_get_03 = + use_facet<money_get<char> >(iss_03.getloc()); + + iss_01.str("10$"); + iterator_type is_it01(iss_01); + string result01; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get_01.get(is_it01, end, false, iss_01, err01, result01); + VERIFY( err01 == ios_base::goodbit ); + VERIFY( *end01 == '$' ); + + iss_02.str("50%"); + iterator_type is_it02(iss_02); + string result02; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get_02.get(is_it02, end, false, iss_02, err02, result02); + VERIFY( err02 == ios_base::goodbit ); + VERIFY( *end02 == '%' ); + + iss_03.str("7 &"); + iterator_type is_it03(iss_03); + string result03; + ios_base::iostate err03 = ios_base::goodbit; + end03 = mon_get_03.get(is_it03, end, false, iss_03, err03, result03); + VERIFY( err03 == ios_base::goodbit ); + VERIFY( *end03 == '&' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/2.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/2.cc new file mode 100644 index 000000000..c1b8e593b --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/2.cc @@ -0,0 +1,118 @@ +// { dg-require-namedlocale "en_HK" } + +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// test string version +void test02() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_hk = locale("en_HK"); + VERIFY( loc_c != loc_hk ); + + // total EPA budget FY 2002 + const string digits1("720000000000"); + + // est. cost, national missile "defense", expressed as a loss in USD 2001 + const string digits2("-10000000000000"); + + // input less than frac_digits + const string digits4("-1"); + + iterator_type end; + istringstream iss; + iss.imbue(loc_hk); + // cache the money_get facet + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + // now try with showbase, to get currency symbol in format + iss.setf(ios_base::showbase); + + iss.str("HK$7,200,000,000.00"); + iterator_type is_it09(iss); + string result9; + ios_base::iostate err09 = ios_base::goodbit; + mon_get.get(is_it09, end, false, iss, err09, result9); + VERIFY( result9 == digits1 ); + VERIFY( err09 == ios_base::eofbit ); + + iss.str("(HKD 100,000,000,000.00)"); + iterator_type is_it10(iss); + string result10; + ios_base::iostate err10 = ios_base::goodbit; + mon_get.get(is_it10, end, true, iss, err10, result10); + VERIFY( result10 == digits2 ); + VERIFY( err10 == ios_base::eofbit ); + + iss.str("(HKD .01)"); + iterator_type is_it11(iss); + string result11; + ios_base::iostate err11 = ios_base::goodbit; + mon_get.get(is_it11, end, true, iss, err11, result11); + VERIFY( result11 == digits4 ); + VERIFY( err11 == ios_base::eofbit ); + + // for the "en_HK" locale the parsing of the very same input streams must + // be successful without showbase too, since the symbol field appears in + // the first positions in the format and the symbol, when present, must be + // consumed. + iss.unsetf(ios_base::showbase); + + iss.str("HK$7,200,000,000.00"); + iterator_type is_it12(iss); + string result12; + ios_base::iostate err12 = ios_base::goodbit; + mon_get.get(is_it12, end, false, iss, err12, result12); + VERIFY( result12 == digits1 ); + VERIFY( err12 == ios_base::eofbit ); + + iss.str("(HKD 100,000,000,000.00)"); + iterator_type is_it13(iss); + string result13; + ios_base::iostate err13 = ios_base::goodbit; + mon_get.get(is_it13, end, true, iss, err13, result13); + VERIFY( result13 == digits2 ); + VERIFY( err13 == ios_base::eofbit ); + + iss.str("(HKD .01)"); + iterator_type is_it14(iss); + string result14; + ios_base::iostate err14 = ios_base::goodbit; + mon_get.get(is_it14, end, true, iss, err14, result14); + VERIFY( result14 == digits4 ); + VERIFY( err14 == ios_base::eofbit ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/22131.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/22131.cc new file mode 100644 index 000000000..48acd2284 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/22131.cc @@ -0,0 +1,82 @@ +// 2005-06-28 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money_io : public std::moneypunct<char, false> +{ + std::string do_grouping() const { return "\1"; } + char_type do_thousands_sep() const { return '#'; } + + pattern do_neg_format() const + { + pattern pat = { { symbol, none, sign, value } }; + return pat; + } +}; + +// libstdc++/22131 +void test01() +{ + using namespace std; + typedef istreambuf_iterator<char> InIt; + + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new My_money_io); + + string buffer1("00#0#1"); + string buffer2("000##1"); + + bool intl = false; + + InIt iend1, iend2; + ios_base::iostate err1, err2; + string val1, val2; + + const money_get<char,InIt>& mg = + use_facet<money_get<char, InIt> >(loc); + + istringstream fmt1(buffer1); + fmt1.imbue(loc); + InIt ibeg1(fmt1); + err1 = ios_base::goodbit; + mg.get(ibeg1, iend1, intl, fmt1, err1, val1); + VERIFY( err1 == (ios_base::eofbit | ios_base::failbit) ); + VERIFY( val1 == "1" ); + + istringstream fmt2(buffer2); + fmt2.imbue(loc); + InIt ibeg2(fmt2); + err2 = ios_base::goodbit; + mg.get(ibeg2, iend2, intl, fmt2, err2, val2); + VERIFY( err2 == ios_base::failbit ); + VERIFY( *ibeg2 == '#' ); + VERIFY( val2 == "" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/3.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/3.cc new file mode 100644 index 000000000..507214dc9 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/3.cc @@ -0,0 +1,71 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// test double version +void test03() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + // total EPA budget FY 2002 + const long double digits1 = 720000000000.0; + + iterator_type end; + istringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + iss.str("7.200.000.000,00 "); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); + VERIFY( result1 == digits1 ); + VERIFY( err01 == ios_base::eofbit ); + + iss.str("7.200.000.000,00 "); + iterator_type is_it02(iss); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + mon_get.get(is_it02, end, false, iss, err02, result2); + VERIFY( result2 == digits1 ); + VERIFY( err02 == ios_base::eofbit ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/38399.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/38399.cc new file mode 100644 index 000000000..506cc866e --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/38399.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2008, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +class my_moneypunct : public std::moneypunct<char> +{ +protected: + //this should disable fraction part of monetary value + int do_frac_digits() const { return 0; } +}; + +// libstdc++/38399 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale(), new my_moneypunct()); + stringstream ss("123.455"); + ss.imbue(loc); + string digits; + ios_base::iostate err; + istreambuf_iterator<char> iter = + use_facet<money_get<char> >(loc).get(ss, 0, false, ss, err, digits); + + string rest = string(iter, istreambuf_iterator<char>()); + VERIFY( digits == "123" ); + VERIFY( rest == ".455" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/39168.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/39168.cc new file mode 100644 index 000000000..e4d70a3e6 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/39168.cc @@ -0,0 +1,56 @@ +// Copyright (C) 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <sstream> +#include <locale> +#include <climits> +#include <testsuite_hooks.h> + +class my_moneypunct: public std::moneypunct<char> +{ +protected: + std::string do_grouping() const { return std::string(1, CHAR_MAX); } +}; + +// libstdc++/39168 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + istringstream iss; + iss.imbue(locale(iss.getloc(), new my_moneypunct)); + const money_get<char>& mg = use_facet<money_get<char> >(iss.getloc()); + + string digits; + ios_base::iostate err = ios_base::goodbit; + + iss.str("123,456"); + iterator_type end = mg.get(iss.rdbuf(), 0, false, iss, err, digits); + VERIFY( err == ios_base::goodbit ); + VERIFY( digits == "123" ); + VERIFY( *end == ',' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/4.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/4.cc new file mode 100644 index 000000000..f48cc0efb --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/4.cc @@ -0,0 +1,66 @@ +// { dg-require-namedlocale "en_HK" } + +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// test double version +void test04() +{ + using namespace std; + typedef istreambuf_iterator<char> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_hk = locale("en_HK"); + VERIFY( loc_c != loc_hk ); + + // input less than frac_digits + const long double digits4 = -1.0; + + iterator_type end; + istringstream iss; + iss.imbue(loc_hk); + // cache the money_get facet + const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); + + // now try with showbase, to get currency symbol in format + iss.setf(ios_base::showbase); + + iss.str("(HKD .01)"); + iterator_type is_it03(iss); + long double result3; + ios_base::iostate err03 = ios_base::goodbit; + mon_get.get(is_it03, end, true, iss, err03, result3); + VERIFY( result3 == digits4 ); + VERIFY( err03 == ios_base::eofbit ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/5.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/5.cc new file mode 100644 index 000000000..3d0e20df3 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/5.cc @@ -0,0 +1,70 @@ +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 +// Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +void test05() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // Check money_get works with other iterators besides streambuf + // input iterators. + typedef string::const_iterator iter_type; + typedef money_get<char, iter_type> mon_get_type; + const ios_base::iostate goodbit = ios_base::goodbit; + ios_base::iostate err = goodbit; + const locale loc_c = locale::classic(); + const string str = "1Eleanor Roosevelt"; + + istringstream iss; + iss.imbue(locale(loc_c, new mon_get_type)); + + // Iterator advanced, state, output. + const mon_get_type& mg = use_facet<mon_get_type>(iss.getloc()); + + // 01 string + string res1; + iter_type end1 = mg.get(str.begin(), str.end(), false, iss, err, res1); + string rem1(end1, str.end()); + VERIFY( err == goodbit ); + VERIFY( res1 == "1" ); + VERIFY( rem1 == "Eleanor Roosevelt" ); + + // 02 long double + iss.clear(); + err = goodbit; + long double res2; + iter_type end2 = mg.get(str.begin(), str.end(), false, iss, err, res2); + string rem2(end2, str.end()); + VERIFY( err == goodbit ); + VERIFY( res2 == 1 ); + VERIFY( rem2 == "Eleanor Roosevelt" ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/6.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/6.cc new file mode 100644 index 000000000..1afe04646 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/6.cc @@ -0,0 +1,97 @@ +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money_io : public std::moneypunct<char,false> +{ + char_type do_decimal_point() const { return '.'; } + std::string do_grouping() const { return "\004"; } + + std::string do_curr_symbol() const { return "$"; } + std::string do_positive_sign() const { return ""; } + std::string do_negative_sign() const { return "-"; } + + int do_frac_digits() const { return 2; } + + pattern do_neg_format() const + { + pattern pat = { { symbol, none, sign, value } }; + return pat; + } +}; + +// libstdc++/5579 +void test06() +{ + using namespace std; + typedef istreambuf_iterator<char> InIt; + + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new My_money_io); + + string bufferp("$1234.56"); + string buffern("$-1234.56"); + string bufferp_ns("1234.56"); + string buffern_ns("-1234.56"); + + bool intl = false; + + InIt iendp, iendn, iendp_ns, iendn_ns; + ios_base::iostate err; + string valp, valn, valp_ns, valn_ns; + + const money_get<char,InIt>& mg = + use_facet<money_get<char, InIt> >(loc); + + istringstream fmtp(bufferp); + fmtp.imbue(loc); + InIt ibegp(fmtp); + mg.get(ibegp,iendp,intl,fmtp,err,valp); + VERIFY( valp == "123456" ); + + istringstream fmtn(buffern); + fmtn.imbue(loc); + InIt ibegn(fmtn); + mg.get(ibegn,iendn,intl,fmtn,err,valn); + VERIFY( valn == "-123456" ); + + istringstream fmtp_ns(bufferp_ns); + fmtp_ns.imbue(loc); + InIt ibegp_ns(fmtp_ns); + mg.get(ibegp_ns,iendp_ns,intl,fmtp_ns,err,valp_ns); + VERIFY( valp_ns == "123456" ); + + istringstream fmtn_ns(buffern_ns); + fmtn_ns.imbue(loc); + InIt ibegn_ns(fmtn_ns); + mg.get(ibegn_ns,iendn_ns,intl,fmtn_ns,err,valn_ns); + VERIFY( valn_ns == "-123456" ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/7.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/7.cc new file mode 100644 index 000000000..c5f9ae2d2 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/7.cc @@ -0,0 +1,72 @@ +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// We were appending to the string val passed by reference, instead +// of constructing a temporary candidate, eventually copied into +// val in case of successful parsing. +void test07() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<char> InIt; + InIt iend1, iend2, iend3; + + locale loc_c = locale::classic(); + string buffer1("123"); + string buffer2("456"); + string buffer3("Golgafrincham"); // From Nathan's original idea. + + string val; + + ios_base::iostate err; + + const money_get<char, InIt>& mg = use_facet<money_get<char, InIt> >(loc_c); + + istringstream fmt1(buffer1); + fmt1.imbue(loc_c); + InIt ibeg1(fmt1); + mg.get(ibeg1, iend1, false, fmt1, err, val); + VERIFY( val == buffer1 ); + + istringstream fmt2(buffer2); + fmt2.imbue(loc_c); + InIt ibeg2(fmt2); + mg.get(ibeg2, iend2, false, fmt2, err, val); + VERIFY( val == buffer2 ); + + val = buffer3; + istringstream fmt3(buffer3); + fmt3.imbue(loc_c); + InIt ibeg3(fmt3); + mg.get(ibeg3, iend3, false, fmt3, err, val); + VERIFY( val == buffer3 ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/8.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/8.cc new file mode 100644 index 000000000..c0c45954a --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/8.cc @@ -0,0 +1,122 @@ +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money_io_a : public std::moneypunct<char,false> +{ + char_type do_decimal_point() const { return '.'; } + std::string do_grouping() const { return "\004"; } + + std::string do_curr_symbol() const { return "$"; } + std::string do_positive_sign() const { return "()"; } + + int do_frac_digits() const { return 2; } + + pattern do_neg_format() const + { + pattern pat = { { sign, value, space, symbol } }; + return pat; + } +}; + +struct My_money_io_b : public std::moneypunct<char,false> +{ + char_type do_decimal_point() const { return '.'; } + std::string do_grouping() const { return "\004"; } + + std::string do_curr_symbol() const { return "$"; } + std::string do_positive_sign() const { return "()"; } + + int do_frac_digits() const { return 2; } + + pattern do_neg_format() const + { + pattern pat = { { sign, value, symbol, none } }; + return pat; + } +}; + +// This one exercises patterns of the type { X, Y, Z, symbol } and +// { X, Y, symbol, none } for a two character long sign. Therefore +// the optional symbol (showbase is false by default) must be consumed +// if present, since "rest of the sign" is left to read. +void test08() +{ + using namespace std; + typedef istreambuf_iterator<char> InIt; + + bool intl = false; + bool test __attribute__((unused)) = true; + ios_base::iostate err; + + locale loc_a(locale::classic(), new My_money_io_a); + + string buffer_a("(1234.56 $)"); + string buffer_a_ns("(1234.56 )"); + + InIt iend_a, iend_a_ns; + string val_a, val_a_ns; + + const money_get<char,InIt>& mg_a = use_facet<money_get<char, InIt> >(loc_a); + + istringstream fmt_a(buffer_a); + fmt_a.imbue(loc_a); + InIt ibeg_a(fmt_a); + mg_a.get(ibeg_a,iend_a,intl,fmt_a,err,val_a); + VERIFY( val_a == "123456" ); + + istringstream fmt_a_ns(buffer_a_ns); + fmt_a_ns.imbue(loc_a); + InIt ibeg_a_ns(fmt_a_ns); + mg_a.get(ibeg_a_ns,iend_a_ns,intl,fmt_a_ns,err,val_a_ns); + VERIFY( val_a_ns == "123456" ); + + locale loc_b(locale::classic(), new My_money_io_b); + + string buffer_b("(1234.56$)"); + string buffer_b_ns("(1234.56)"); + + InIt iend_b, iend_b_ns; + string val_b, val_b_ns; + + const money_get<char,InIt>& mg_b = use_facet<money_get<char, InIt> >(loc_b); + + istringstream fmt_b(buffer_b); + fmt_b.imbue(loc_b); + InIt ibeg_b(fmt_b); + mg_b.get(ibeg_b,iend_b,intl,fmt_b,err,val_b); + VERIFY( val_b == "123456" ); + + istringstream fmt_b_ns(buffer_b_ns); + fmt_b_ns.imbue(loc_b); + InIt ibeg_b_ns(fmt_b_ns); + mg_b.get(ibeg_b_ns,iend_b_ns,intl,fmt_b_ns,err,val_b_ns); + VERIFY( val_b_ns == "123456" ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/9.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/9.cc new file mode 100644 index 000000000..00bf88371 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/9.cc @@ -0,0 +1,90 @@ +// 2003-05-27 Brendan Kehoe <brendan@zen.org> + +// Copyright (C) 2003, 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// $22.2.6.3/3 +// The number of digits required after the decimal point (if any) is exactly +// the value returned by frac_digits(). + +#include <locale> +#include <sstream> + +class dublin : public std::moneypunct<char> { +public: + int do_frac_digits() const { return 3; } +}; + +int main() +{ + std::istringstream liffey; + std::string coins; + + std::locale eire(std::locale::classic(), new dublin); + liffey.imbue(eire); + + const std::money_get<char>& greed + = std::use_facet<std::money_get<char> >(liffey.getloc()); + + typedef std::istreambuf_iterator<char> iterator_type; + iterator_type is(liffey); + iterator_type end; + + std::ios_base::iostate err01 = std::ios_base::goodbit; + + int fails = 0; + + // Feed it 1 digit too many, which should fail. + liffey.str("12.3456"); + greed.get(is, end, false, liffey, err01, coins); + if (! (err01 & std::ios_base::failbit )) + fails |= 0x01; + + err01 = std::ios_base::goodbit; + + // Feed it exactly what it wants, which should succeed. + liffey.str("12.345"); + greed.get(is, end, false, liffey, err01, coins); + if ( err01 & std::ios_base::failbit ) + fails |= 0x02; + + err01 = std::ios_base::goodbit; + + // Feed it 1 digit too few, which should fail. + liffey.str("12.34"); + greed.get(is, end, false, liffey, err01, coins); + if (! ( err01 & std::ios_base::failbit )) + fails |= 0x04; + + err01 = std::ios_base::goodbit; + + // Feed it only a decimal-point, which should fail. + liffey.str("12."); + greed.get(is, end, false, liffey, err01, coins); + if (! (err01 & std::ios_base::failbit )) + fails |= 0x08; + + err01 = std::ios_base::goodbit; + + // Feed it no decimal-point at all, which should succeed. + liffey.str("12"); + greed.get(is, end, false, liffey, err01, coins); + if ( err01 & std::ios_base::failbit ) + fails |= 0x10; + + return fails; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/wrapped_env.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/wrapped_env.cc new file mode 100644 index 000000000..c0a769d78 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/wrapped_env.cc @@ -0,0 +1,74 @@ +// { dg-require-namedlocale "de_DE" } +// { dg-require-namedlocale "de_DE@euro" } +// { dg-require-namedlocale "en_HK" } + +// 2001-08-15 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.4.1.1 collate members + +#include <testsuite_hooks.h> + +#define main discard_main_1 +#include "1.cc" +#undef main + +#define main discard_main_2 +#include "2.cc" +#undef main + +#define main discard_main_3 +#include "3.cc" +#undef main + +#define main discard_main_4 +#include "4.cc" +#undef main + +#define main discard_main_5 +#include "5.cc" +#undef main + +#define main discard_main_6 +#include "6.cc" +#undef main + +#define main discard_main_7 +#include "7.cc" +#undef main + +#define main discard_main_8 +#include "8.cc" +#undef main + +int main() +{ + using namespace __gnu_test; + func_callback two; + two.push_back(&test01); + two.push_back(&test02); + two.push_back(&test03); + two.push_back(&test04); + two.push_back(&test05); + two.push_back(&test06); + two.push_back(&test07); + two.push_back(&test08); + run_tests_wrapped_env("de_DE", "LANG", two); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/wrapped_locale.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/wrapped_locale.cc new file mode 100644 index 000000000..795271f3f --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/wrapped_locale.cc @@ -0,0 +1,74 @@ +// { dg-require-namedlocale "ja_JP.eucjp" } +// { dg-require-namedlocale "de_DE@euro" } +// { dg-require-namedlocale "en_HK" } + +// 2001-08-15 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.4.1.1 collate members + +#include <testsuite_hooks.h> + +#define main discard_main_1 +#include "1.cc" +#undef main + +#define main discard_main_2 +#include "2.cc" +#undef main + +#define main discard_main_3 +#include "3.cc" +#undef main + +#define main discard_main_4 +#include "4.cc" +#undef main + +#define main discard_main_5 +#include "5.cc" +#undef main + +#define main discard_main_6 +#include "6.cc" +#undef main + +#define main discard_main_7 +#include "7.cc" +#undef main + +#define main discard_main_8 +#include "8.cc" +#undef main + +int main() +{ + using namespace __gnu_test; + func_callback two; + two.push_back(&test01); + two.push_back(&test02); + two.push_back(&test03); + two.push_back(&test04); + two.push_back(&test05); + two.push_back(&test06); + two.push_back(&test07); + two.push_back(&test08); + run_tests_wrapped_locale("ja_JP.eucjp", two); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/1.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/1.cc new file mode 100644 index 000000000..43957a593 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/1.cc @@ -0,0 +1,125 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// test wstring version +void test01() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + // sanity check the data is correct. + const wstring empty; + + // total EPA budget FY 2002 + const wstring digits1(L"720000000000"); + + iterator_type end; + wistringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); + + iss.str(L"7.200.000.000,00 "); + iterator_type is_it01(iss); + wstring result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); + VERIFY( result1 == digits1 ); + VERIFY( err01 == ios_base::eofbit ); + + iss.str(L"7.200.000.000,00 "); + iterator_type is_it02(iss); + wstring result2; + ios_base::iostate err02 = ios_base::goodbit; + mon_get.get(is_it02, end, true, iss, err02, result2); + VERIFY( result2 == digits1 ); + VERIFY( err02 == ios_base::eofbit ); + + iss.str(L"7.200.000.000,00 a"); + iterator_type is_it03(iss); + wstring result3; + ios_base::iostate err03 = ios_base::goodbit; + mon_get.get(is_it03, end, true, iss, err03, result3); + VERIFY( result3 == digits1 ); + VERIFY( err03 == ios_base::goodbit ); + + iss.str(L""); + iterator_type is_it04(iss); + wstring result4; + ios_base::iostate err04 = ios_base::goodbit; + mon_get.get(is_it04, end, true, iss, err04, result4); + VERIFY( result4 == empty ); + VERIFY( err04 == (ios_base::failbit | ios_base::eofbit) ); + + iss.str(L"working for enlightenment and peace in a mad world"); + iterator_type is_it05(iss); + wstring result5; + ios_base::iostate err05 = ios_base::goodbit; + mon_get.get(is_it05, end, true, iss, err05, result5); + VERIFY( result5 == empty ); + VERIFY( err05 == ios_base::failbit ); + + // now try with showbase, to get currency symbol in format + iss.setf(ios_base::showbase); + + iss.str(L"7.200.000.000,00 EUR "); + iterator_type is_it06(iss); + wstring result6; + ios_base::iostate err06 = ios_base::goodbit; + mon_get.get(is_it06, end, true, iss, err06, result6); + VERIFY( result6 == digits1 ); + VERIFY( err06 == ios_base::eofbit ); + + iss.str(L"7.200.000.000,00 EUR "); // Extra space. + iterator_type is_it07(iss); + wstring result7; + ios_base::iostate err07 = ios_base::goodbit; + mon_get.get(is_it07, end, true, iss, err07, result7); + VERIFY( result7 == digits1 ); + VERIFY( err07 == ios_base::goodbit ); + + iss.str(L"7.200.000.000,00 \x20ac"); + iterator_type is_it08(iss); + wstring result8; + ios_base::iostate err08 = ios_base::goodbit; + mon_get.get(is_it08, end, false, iss, err08, result8); + VERIFY( result8 == digits1 ); + VERIFY( err08 == ios_base::eofbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc new file mode 100644 index 000000000..51682b9c0 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/10.cc @@ -0,0 +1,64 @@ +// { dg-require-namedlocale "en_US" } + +// 2003-10-23 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + locale loc_us = locale("en_US"); + + iterator_type end; + wistringstream iss; + iss.imbue(loc_us); + + const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); + + iss.str(L"-$0 "); + iterator_type is_it(iss); + wstring extracted_amount; + ios_base::iostate err = ios_base::goodbit; + mon_get.get(is_it, end, false, iss, err, extracted_amount); + VERIFY( extracted_amount == L"0" ); + VERIFY( err == ios_base::goodbit ); + + iss.str(L"-$ "); + iterator_type is_it_2(iss); + extracted_amount.clear(); + err = ios_base::goodbit; + mon_get.get(is_it_2, end, false, iss, err, extracted_amount); + VERIFY( extracted_amount.empty() ); + VERIFY( err == ios_base::failbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11.cc new file mode 100644 index 000000000..bab3e53fd --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11.cc @@ -0,0 +1,64 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2003-10-24 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_de = locale("de_DE@euro"); + + iterator_type end; + wistringstream iss; + iss.imbue(loc_de); + + // cache the money_get facet + const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); + + // A _very_ big amount. + wstring str = L"1"; + for (int i = 0; i < 2 * numeric_limits<long double>::digits10; ++i) + str += L".000"; + str += L",00 "; + + iss.str(str); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); + VERIFY( err01 == ios_base::eofbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11528.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11528.cc new file mode 100644 index 000000000..3f552f591 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/11528.cc @@ -0,0 +1,54 @@ +// { dg-require-namedlocale "en_US" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + locale loc_us = locale("en_US"); + + iterator_type end; + wistringstream iss; + iss.imbue(loc_us); + + const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); + + iss.str(L"$.00 "); + iterator_type is_it(iss); + wstring extracted_amount; + ios_base::iostate err = ios_base::goodbit; + mon_get.get(is_it, end, false, iss, err, extracted_amount); + VERIFY( extracted_amount == L"0" ); + VERIFY( err == ios_base::goodbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/12.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/12.cc new file mode 100644 index 000000000..c9e7c1857 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/12.cc @@ -0,0 +1,71 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2004-02-05 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// Same as 3.cc but no thousands-sep in input: they are always optional. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<wchar_t> iterator_type; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + // total EPA budget FY 2002 + const long double digits1 = 720000000000.0; + + iterator_type end; + wistringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); + + iss.str(L"7200000000,00 "); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); + VERIFY( result1 == digits1 ); + VERIFY( err01 == ios_base::eofbit ); + + iss.str(L"7200000000,00 "); + iterator_type is_it02(iss); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + mon_get.get(is_it02, end, false, iss, err02, result2); + VERIFY( result2 == digits1 ); + VERIFY( err02 == ios_base::eofbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/13.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/13.cc new file mode 100644 index 000000000..99b895ee9 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/13.cc @@ -0,0 +1,68 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2004-02-05 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// No thousands-sep allowed after the decimal-point. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<wchar_t> iterator_type; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + iterator_type end01, end02; + wistringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); + + iss.str(L"500,1.0 "); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get.get(is_it01, end01, true, iss, err01, result1); + VERIFY( err01 == ios_base::failbit ); + VERIFY( *end01 == '.' ); + + iss.str(L"500,1.0 "); + iterator_type is_it02(iss); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get.get(is_it02, end02, false, iss, err02, result2); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == '.' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/14.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/14.cc new file mode 100644 index 000000000..56ba0d4ac --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/14.cc @@ -0,0 +1,61 @@ +// 2004-02-21 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money : public std::moneypunct<wchar_t, false> +{ + std::wstring do_positive_sign() const { return L"+"; } + std::wstring do_negative_sign() const { return L""; } +}; + +void test01() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> InIt; + + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new My_money); + + wstring buffer(L"69"); + + InIt iend; + ios_base::iostate err; + wstring val; + + const money_get<wchar_t, InIt>& mg = + use_facet<money_get<wchar_t, InIt> >(loc); + + wistringstream fmt(buffer); + fmt.imbue(loc); + InIt ibeg(fmt); + mg.get(ibeg, iend, false, fmt, err, val); + VERIFY( val == L"-69" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/15.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/15.cc new file mode 100644 index 000000000..08fb6225e --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/15.cc @@ -0,0 +1,70 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2004-03-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// The grammar doesn't allow thousands separator at the beginning of a +// string, neither two consecutive thousands separators. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<wchar_t> iterator_type; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + iterator_type end01, end02; + wistringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<wchar_t>& mon_get = + use_facet<money_get<wchar_t> >(iss.getloc()); + + iss.str(L".100"); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get.get(is_it01, end01, true, iss, err01, result1); + VERIFY( err01 == ios_base::failbit ); + VERIFY( *end01 == L'.' ); + + iss.str(L"30..0"); + iterator_type is_it02(iss); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get.get(is_it02, end02, false, iss, err02, result2); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == L'.' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/16.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/16.cc new file mode 100644 index 000000000..4736617fc --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/16.cc @@ -0,0 +1,77 @@ +// { dg-require-namedlocale "de_DE@euro" } +// { dg-require-namedlocale "en_HK" } + +// 2004-03-02 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// Fail as soon as value digits are not present. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<wchar_t> iterator_type; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + locale loc_hk = locale("en_HK"); + VERIFY( loc_hk != loc_de ); + VERIFY( loc_c != loc_hk ); + + iterator_type end01, end02; + wistringstream iss01, iss02; + iss01.imbue(loc_de); + iss02.imbue(loc_hk); + + // cache the money_get facet + const money_get<wchar_t>& mon_get_01 = + use_facet<money_get<wchar_t> >(iss01.getloc()); + const money_get<wchar_t>& mon_get_02 = + use_facet<money_get<wchar_t> >(iss02.getloc()); + + iss01.setf(ios_base::showbase); + iss01.str(L"EUR "); + iterator_type is_it01(iss01); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get_01.get(is_it01, end01, true, iss01, err01, result1); + VERIFY( err01 == ios_base::failbit ); + VERIFY( *end01 == L'E' ); + + iss02.str(L"(HKD )"); + iterator_type is_it02(iss02); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get_02.get(is_it02, end02, true, iss02, err02, result2); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == L')' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/17.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/17.cc new file mode 100644 index 000000000..857032e47 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/17.cc @@ -0,0 +1,72 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2004-03-08 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// 22.2.6.3, p2: "The value _space_ indicates that at least one space +// is required at that position." +void test01() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + iterator_type end, end02; + wistringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<wchar_t>& mon_get = + use_facet<money_get<wchar_t> >(iss.getloc()); + + iss.str(L"7.200.000.000,00"); + iterator_type is_it01(iss); + wstring result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); + VERIFY( err01 == (ios_base::failbit | ios_base::eofbit) ); + + // now try with showbase, to get currency symbol in format + iss.setf(ios_base::showbase); + + iss.str(L"7.200.000.000,00EUR "); + iterator_type is_it02(iss); + wstring result2; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get.get(is_it02, end, true, iss, err02, result2); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == L'E' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/18.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/18.cc new file mode 100644 index 000000000..c1226ad7a --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/18.cc @@ -0,0 +1,70 @@ +// { dg-require-namedlocale "en_HK" } + +// 2004-03-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// If (str.flags() & str.showbase) is false, the currency symbol is optional, +// but, if found, must be consumed entirely. +void test01() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_hk = locale("en_HK"); + VERIFY( loc_c != loc_hk ); + + iterator_type end, end01, end02; + wistringstream iss; + iss.imbue(loc_hk); + // cache the money_get facet + const money_get<wchar_t>& mon_get = + use_facet<money_get<wchar_t> >(iss.getloc()); + + iss.str(L"HK7,200,000,000.00"); + iterator_type is_it01(iss); + wstring result01; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get.get(is_it01, end, false, iss, err01, result01); + VERIFY( err01 == ios_base::failbit ); + VERIFY( *end01 == L'7' ); + + iss.str(L"(HK100,000,000,000.00)"); + iterator_type is_it02(iss); + wstring result02; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get.get(is_it02, end, true, iss, err02, result02); + VERIFY( err02 == ios_base::failbit ); + VERIFY( *end02 == L'1' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/19.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/19.cc new file mode 100644 index 000000000..43c7a2405 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/19.cc @@ -0,0 +1,124 @@ +// 2004-03-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money_io_01 : public std::moneypunct<wchar_t, false> +{ + std::wstring do_curr_symbol() const { return L"$"; } + std::wstring do_positive_sign() const { return L""; } + std::wstring do_negative_sign() const { return L""; } + + pattern do_neg_format() const + { + pattern pat = { { value, symbol, none, sign } }; + return pat; + } +}; + +struct My_money_io_02 : public std::moneypunct<wchar_t, false> +{ + std::wstring do_curr_symbol() const { return L"%"; } + std::wstring do_positive_sign() const { return L""; } + std::wstring do_negative_sign() const { return L"-"; } + + pattern do_neg_format() const + { + pattern pat = { { value, symbol, sign, none } }; + return pat; + } +}; + +struct My_money_io_03 : public std::moneypunct<wchar_t, false> +{ + std::wstring do_curr_symbol() const { return L"&"; } + std::wstring do_positive_sign() const { return L""; } + std::wstring do_negative_sign() const { return L""; } + + pattern do_neg_format() const + { + pattern pat = { { value, space, symbol, sign } }; + return pat; + } +}; + +// When both do_positive_sign and do_negative_sign return an empty +// string, patterns of the forms { value, symbol, none, sign }, +// { value, symbol, sign, none } and { X, Y, symbol, sign } imply +// that the symbol is not consumed since no other characters are +// needed to complete the format. +void test01() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_01(locale::classic(), new My_money_io_01); + locale loc_02(locale::classic(), new My_money_io_02); + locale loc_03(locale::classic(), new My_money_io_03); + + iterator_type end, end01, end02, end03; + wistringstream iss_01, iss_02, iss_03; + iss_01.imbue(loc_01); + iss_02.imbue(loc_02); + iss_03.imbue(loc_03); + // cache the money_get facet + const money_get<wchar_t>& mon_get_01 = + use_facet<money_get<wchar_t> >(iss_01.getloc()); + const money_get<wchar_t>& mon_get_02 = + use_facet<money_get<wchar_t> >(iss_02.getloc()); + const money_get<wchar_t>& mon_get_03 = + use_facet<money_get<wchar_t> >(iss_03.getloc()); + + iss_01.str(L"10$"); + iterator_type is_it01(iss_01); + wstring result01; + ios_base::iostate err01 = ios_base::goodbit; + end01 = mon_get_01.get(is_it01, end, false, iss_01, err01, result01); + VERIFY( err01 == ios_base::goodbit ); + VERIFY( *end01 == L'$' ); + + iss_02.str(L"50%"); + iterator_type is_it02(iss_02); + wstring result02; + ios_base::iostate err02 = ios_base::goodbit; + end02 = mon_get_02.get(is_it02, end, false, iss_02, err02, result02); + VERIFY( err02 == ios_base::goodbit ); + VERIFY( *end02 == L'%' ); + + iss_03.str(L"7 &"); + iterator_type is_it03(iss_03); + wstring result03; + ios_base::iostate err03 = ios_base::goodbit; + end03 = mon_get_03.get(is_it03, end, false, iss_03, err03, result03); + VERIFY( err03 == ios_base::goodbit ); + VERIFY( *end03 == L'&' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/2.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/2.cc new file mode 100644 index 000000000..15bccc6ec --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/2.cc @@ -0,0 +1,118 @@ +// { dg-require-namedlocale "en_HK" } + +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// test wstring version +void test02() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_hk = locale("en_HK"); + VERIFY( loc_c != loc_hk ); + + // total EPA budget FY 2002 + const wstring digits1(L"720000000000"); + + // est. cost, national missile "defense", expressed as a loss in USD 2001 + const wstring digits2(L"-10000000000000"); + + // input less than frac_digits + const wstring digits4(L"-1"); + + iterator_type end; + wistringstream iss; + iss.imbue(loc_hk); + // cache the money_get facet + const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); + + // now try with showbase, to get currency symbol in format + iss.setf(ios_base::showbase); + + iss.str(L"HK$7,200,000,000.00"); + iterator_type is_it09(iss); + wstring result9; + ios_base::iostate err09 = ios_base::goodbit; + mon_get.get(is_it09, end, false, iss, err09, result9); + VERIFY( result9 == digits1 ); + VERIFY( err09 == ios_base::eofbit ); + + iss.str(L"(HKD 100,000,000,000.00)"); + iterator_type is_it10(iss); + wstring result10; + ios_base::iostate err10 = ios_base::goodbit; + mon_get.get(is_it10, end, true, iss, err10, result10); + VERIFY( result10 == digits2 ); + VERIFY( err10 == ios_base::eofbit ); + + iss.str(L"(HKD .01)"); + iterator_type is_it11(iss); + wstring result11; + ios_base::iostate err11 = ios_base::goodbit; + mon_get.get(is_it11, end, true, iss, err11, result11); + VERIFY( result11 == digits4 ); + VERIFY( err11 == ios_base::eofbit ); + + // for the "en_HK" locale the parsing of the very same input streams must + // be successful without showbase too, since the symbol field appears in + // the first positions in the format and the symbol, when present, must be + // consumed. + iss.unsetf(ios_base::showbase); + + iss.str(L"HK$7,200,000,000.00"); + iterator_type is_it12(iss); + wstring result12; + ios_base::iostate err12 = ios_base::goodbit; + mon_get.get(is_it12, end, false, iss, err12, result12); + VERIFY( result12 == digits1 ); + VERIFY( err12 == ios_base::eofbit ); + + iss.str(L"(HKD 100,000,000,000.00)"); + iterator_type is_it13(iss); + wstring result13; + ios_base::iostate err13 = ios_base::goodbit; + mon_get.get(is_it13, end, true, iss, err13, result13); + VERIFY( result13 == digits2 ); + VERIFY( err13 == ios_base::eofbit ); + + iss.str(L"(HKD .01)"); + iterator_type is_it14(iss); + wstring result14; + ios_base::iostate err14 = ios_base::goodbit; + mon_get.get(is_it14, end, true, iss, err14, result14); + VERIFY( result14 == digits4 ); + VERIFY( err14 == ios_base::eofbit ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/22131.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/22131.cc new file mode 100644 index 000000000..7613daabd --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/22131.cc @@ -0,0 +1,82 @@ +// 2005-06-28 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money_io : public std::moneypunct<wchar_t, false> +{ + std::string do_grouping() const { return "\1"; } + char_type do_thousands_sep() const { return L'#'; } + + pattern do_neg_format() const + { + pattern pat = { { symbol, none, sign, value } }; + return pat; + } +}; + +// libstdc++/22131 +void test01() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> InIt; + + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new My_money_io); + + wstring buffer1(L"00#0#1"); + wstring buffer2(L"000##1"); + + bool intl = false; + + InIt iend1, iend2; + ios_base::iostate err1, err2; + wstring val1, val2; + + const money_get<wchar_t,InIt>& mg = + use_facet<money_get<wchar_t, InIt> >(loc); + + wistringstream fmt1(buffer1); + fmt1.imbue(loc); + InIt ibeg1(fmt1); + err1 = ios_base::goodbit; + mg.get(ibeg1, iend1, intl, fmt1, err1, val1); + VERIFY( err1 == (ios_base::eofbit | ios_base::failbit) ); + VERIFY( val1 == L"1" ); + + wistringstream fmt2(buffer2); + fmt2.imbue(loc); + InIt ibeg2(fmt2); + err2 = ios_base::goodbit; + mg.get(ibeg2, iend2, intl, fmt2, err2, val2); + VERIFY( err2 == ios_base::failbit ); + VERIFY( *ibeg2 == L'#' ); + VERIFY( val2 == L"" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/3.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/3.cc new file mode 100644 index 000000000..136369ed7 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/3.cc @@ -0,0 +1,71 @@ +// { dg-require-namedlocale "de_DE@euro" } + +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// test double version +void test03() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE@euro"); + VERIFY( loc_c != loc_de ); + + // total EPA budget FY 2002 + const long double digits1 = 720000000000.0; + + iterator_type end; + wistringstream iss; + iss.imbue(loc_de); + // cache the money_get facet + const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); + + iss.str(L"7.200.000.000,00 "); + iterator_type is_it01(iss); + long double result1; + ios_base::iostate err01 = ios_base::goodbit; + mon_get.get(is_it01, end, true, iss, err01, result1); + VERIFY( result1 == digits1 ); + VERIFY( err01 == ios_base::eofbit ); + + iss.str(L"7.200.000.000,00 "); + iterator_type is_it02(iss); + long double result2; + ios_base::iostate err02 = ios_base::goodbit; + mon_get.get(is_it02, end, false, iss, err02, result2); + VERIFY( result2 == digits1 ); + VERIFY( err02 == ios_base::eofbit ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/38399.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/38399.cc new file mode 100644 index 000000000..1fdfa90d7 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/38399.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2008, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +class my_moneypunct : public std::moneypunct<wchar_t> +{ +protected: + //this should disable fraction part of monetary value + int do_frac_digits() const { return 0; } +}; + +// libstdc++/38399 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale(), new my_moneypunct()); + wstringstream ss(L"123.455"); + ss.imbue(loc); + wstring digits; + ios_base::iostate err; + istreambuf_iterator<wchar_t> iter = + use_facet<money_get<wchar_t> >(loc).get(ss, 0, false, ss, err, digits); + + wstring rest = wstring(iter, istreambuf_iterator<wchar_t>()); + VERIFY( digits == L"123" ); + VERIFY( rest == L".455" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/39168.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/39168.cc new file mode 100644 index 000000000..986be5c3f --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/39168.cc @@ -0,0 +1,56 @@ +// Copyright (C) 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <sstream> +#include <locale> +#include <climits> +#include <testsuite_hooks.h> + +class my_moneypunct: public std::moneypunct<wchar_t> +{ +protected: + std::string do_grouping() const { return std::string(1, CHAR_MAX); } +}; + +// libstdc++/39168 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + wistringstream iss; + iss.imbue(locale(iss.getloc(), new my_moneypunct)); + const money_get<wchar_t>& mg = use_facet<money_get<wchar_t> >(iss.getloc()); + + wstring digits; + ios_base::iostate err = ios_base::goodbit; + + iss.str(L"123,456"); + iterator_type end = mg.get(iss.rdbuf(), 0, false, iss, err, digits); + VERIFY( err == ios_base::goodbit ); + VERIFY( digits == L"123" ); + VERIFY( *end == L',' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/4.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/4.cc new file mode 100644 index 000000000..bfb803d78 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/4.cc @@ -0,0 +1,66 @@ +// { dg-require-namedlocale "en_HK" } + +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// test double version +void test04() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> iterator_type; + + bool test __attribute__((unused)) = true; + + // basic construction + locale loc_c = locale::classic(); + locale loc_hk = locale("en_HK"); + VERIFY( loc_c != loc_hk ); + + // input less than frac_digits + const long double digits4 = -1.0; + + iterator_type end; + wistringstream iss; + iss.imbue(loc_hk); + // cache the money_get facet + const money_get<wchar_t>& mon_get = use_facet<money_get<wchar_t> >(iss.getloc()); + + // now try with showbase, to get currency symbol in format + iss.setf(ios_base::showbase); + + iss.str(L"(HKD .01)"); + iterator_type is_it03(iss); + long double result3; + ios_base::iostate err03 = ios_base::goodbit; + mon_get.get(is_it03, end, true, iss, err03, result3); + VERIFY( result3 == digits4 ); + VERIFY( err03 == ios_base::eofbit ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/5.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/5.cc new file mode 100644 index 000000000..1fa4901ed --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/5.cc @@ -0,0 +1,70 @@ +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 +// Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +void test05() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // Check money_get works with other iterators besides streambuf + // input iterators. + typedef wstring::const_iterator iter_type; + typedef money_get<wchar_t, iter_type> mon_get_type; + const ios_base::iostate goodbit = ios_base::goodbit; + ios_base::iostate err = goodbit; + const locale loc_c = locale::classic(); + const wstring str = L"1Eleanor Roosevelt"; + + wistringstream iss; + iss.imbue(locale(loc_c, new mon_get_type)); + + // Iterator advanced, state, output. + const mon_get_type& mg = use_facet<mon_get_type>(iss.getloc()); + + // 01 wstring + wstring res1; + iter_type end1 = mg.get(str.begin(), str.end(), false, iss, err, res1); + wstring rem1(end1, str.end()); + VERIFY( err == goodbit ); + VERIFY( res1 == L"1" ); + VERIFY( rem1 == L"Eleanor Roosevelt" ); + + // 02 long double + iss.clear(); + err = goodbit; + long double res2; + iter_type end2 = mg.get(str.begin(), str.end(), false, iss, err, res2); + wstring rem2(end2, str.end()); + VERIFY( err == goodbit ); + VERIFY( res2 == 1 ); + VERIFY( rem2 == L"Eleanor Roosevelt" ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/6.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/6.cc new file mode 100644 index 000000000..828c8abb1 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/6.cc @@ -0,0 +1,95 @@ +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money_io : public std::moneypunct<wchar_t,false> +{ + char_type do_decimal_point() const { return '.'; } + std::string do_grouping() const { return "\004"; } + + std::wstring do_curr_symbol() const { return L"$"; } + std::wstring do_positive_sign() const { return L""; } + std::wstring do_negative_sign() const { return L"-"; } + + int do_frac_digits() const { return 2; } + + pattern do_neg_format() const + { + pattern pat = { { symbol, none, sign, value } }; + return pat; + } +}; + +// libstdc++/5579 +void test06() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> InIt; + + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new My_money_io); + + wstring bufferp(L"$1234.56"); + wstring buffern(L"$-1234.56"); + wstring bufferp_ns(L"1234.56"); + wstring buffern_ns(L"-1234.56"); + + bool intl = false; + + InIt iendp, iendn, iendp_ns, iendn_ns; + ios_base::iostate err; + wstring valp, valn, valp_ns, valn_ns; + + const money_get<wchar_t,InIt>& mg = use_facet<money_get<wchar_t, InIt> >(loc); + wistringstream fmtp(bufferp); + fmtp.imbue(loc); + InIt ibegp(fmtp); + mg.get(ibegp,iendp,intl,fmtp,err,valp); + VERIFY( valp == L"123456" ); + + wistringstream fmtn(buffern); + fmtn.imbue(loc); + InIt ibegn(fmtn); + mg.get(ibegn,iendn,intl,fmtn,err,valn); + VERIFY( valn == L"-123456" ); + + wistringstream fmtp_ns(bufferp_ns); + fmtp_ns.imbue(loc); + InIt ibegp_ns(fmtp_ns); + mg.get(ibegp_ns,iendp_ns,intl,fmtp_ns,err,valp_ns); + VERIFY( valp_ns == L"123456" ); + + wistringstream fmtn_ns(buffern_ns); + fmtn_ns.imbue(loc); + InIt ibegn_ns(fmtn_ns); + mg.get(ibegn_ns,iendn_ns,intl,fmtn_ns,err,valn_ns); + VERIFY( valn_ns == L"-123456" ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/7.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/7.cc new file mode 100644 index 000000000..706879ecb --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/7.cc @@ -0,0 +1,72 @@ +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +// We were appending to the string val passed by reference, instead +// of constructing a temporary candidate, eventually copied into +// val in case of successful parsing. +void test07() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<wchar_t> InIt; + InIt iend1, iend2, iend3; + + locale loc_c = locale::classic(); + wstring buffer1(L"123"); + wstring buffer2(L"456"); + wstring buffer3(L"Golgafrincham"); // From Nathan's original idea. + + wstring val; + + ios_base::iostate err; + + const money_get<wchar_t, InIt>& mg = use_facet<money_get<wchar_t, InIt> >(loc_c); + + wistringstream fmt1(buffer1); + fmt1.imbue(loc_c); + InIt ibeg1(fmt1); + mg.get(ibeg1, iend1, false, fmt1, err, val); + VERIFY( val == buffer1 ); + + wistringstream fmt2(buffer2); + fmt2.imbue(loc_c); + InIt ibeg2(fmt2); + mg.get(ibeg2, iend2, false, fmt2, err, val); + VERIFY( val == buffer2 ); + + val = buffer3; + wistringstream fmt3(buffer3); + fmt3.imbue(loc_c); + InIt ibeg3(fmt3); + mg.get(ibeg3, iend3, false, fmt3, err, val); + VERIFY( val == buffer3 ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/8.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/8.cc new file mode 100644 index 000000000..aa960daf2 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/8.cc @@ -0,0 +1,122 @@ +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1.1 money_get members + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> + +struct My_money_io_a : public std::moneypunct<wchar_t,false> +{ + char_type do_decimal_point() const { return '.'; } + std::string do_grouping() const { return "\004"; } + + std::wstring do_curr_symbol() const { return L"$"; } + std::wstring do_positive_sign() const { return L"()"; } + + int do_frac_digits() const { return 2; } + + pattern do_neg_format() const + { + pattern pat = { { sign, value, space, symbol } }; + return pat; + } +}; + +struct My_money_io_b : public std::moneypunct<wchar_t,false> +{ + char_type do_decimal_point() const { return '.'; } + std::string do_grouping() const { return "\004"; } + + std::wstring do_curr_symbol() const { return L"$"; } + std::wstring do_positive_sign() const { return L"()"; } + + int do_frac_digits() const { return 2; } + + pattern do_neg_format() const + { + pattern pat = { { sign, value, symbol, none } }; + return pat; + } +}; + +// This one exercises patterns of the type { X, Y, Z, symbol } and +// { X, Y, symbol, none } for a two character long sign. Therefore +// the optional symbol (showbase is false by default) must be consumed +// if present, since "rest of the sign" is left to read. +void test08() +{ + using namespace std; + typedef istreambuf_iterator<wchar_t> InIt; + + bool intl = false; + bool test __attribute__((unused)) = true; + ios_base::iostate err; + + locale loc_a(locale::classic(), new My_money_io_a); + + wstring buffer_a(L"(1234.56 $)"); + wstring buffer_a_ns(L"(1234.56 )"); + + InIt iend_a, iend_a_ns; + wstring val_a, val_a_ns; + + const money_get<wchar_t,InIt>& mg_a = use_facet<money_get<wchar_t, InIt> >(loc_a); + + wistringstream fmt_a(buffer_a); + fmt_a.imbue(loc_a); + InIt ibeg_a(fmt_a); + mg_a.get(ibeg_a,iend_a,intl,fmt_a,err,val_a); + VERIFY( val_a == L"123456" ); + + wistringstream fmt_a_ns(buffer_a_ns); + fmt_a_ns.imbue(loc_a); + InIt ibeg_a_ns(fmt_a_ns); + mg_a.get(ibeg_a_ns,iend_a_ns,intl,fmt_a_ns,err,val_a_ns); + VERIFY( val_a_ns == L"123456" ); + + locale loc_b(locale::classic(), new My_money_io_b); + + wstring buffer_b(L"(1234.56$)"); + wstring buffer_b_ns(L"(1234.56)"); + + InIt iend_b, iend_b_ns; + wstring val_b, val_b_ns; + + const money_get<wchar_t,InIt>& mg_b = use_facet<money_get<wchar_t, InIt> >(loc_b); + + wistringstream fmt_b(buffer_b); + fmt_b.imbue(loc_b); + InIt ibeg_b(fmt_b); + mg_b.get(ibeg_b,iend_b,intl,fmt_b,err,val_b); + VERIFY( val_b == L"123456" ); + + wistringstream fmt_b_ns(buffer_b_ns); + fmt_b_ns.imbue(loc_b); + InIt ibeg_b_ns(fmt_b_ns); + mg_b.get(ibeg_b_ns,iend_b_ns,intl,fmt_b_ns,err,val_b_ns); + VERIFY( val_b_ns == L"123456" ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/9.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/9.cc new file mode 100644 index 000000000..abb82eb0f --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/9.cc @@ -0,0 +1,90 @@ +// 2003-05-27 Brendan Kehoe <brendan@zen.org> + +// Copyright (C) 2003, 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// $22.2.6.3/3 +// The number of digits required after the decimal point (if any) is exactly +// the value returned by frac_digits(). + +#include <locale> +#include <sstream> + +class dublin : public std::moneypunct<wchar_t> { +public: + int do_frac_digits() const { return 3; } +}; + +int main() +{ + std::wistringstream liffey; + std::wstring coins; + + std::locale eire(std::locale::classic(), new dublin); + liffey.imbue(eire); + + const std::money_get<wchar_t>& greed + = std::use_facet<std::money_get<wchar_t> >(liffey.getloc()); + + typedef std::istreambuf_iterator<wchar_t> iterator_type; + iterator_type is(liffey); + iterator_type end; + + std::ios_base::iostate err01 = std::ios_base::goodbit; + + int fails = 0; + + // Feed it 1 digit too many, which should fail. + liffey.str(L"12.3456"); + greed.get(is, end, false, liffey, err01, coins); + if (! (err01 & std::ios_base::failbit )) + fails |= 0x01; + + err01 = std::ios_base::goodbit; + + // Feed it exactly what it wants, which should succeed. + liffey.str(L"12.345"); + greed.get(is, end, false, liffey, err01, coins); + if ( err01 & std::ios_base::failbit ) + fails |= 0x02; + + err01 = std::ios_base::goodbit; + + // Feed it 1 digit too few, which should fail. + liffey.str(L"12.34"); + greed.get(is, end, false, liffey, err01, coins); + if (! ( err01 & std::ios_base::failbit )) + fails |= 0x04; + + err01 = std::ios_base::goodbit; + + // Feed it only a decimal-point, which should fail. + liffey.str(L"12."); + greed.get(is, end, false, liffey, err01, coins); + if (! (err01 & std::ios_base::failbit )) + fails |= 0x08; + + err01 = std::ios_base::goodbit; + + // Feed it no decimal-point at all, which should succeed. + liffey.str(L"12"); + greed.get(is, end, false, liffey, err01, coins); + if ( err01 & std::ios_base::failbit ) + fails |= 0x10; + + return fails; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/wrapped_env.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/wrapped_env.cc new file mode 100644 index 000000000..c0a769d78 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/wrapped_env.cc @@ -0,0 +1,74 @@ +// { dg-require-namedlocale "de_DE" } +// { dg-require-namedlocale "de_DE@euro" } +// { dg-require-namedlocale "en_HK" } + +// 2001-08-15 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.4.1.1 collate members + +#include <testsuite_hooks.h> + +#define main discard_main_1 +#include "1.cc" +#undef main + +#define main discard_main_2 +#include "2.cc" +#undef main + +#define main discard_main_3 +#include "3.cc" +#undef main + +#define main discard_main_4 +#include "4.cc" +#undef main + +#define main discard_main_5 +#include "5.cc" +#undef main + +#define main discard_main_6 +#include "6.cc" +#undef main + +#define main discard_main_7 +#include "7.cc" +#undef main + +#define main discard_main_8 +#include "8.cc" +#undef main + +int main() +{ + using namespace __gnu_test; + func_callback two; + two.push_back(&test01); + two.push_back(&test02); + two.push_back(&test03); + two.push_back(&test04); + two.push_back(&test05); + two.push_back(&test06); + two.push_back(&test07); + two.push_back(&test08); + run_tests_wrapped_env("de_DE", "LANG", two); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/wrapped_locale.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/wrapped_locale.cc new file mode 100644 index 000000000..795271f3f --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/wrapped_locale.cc @@ -0,0 +1,74 @@ +// { dg-require-namedlocale "ja_JP.eucjp" } +// { dg-require-namedlocale "de_DE@euro" } +// { dg-require-namedlocale "en_HK" } + +// 2001-08-15 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.4.1.1 collate members + +#include <testsuite_hooks.h> + +#define main discard_main_1 +#include "1.cc" +#undef main + +#define main discard_main_2 +#include "2.cc" +#undef main + +#define main discard_main_3 +#include "3.cc" +#undef main + +#define main discard_main_4 +#include "4.cc" +#undef main + +#define main discard_main_5 +#include "5.cc" +#undef main + +#define main discard_main_6 +#include "6.cc" +#undef main + +#define main discard_main_7 +#include "7.cc" +#undef main + +#define main discard_main_8 +#include "8.cc" +#undef main + +int main() +{ + using namespace __gnu_test; + func_callback two; + two.push_back(&test01); + two.push_back(&test02); + two.push_back(&test03); + two.push_back(&test04); + two.push_back(&test05); + two.push_back(&test06); + two.push_back(&test07); + two.push_back(&test08); + run_tests_wrapped_locale("ja_JP.eucjp", two); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/requirements/base_classes.cc b/libstdc++-v3/testsuite/22_locale/money_get/requirements/base_classes.cc new file mode 100644 index 000000000..5182b1ceb --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/requirements/base_classes.cc @@ -0,0 +1,32 @@ +// { dg-do compile } +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1 Template class money_get + +#include <locale> + +void test01() +{ + // Check for required base class. + typedef std::money_get<char> test_type; + typedef std::locale::facet base_type; + const test_type& obj = std::use_facet<test_type>(std::locale()); + const base_type* base __attribute__((unused)) = &obj; +} diff --git a/libstdc++-v3/testsuite/22_locale/money_get/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/22_locale/money_get/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..d6b2f7d0a --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/requirements/explicit_instantiation.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1 Template class money_get + +#include <locale> + +// Should be able to instantiate this for other types besides char, wchar_t +template class std::money_get<unsigned char>; diff --git a/libstdc++-v3/testsuite/22_locale/money_get/requirements/typedefs.cc b/libstdc++-v3/testsuite/22_locale/money_get/requirements/typedefs.cc new file mode 100644 index 000000000..b5bcbae54 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/money_get/requirements/typedefs.cc @@ -0,0 +1,32 @@ +// { dg-do compile } +// 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 22.2.6.1 Template class money_get + +#include <locale> + +void test01() +{ + // Check for required typedefs + typedef std::money_get<char> test_type; + typedef test_type::char_type char_type; + typedef test_type::string_type string_type; + typedef test_type::iter_type iter_type; +} |