]>
Commit | Line | Data |
---|---|---|
23cac885 BK |
1 | // 1999-07-26 bkoz |
2 | ||
3 | // Copyright (C) 1999, 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
19 | // USA. | |
20 | ||
21 | // 27.6.1.2.3 character extractors | |
22 | ||
23 | #include <istream> | |
24 | #include <sstream> | |
25 | #include <testsuite_hooks.h> | |
26 | ||
27 | void test01() | |
28 | { | |
29 | bool test = true; | |
30 | std::string str_01; | |
31 | const std::string str_02("coltrane playing 'softly as a morning sunrise'"); | |
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); | |
36 | std::istream is_01(NULL); | |
37 | std::istream is_02(&isbuf_02); | |
38 | ||
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 | int n = 20; | |
45 | char array1[n]; | |
46 | typedef std::ios::traits_type ctraits_type; | |
47 | ctraits_type::int_type i1, i2; | |
48 | ||
49 | // testing with width() control enabled. | |
50 | is_02.width(8); | |
51 | state1 = is_02.rdstate(); | |
52 | is_02 >> array1; // should snake "coltran" | |
53 | state2 = is_02.rdstate(); | |
54 | VERIFY( state1 == state2 ); | |
55 | VERIFY( !ctraits_type::compare(array1, "coltran", 7) ); | |
56 | ||
57 | is_02.width(1); | |
58 | state1 = is_02.rdstate(); | |
59 | is_02 >> array1; // should snake nothing, set failbit | |
60 | state2 = is_02.rdstate(); | |
61 | VERIFY( state1 != state2 ); | |
62 | VERIFY( state2 == statefail ); | |
63 | VERIFY( array1[0] == '\0' ); | |
64 | ||
65 | is_02.width(8); | |
66 | is_02.clear(); | |
67 | state1 = is_02.rdstate(); | |
68 | VERIFY( !state1 ); | |
69 | is_02 >> array1; // should snake "e" | |
70 | state2 = is_02.rdstate(); | |
71 | VERIFY( state1 == state2 ); | |
72 | VERIFY( !ctraits_type::compare(array1, "e", 1) ); | |
73 | ||
74 | // testing for correct exception setting | |
75 | const std::string str_04(" impulse!!"); | |
76 | std::stringbuf isbuf_03(str_04, std::ios_base::in); | |
77 | std::stringbuf isbuf_04(str_04, std::ios_base::in); | |
78 | std::istream is_03(&isbuf_03); | |
79 | std::istream is_04(&isbuf_04); | |
80 | ||
81 | is_03 >> array1; | |
82 | VERIFY( !ctraits_type::compare(array1,"impulse!!", 10) ); | |
83 | VERIFY( is_03.rdstate() == std::ios_base::eofbit ); | |
84 | ||
85 | is_04.width(9); | |
86 | is_04 >> array1; | |
87 | VERIFY( ! std::ios::traits_type::compare(array1,"impulse!", 9) ); | |
88 | VERIFY( !is_04.rdstate() ); | |
89 | } | |
90 | ||
91 | int main() | |
92 | { | |
93 | test01(); | |
94 | return 0; | |
95 | } |