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