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