brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · 9e9405a Raw
105 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// <sstream>10 11// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >12// class basic_ostringstream13 14// explicit basic_ostringstream(const basic_string<charT,traits,allocator>& str,15//                              ios_base::openmode which = ios_base::in);16 17#include <sstream>18#include <cassert>19 20#include "test_macros.h"21#include "operator_hijacker.h"22 23int main(int, char**)24{25    {26        std::ostringstream ss(" 123 456");27        assert(ss.rdbuf() != nullptr);28        assert(ss.good());29        assert(ss.str() == " 123 456");30        int i = 234;31        ss << i << ' ' << 567;32        assert(ss.str() == "234 5676");33    }34    {35      std::basic_ostringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(" 123 456");36      assert(ss.rdbuf() != nullptr);37      assert(ss.good());38      assert(ss.str() == " 123 456");39      int i = 234;40      ss << i << ' ' << 567;41      assert(ss.str() == "234 5676");42    }43    {44        std::ostringstream ss(" 123 456", std::ios_base::in);45        assert(ss.rdbuf() != nullptr);46        assert(ss.good());47        assert(ss.str() == " 123 456");48        int i = 234;49        ss << i << ' ' << 567;50        assert(ss.str() == "234 5676");51    }52    {53      std::basic_ostringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(54          " 123 456", std::ios_base::in);55      assert(ss.rdbuf() != nullptr);56      assert(ss.good());57      assert(ss.str() == " 123 456");58      int i = 234;59      ss << i << ' ' << 567;60      assert(ss.str() == "234 5676");61    }62#ifndef TEST_HAS_NO_WIDE_CHARACTERS63    {64        std::wostringstream ss(L" 123 456");65        assert(ss.rdbuf() != nullptr);66        assert(ss.good());67        assert(ss.str() == L" 123 456");68        int i = 234;69        ss << i << ' ' << 567;70        assert(ss.str() == L"234 5676");71    }72    {73      std::basic_ostringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(74          L" 123 456");75      assert(ss.rdbuf() != nullptr);76      assert(ss.good());77      assert(ss.str() == L" 123 456");78      int i = 234;79      ss << i << ' ' << 567;80      assert(ss.str() == L"234 5676");81    }82    {83        std::wostringstream ss(L" 123 456", std::ios_base::in);84        assert(ss.rdbuf() != nullptr);85        assert(ss.good());86        assert(ss.str() == L" 123 456");87        int i = 234;88        ss << i << ' ' << 567;89        assert(ss.str() == L"234 5676");90    }91    {92      std::basic_ostringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(93          L" 123 456", std::ios_base::in);94      assert(ss.rdbuf() != nullptr);95      assert(ss.good());96      assert(ss.str() == L" 123 456");97      int i = 234;98      ss << i << ' ' << 567;99      assert(ss.str() == L"234 5676");100    }101#endif102 103  return 0;104}105