]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/conversions/buffer/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / conversions / buffer / 1.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
b6584a72 2
a945c346 3// Copyright (C) 2015-2024 Free Software Foundation, Inc.
b6584a72
JW
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 3, 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 COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20// 22.3.3.2.3 Buffer conversions
21
22#include <locale>
23#include <sstream>
24#include <testsuite_hooks.h>
e9ecac30 25#include <testsuite_common_types.h>
b6584a72
JW
26
27template<typename Elem>
28struct cvt : std::codecvt<Elem, char, std::mbstate_t> { };
29
30template<typename Elem>
31using buf_conv = std::wbuffer_convert<cvt<Elem>, Elem>;
32
33using std::string;
b6584a72 34using std::wstring;
b6584a72
JW
35
36void test01()
37{
43e2a441 38#ifdef _GLIBCXX_USE_WCHAR_T
b6584a72
JW
39 buf_conv<wchar_t> buf;
40 std::stringbuf sbuf;
41 VERIFY( buf.rdbuf() == nullptr );
42 VERIFY( buf.rdbuf(&sbuf) == nullptr );
43 VERIFY( buf.rdbuf() == &sbuf );
44 VERIFY( buf.rdbuf(nullptr) == &sbuf );
e9ecac30
JW
45
46 __gnu_test::implicitly_default_constructible test;
47 test.operator()<buf_conv<wchar_t>>(); // P0935R0
43e2a441 48#endif
b6584a72
JW
49}
50
51void test02()
52{
53 std::stringbuf sbuf;
54 buf_conv<char> buf(&sbuf); // noconv
55
43e2a441 56 std::stringstream ss;
b6584a72
JW
57 ss.std::ios::rdbuf(&buf);
58 string input = "King for a day...";
59 ss << input << std::flush;
60 string output = sbuf.str();
61 VERIFY( input == output );
62}
63
64void test03()
65{
43e2a441 66#ifdef _GLIBCXX_USE_WCHAR_T
b6584a72
JW
67 std::stringbuf sbuf;
68 buf_conv<wchar_t> buf(&sbuf);
69
43e2a441 70 std::wstringstream ss;
b6584a72
JW
71 ss.std::wios::rdbuf(&buf);
72 wstring input = L"Fool for a lifetime";
73 ss << input << std::flush;
74 string output = sbuf.str();
75 VERIFY( output == "Fool for a lifetime" );
43e2a441 76#endif
b6584a72
JW
77}
78
79int main()
80{
81 test01();
82 test02();
83 test03();
84}