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//===----------------------------------------------------------------------===//
8
9// <sstream>
10
11// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12// class basic_stringbuf
13
14// explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out); // before C++20
15// basic_stringbuf() : basic_stringbuf(ios_base::in | ios_base::out) {} // C++20
16// explicit basic_stringbuf(ios_base::openmode which); // C++20
17
18// XFAIL: FROZEN-CXX03-HEADERS-FIXME
19
20#include <sstream>
21#include <cassert>
22
23#include "test_macros.h"
24#if TEST_STD_VER >= 11
25#include "test_convertible.h"
26#endif
27
28template<typename CharT>
29struct testbuf
30 : std::basic_stringbuf<CharT>
31{
32 void check()
33 {
34 // LWG2995
35 // It is implementation-defined whether the sequence pointers (eback(),
36 // gptr(), egptr(), pbase(), pptr(), epptr()) are initialized to null
37 // pointers.
38 // This tests the libc++ specific implementation.
39 LIBCPP_ASSERT(this->eback() != nullptr);
40 LIBCPP_ASSERT(this->gptr() != nullptr);
41 LIBCPP_ASSERT(this->egptr() != nullptr);
42 LIBCPP_ASSERT(this->pbase() != nullptr);
43 LIBCPP_ASSERT(this->pptr() != nullptr);
44 LIBCPP_ASSERT(this->epptr() != nullptr);
45 assert(this->str().empty());
46 }
47};
48
49int main(int, char**)
50{
51 {
52 std::stringbuf buf;
53 assert(buf.str() == "");
54 }
55 {
56 testbuf<char> buf;
57 buf.check();
58 }
59#ifndef TEST_HAS_NO_WIDE_CHARACTERS
60 {
61 std::wstringbuf buf;
62 assert(buf.str() == L"");
63 }
64 {
65 testbuf<wchar_t> buf;
66 buf.check();
67 }
68#endif
69
70#if TEST_STD_VER >= 11
71 {
72 typedef std::stringbuf B;
73 static_assert(test_convertible<B>(), "");
74 static_assert(!test_convertible<B, std::ios_base::openmode>(), "");
75 }
76#endif
77
78 return 0;
79}
80

source code of libcxx/test/std/input.output/string.streams/stringbuf/stringbuf.cons/default.pass.cpp