Reset branch to trunk.
[official-gcc.git] / trunk / libstdc++-v3 / testsuite / 22_locale / money_get / get / wchar_t / 9.cc
blobabb82eb0fd89a76ba64bdae5e336814d33b6632d
1 // 2003-05-27 Brendan Kehoe <brendan@zen.org>
3 // Copyright (C) 2003, 2004, 2009 Free Software Foundation
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // $22.2.6.3/3
21 // The number of digits required after the decimal point (if any) is exactly
22 // the value returned by frac_digits().
24 #include <locale>
25 #include <sstream>
27 class dublin : public std::moneypunct<wchar_t> {
28 public:
29 int do_frac_digits() const { return 3; }
32 int main()
34 std::wistringstream liffey;
35 std::wstring coins;
37 std::locale eire(std::locale::classic(), new dublin);
38 liffey.imbue(eire);
40 const std::money_get<wchar_t>& greed
41 = std::use_facet<std::money_get<wchar_t> >(liffey.getloc());
43 typedef std::istreambuf_iterator<wchar_t> iterator_type;
44 iterator_type is(liffey);
45 iterator_type end;
47 std::ios_base::iostate err01 = std::ios_base::goodbit;
49 int fails = 0;
51 // Feed it 1 digit too many, which should fail.
52 liffey.str(L"12.3456");
53 greed.get(is, end, false, liffey, err01, coins);
54 if (! (err01 & std::ios_base::failbit ))
55 fails |= 0x01;
57 err01 = std::ios_base::goodbit;
59 // Feed it exactly what it wants, which should succeed.
60 liffey.str(L"12.345");
61 greed.get(is, end, false, liffey, err01, coins);
62 if ( err01 & std::ios_base::failbit )
63 fails |= 0x02;
65 err01 = std::ios_base::goodbit;
67 // Feed it 1 digit too few, which should fail.
68 liffey.str(L"12.34");
69 greed.get(is, end, false, liffey, err01, coins);
70 if (! ( err01 & std::ios_base::failbit ))
71 fails |= 0x04;
73 err01 = std::ios_base::goodbit;
75 // Feed it only a decimal-point, which should fail.
76 liffey.str(L"12.");
77 greed.get(is, end, false, liffey, err01, coins);
78 if (! (err01 & std::ios_base::failbit ))
79 fails |= 0x08;
81 err01 = std::ios_base::goodbit;
83 // Feed it no decimal-point at all, which should succeed.
84 liffey.str(L"12");
85 greed.get(is, end, false, liffey, err01, coins);
86 if ( err01 & std::ios_base::failbit )
87 fails |= 0x10;
89 return fails;