1// 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
27void
28test03()
29{
30  typedef std::char_traits<char>	traits_type;
31
32  bool test __attribute__((unused)) = true;
33  const char str_lit01[] =
34  "   sun*ra \n\t\t\t   & his arkestra, featuring john gilmore: \n"
35  "                         "
36    "jazz in silhouette: images and forecasts of tomorrow";
37
38  std::string str01(str_lit01);
39  std::string strtmp;
40
41  std::stringbuf sbuf_03;
42  std::stringbuf sbuf_04(str01, std::ios_base::in);
43  std::stringbuf sbuf_05(str01, std::ios_base::in);
44
45  std::istream is_00(NULL);
46  std::istream is_04(&sbuf_04);
47  std::istream is_05(&sbuf_05);
48  std::ios_base::iostate statefail, stateeof;
49  statefail = std::ios_base::failbit;
50  stateeof = std::ios_base::eofbit;
51  char carray1[400] = "";
52
53  // int_type get()
54  // istream& get(char*, streamsize, char delim)
55  // istream& get(char*, streamsize)
56  // istream& get(streambuf&, char delim)
57  // istream& get(streambuf&)
58  is_00.get(carray1, 2);
59  VERIFY( static_cast<bool>(is_00.rdstate() & statefail) );
60  VERIFY( is_00.gcount() == 0 );
61
62  is_04.get(carray1, 4);
63  VERIFY( !(is_04.rdstate() & statefail) );
64  VERIFY( !traits_type::compare(carray1, "   ", 4) );
65  VERIFY( is_04.gcount() == 3 );
66
67  is_04.clear();
68  is_04.get(carray1 + 3, 200);
69  VERIFY( !(is_04.rdstate() & statefail) );
70  VERIFY( !(is_04.rdstate() & stateeof) );
71  VERIFY( !traits_type::compare(carray1, str_lit01, 10) );
72  VERIFY( is_04.gcount() == 7 );
73
74  is_04.clear();
75  is_04.get(carray1, 200);
76  VERIFY( !(is_04.rdstate() & stateeof) );
77  VERIFY( static_cast<bool>(is_04.rdstate() & statefail) ); // delimiter
78  VERIFY( is_04.gcount() == 0 );
79  is_04.clear();
80  is_04.get(carray1, 200, '[');
81  VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) );
82  VERIFY( !(is_04.rdstate() & statefail) );
83  VERIFY( is_04.gcount() == 125 );
84  is_04.clear();
85  is_04.get(carray1, 200);
86  VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) );
87  VERIFY( static_cast<bool>(is_04.rdstate() & statefail) );
88  VERIFY( is_04.gcount() == 0 );
89
90  std::stringbuf sbuf_02(std::ios_base::in);
91  is_05.clear();
92  is_05.get(sbuf_02);
93  VERIFY( is_05.gcount() == 0 );
94  VERIFY( static_cast<bool>(is_05.rdstate() & statefail) );
95  VERIFY( !(is_05.rdstate() & stateeof) );
96
97  is_05.clear();
98  is_05.get(sbuf_03);
99  VERIFY( is_05.gcount() == 10 );
100  VERIFY( sbuf_03.str() == "   sun*ra " );
101  VERIFY( !(is_05.rdstate() & statefail) );
102  VERIFY( !(is_05.rdstate() & stateeof) );
103
104  is_05.clear();
105  is_05.get(sbuf_03, '|');
106  VERIFY( is_05.gcount() == 125 );
107  VERIFY( sbuf_03.str() == str_lit01 );
108  VERIFY( !(is_05.rdstate() & statefail) );
109  VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) );
110
111  is_05.clear();
112  is_05.get(sbuf_03, '|');
113  VERIFY( is_05.gcount() == 0 );
114  VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) );
115  VERIFY( static_cast<bool>(is_05.rdstate() & statefail) );
116}
117
118int
119main()
120{
121  test03();
122  return 0;
123}
124