brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · 7fcbe78 Raw
136 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710// UNSUPPORTED: no-localization11// UNSUPPORTED: libcpp-has-no-experimental-syncstream12 13// <syncstream>14 15// template <class charT, class traits, class Allocator>16// class basic_osyncstream;17 18// basic_osyncstream(basic_osyncstream&&) noexcept;19 20// TODO Why is this noexcept?21// Does the reasoning for https://cplusplus.github.io/LWG/issue3867 not hold true here?22 23#include <cassert>24#include <sstream>25#include <syncstream>26 27#include "test_macros.h"28#include "constexpr_char_traits.h"29#include "test_allocator.h"30 31template <class CharT>32void test() {33  {34    using OS = std::basic_osyncstream<CharT>;35    using W  = std::basic_syncbuf<CharT>;36 37    const std::allocator<CharT> alloc;38    {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)});44    }45    {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#endif50      {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#endif55        assert(os.get_wrapped() == &w);56        assert(os.rdbuf()->get_wrapped() == &w);57        assert(os.rdbuf()->get_allocator() == alloc);58      }59#if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)60      assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w) == 0);61#endif62    }63  }64 65  {66    using OS = std::basic_osyncstream<CharT, constexpr_char_traits<CharT>>;67    using W  = std::basic_stringbuf<CharT, constexpr_char_traits<CharT>>;68 69    const std::allocator<CharT> alloc;70    {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);75    }76    {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#endif81      {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#endif86        assert(os.get_wrapped() == &w);87        assert(os.rdbuf()->get_wrapped() == &w);88        assert(os.rdbuf()->get_allocator() == alloc);89      }90#if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)91      assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w) == 0);92#endif93    }94  }95 96  {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>>;99 100    const test_allocator<CharT> alloc;101    {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);106    }107    {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#endif112      {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#endif117        assert(os.get_wrapped() == &w);118        assert(os.rdbuf()->get_wrapped() == &w);119        assert(os.rdbuf()->get_allocator() == alloc);120      }121#if defined(_LIBCPP_VERSION) && !defined(TEST_HAS_NO_THREADS)122      assert(std::__wrapped_streambuf_mutex::__instance().__get_count(&w) == 0);123#endif124    }125  }126}127 128int main(int, char**) {129  test<char>();130#ifndef TEST_HAS_NO_WIDE_CHARACTERS131  test<wchar_t>();132#endif133 134  return 0;135}136