1// 2003-05-27 Brendan Kehoe  <brendan@zen.org>
2
3// Copyright (C) 2003-2015 Free Software Foundation, Inc.
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.
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 COPYING3.  If not see
18// <http://www.gnu.org/licenses/>.
19
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().
23
24#include <locale>
25#include <sstream>
26
27class dublin : public std::moneypunct<wchar_t> {
28public:
29  int do_frac_digits() const { return 3; }
30};
31
32int main()
33{
34  std::wistringstream liffey;
35  std::wstring coins;
36
37  std::locale eire(std::locale::classic(), new dublin);
38  liffey.imbue(eire);
39
40  const std::money_get<wchar_t>& greed
41    = std::use_facet<std::money_get<wchar_t> >(liffey.getloc());
42
43  typedef std::istreambuf_iterator<wchar_t> iterator_type;
44  iterator_type is(liffey);
45  iterator_type end;
46
47  std::ios_base::iostate err01 = std::ios_base::goodbit;
48
49  int fails = 0;
50
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;
56
57  err01 = std::ios_base::goodbit;
58
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;
64
65  err01 = std::ios_base::goodbit;
66
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;
72
73  err01 = std::ios_base::goodbit;
74
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;
80
81  err01 = std::ios_base::goodbit;
82
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;
88
89  return fails;
90}
91