Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/char16_t/80624.cc

raw
1 // Copyright (C) 2017-2025 Free Software Foundation, Inc.
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
6 // Free Software Foundation; either version 3, or (at your option)
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
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do run { target c++11 } }
19
20 #include <streambuf>
21 #include <testsuite_hooks.h>
22
23 struct streambuf : std::basic_streambuf<char16_t>
24 {
25 basic_streambuf* setbuf(char_type* s, std::streamsize n) override
26 {
27 setp(s, s + n);
28 setg(s, s, s + n);
29 return this;
30 }
31 };
32
33 void
34 test01()
35 {
36 using traits = streambuf::traits_type;
37
38 char16_t buf[2] = { };
39 streambuf sb;
40 sb.pubsetbuf(buf, 2);
41
42 streambuf::int_type res;
43
44 res = sb.sputc(streambuf::char_type(-1));
45 VERIFY( traits::eq_int_type(res, traits::eof()) == false );
46 res = sb.sputc(streambuf::char_type(-2));
47 VERIFY( traits::eq_int_type(res, traits::eof()) == false );
48 res = sb.sputc(streambuf::char_type(1));
49 VERIFY( traits::eq_int_type(res, traits::eof()) == true );
50
51 VERIFY( buf[0] == streambuf::char_type(-1) );
52 VERIFY( buf[1] == streambuf::char_type(-2) );
53 }
54
55 int
56 main()
57 {
58 test01();
59 }