1// Copyright (C) 2003 Free Software Foundation 2// 3// This file is part of the GNU ISO C++ Library. This library is free 4// software; you can redistribute it and/or modify it under the 5// terms of the GNU General Public License as published by the 6// Free Software Foundation; either version 2, or (at your option) 7// any later version. 8 9// This library is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13 14// You should have received a copy of the GNU General Public License along 15// with this library; see the file COPYING. If not, write to the Free 16// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 17// USA. 18 19// 22.2.2.1.1 num_get members 20 21#include <locale> 22#include <sstream> 23#include <testsuite_hooks.h> 24 25struct Punct1: std::numpunct<wchar_t> 26{ 27 std::string do_grouping() const { return "\1"; } 28 wchar_t do_thousands_sep() const { return L'2'; } 29 wchar_t do_decimal_point() const { return L'4'; } 30}; 31 32struct Punct2: std::numpunct<wchar_t> 33{ 34 std::string do_grouping() const { return "\1"; } 35 wchar_t do_thousands_sep() const { return L'2'; } 36 wchar_t do_decimal_point() const { return L'2'; } 37}; 38 39// http://gcc.gnu.org/ml/libstdc++/2003-12/msg00201.html 40void test01() 41{ 42 using namespace std; 43 typedef istreambuf_iterator<wchar_t> iterator_type; 44 45 bool test __attribute__((unused)) = true; 46 47 wistringstream iss1, iss2; 48 iss1.imbue(locale(iss1.getloc(), new Punct1)); 49 iss2.imbue(locale(iss2.getloc(), new Punct2)); 50 const num_get<wchar_t>& ng1 = use_facet<num_get<wchar_t> >(iss1.getloc()); 51 const num_get<wchar_t>& ng2 = use_facet<num_get<wchar_t> >(iss2.getloc()); 52 53 ios_base::iostate err = ios_base::goodbit; 54 iterator_type end; 55 double d = 0.0; 56 double d1 = 13.0; 57 double d2 = 1.0; 58 double d3 = 30.0; 59 long l = 0l; 60 long l1 = 13l; 61 long l2 = 10l; 62 63 iss1.str(L"1234"); 64 err = ios_base::goodbit; 65 end = ng1.get(iss1.rdbuf(), 0, iss1, err, d); 66 VERIFY( err == ios_base::eofbit ); 67 VERIFY( d == d1 ); 68 69 iss1.str(L"142"); 70 iss1.clear(); 71 err = ios_base::goodbit; 72 end = ng1.get(iss1.rdbuf(), 0, iss1, err, d); 73 VERIFY( err == ios_base::goodbit ); 74 VERIFY( d == d2 ); 75 76 iss1.str(L"3e14"); 77 iss1.clear(); 78 err = ios_base::goodbit; 79 end = ng1.get(iss1.rdbuf(), 0, iss1, err, d); 80 VERIFY( err == ios_base::goodbit ); 81 VERIFY( d == d3 ); 82 83 iss1.str(L"1234"); 84 iss1.clear(); 85 err = ios_base::goodbit; 86 end = ng1.get(iss1.rdbuf(), 0, iss1, err, l); 87 VERIFY( err == ios_base::goodbit ); 88 VERIFY( l == l1 ); 89 90 iss2.str(L"123"); 91 err = ios_base::goodbit; 92 end = ng2.get(iss2.rdbuf(), 0, iss2, err, d); 93 VERIFY( err == ios_base::eofbit ); 94 VERIFY( d == d1 ); 95 96 iss2.str(L"120"); 97 iss2.clear(); 98 err = ios_base::goodbit; 99 end = ng2.get(iss2.rdbuf(), 0, iss2, err, l); 100 VERIFY( err == ios_base::eofbit ); 101 VERIFY( l == l2 ); 102} 103 104int main() 105{ 106 test01(); 107 return 0; 108} 109