Debian Codegraph @

libcxx/test/std/input.output/iostream.format/input.streams/istream/istream.assign/member_swap.pass.cpp

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