]>
Commit | Line | Data |
---|---|---|
a945c346 | 1 | // Copyright (C) 2020-2024 Free Software Foundation, Inc. |
a0e4d7b4 TR |
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 | ||
be08d573 | 18 | // C++20 29.8.5.2 basic_stringstream constructors [stringstream.cons] |
a0e4d7b4 | 19 | |
f1b06f57 | 20 | // { dg-do run { target c++20 } } |
a04b73e1 | 21 | // { dg-require-effective-target cxx11_abi } |
a0e4d7b4 TR |
22 | |
23 | #include <sstream> | |
24 | #include <string> | |
25 | #include <testsuite_allocator.h> | |
26 | #include <testsuite_hooks.h> | |
27 | ||
28 | void | |
29 | test01() | |
30 | { | |
31 | std::wistringstream::allocator_type a; | |
32 | std::wistringstream stm(std::ios_base::in, a); | |
33 | } | |
34 | ||
35 | auto const cstr = L"This is a test"; | |
36 | ||
37 | void | |
38 | test02() | |
39 | { | |
40 | std::wstring s1(cstr); | |
41 | std::wistringstream stm(std::move(s1)); | |
42 | VERIFY( s1.empty() ); | |
43 | ||
44 | std::wstring s2(cstr); | |
45 | VERIFY( stm.str() == s2 ); | |
46 | } | |
47 | ||
48 | void | |
49 | test03() | |
50 | { | |
be08d573 JW |
51 | using C = wchar_t; |
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>; | |
a0e4d7b4 TR |
56 | |
57 | auto const mode = std::ios_base::in; | |
be08d573 JW |
58 | alloc_type a1(1); |
59 | const string s1(cstr, a1); | |
a0e4d7b4 | 60 | |
be08d573 | 61 | // basic_stringstream() |
a0e4d7b4 | 62 | { |
be08d573 JW |
63 | alloc_type a0; |
64 | stringstream ss; | |
65 | VERIFY( ss.str().empty() ); | |
66 | VERIFY( ss.rdbuf()->get_allocator() == a0 ); | |
67 | VERIFY( ss.str().get_allocator() == a0 ); | |
a0e4d7b4 TR |
68 | } |
69 | ||
be08d573 | 70 | // basic_stringstream(openmode) |
a0e4d7b4 | 71 | { |
be08d573 JW |
72 | alloc_type a0; |
73 | stringstream ss(mode); | |
74 | VERIFY( ss.str().empty() ); | |
75 | VERIFY( ss.rdbuf()->get_allocator() == a0 ); | |
76 | VERIFY( ss.str().get_allocator() == a0 ); | |
a0e4d7b4 TR |
77 | } |
78 | ||
be08d573 | 79 | // basic_stringstream(const basic_string<C,T,A>&, openmode = in) |
a0e4d7b4 | 80 | { |
be08d573 JW |
81 | stringstream ss(s1); |
82 | VERIFY( ss.str() == cstr ); | |
83 | VERIFY( ss.rdbuf()->get_allocator() == a1 ); | |
84 | VERIFY( ss.str().get_allocator() == a1 ); | |
85 | } | |
86 | ||
87 | // basic_stringstream(const basic_string<C,T,A>&, openmode = in) | |
88 | { | |
89 | stringstream ss(s1, mode); | |
90 | VERIFY( ss.str() == cstr ); | |
91 | VERIFY( ss.rdbuf()->get_allocator() == a1 ); | |
92 | VERIFY( ss.str().get_allocator() == a1 ); | |
93 | } | |
94 | ||
95 | // basic_stringstream(openmode, const A&) | |
96 | { | |
97 | stringstream ss(mode, a1); | |
98 | VERIFY( ss.str().empty() ); | |
99 | VERIFY( ss.rdbuf()->get_allocator() == a1 ); | |
100 | VERIFY( ss.str().get_allocator() == a1 ); | |
101 | } | |
102 | ||
103 | // basic_stringstream(basic_string<C,T,A>&&, openmode = in) | |
104 | { | |
105 | stringstream ss(string{s1}); | |
106 | VERIFY( ss.str() == s1 ); | |
107 | VERIFY( ss.rdbuf()->get_allocator() == a1 ); | |
108 | VERIFY( ss.str().get_allocator() == a1 ); | |
109 | } | |
110 | ||
111 | // basic_stringstream(basic_string<C,T,A>&&, openmode = in) | |
112 | { | |
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 ); | |
117 | } | |
118 | ||
119 | // basic_stringstream(const basic_string<C,T,SA>&, const A&) | |
120 | { | |
121 | alloc_type a2(2); | |
122 | stringstream ss(s1, a2); | |
123 | VERIFY( ss.str() == s1 ); | |
124 | VERIFY( ss.rdbuf()->get_allocator() == a2 ); | |
125 | VERIFY( ss.str().get_allocator() == a2 ); | |
126 | } | |
127 | ||
128 | // basic_stringstream(const basic_string<C,T,SA>&, const A&) | |
129 | { | |
130 | alloc_type a2(2); | |
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 ); | |
136 | } | |
137 | ||
138 | // basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&) | |
139 | { | |
140 | alloc_type a2(2); | |
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 ); | |
145 | } | |
146 | ||
147 | // basic_stringstream(const basic_string<C,T,SA>&, openmode, const A&) | |
148 | { | |
149 | alloc_type a2(2); | |
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 ); | |
155 | } | |
156 | ||
157 | // basic_stringstream(const basic_string<C,T,SA>&, openmode = in) | |
158 | { | |
159 | alloc_type a0; | |
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 ); | |
a0e4d7b4 TR |
165 | } |
166 | } | |
167 | ||
168 | int | |
169 | main() | |
170 | { | |
171 | test01(); | |
172 | test02(); | |
173 | test03(); | |
174 | return 0; | |
175 | } |