]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/4.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 // 29.8.2.4 basic_stringbuf member functions [stringbuf.members]
20 // { dg-do run { target c++20 } }
21 // { dg-require-effective-target cxx11_abi }
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
29 const std::wstring s0
= L
"this is not a short string";
32 VERIFY( sb
.str() == s0
);
33 VERIFY( sb
.str() == s0
);
35 using Alloc
= __gnu_test::uneq_allocator
<wchar_t>;
37 std::basic_string
<wchar_t, std::char_traits
<wchar_t>, Alloc
> s1
= sb
.str(a1
);
38 VERIFY( s1
.get_allocator() == a1
);
39 VERIFY( sb
.str(a1
).get_allocator() == a1
);
40 VERIFY( sb
.str(a1
) == s1
);
41 VERIFY( std::move(sb
).str(a1
) == s1
);
42 VERIFY( std::move(sb
).str(a1
) == s1
);
45 VERIFY( sb
.str(a2
).get_allocator() == a2
);
46 VERIFY( sb
.str(a2
) == s1
);
48 VERIFY( std::move(sb
).str() == s0
);
49 VERIFY( std::move(sb
).str().empty() );
50 VERIFY( sb
.str().empty() );
51 VERIFY( sb
.str(a1
).empty() );
56 std::wstringbuf
sb(L
"123");
57 std::wstring str
= L
"ABCDEF";
58 sb
.sputn(str
.c_str(), str
.size());
59 VERIFY( sb
.str() == str
);
60 VERIFY( std::move(sb
).str() == str
);
61 VERIFY( std::move(sb
).str().empty() );
67 using Alloc
= __gnu_test::tracker_allocator
<wchar_t>;
68 using Str
= std::basic_string
<wchar_t, std::char_traits
<wchar_t>, Alloc
>;
69 Str s1
= L
"string that is not short, quite long even";
70 auto count1
= __gnu_test::tracker_allocator_counter::get_allocation_count();
72 auto count2
= __gnu_test::tracker_allocator_counter::get_allocation_count();
73 VERIFY( count1
== count2
);
74 VERIFY( sb
.str() == s1
.c_str() );
80 const std::wstring str
= L
"Another quite long string, not at all short";
81 std::wstring str2
= str
;
82 sb
.str(std::move(str2
));
83 VERIFY( str2
.empty() );
84 VERIFY( sb
.str() == str
);