blob: 0e535814ae54ee56ba4e0845dbc25024c8fec896 [file] [log] [blame]
Howard Hinnanted395bf2010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth41d7aea2019-01-19 10:56:40 +00003// 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
Howard Hinnanted395bf2010-05-11 19:42:16 +00006//
7//===----------------------------------------------------------------------===//
8
9// <sstream>
10
11// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12// class basic_stringstream
13
Marek Kurdeje98f5092021-01-19 08:21:09 +010014// explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20
15// basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20
16// explicit basic_stringstream(ios_base::openmode which); // C++20
Howard Hinnanted395bf2010-05-11 19:42:16 +000017
Nikolas Klauser4c3a8832024-12-21 13:01:48 +010018// XFAIL: FROZEN-CXX03-HEADERS-FIXME
19
Howard Hinnanted395bf2010-05-11 19:42:16 +000020#include <sstream>
21#include <cassert>
22
Marshall Clow57d39092019-05-31 18:35:30 +000023#include "test_macros.h"
Mark de Weverfd91e492024-08-06 19:47:56 +020024#include "operator_hijacker.h"
Marek Kurdeje98f5092021-01-19 08:21:09 +010025#if TEST_STD_VER >= 11
26#include "test_convertible.h"
27
28template <typename S>
29void test() {
30 static_assert(test_convertible<S>(), "");
31 static_assert(!test_convertible<S, std::ios_base::openmode>(), "");
32}
33#endif
Marshall Clow57d39092019-05-31 18:35:30 +000034
JF Bastiend40600b2019-02-04 20:31:13 +000035int main(int, char**)
Howard Hinnanted395bf2010-05-11 19:42:16 +000036{
37 {
38 std::stringstream ss;
Mark de Weverfd91e492024-08-06 19:47:56 +020039 assert(ss.rdbuf() != nullptr);
Howard Hinnanted395bf2010-05-11 19:42:16 +000040 assert(ss.good());
41 assert(ss.str() == "");
42 }
43 {
Mark de Weverfd91e492024-08-06 19:47:56 +020044 std::basic_stringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss;
45 assert(ss.rdbuf() != nullptr);
46 assert(ss.good());
47 assert(ss.str() == "");
48 }
49 {
Howard Hinnanted395bf2010-05-11 19:42:16 +000050 std::stringstream ss(std::ios_base::in);
Mark de Weverfd91e492024-08-06 19:47:56 +020051 assert(ss.rdbuf() != nullptr);
Howard Hinnanted395bf2010-05-11 19:42:16 +000052 assert(ss.good());
53 assert(ss.str() == "");
54 }
Mark de Weverfd91e492024-08-06 19:47:56 +020055 {
56 std::basic_stringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(std::ios_base::in);
57 assert(ss.rdbuf() != nullptr);
58 assert(ss.good());
59 assert(ss.str() == "");
60 }
Louis Dionne65209da2021-08-23 15:32:36 -040061#ifndef TEST_HAS_NO_WIDE_CHARACTERS
Howard Hinnanted395bf2010-05-11 19:42:16 +000062 {
63 std::wstringstream ss;
Mark de Weverfd91e492024-08-06 19:47:56 +020064 assert(ss.rdbuf() != nullptr);
Howard Hinnanted395bf2010-05-11 19:42:16 +000065 assert(ss.good());
66 assert(ss.str() == L"");
67 }
68 {
69 std::wstringstream ss(std::ios_base::in);
Mark de Weverfd91e492024-08-06 19:47:56 +020070 assert(ss.rdbuf() != nullptr);
Howard Hinnanted395bf2010-05-11 19:42:16 +000071 assert(ss.good());
72 assert(ss.str() == L"");
73 }
Louis Dionne65209da2021-08-23 15:32:36 -040074#endif
JF Bastiend40600b2019-02-04 20:31:13 +000075
Marek Kurdeje98f5092021-01-19 08:21:09 +010076#if TEST_STD_VER >= 11
77 test<std::stringstream>();
Mark de Wevera6c474e2022-02-02 19:28:04 +010078# ifndef TEST_HAS_NO_WIDE_CHARACTERS
Marek Kurdeje98f5092021-01-19 08:21:09 +010079 test<std::wstringstream>();
Louis Dionne65209da2021-08-23 15:32:36 -040080# endif
Marek Kurdeje98f5092021-01-19 08:21:09 +010081#endif
82
83 return 0;
Howard Hinnanted395bf2010-05-11 19:42:16 +000084}