]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc
1 // Copyright (C) 2004-2020 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/>.
19 // 27.6.1.3 unformatted input functions
21 #include <cwchar> // for wcslen
23 #include <testsuite_hooks.h>
25 class Inbuf
: public std::wstreambuf
27 static const wchar_t buf
[];
28 const wchar_t* current
;
35 size
= std::wcslen(buf
);
40 if (current
< buf
+ size
)
41 return traits_type::to_int_type(*current
);
42 return traits_type::eof();
47 if (current
< buf
+ size
)
48 return traits_type::to_int_type(*current
++);
49 return traits_type::eof();
53 const wchar_t Inbuf::buf
[] = L
"1234567890abcdefghij";
59 typedef char_traits
<wchar_t> traits_type
;
65 traits_type::assign(buffer
, sizeof(buffer
) / sizeof(wchar_t), L
'X');
67 is
.getline(buffer
, sizeof(buffer
) / sizeof(wchar_t), L
'0');
68 VERIFY( is
.rdstate() == ios_base::goodbit
);
69 VERIFY( !traits_type::compare(buffer
, L
"123456789\0",
70 sizeof(buffer
) / sizeof(wchar_t)) );
71 VERIFY( is
.gcount() == 10 );
74 traits_type::assign(buffer
, sizeof(buffer
) / sizeof(wchar_t), L
'X');
75 is
.getline(buffer
, sizeof(buffer
) / sizeof(wchar_t));
76 VERIFY( is
.rdstate() == ios_base::failbit
);
77 VERIFY( !traits_type::compare(buffer
, L
"abcdefghi\0",
78 sizeof(buffer
) / sizeof(wchar_t)) );
79 VERIFY( is
.gcount() == 9 );
82 traits_type::assign(buffer
, sizeof(buffer
) / sizeof(wchar_t), L
'X');
83 is
.getline(buffer
, sizeof(buffer
) / sizeof(wchar_t));
84 VERIFY( is
.rdstate() == ios_base::eofbit
);
85 VERIFY( !traits_type::compare(buffer
, L
"j\0XXXXXXXX",
86 sizeof(buffer
) / sizeof(wchar_t)) );
87 VERIFY( is
.gcount() == 1 );
90 traits_type::assign(buffer
, sizeof(buffer
) / sizeof(wchar_t), L
'X');
91 is
.getline(buffer
, sizeof(buffer
) / sizeof(wchar_t));
92 VERIFY( is
.rdstate() == (ios_base::eofbit
| ios_base::failbit
) );
93 VERIFY( !traits_type::compare(buffer
, L
"\0XXXXXXXXX",
94 sizeof(buffer
) / sizeof(wchar_t)) );
95 VERIFY( is
.gcount() == 0 );