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/] [getline/] [char/] [1.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 1999-08-11 bkoz
2
 
3
// Copyright (C) 1999, 2000, 2001, 2002, 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.3 unformatted input functions
22
 
23
#include <istream>
24
#include <sstream>
25
#include <testsuite_hooks.h>
26
 
27
void
28
test02()
29
{
30
  typedef std::char_traits<char>        traits_type;
31
 
32
  bool test __attribute__((unused)) = true;
33
  const char str_lit01[] = "\t\t\t    sun*ra \n"
34
  "                            "
35
  "and his myth science arkestra present\n"
36
  "                            "
37
  "angles and demons @ play\n"
38
  "                            "
39
  "the nubians of plutonia";
40
  std::string str01(str_lit01);
41
  std::string strtmp;
42
 
43
  std::stringbuf sbuf_04(str01, std::ios_base::in);
44
 
45
  std::istream is_00(NULL);
46
  std::istream is_04(&sbuf_04);
47
  std::ios_base::iostate state1, state2, statefail, stateeof;
48
  statefail = std::ios_base::failbit;
49
  stateeof = std::ios_base::eofbit;
50
  char carray1[400] = "";
51
 
52
  // istream& getline(char* s, streamsize n, char delim)
53
  // istream& getline(char* s, streamsize n)
54
  state1 = is_00.rdstate();
55
  is_00.getline(carray1, 20, '*');
56
  state2 = is_00.rdstate();
57
  // make sure failbit was set, since we couldn't extract
58
  // from the NULL streambuf...
59
  VERIFY( state1 != state2 );
60
  VERIFY( static_cast<bool>(state2 & statefail) );
61
 
62
  VERIFY( is_04.gcount() == 0 );
63
  state1 = is_04.rdstate();
64
  is_04.getline(carray1, 1, '\t'); // extracts, throws away
65
  state2 = is_04.rdstate();
66
  VERIFY( is_04.gcount() == 1 );
67
  VERIFY( state1 == state2 );
68
  VERIFY( state1 == 0 );
69
  VERIFY( !traits_type::compare("", carray1, 1) );
70
 
71
  state1 = is_04.rdstate();
72
  is_04.getline(carray1, 20, '*');
73
  state2 = is_04.rdstate();
74
  VERIFY( is_04.gcount() == 10 );
75
  VERIFY( state1 == state2 );
76
  VERIFY( state1 == 0 );
77
  VERIFY( !traits_type::compare("\t\t    sun", carray1, 10) );
78
 
79
  state1 = is_04.rdstate();
80
  is_04.getline(carray1, 20);
81
  state2 = is_04.rdstate();
82
  VERIFY( is_04.gcount() == 4 );
83
  VERIFY( state1 == state2 );
84
  VERIFY( state1 == 0 );
85
  VERIFY( !traits_type::compare("ra ", carray1, 4) );
86
 
87
  state1 = is_04.rdstate();
88
  is_04.getline(carray1, 65);
89
  state2 = is_04.rdstate();
90
  VERIFY( is_04.gcount() == 64 );
91
  VERIFY( state1 != state2 );
92
  VERIFY( state2 == statefail );
93
  VERIFY( !traits_type::compare(
94
  "                            and his myth science arkestra presen",
95
                               carray1, 65) );
96
 
97
  is_04.clear();
98
  state1 = is_04.rdstate();
99
  is_04.getline(carray1, 120, '|');
100
  state2 = is_04.rdstate();
101
  VERIFY( is_04.gcount() == 106 );
102
  VERIFY( state1 != state2 );
103
  VERIFY( state2 == stateeof );
104
 
105
  is_04.clear();
106
  state1 = is_04.rdstate();
107
  is_04.getline(carray1, 100, '|');
108
  state2 = is_04.rdstate();
109
  VERIFY( is_04.gcount() == 0 );
110
  VERIFY( state1 != state2 );
111
  VERIFY( static_cast<bool>(state2 & stateeof) );
112
  VERIFY( static_cast<bool>(state2 & statefail) );
113
}
114
 
115
int
116
main()
117
{
118
  test02();
119
  return 0;
120
}

powered by: WebSVN 2.1.0

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