]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_syncbuf / basic_ops / 1.cc
CommitLineData
7adcbafe 1// Copyright (C) 2020-2022 Free Software Foundation, Inc.
6bcbcea0
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
18// { dg-options "-std=gnu++2a" }
19// { dg-additional-options "-pthread" { target pthread } }
20// { dg-do run { target c++2a } }
a04b73e1 21// { dg-require-effective-target cxx11_abi }
6bcbcea0
TR
22
23#include <sstream>
24#include <string_view>
25#include <syncstream>
26
27#include <testsuite_allocator.h>
28#include <testsuite_hooks.h>
29
30void
31test01() // construction
32{
33 {
34 std::syncbuf s1;
35 VERIFY( s1.get_wrapped() == nullptr );
36
37 std::stringbuf b;
38 std::syncbuf s2(&b);
39 VERIFY( s2.get_wrapped() == &b );
40 }
41
42 {
43 using alloc_type = __gnu_test::uneq_allocator<char>;
44 using sbuf_t = std::basic_syncbuf<char, std::char_traits<char>,
45 alloc_type>;
46
47 sbuf_t b;
48
49 alloc_type aa;
50 sbuf_t s1(&b, aa);
51 VERIFY( aa == s1.get_allocator() );
52
53 alloc_type aaa(42);
54 sbuf_t s2(&b, aaa);
55 VERIFY( aaa == s2.get_allocator() );
56
57 VERIFY( s1.get_allocator() != s2.get_allocator() );
58 }
59}
60
61void
62test02() // moving
63{
64 {
65 std::stringbuf b;
66 std::syncbuf s1(&b);
67
68 std::syncbuf s2(std::move(s1));
69
70 VERIFY( s1.get_wrapped() == nullptr );
71 VERIFY( s2.get_wrapped() == &b );
72 }
73
74 {
75 std::stringbuf b;
76 std::syncbuf s1(&b);
77
78 std::syncbuf s2;
79 s2 = std::move(s1);
80
81 VERIFY( s1.get_wrapped() == nullptr );
82 VERIFY( s2.get_wrapped() == &b );
83 }
84}
85
86void
87test03() // swaping
88{
89 std::stringbuf b;
90 std::syncbuf s1(&b);
91
92 std::syncbuf s2;
93 std::swap(s1, s2);
94
95 VERIFY( s1.get_wrapped() == nullptr );
96 VERIFY( s2.get_wrapped() == &b );
97}
98
99void
100test04() // emitting
101{
102 {
103 std::stringbuf b;
104 std::syncbuf s(&b);
105
106 const std::string_view txt("This is a test");
107 s.sputn(txt.data(), txt.size());
108
109 VERIFY( b.str() != txt );
110 VERIFY( s.pubsync() == 0 );
111 VERIFY( b.str() != txt );
112
113 VERIFY( s.emit() );
114 VERIFY( b.str() == txt );
115 }
116
117 {
118 std::stringbuf b;
119 std::syncbuf s(&b);
120 s.set_emit_on_sync(true);
121
122 const std::string_view txt("This is a test");
123 s.sputn(txt.data(), txt.size());
124
125 VERIFY( s.pubsync() == 0 );
126 VERIFY( b.str() == txt );
127 }
128}
129
130int main()
131{
132 test01();
133 test02();
134 test03();
135 test04();
136 return 0;
137}