1// 2003-05-27 Brendan Kehoe  <brendan@zen.org>
2
3// Copyright (C) 2003, 2004 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.
10
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.
15
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19// USA.
20
21// $22.2.6.3/3
22// The number of digits required after the decimal point (if any) is exactly
23// the value returned by frac_digits().
24
25#include <locale>
26#include <sstream>
27
28class dublin : public std::moneypunct<wchar_t> {
29public:
30  int do_frac_digits() const { return 3; }
31};
32
33int main()
34{
35  std::wistringstream liffey;
36  std::wstring coins;
37
38  std::locale eire(std::locale::classic(), new dublin);
39  liffey.imbue(eire);
40
41  const std::money_get<wchar_t>& greed
42    = std::use_facet<std::money_get<wchar_t> >(liffey.getloc());
43
44  typedef std::istreambuf_iterator<wchar_t> iterator_type;
45  iterator_type is(liffey);
46  iterator_type end;
47
48  std::ios_base::iostate err01 = std::ios_base::goodbit;
49
50  int fails = 0;
51
52  // Feed it 1 digit too many, which should fail.
53  liffey.str(L"12.3456");
54  greed.get(is, end, false, liffey, err01, coins);
55  if (! (err01 & std::ios_base::failbit ))
56    fails |= 0x01;
57
58  err01 = std::ios_base::goodbit;
59
60  // Feed it exactly what it wants, which should succeed.
61  liffey.str(L"12.345");
62  greed.get(is, end, false, liffey, err01, coins);
63  if ( err01 & std::ios_base::failbit )
64    fails |= 0x02;
65
66  err01 = std::ios_base::goodbit;
67
68  // Feed it 1 digit too few, which should fail.
69  liffey.str(L"12.34");
70  greed.get(is, end, false, liffey, err01, coins);
71  if (! ( err01 & std::ios_base::failbit ))
72    fails |= 0x04;
73
74  err01 = std::ios_base::goodbit;
75
76  // Feed it only a decimal-point, which should fail.
77  liffey.str(L"12.");
78  greed.get(is, end, false, liffey, err01, coins);
79  if (! (err01 & std::ios_base::failbit ))
80    fails |= 0x08;
81
82  err01 = std::ios_base::goodbit;
83
84  // Feed it no decimal-point at all, which should succeed.
85  liffey.str(L"12");
86  greed.get(is, end, false, liffey, err01, coins);
87  if ( err01 & std::ios_base::failbit )
88    fails |= 0x10;
89
90  return fails;
91}
92