OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [22_locale/] [money_get/] [get/] [char/] [9.cc] - Blame information for rev 424

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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