1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // REQUIRES: locale.en_US.UTF-8
10 // REQUIRES: locale.fr_FR.UTF-8
14 // template <class charT, class traits> class basic_ios
16 // basic_ios& copyfmt(const basic_ios& rhs);
18 // XFAIL: FROZEN-CXX03-HEADERS-FIXME
26 #include "platform_support.h" // locale name macros
28 #include "test_macros.h"
29 #include "operator_hijacker.h"
32 : public std::streambuf
36 bool f1_called
= false;
37 bool f2_called
= false;
39 bool g1_called
= false;
40 bool g2_called
= false;
41 bool g3_called
= false;
43 void f1(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
45 if (ev
== std::ios_base::erase_event
)
52 assert(stream
.getloc().name() == LOCALE_en_US_UTF_8
);
58 void f2(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
60 if (ev
== std::ios_base::erase_event
)
67 assert(stream
.getloc().name() == LOCALE_en_US_UTF_8
);
73 void g1(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
75 if (ev
== std::ios_base::copyfmt_event
)
82 assert(stream
.getloc().name() == LOCALE_fr_FR_UTF_8
);
88 void g2(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
90 if (ev
== std::ios_base::copyfmt_event
)
97 assert(stream
.getloc().name() == LOCALE_fr_FR_UTF_8
);
103 void g3(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
105 if (ev
== std::ios_base::copyfmt_event
)
112 assert(stream
.getloc().name() == LOCALE_fr_FR_UTF_8
);
118 int main(int, char**)
122 ios1
.flags(std::ios::boolalpha
| std::ios::dec
| std::ios::fixed
);
125 ios1
.imbue(std::locale(LOCALE_en_US_UTF_8
));
126 ios1
.exceptions(std::ios::failbit
);
127 ios1
.setstate(std::ios::eofbit
);
128 ios1
.register_callback(f1
, 4);
129 ios1
.register_callback(f2
, 5);
137 ios1
.tie((std::ostream
*)1);
142 ios2
.flags(std::ios::showpoint
| std::ios::uppercase
);
145 ios2
.imbue(std::locale(LOCALE_fr_FR_UTF_8
));
146 ios2
.exceptions(std::ios::eofbit
);
147 ios2
.setstate(std::ios::goodbit
);
148 ios2
.register_callback(g1
, 7);
149 ios2
.register_callback(g2
, 8);
150 ios2
.register_callback(g3
, 9);
160 ios2
.tie((std::ostream
*)2);
166 #ifndef TEST_HAS_NO_EXCEPTIONS
172 catch (std::ios_base::failure
&)
175 assert(ios1
.rdstate() == std::ios::eofbit
);
176 assert(ios1
.rdbuf() == &sb1
);
177 assert(ios1
.flags() == (std::ios::showpoint
| std::ios::uppercase
));
178 assert(ios1
.precision() == 2);
179 assert(ios1
.width() == 12);
180 assert(ios1
.getloc().name() == LOCALE_fr_FR_UTF_8
);
181 assert(ios1
.exceptions() == std::ios::eofbit
);
187 assert(ios1
.iword(0) == 4);
188 assert(ios1
.iword(1) == 5);
189 assert(ios1
.iword(2) == 6);
190 assert(ios1
.iword(3) == 7);
191 assert(ios1
.iword(4) == 8);
192 assert(ios1
.iword(5) == 9);
193 assert(ios1
.pword(0) == &d1
);
194 assert(ios1
.pword(1) == &d2
);
195 assert(ios1
.tie() == (std::ostream
*)2);
196 assert(ios1
.fill() == '2');
200 std::basic_stringbuf
<char, operator_hijacker_char_traits
<char> > sb
;
201 std::basic_ios
<char, operator_hijacker_char_traits
<char> > ios(std::addressof(sb
));