]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/1.cc
1c2e31ce528432ad45e8c88814037612639fe361
1 // Copyright (C) 2004-2024 Free Software Foundation, Inc.
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
6 // Free Software Foundation; either version 3, or (at your option)
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.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 27.6.1.3 unformatted input functions
22 #include <testsuite_hooks.h>
27 typedef std::char_traits
<wchar_t> traits_type
;
29 const wchar_t str_lit01
[] =
30 L
" sun*ra \n\t\t\t & his arkestra, featuring john gilmore: \n"
32 L
"jazz in silhouette: images and forecasts of tomorrow";
34 std::wstring
str01(str_lit01
);
37 std::wstringbuf sbuf_03
;
38 std::wstringbuf
sbuf_04(str01
, std::ios_base::in
);
39 std::wstringbuf
sbuf_05(str01
, std::ios_base::in
);
41 std::wistream
is_00(0);
42 std::wistream
is_04(&sbuf_04
);
43 std::wistream
is_05(&sbuf_05
);
44 std::ios_base::iostate statefail
, stateeof
;
45 statefail
= std::ios_base::failbit
;
46 stateeof
= std::ios_base::eofbit
;
47 wchar_t carray1
[400] = L
"";
50 // istream& get(wchar_t*, streamsize, wchar_t delim)
51 // istream& get(wchar_t*, streamsize)
52 // istream& get(streambuf&, wchar_t delim)
53 // istream& get(streambuf&)
54 is_00
.get(carray1
, 2);
55 VERIFY( static_cast<bool>(is_00
.rdstate() & statefail
) );
56 VERIFY( is_00
.gcount() == 0 );
58 is_04
.get(carray1
, 4);
59 VERIFY( !(is_04
.rdstate() & statefail
) );
60 VERIFY( !traits_type::compare(carray1
, L
" ", 4) );
61 VERIFY( is_04
.gcount() == 3 );
64 is_04
.get(carray1
+ 3, 200);
65 VERIFY( !(is_04
.rdstate() & statefail
) );
66 VERIFY( !(is_04
.rdstate() & stateeof
) );
67 VERIFY( !traits_type::compare(carray1
, str_lit01
, 10) );
68 VERIFY( is_04
.gcount() == 7 );
71 is_04
.get(carray1
, 200);
72 VERIFY( !(is_04
.rdstate() & stateeof
) );
73 VERIFY( static_cast<bool>(is_04
.rdstate() & statefail
) ); // delimiter
74 VERIFY( is_04
.gcount() == 0 );
76 is_04
.get(carray1
, 200, L
'[');
77 VERIFY( static_cast<bool>(is_04
.rdstate() & stateeof
) );
78 VERIFY( !(is_04
.rdstate() & statefail
) );
79 VERIFY( is_04
.gcount() == 125 );
81 is_04
.get(carray1
, 200);
82 VERIFY( static_cast<bool>(is_04
.rdstate() & stateeof
) );
83 VERIFY( static_cast<bool>(is_04
.rdstate() & statefail
) );
84 VERIFY( is_04
.gcount() == 0 );
86 std::wstringbuf
sbuf_02(std::ios_base::in
);
89 VERIFY( is_05
.gcount() == 0 );
90 VERIFY( static_cast<bool>(is_05
.rdstate() & statefail
) );
91 VERIFY( !(is_05
.rdstate() & stateeof
) );
95 VERIFY( is_05
.gcount() == 10 );
96 VERIFY( sbuf_03
.str() == L
" sun*ra " );
97 VERIFY( !(is_05
.rdstate() & statefail
) );
98 VERIFY( !(is_05
.rdstate() & stateeof
) );
101 is_05
.get(sbuf_03
, L
'|');
102 VERIFY( is_05
.gcount() == 125 );
103 VERIFY( sbuf_03
.str() == str_lit01
);
104 VERIFY( !(is_05
.rdstate() & statefail
) );
105 VERIFY( static_cast<bool>(is_05
.rdstate() & stateeof
) );
108 is_05
.get(sbuf_03
, L
'|');
109 VERIFY( is_05
.gcount() == 0 );
110 VERIFY( static_cast<bool>(is_05
.rdstate() & stateeof
) );
111 VERIFY( static_cast<bool>(is_05
.rdstate() & statefail
) );