2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / money_get / get / char / 9.cc
blobcb56e1a362bbf13225e427551eb85c392a2ee6f1
1 // 2003-05-27 Brendan Kehoe <brendan@zen.org>
3 // Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // $22.2.6.3.3/8
22 // The number of digits required after the decimal point (if any) is exactly
23 // the value returned by frac_digits().
25 #include <locale>
26 #include <sstream>
28 class dublin : public std::moneypunct<char> {
29 public:
30 int do_frac_digits() const { return 3; }
33 int main()
35 std::istringstream liffey;
36 std::string coins;
38 std::locale eire(std::locale::classic(), new dublin);
39 liffey.imbue(eire);
41 const std::money_get<char>& greed
42 = std::use_facet<std::money_get<char> >(liffey.getloc());
44 typedef std::istreambuf_iterator<char> iterator_type;
45 iterator_type is(liffey);
46 iterator_type end;
48 std::ios_base::iostate err01 = std::ios_base::goodbit;
50 int fails = 0;
52 // Feed it 1 digit too many, which should fail.
53 liffey.str("12.3456");
54 greed.get(is, end, false, liffey, err01, coins);
55 if (! (err01 & std::ios_base::failbit ))
56 fails |= 0x01;
58 err01 = std::ios_base::goodbit;
60 // Feed it exactly what it wants, which should succeed.
61 liffey.str("12.345");
62 greed.get(is, end, false, liffey, err01, coins);
63 if ( err01 & std::ios_base::failbit )
64 fails |= 0x02;
66 err01 = std::ios_base::goodbit;
68 // Feed it 1 digit too few, which should fail.
69 liffey.str("12.34");
70 greed.get(is, end, false, liffey, err01, coins);
71 if (! ( err01 & std::ios_base::failbit ))
72 fails |= 0x04;
74 err01 = std::ios_base::goodbit;
76 // Feed it only a decimal-point, which should fail.
77 liffey.str("12.");
78 greed.get(is, end, false, liffey, err01, coins);
79 if (! (err01 & std::ios_base::failbit ))
80 fails |= 0x08;
82 err01 = std::ios_base::goodbit;
84 // Feed it no decimal-point at all, which should succeed.
85 liffey.str("12");
86 greed.get(is, end, false, liffey, err01, coins);
87 if ( err01 & std::ios_base::failbit )
88 fails |= 0x10;
90 return fails;