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