]>
Commit | Line | Data |
---|---|---|
23cac885 BK |
1 | // 1999-07-26 bkoz |
2 | ||
83ffe9cd | 3 | // Copyright (C) 1999-2023 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.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 | ||
23cac885 BK |
30 | std::string str_01; |
31 | const std::string str_02("or coltrane playing tunji with jimmy garrison"); | |
32 | const std::string str_03("coltrane"); | |
33 | ||
34 | std::stringbuf isbuf_01(std::ios_base::in); | |
35 | std::stringbuf isbuf_02(str_02, std::ios_base::in); | |
8fc81078 | 36 | std::istream is_01(0); |
23cac885 BK |
37 | std::istream is_02(&isbuf_02); |
38 | std::ios_base::iostate state1, state2, statefail; | |
39 | statefail = std::ios_base::failbit; | |
40 | ||
41 | // template<_CharT, _Traits> | |
42 | // basic_istream& operator>>(istream&, _CharT&) | |
43 | char c1 = 'c', c2 = 'c'; | |
44 | state1 = is_01.rdstate(); | |
45 | is_01 >> c1; | |
46 | state2 = is_01.rdstate(); | |
47 | VERIFY( state1 != state2 ); | |
48 | VERIFY( c1 == c2 ); | |
49 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
50 | ||
51 | state1 = is_02.rdstate(); | |
52 | is_02 >> c1; | |
53 | state2 = is_02.rdstate(); | |
54 | VERIFY( state1 == state2 ); | |
55 | VERIFY( c1 == 'o' ); | |
56 | is_02 >> c1; | |
57 | is_02 >> c1; | |
58 | VERIFY( c1 == 'c' ); | |
59 | VERIFY( !static_cast<bool>(state2 & statefail) ); | |
60 | ||
61 | // template<_CharT, _Traits> | |
62 | // basic_istream& operator>>(istream&, unsigned char&) | |
63 | unsigned char uc1 = 'c'; | |
64 | state1 = is_02.rdstate(); | |
65 | is_02 >> uc1; | |
66 | state2 = is_02.rdstate(); | |
67 | VERIFY( state1 == state2 ); | |
68 | VERIFY( uc1 == 'o' ); | |
69 | is_02 >> uc1; | |
70 | is_02 >> uc1; | |
71 | VERIFY( uc1 == 't' ); | |
72 | ||
73 | // template<_CharT, _Traits> | |
74 | // basic_istream& operator>>(istream&, signed char&) | |
75 | signed char sc1 = 'c'; | |
76 | state1 = is_02.rdstate(); | |
77 | is_02 >> sc1; | |
78 | state2 = is_02.rdstate(); | |
79 | VERIFY( state1 == state2 ); | |
80 | VERIFY( sc1 == 'r' ); | |
81 | is_02 >> sc1; | |
82 | is_02 >> sc1; | |
83 | VERIFY( sc1 == 'n' ); | |
84 | } | |
85 | ||
86 | int main() | |
87 | { | |
88 | test02(); | |
89 | return 0; | |
90 | } |