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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_istream/] [getline/] [char/] [1.cc] - Blame information for rev 424

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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