1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-localization
11 // UNSUPPORTED: libcpp-has-no-experimental-syncstream
15 // template <class charT, class traits, class Allocator>
16 // class basic_osyncstream;
18 // basic_osyncstream(basic_osyncstream&&) noexcept;
20 // TODO Why is this noexcept?
21 // Does the reasoning for https://cplusplus.github.io/LWG/issue3867 not hold true here?
27 #include "test_macros.h"
28 #include "constexpr_char_traits.h"
29 #include "test_allocator.h"
31 template <class CharT
>
34 using OS
= std::basic_osyncstream
<CharT
>;
35 using W
= std::basic_syncbuf
<CharT
>;
37 const std::allocator
<CharT
> alloc
;
39 OS os
= {OS
{nullptr, alloc
}};
40 assert(os
.get_wrapped() == nullptr);
41 assert(os
.rdbuf()->get_wrapped() == nullptr);
42 assert(os
.rdbuf()->get_allocator() == alloc
);
43 ASSERT_NOEXCEPT(OS
{std::move(os
)});
47 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
48 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w
) == 0);
51 OS os
= {OS
{&w
, alloc
}};
52 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
53 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w
) == 1);
55 assert(os
.get_wrapped() == &w
);
56 assert(os
.rdbuf()->get_wrapped() == &w
);
57 assert(os
.rdbuf()->get_allocator() == alloc
);
59 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
60 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w
) == 0);
66 using OS
= std::basic_osyncstream
<CharT
, constexpr_char_traits
<CharT
>>;
67 using W
= std::basic_stringbuf
<CharT
, constexpr_char_traits
<CharT
>>;
69 const std::allocator
<CharT
> alloc
;
71 OS os
= {OS
{nullptr, alloc
}};
72 assert(os
.get_wrapped() == nullptr);
73 assert(os
.rdbuf()->get_wrapped() == nullptr);
74 assert(os
.rdbuf()->get_allocator() == alloc
);
78 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
79 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w
) == 0);
82 OS os
= {OS
{&w
, alloc
}};
83 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
84 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w
) == 1);
86 assert(os
.get_wrapped() == &w
);
87 assert(os
.rdbuf()->get_wrapped() == &w
);
88 assert(os
.rdbuf()->get_allocator() == alloc
);
90 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
91 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w
) == 0);
97 using OS
= std::basic_osyncstream
<CharT
, constexpr_char_traits
<CharT
>, test_allocator
<CharT
>>;
98 using W
= std::basic_stringbuf
<CharT
, constexpr_char_traits
<CharT
>, test_allocator
<CharT
>>;
100 const test_allocator
<CharT
> alloc
;
102 OS os
= {OS
{nullptr, alloc
}};
103 assert(os
.get_wrapped() == nullptr);
104 assert(os
.rdbuf()->get_wrapped() == nullptr);
105 assert(os
.rdbuf()->get_allocator() == alloc
);
109 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
110 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w
) == 0);
113 OS os
= {OS
{&w
, alloc
}};
114 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
115 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w
) == 1);
117 assert(os
.get_wrapped() == &w
);
118 assert(os
.rdbuf()->get_wrapped() == &w
);
119 assert(os
.rdbuf()->get_allocator() == alloc
);
121 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
122 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w
) == 0);
128 int main(int, char**) {
130 #ifndef TEST_HAS_NO_WIDE_CHARACTERS