[MemProf] Templatize CallStackRadixTreeBuilder (NFC) (#117014)
[llvm-project.git] / libcxx / test / std / input.output / syncstream / osyncstream / syncstream.osyncstream.cons / cons.move.pass.cpp
blob7fcbe78e5a812adb09ea7084237e2646de08b681
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 // 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?
23 #include <cassert>
24 #include <sstream>
25 #include <syncstream>
27 #include "test_macros.h"
28 #include "constexpr_char_traits.h"
29 #include "test_allocator.h"
31 template <class CharT>
32 void test() {
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)});
46 W w;
47 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
48 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w) == 0);
49 #endif
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);
54 #endif
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);
61 #endif
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);
77 W w;
78 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
79 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w) == 0);
80 #endif
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);
85 #endif
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);
92 #endif
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);
108 W w;
109 #if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)
110 assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w) == 0);
111 #endif
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);
116 #endif
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);
123 #endif
128 int main(int, char**) {
129 test<char>();
130 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
131 test<wchar_t>();
132 #endif
134 return 0;