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