]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_istream/get/char/1.cc
Update copyright years.
[gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / get / char / 1.cc
CommitLineData
23cac885
BK
1// 1999-08-11 bkoz
2
5624e564 3// Copyright (C) 1999-2015 Free Software Foundation, Inc.
23cac885
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
23cac885
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
23cac885
BK
19
20// 27.6.1.3 unformatted input functions
23cac885 21
23cac885
BK
22#include <istream>
23#include <sstream>
23cac885
BK
24#include <testsuite_hooks.h>
25
26void
27test03()
28{
29 typedef std::char_traits<char> traits_type;
30
11f10e6b 31 bool test __attribute__((unused)) = true;
23cac885
BK
32 const char str_lit01[] =
33 " sun*ra \n\t\t\t & his arkestra, featuring john gilmore: \n"
34 " "
35 "jazz in silhouette: images and forecasts of tomorrow";
36
37 std::string str01(str_lit01);
38 std::string strtmp;
39
40 std::stringbuf sbuf_03;
41 std::stringbuf sbuf_04(str01, std::ios_base::in);
42 std::stringbuf sbuf_05(str01, std::ios_base::in);
43
8fc81078 44 std::istream is_00(0);
23cac885
BK
45 std::istream is_04(&sbuf_04);
46 std::istream is_05(&sbuf_05);
11f10e6b 47 std::ios_base::iostate statefail, stateeof;
23cac885
BK
48 statefail = std::ios_base::failbit;
49 stateeof = std::ios_base::eofbit;
23cac885
BK
50 char carray1[400] = "";
51
52 // int_type get()
53 // istream& get(char*, streamsize, char delim)
54 // istream& get(char*, streamsize)
55 // istream& get(streambuf&, char delim)
56 // istream& get(streambuf&)
57 is_00.get(carray1, 2);
58 VERIFY( static_cast<bool>(is_00.rdstate() & statefail) );
59 VERIFY( is_00.gcount() == 0 );
60
61 is_04.get(carray1, 4);
62 VERIFY( !(is_04.rdstate() & statefail) );
63 VERIFY( !traits_type::compare(carray1, " ", 4) );
64 VERIFY( is_04.gcount() == 3 );
65
66 is_04.clear();
67 is_04.get(carray1 + 3, 200);
68 VERIFY( !(is_04.rdstate() & statefail) );
69 VERIFY( !(is_04.rdstate() & stateeof) );
70 VERIFY( !traits_type::compare(carray1, str_lit01, 10) );
71 VERIFY( is_04.gcount() == 7 );
72
73 is_04.clear();
74 is_04.get(carray1, 200);
75 VERIFY( !(is_04.rdstate() & stateeof) );
76 VERIFY( static_cast<bool>(is_04.rdstate() & statefail) ); // delimiter
77 VERIFY( is_04.gcount() == 0 );
78 is_04.clear();
79 is_04.get(carray1, 200, '[');
80 VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) );
81 VERIFY( !(is_04.rdstate() & statefail) );
82 VERIFY( is_04.gcount() == 125 );
83 is_04.clear();
84 is_04.get(carray1, 200);
85 VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) );
86 VERIFY( static_cast<bool>(is_04.rdstate() & statefail) );
87 VERIFY( is_04.gcount() == 0 );
88
89 std::stringbuf sbuf_02(std::ios_base::in);
90 is_05.clear();
91 is_05.get(sbuf_02);
92 VERIFY( is_05.gcount() == 0 );
93 VERIFY( static_cast<bool>(is_05.rdstate() & statefail) );
94 VERIFY( !(is_05.rdstate() & stateeof) );
95
96 is_05.clear();
97 is_05.get(sbuf_03);
98 VERIFY( is_05.gcount() == 10 );
99 VERIFY( sbuf_03.str() == " sun*ra " );
100 VERIFY( !(is_05.rdstate() & statefail) );
101 VERIFY( !(is_05.rdstate() & stateeof) );
102
103 is_05.clear();
104 is_05.get(sbuf_03, '|');
105 VERIFY( is_05.gcount() == 125 );
106 VERIFY( sbuf_03.str() == str_lit01 );
107 VERIFY( !(is_05.rdstate() & statefail) );
108 VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) );
109
110 is_05.clear();
111 is_05.get(sbuf_03, '|');
112 VERIFY( is_05.gcount() == 0 );
113 VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) );
114 VERIFY( static_cast<bool>(is_05.rdstate() & statefail) );
115}
116
117int
118main()
119{
120 test03();
121 return 0;
122}
This page took 1.05306 seconds and 5 git commands to generate.