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/] [num_get/] [get/] [char/] [2.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 2001-11-21 Benjamin Kosnik  <bkoz@redhat.com>
2
 
3
// Copyright (C) 2001, 2002, 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.2.1.1  num_get members
22
 
23
#include <locale>
24
#include <sstream>
25
#include <testsuite_hooks.h>
26
 
27
void test02()
28
{
29
  using namespace std;
30
  typedef istreambuf_iterator<char> iterator_type;
31
 
32
  bool test __attribute__((unused)) = true;
33
 
34
  // basic construction
35
  locale loc_c = locale::classic();
36
 
37
  // sanity check the data is correct.
38
  const string empty;
39
 
40
  bool b1 = true;
41
  bool b0 = false;
42
  unsigned long ul1 = 1294967294;
43
  unsigned long ul2 = 0;
44
  unsigned long ul;
45
  double d1 =  1.02345e+308;
46
  double d2 = 3.15e-308;
47
  double d;
48
 
49
  // cache the num_get facet
50
  istringstream iss;
51
  iss.imbue(loc_c);
52
  const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc());
53
  const ios_base::iostate goodbit = ios_base::goodbit;
54
  const ios_base::iostate eofbit = ios_base::eofbit;
55
  ios_base::iostate err = ios_base::goodbit;
56
 
57
  // C
58
  // bool, more twisted examples
59
  iss.str("true ");
60
  iss.clear();
61
  iss.setf(ios_base::boolalpha);
62
  err = goodbit;
63
  ng.get(iss.rdbuf(), 0, iss, err, b0);
64
  VERIFY( b0 == true );
65
  VERIFY( err == goodbit );
66
 
67
  iss.str("false ");
68
  iss.clear();
69
  iss.setf(ios_base::boolalpha);
70
  err = goodbit;
71
  ng.get(iss.rdbuf(), 0, iss, err, b1);
72
  VERIFY( b1 == false );
73
  VERIFY( err == goodbit );
74
 
75
  // unsigned long, in a locale that does not group
76
  iss.imbue(loc_c);
77
  iss.str("1294967294");
78
  iss.clear();
79
  err = goodbit;
80
  ng.get(iss.rdbuf(), 0, iss, err, ul);
81
  VERIFY( ul == ul1);
82
  VERIFY( err == eofbit );
83
 
84
  iss.str("0+++++++++++++++++++");
85
  iss.clear();
86
  err = goodbit;
87
  ng.get(iss.rdbuf(), 0, iss, err, ul);
88
  VERIFY( ul == ul2);
89
  VERIFY( err == goodbit );
90
 
91
  // double
92
  iss.imbue(loc_c);
93
  iss.str("1.02345e+308++++++++");
94
  iss.clear();
95
  iss.width(20);
96
  iss.setf(ios_base::left, ios_base::adjustfield);
97
  err = goodbit;
98
  ng.get(iss.rdbuf(), 0, iss, err, d);
99
  VERIFY( d == d1 );
100
  VERIFY( err == goodbit );
101
 
102
  iss.str("+3.15e-308");
103
  iss.clear();
104
  iss.width(20);
105
  iss.setf(ios_base::right, ios_base::adjustfield);
106
  err = goodbit;
107
  ng.get(iss.rdbuf(), 0, iss, err, d);
108
  VERIFY( d == d2 );
109
  VERIFY( err == eofbit );
110
}
111
 
112
int main()
113
{
114
  test02();
115
  return 0;
116
}
117
 
118
 
119
// Kathleen Hannah, humanitarian, woman, art-thief

powered by: WebSVN 2.1.0

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