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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_istream/] [extractors_character/] [char/] [3.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 1999-07-26 bkoz
2
 
3
// Copyright (C) 1999, 2003 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
// 27.6.1.2.3 character extractors
22
 
23
#include <istream>
24
#include <sstream>
25
#include <testsuite_hooks.h>
26
 
27
void test01()
28
{
29
  bool test __attribute__((unused)) = true;
30
  std::string str_01;
31
  const std::string str_02("coltrane playing 'softly as a morning sunrise'");
32
  const std::string str_03("coltrane");
33
 
34
  std::stringbuf isbuf_01(std::ios_base::in);
35
  std::stringbuf isbuf_02(str_02, std::ios_base::in);
36
  std::istream is_01(NULL);
37
  std::istream is_02(&isbuf_02);
38
 
39
  std::ios_base::iostate state1, state2, statefail;
40
  statefail = std::ios_base::failbit;
41
 
42
  // template<_CharT, _Traits>
43
  //  basic_istream& operator>>(istream&, _CharT*)
44
  int n = 20;
45
  char array1[n];
46
  typedef std::ios::traits_type ctraits_type;
47
 
48
  // testing with width() control enabled.
49
  is_02.width(8);
50
  state1 = is_02.rdstate();
51
  is_02 >> array1;   // should snake "coltran"
52
  state2 = is_02.rdstate();
53
  VERIFY( state1 == state2 );
54
  VERIFY( !ctraits_type::compare(array1, "coltran", 7) );
55
 
56
  is_02.width(1);
57
  state1 = is_02.rdstate();
58
  is_02 >> array1;   // should snake nothing, set failbit
59
  state2 = is_02.rdstate();
60
  VERIFY( state1 != state2 );
61
  VERIFY( state2 == statefail );
62
  VERIFY( array1[0] == '\0' );
63
 
64
  is_02.width(8);
65
  is_02.clear();
66
  state1 = is_02.rdstate();
67
  VERIFY( !state1 );
68
  is_02 >> array1;   // should snake "e"
69
  state2 = is_02.rdstate();
70
  VERIFY( state1 == state2 );
71
  VERIFY( !ctraits_type::compare(array1, "e", 1) );
72
 
73
  // testing for correct exception setting
74
  const std::string str_04("   impulse!!");
75
  std::stringbuf isbuf_03(str_04, std::ios_base::in);
76
  std::stringbuf isbuf_04(str_04, std::ios_base::in);
77
  std::istream is_03(&isbuf_03);
78
  std::istream is_04(&isbuf_04);
79
 
80
  is_03 >> array1;
81
  VERIFY( !ctraits_type::compare(array1,"impulse!!", 10) );
82
  VERIFY( is_03.rdstate() == std::ios_base::eofbit );
83
 
84
  is_04.width(9);
85
  is_04 >> array1;
86
  VERIFY( ! std::ios::traits_type::compare(array1,"impulse!", 9) );
87
  VERIFY( !is_04.rdstate() );
88
}
89
 
90
int main()
91
{
92
  test01();
93
  return 0;
94
}

powered by: WebSVN 2.1.0

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