]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc
1 // Copyright (C) 2020-2021 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.3.2 basic_istringstream constructors [istringstream.cons]
20 // { dg-options "-std=gnu++2a" }
21 // { dg-do run { target c++2a } }
22 // { dg-require-effective-target cxx11-abi }
26 #include <testsuite_allocator.h>
27 #include <testsuite_hooks.h>
32 std::wistringstream::allocator_type a
;
33 std::wistringstream
stm(std::ios_base::in
, a
);
36 auto const cstr
= L
"This is a test";
41 std::wstring
s1(cstr
);
42 std::wistringstream
stm(std::move(s1
));
45 std::wstring
s2(cstr
);
46 VERIFY( stm
.str() == s2
);
53 using alloc_type
= __gnu_test::uneq_allocator
<C
>;
54 using traits_type
= std::char_traits
<C
>;
55 using string
= std::basic_string
<C
, traits_type
, alloc_type
>;
56 using istringstream
= std::basic_istringstream
<C
, traits_type
, alloc_type
>;
58 auto const mode
= std::ios_base::in
;
60 const string
s1(cstr
, a1
);
62 // basic_istringstream()
66 VERIFY( ss
.str().empty() );
67 VERIFY( ss
.rdbuf()->get_allocator() == a0
);
68 VERIFY( ss
.str().get_allocator() == a0
);
71 // basic_istringstream(openmode)
74 istringstream
ss(mode
);
75 VERIFY( ss
.str().empty() );
76 VERIFY( ss
.rdbuf()->get_allocator() == a0
);
77 VERIFY( ss
.str().get_allocator() == a0
);
80 // basic_istringstream(const basic_string<C,T,A>&, openmode = in)
83 VERIFY( ss
.str() == cstr
);
84 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
85 VERIFY( ss
.str().get_allocator() == a1
);
88 // basic_istringstream(const basic_string<C,T,A>&, openmode = in)
90 istringstream
ss(s1
, mode
);
91 VERIFY( ss
.str() == cstr
);
92 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
93 VERIFY( ss
.str().get_allocator() == a1
);
96 // basic_istringstream(openmode, const A&)
98 istringstream
ss(mode
, a1
);
99 VERIFY( ss
.str().empty() );
100 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
101 VERIFY( ss
.str().get_allocator() == a1
);
104 // basic_istringstream(basic_string<C,T,A>&&, openmode = in)
106 istringstream
ss(string
{s1
});
107 VERIFY( ss
.str() == s1
);
108 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
109 VERIFY( ss
.str().get_allocator() == a1
);
112 // basic_istringstream(basic_string<C,T,A>&&, openmode = in)
114 istringstream
ss(string(s1
), mode
);
115 VERIFY( ss
.str() == s1
);
116 VERIFY( ss
.rdbuf()->get_allocator() == a1
);
117 VERIFY( ss
.str().get_allocator() == a1
);
120 // basic_istringstream(const basic_string<C,T,SA>&, const A&)
123 istringstream
ss(s1
, a2
);
124 VERIFY( ss
.str() == s1
);
125 VERIFY( ss
.rdbuf()->get_allocator() == a2
);
126 VERIFY( ss
.str().get_allocator() == a2
);
129 // basic_istringstream(const basic_string<C,T,SA>&, const A&)
132 const std::wstring s2
= cstr
;
133 istringstream
ss(s2
, a2
);
134 VERIFY( ss
.str() == cstr
);
135 VERIFY( ss
.rdbuf()->get_allocator() == a2
);
136 VERIFY( ss
.str().get_allocator() == a2
);
139 // basic_istringstream(const basic_string<C,T,SA>&, openmode, const A&)
142 istringstream
ss(s1
, mode
, a2
);
143 VERIFY( ss
.str() == s1
);
144 VERIFY( ss
.rdbuf()->get_allocator() == a2
);
145 VERIFY( ss
.str().get_allocator() == a2
);
148 // basic_istringstream(const basic_string<C,T,SA>&, openmode, const A&)
151 const std::wstring s2
= cstr
;
152 istringstream
ss(s2
, mode
, a2
);
153 VERIFY( ss
.str() == cstr
);
154 VERIFY( ss
.rdbuf()->get_allocator() == a2
);
155 VERIFY( ss
.str().get_allocator() == a2
);
158 // basic_istringstream(const basic_string<C,T,SA>&, openmode = in)
161 const std::wstring s2
= cstr
;
162 istringstream
ss(s2
, mode
);
163 VERIFY( ss
.str() == cstr
);
164 VERIFY( ss
.rdbuf()->get_allocator() == a0
);
165 VERIFY( ss
.str().get_allocator() == a0
);