]>
Commit | Line | Data |
---|---|---|
a5544970 | 1 | // Copyright (C) 2004-2019 Free Software Foundation, Inc. |
75a25e3f PC |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
748086b7 | 6 | // Free Software Foundation; either version 3, or (at your option) |
75a25e3f PC |
7 | // any later version. |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
15 | // with this library; see the file COPYING3. If not see |
16 | // <http://www.gnu.org/licenses/>. | |
75a25e3f PC |
17 | |
18 | // 27.6.1.3 unformatted input functions | |
19 | ||
20 | #include <istream> | |
21 | #include <sstream> | |
22 | #include <testsuite_hooks.h> | |
23 | ||
24 | void | |
25 | test02() | |
26 | { | |
27 | typedef std::char_traits<wchar_t> traits_type; | |
28 | ||
75a25e3f PC |
29 | const wchar_t str_lit01[] = L"\t\t\t sun*ra \n" |
30 | L" " | |
31 | L"and his myth science arkestra present\n" | |
32 | L" " | |
33 | L"angles and demons @ play\n" | |
34 | L" " | |
35 | L"the nubians of plutonia"; | |
36 | std::wstring str01(str_lit01); | |
37 | std::wstring strtmp; | |
38 | ||
39 | std::wstringbuf sbuf_04(str01, std::ios_base::in); | |
40 | ||
8fc81078 | 41 | std::wistream is_00(0); |
75a25e3f PC |
42 | std::wistream is_04(&sbuf_04); |
43 | std::ios_base::iostate state1, state2, statefail, stateeof; | |
44 | statefail = std::ios_base::failbit; | |
45 | stateeof = std::ios_base::eofbit; | |
46 | wchar_t carray1[400] = L""; | |
47 | ||
48 | // istream& getline(wchar_t* s, streamsize n, wchar_t delim) | |
49 | // istream& getline(wchar_t* s, streamsize n) | |
50 | state1 = is_00.rdstate(); | |
51 | is_00.getline(carray1, 20, L'*'); | |
52 | state2 = is_00.rdstate(); | |
53 | // make sure failbit was set, since we couldn't extract | |
8fc81078 | 54 | // from the null streambuf... |
75a25e3f PC |
55 | VERIFY( state1 != state2 ); |
56 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
57 | ||
58 | VERIFY( is_04.gcount() == 0 ); | |
59 | state1 = is_04.rdstate(); | |
60 | is_04.getline(carray1, 1, L'\t'); // extracts, throws away | |
61 | state2 = is_04.rdstate(); | |
62 | VERIFY( is_04.gcount() == 1 ); | |
63 | VERIFY( state1 == state2 ); | |
64 | VERIFY( state1 == 0 ); | |
65 | VERIFY( !traits_type::compare(L"", carray1, 1) ); | |
66 | ||
67 | state1 = is_04.rdstate(); | |
68 | is_04.getline(carray1, 20, L'*'); | |
69 | state2 = is_04.rdstate(); | |
70 | VERIFY( is_04.gcount() == 10 ); | |
71 | VERIFY( state1 == state2 ); | |
72 | VERIFY( state1 == 0 ); | |
73 | VERIFY( !traits_type::compare(L"\t\t sun", carray1, 10) ); | |
74 | ||
75 | state1 = is_04.rdstate(); | |
76 | is_04.getline(carray1, 20); | |
77 | state2 = is_04.rdstate(); | |
78 | VERIFY( is_04.gcount() == 4 ); | |
79 | VERIFY( state1 == state2 ); | |
80 | VERIFY( state1 == 0 ); | |
81 | VERIFY( !traits_type::compare(L"ra ", carray1, 4) ); | |
82 | ||
83 | state1 = is_04.rdstate(); | |
84 | is_04.getline(carray1, 65); | |
85 | state2 = is_04.rdstate(); | |
86 | VERIFY( is_04.gcount() == 64 ); | |
87 | VERIFY( state1 != state2 ); | |
88 | VERIFY( state2 == statefail ); | |
89 | VERIFY( !traits_type::compare( | |
90 | L" and his myth science arkestra presen", | |
91 | carray1, 65) ); | |
92 | ||
93 | is_04.clear(); | |
94 | state1 = is_04.rdstate(); | |
95 | is_04.getline(carray1, 120, L'|'); | |
96 | state2 = is_04.rdstate(); | |
97 | VERIFY( is_04.gcount() == 106 ); | |
98 | VERIFY( state1 != state2 ); | |
99 | VERIFY( state2 == stateeof ); | |
100 | ||
101 | is_04.clear(); | |
102 | state1 = is_04.rdstate(); | |
103 | is_04.getline(carray1, 100, L'|'); | |
104 | state2 = is_04.rdstate(); | |
105 | VERIFY( is_04.gcount() == 0 ); | |
106 | VERIFY( state1 != state2 ); | |
107 | VERIFY( static_cast<bool>(state2 & stateeof) ); | |
108 | VERIFY( static_cast<bool>(state2 & statefail) ); | |
109 | } | |
110 | ||
111 | int | |
112 | main() | |
113 | { | |
114 | test02(); | |
115 | return 0; | |
116 | } |