]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/2.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_character / char / 2.cc
1 // 1999-07-26 bkoz
2
3 // Copyright (C) 1999-2014 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.2.3 character extractors
21
22 #include <istream>
23 #include <sstream>
24 #include <testsuite_hooks.h>
25
26 void test02()
27 {
28 typedef std::ios::traits_type ctraits_type;
29
30 bool test __attribute__((unused)) = true;
31 std::string str_01;
32 const std::string str_02("or coltrane playing tunji with jimmy garrison");
33 const std::string str_03("coltrane");
34
35 std::stringbuf isbuf_01(std::ios_base::in);
36 std::stringbuf isbuf_02(str_02, std::ios_base::in);
37 std::istream is_01(0);
38 std::istream is_02(&isbuf_02);
39 std::ios_base::iostate state1, state2, statefail;
40 statefail = std::ios_base::failbit;
41
42 // template<_CharT, _Traits>
43 // basic_istream& operator>>(istream&, _CharT&)
44 char c1 = 'c', c2 = 'c';
45 state1 = is_01.rdstate();
46 is_01 >> c1;
47 state2 = is_01.rdstate();
48 VERIFY( state1 != state2 );
49 VERIFY( c1 == c2 );
50 VERIFY( static_cast<bool>(state2 & statefail) );
51
52 state1 = is_02.rdstate();
53 is_02 >> c1;
54 state2 = is_02.rdstate();
55 VERIFY( state1 == state2 );
56 VERIFY( c1 == 'o' );
57 is_02 >> c1;
58 is_02 >> c1;
59 VERIFY( c1 == 'c' );
60 VERIFY( !static_cast<bool>(state2 & statefail) );
61
62 // template<_CharT, _Traits>
63 // basic_istream& operator>>(istream&, unsigned char&)
64 unsigned char uc1 = 'c';
65 state1 = is_02.rdstate();
66 is_02 >> uc1;
67 state2 = is_02.rdstate();
68 VERIFY( state1 == state2 );
69 VERIFY( uc1 == 'o' );
70 is_02 >> uc1;
71 is_02 >> uc1;
72 VERIFY( uc1 == 't' );
73
74 // template<_CharT, _Traits>
75 // basic_istream& operator>>(istream&, signed char&)
76 signed char sc1 = 'c';
77 state1 = is_02.rdstate();
78 is_02 >> sc1;
79 state2 = is_02.rdstate();
80 VERIFY( state1 == state2 );
81 VERIFY( sc1 == 'r' );
82 is_02 >> sc1;
83 is_02 >> sc1;
84 VERIFY( sc1 == 'n' );
85 }
86
87 int main()
88 {
89 test02();
90 return 0;
91 }