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);
22 #include "platform_support.h" // locale name macros
24 #include "test_macros.h"
27 : public std::streambuf
31 bool f1_called
= false;
32 bool f2_called
= false;
34 bool g1_called
= false;
35 bool g2_called
= false;
36 bool g3_called
= false;
38 void f1(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
40 if (ev
== std::ios_base::erase_event
)
47 assert(stream
.getloc().name() == LOCALE_en_US_UTF_8
);
53 void f2(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
55 if (ev
== std::ios_base::erase_event
)
62 assert(stream
.getloc().name() == LOCALE_en_US_UTF_8
);
68 void g1(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
70 if (ev
== std::ios_base::copyfmt_event
)
77 assert(stream
.getloc().name() == LOCALE_fr_FR_UTF_8
);
83 void g2(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
85 if (ev
== std::ios_base::copyfmt_event
)
92 assert(stream
.getloc().name() == LOCALE_fr_FR_UTF_8
);
98 void g3(std::ios_base::event ev
, std::ios_base
& stream
, int index
)
100 if (ev
== std::ios_base::copyfmt_event
)
107 assert(stream
.getloc().name() == LOCALE_fr_FR_UTF_8
);
113 int main(int, char**)
117 ios1
.flags(std::ios::boolalpha
| std::ios::dec
| std::ios::fixed
);
120 ios1
.imbue(std::locale(LOCALE_en_US_UTF_8
));
121 ios1
.exceptions(std::ios::failbit
);
122 ios1
.setstate(std::ios::eofbit
);
123 ios1
.register_callback(f1
, 4);
124 ios1
.register_callback(f2
, 5);
132 ios1
.tie((std::ostream
*)1);
137 ios2
.flags(std::ios::showpoint
| std::ios::uppercase
);
140 ios2
.imbue(std::locale(LOCALE_fr_FR_UTF_8
));
141 ios2
.exceptions(std::ios::eofbit
);
142 ios2
.setstate(std::ios::goodbit
);
143 ios2
.register_callback(g1
, 7);
144 ios2
.register_callback(g2
, 8);
145 ios2
.register_callback(g3
, 9);
155 ios2
.tie((std::ostream
*)2);
161 #ifndef TEST_HAS_NO_EXCEPTIONS
167 catch (std::ios_base::failure
&)
170 assert(ios1
.rdstate() == std::ios::eofbit
);
171 assert(ios1
.rdbuf() == &sb1
);
172 assert(ios1
.flags() == (std::ios::showpoint
| std::ios::uppercase
));
173 assert(ios1
.precision() == 2);
174 assert(ios1
.width() == 12);
175 assert(ios1
.getloc().name() == LOCALE_fr_FR_UTF_8
);
176 assert(ios1
.exceptions() == std::ios::eofbit
);
182 assert(ios1
.iword(0) == 4);
183 assert(ios1
.iword(1) == 5);
184 assert(ios1
.iword(2) == 6);
185 assert(ios1
.iword(3) == 7);
186 assert(ios1
.iword(4) == 8);
187 assert(ios1
.iword(5) == 9);
188 assert(ios1
.pword(0) == &d1
);
189 assert(ios1
.pword(1) == &d2
);
190 assert(ios1
.tie() == (std::ostream
*)2);
191 assert(ios1
.fill() == '2');