Home | History | Annotate | Download | only in ostream.assign
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <ostream>
     11 
     12 // template <class charT, class traits = char_traits<charT> >
     13 // class basic_ostream;
     14 
     15 // void swap(basic_ostream& rhs);
     16 
     17 #include <ostream>
     18 #include <cassert>
     19 
     20 template <class CharT>
     21 struct testbuf
     22     : public std::basic_streambuf<CharT>
     23 {
     24     testbuf() {}
     25 };
     26 
     27 template <class CharT>
     28 struct test_ostream
     29     : public std::basic_ostream<CharT>
     30 {
     31     typedef std::basic_ostream<CharT> base;
     32     test_ostream(testbuf<CharT>* sb) : base(sb) {}
     33 
     34     void swap(test_ostream& s) {base::swap(s);}
     35 };
     36 
     37 int main()
     38 {
     39     {
     40         testbuf<char> sb1;
     41         testbuf<char> sb2;
     42         test_ostream<char> os1(&sb1);
     43         test_ostream<char> os2(&sb2);
     44         os1.swap(os2);
     45         assert(os1.rdbuf() == &sb1);
     46         assert(os1.tie() == 0);
     47         assert(os1.fill() == ' ');
     48         assert(os1.rdstate() == os1.goodbit);
     49         assert(os1.exceptions() == os1.goodbit);
     50         assert(os1.flags() == (os1.skipws | os1.dec));
     51         assert(os1.precision() == 6);
     52         assert(os1.getloc().name() == "C");
     53         assert(os2.rdbuf() == &sb2);
     54         assert(os2.tie() == 0);
     55         assert(os2.fill() == ' ');
     56         assert(os2.rdstate() == os2.goodbit);
     57         assert(os2.exceptions() == os2.goodbit);
     58         assert(os2.flags() == (os2.skipws | os2.dec));
     59         assert(os2.precision() == 6);
     60         assert(os2.getloc().name() == "C");
     61     }
     62     {
     63         testbuf<wchar_t> sb1;
     64         testbuf<wchar_t> sb2;
     65         test_ostream<wchar_t> os1(&sb1);
     66         test_ostream<wchar_t> os2(&sb2);
     67         os1.swap(os2);
     68         assert(os1.rdbuf() == &sb1);
     69         assert(os1.tie() == 0);
     70         assert(os1.fill() == ' ');
     71         assert(os1.rdstate() == os1.goodbit);
     72         assert(os1.exceptions() == os1.goodbit);
     73         assert(os1.flags() == (os1.skipws | os1.dec));
     74         assert(os1.precision() == 6);
     75         assert(os1.getloc().name() == "C");
     76         assert(os2.rdbuf() == &sb2);
     77         assert(os2.tie() == 0);
     78         assert(os2.fill() == ' ');
     79         assert(os2.rdstate() == os2.goodbit);
     80         assert(os2.exceptions() == os2.goodbit);
     81         assert(os2.flags() == (os2.skipws | os2.dec));
     82         assert(os2.precision() == 6);
     83         assert(os2.getloc().name() == "C");
     84     }
     85 }
     86