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 // <ios>
11
12 // template <class charT, class traits> class basic_ios
13
14 // void move(basic_ios&& rhs);
15
16 #include <ios>
17 #include <streambuf>
18 #include <cassert>
19
20 #include "platform_support.h" // locale name macros
21
22 struct testbuf
23 : public std::streambuf
24 {
25 };
26
27 struct testios
28 : public std::ios
29 {
testiostestios30 testios(std::streambuf* p) : std::ios(p) {}
swaptestios31 void swap(std::ios& x) {std::ios::swap(x);}
32 };
33
34 bool f1_called = false;
35 bool f2_called = false;
36
37 bool g1_called = false;
38 bool g2_called = false;
39 bool g3_called = false;
40
f1(std::ios_base::event ev,std::ios_base & stream,int index)41 void f1(std::ios_base::event ev, std::ios_base& stream, int index)
42 {
43 assert(index == 4);
44 f1_called = true;
45 }
46
f2(std::ios_base::event ev,std::ios_base & stream,int index)47 void f2(std::ios_base::event ev, std::ios_base& stream, int index)
48 {
49 assert(index == 5);
50 f2_called = true;
51 }
52
g1(std::ios_base::event ev,std::ios_base & stream,int index)53 void g1(std::ios_base::event ev, std::ios_base& stream, int index)
54 {
55 assert(index == 7);
56 g1_called = true;
57 }
58
g2(std::ios_base::event ev,std::ios_base & stream,int index)59 void g2(std::ios_base::event ev, std::ios_base& stream, int index)
60 {
61 assert(index == 8);
62 g2_called = true;
63 }
64
g3(std::ios_base::event ev,std::ios_base & stream,int index)65 void g3(std::ios_base::event ev, std::ios_base& stream, int index)
66 {
67 assert(index == 9);
68 g3_called = true;
69 }
70
main()71 int main()
72 {
73 testbuf sb1;
74 testios ios1(&sb1);
75 ios1.flags(std::ios::boolalpha | std::ios::dec | std::ios::fixed);
76 ios1.precision(1);
77 ios1.width(11);
78 ios1.imbue(std::locale(LOCALE_en_US_UTF_8));
79 ios1.exceptions(std::ios::failbit);
80 ios1.setstate(std::ios::eofbit);
81 ios1.register_callback(f1, 4);
82 ios1.register_callback(f2, 5);
83 ios1.iword(0) = 1;
84 ios1.iword(1) = 2;
85 ios1.iword(2) = 3;
86 char c1, c2, c3;
87 ios1.pword(0) = &c1;
88 ios1.pword(1) = &c2;
89 ios1.pword(2) = &c3;
90 ios1.tie((std::ostream*)1);
91 ios1.fill('1');
92
93 testbuf sb2;
94 testios ios2(&sb2);
95 ios2.flags(std::ios::showpoint | std::ios::uppercase);
96 ios2.precision(2);
97 ios2.width(12);
98 ios2.imbue(std::locale(LOCALE_fr_FR_UTF_8));
99 ios2.exceptions(std::ios::eofbit);
100 ios2.setstate(std::ios::goodbit);
101 ios2.register_callback(g1, 7);
102 ios2.register_callback(g2, 8);
103 ios2.register_callback(g3, 9);
104 ios2.iword(0) = 4;
105 ios2.iword(1) = 5;
106 ios2.iword(2) = 6;
107 ios2.iword(3) = 7;
108 ios2.iword(4) = 8;
109 ios2.iword(5) = 9;
110 char d1, d2;
111 ios2.pword(0) = &d1;
112 ios2.pword(1) = &d2;
113 ios2.tie((std::ostream*)2);
114 ios2.fill('2');
115
116 ios1.swap(ios2);
117
118 assert(ios1.rdstate() == std::ios::goodbit);
119 assert(ios1.rdbuf() == &sb1);
120 assert(ios1.flags() == (std::ios::showpoint | std::ios::uppercase));
121 assert(ios1.precision() == 2);
122 assert(ios1.width() == 12);
123 assert(ios1.getloc().name() == LOCALE_fr_FR_UTF_8);
124 assert(ios1.exceptions() == std::ios::eofbit);
125 assert(!f1_called);
126 assert(!f2_called);
127 assert(!g1_called);
128 assert(!g2_called);
129 assert(!g3_called);
130 assert(ios1.iword(0) == 4);
131 assert(ios1.iword(1) == 5);
132 assert(ios1.iword(2) == 6);
133 assert(ios1.iword(3) == 7);
134 assert(ios1.iword(4) == 8);
135 assert(ios1.iword(5) == 9);
136 assert(ios1.pword(0) == &d1);
137 assert(ios1.pword(1) == &d2);
138 assert(ios1.tie() == (std::ostream*)2);
139 assert(ios1.fill() == '2');
140 ios1.imbue(std::locale("C"));
141 assert(!f1_called);
142 assert(!f2_called);
143 assert(g1_called);
144 assert(g2_called);
145 assert(g3_called);
146
147 assert(ios2.rdstate() == std::ios::eofbit);
148 assert(ios2.rdbuf() == &sb2);
149 assert(ios2.flags() == (std::ios::boolalpha | std::ios::dec | std::ios::fixed));
150 assert(ios2.precision() == 1);
151 assert(ios2.width() == 11);
152 assert(ios2.getloc().name() == LOCALE_en_US_UTF_8);
153 assert(ios2.exceptions() == std::ios::failbit);
154 assert(ios2.iword(0) == 1);
155 assert(ios2.iword(1) == 2);
156 assert(ios2.iword(2) == 3);
157 assert(ios2.pword(0) == &c1);
158 assert(ios2.pword(1) == &c2);
159 assert(ios2.pword(2) == &c3);
160 assert(ios2.tie() == (std::ostream*)1);
161 assert(ios2.fill() == '1');
162 ios2.imbue(std::locale("C"));
163 assert(f1_called);
164 assert(f2_called);
165 }
166