]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc
1 // Copyright (C) 2020-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 // C++20 29.8.5.2 basic_stringstream constructors [stringstream.cons]
20 // { dg-do run { target c++20 } }
21 // { dg-require-effective-target cxx11_abi }
25 #include <testsuite_allocator.h>
26 #include <testsuite_hooks.h>
31 std::wistringstream::allocator_type a
;
32 std::wistringstream
stm(std::ios_base::in
, a
);
35 auto const cstr
= L
"This is a test";
40 std::wstring
s1(cstr
);
41 std::wistringstream
stm(std::move(s1
));
44 std::wstring
s2(cstr
);
45 VERIFY( stm
.str() == s2
);
52 using alloc_type
= __gnu_test::uneq_allocator
<C
>;
53 using traits_type
= std::char_traits
<C
>;
54 using string
= std::basic_string
<C
, traits_type
, alloc_type
>;
55 using stringstream
= std::basic_stringstream
<C
, traits_type
, alloc_type
>;
57 auto const mode
= std::ios_base::in
;
59 const string
s1(cstr
, a1
);
61 // basic_stringstream()
65 VERIFY( ss
.str().empty() );
66 VERIFY( ss
.rdbuf()->get_allocator() == a0
);
67 VERIFY( ss
.str().get_allocator() == a0
);
70 // basic_stringstream(openmode)
73 stringstream
ss(mode
);
74 VERIFY( ss
.str().empty() );
75 VERIFY( ss
.rdbuf()->get_allocator() == a0
);
76 VERIFY( ss
.str().get_allocator() == a0
);
79 // basic_stringstream(const basic_string<C,T,A>&, openmode = in)
82 VERIFY( ss
.str() == cstr
);
83 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
84 VERIFY( ss
.str().get_allocator() == a1
);
87 // basic_stringstream(const basic_string<C,T,A>&, openmode = in)
89 stringstream
ss(s1
, mode
);
90 VERIFY( ss
.str() == cstr
);
91 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
92 VERIFY( ss
.str().get_allocator() == a1
);
95 // basic_stringstream(openmode, const A&)
97 stringstream
ss(mode
, a1
);
98 VERIFY( ss
.str().empty() );
99 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
100 VERIFY( ss
.str().get_allocator() == a1
);
103 // basic_stringstream(basic_string<C,T,A>&&, openmode = in)
105 stringstream
ss(string
{s1
});
106 VERIFY( ss
.str() == s1
);
107 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
108 VERIFY( ss
.str().get_allocator() == a1
);
111 // basic_stringstream(basic_string<C,T,A>&&, openmode = in)
113 stringstream
ss(string(s1
), mode
);
114 VERIFY( ss
.str() == s1
);
115 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
116 VERIFY( ss
.str().get_allocator() == a1
);
119 // basic_stringstream(const basic_string<C,T,SA>&, const A&)
122 stringstream
ss(s1
, a2
);
123 VERIFY( ss
.str() == s1
);
124 VERIFY( ss
.rdbuf()->get_allocator() == a2
);
125 VERIFY( ss
.str().get_allocator() == a2
);
128 // basic_stringstream(const basic_string<C,T,SA>&, const A&)
131 const std::wstring s2
= cstr
;
132 stringstream
ss(s2
, a2
);
133 VERIFY( ss
.str() == cstr
);
134 VERIFY( ss
.rdbuf()->get_allocator() == a2
);
135 VERIFY( ss
.str().get_allocator() == a2
);
138 // basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&)
141 stringstream
ss(s1
, mode
, a2
);
142 VERIFY( ss
.str() == s1
);
143 VERIFY( ss
.rdbuf()->get_allocator() == a2
);
144 VERIFY( ss
.str().get_allocator() == a2
);
147 // basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&)
150 const std::wstring s2
= cstr
;
151 stringstream
ss(s2
, mode
, a2
);
152 VERIFY( ss
.str() == cstr
);
153 VERIFY( ss
.rdbuf()->get_allocator() == a2
);
154 VERIFY( ss
.str().get_allocator() == a2
);
157 // basic_stringstream(const basic_string<C,T,SA>&, openmode = in)
160 const std::wstring s2
= cstr
;
161 stringstream
ss(s2
, mode
);
162 VERIFY( ss
.str() == cstr
);
163 VERIFY( ss
.rdbuf()->get_allocator() == a0
);
164 VERIFY( ss
.str().get_allocator() == a0
);