[MemProf] Templatize CallStackRadixTreeBuilder (NFC) (#117014)
[llvm-project.git] / libcxx / test / std / input.output / syncstream / osyncstream / syncstream.osyncstream.cons / cons.ostream.pass.cpp
blob411473c053d9b03f92661e2f652ca6e452ed5677
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-localization
11 // UNSUPPORTED: libcpp-has-no-experimental-syncstream
13 // <syncstream>
15 // template <class charT, class traits, class Allocator>
16 // class basic_osyncstream;
18 // explicit basic_osyncstream(basic_ostream& os);
20 #include <cassert>
21 #include <concepts>
22 #include <syncstream>
23 #include <sstream>
25 #include "test_macros.h"
26 #include "constexpr_char_traits.h"
27 #include "test_allocator.h"
29 template <class CharT>
30 void test() {
32 using OS = std::basic_osyncstream<CharT>;
33 using W = std::basic_ostringstream<CharT>;
35 static_assert(!std::convertible_to<std::basic_ostream<CharT>&, OS>);
36 static_assert(std::constructible_from<OS, std::basic_ostream<CharT>&>);
39 W w;
40 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
41 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w.rdbuf()) == 0);
42 #endif
44 OS os{w};
45 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
46 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w.rdbuf()) == 1);
47 #endif
48 assert(os.get_wrapped() == w.rdbuf());
49 assert(os.rdbuf()->get_wrapped() == w.rdbuf());
50 assert(os.rdbuf()->get_allocator() == std::allocator<CharT>());
52 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
53 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w.rdbuf()) == 0);
54 #endif
59 using OS = std::basic_osyncstream<CharT, constexpr_char_traits<CharT>>;
60 using W = std::basic_ostringstream<CharT, constexpr_char_traits<CharT>>;
62 static_assert(!std::convertible_to<std::basic_ostream<CharT, constexpr_char_traits<CharT>>&, OS>);
63 static_assert(std::constructible_from<OS, std::basic_ostream<CharT, constexpr_char_traits<CharT>>&>);
66 W w;
67 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
68 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w.rdbuf()) == 0);
69 #endif
71 OS os{w};
72 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
73 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w.rdbuf()) == 1);
74 #endif
75 assert(os.get_wrapped() == w.rdbuf());
76 assert(os.rdbuf()->get_wrapped() == w.rdbuf());
77 assert(os.rdbuf()->get_allocator() == std::allocator<CharT>());
79 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
80 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w.rdbuf()) == 0);
81 #endif
86 using OS = std::basic_osyncstream<CharT, constexpr_char_traits<CharT>, test_allocator<CharT>>;
87 using W = std::basic_ostringstream<CharT, constexpr_char_traits<CharT>, test_allocator<CharT>>;
89 static_assert(!std::convertible_to<std::basic_ostream<CharT, constexpr_char_traits<CharT>>&, OS>);
90 static_assert(std::constructible_from<OS, std::basic_ostream<CharT, constexpr_char_traits<CharT>>&>);
93 W w;
94 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
95 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w.rdbuf()) == 0);
96 #endif
98 OS os{w};
99 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
100 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w.rdbuf()) == 1);
101 #endif
102 assert(os.get_wrapped() == w.rdbuf());
103 assert(os.rdbuf()->get_wrapped() == w.rdbuf());
104 assert(os.rdbuf()->get_allocator() == test_allocator<CharT>());
106 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
107 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(w.rdbuf()) == 0);
108 #endif
113 int main(int, char**) {
114 test<char>();
115 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
116 test<wchar_t>();
117 #endif
119 return 0;