brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 032d2cf Raw
91 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// <ostream>10 11// template <class charT, class traits = char_traits<charT> >12// class basic_ostream;13 14// void swap(basic_ostream& rhs);15 16#include <ostream>17#include <cassert>18 19#include "test_macros.h"20 21template <class CharT>22struct testbuf23    : public std::basic_streambuf<CharT>24{25    testbuf() {}26};27 28template <class CharT>29struct test_ostream30    : public std::basic_ostream<CharT>31{32    typedef std::basic_ostream<CharT> base;33    test_ostream(testbuf<CharT>* sb) : base(sb) {}34 35    void swap(test_ostream& s) {base::swap(s);}36};37 38int main(int, char**)39{40    {41        testbuf<char> sb1;42        testbuf<char> sb2;43        test_ostream<char> os1(&sb1);44        test_ostream<char> os2(&sb2);45        os1.swap(os2);46        assert(os1.rdbuf() == &sb1);47        assert(os1.tie() == 0);48        assert(os1.fill() == ' ');49        assert(os1.rdstate() == os1.goodbit);50        assert(os1.exceptions() == os1.goodbit);51        assert(os1.flags() == (os1.skipws | os1.dec));52        assert(os1.precision() == 6);53        assert(os1.getloc().name() == "C");54        assert(os2.rdbuf() == &sb2);55        assert(os2.tie() == 0);56        assert(os2.fill() == ' ');57        assert(os2.rdstate() == os2.goodbit);58        assert(os2.exceptions() == os2.goodbit);59        assert(os2.flags() == (os2.skipws | os2.dec));60        assert(os2.precision() == 6);61        assert(os2.getloc().name() == "C");62    }63#ifndef TEST_HAS_NO_WIDE_CHARACTERS64    {65        testbuf<wchar_t> sb1;66        testbuf<wchar_t> sb2;67        test_ostream<wchar_t> os1(&sb1);68        test_ostream<wchar_t> os2(&sb2);69        os1.swap(os2);70        assert(os1.rdbuf() == &sb1);71        assert(os1.tie() == 0);72        assert(os1.fill() == ' ');73        assert(os1.rdstate() == os1.goodbit);74        assert(os1.exceptions() == os1.goodbit);75        assert(os1.flags() == (os1.skipws | os1.dec));76        assert(os1.precision() == 6);77        assert(os1.getloc().name() == "C");78        assert(os2.rdbuf() == &sb2);79        assert(os2.tie() == 0);80        assert(os2.fill() == ' ');81        assert(os2.rdstate() == os2.goodbit);82        assert(os2.exceptions() == os2.goodbit);83        assert(os2.flags() == (os2.skipws | os2.dec));84        assert(os2.precision() == 6);85        assert(os2.getloc().name() == "C");86    }87#endif88 89  return 0;90}91