OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [22_locale/] [money_get/] [get/] [char/] [9.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 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
 
28
class dublin : public std::moneypunct<char> {
29
public:
30
  int do_frac_digits() const { return 3; }
31
};
32
 
33
int main()
34
{
35
  std::istringstream liffey;
36
  std::string coins;
37
 
38
  std::locale eire(std::locale::classic(), new dublin);
39
  liffey.imbue(eire);
40
 
41
  const std::money_get<char>& greed
42
    = std::use_facet<std::money_get<char> >(liffey.getloc());
43
 
44
  typedef std::istreambuf_iterator<char> 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("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("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("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("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("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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.