1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // REQUIRES: locale.en_US.UTF-8
11 // REQUIRES: locale.fr_FR.UTF-8
15 // template <class charT, class traits> class basic_ios
17 // basic_ios& copyfmt(const basic_ios& rhs);
23 #include "platform_support.h" // locale name macros
25 #include "test_macros.h"
28 : public std::streambuf
32 bool f1_called = false;
33 bool f2_called = false;
35 bool g1_called = false;
36 bool g2_called = false;
37 bool g3_called = false;
39 void f1(std::ios_base::event ev, std::ios_base& stream, int index)
41 if (ev == std::ios_base::erase_event)
48 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
54 void f2(std::ios_base::event ev, std::ios_base& stream, int index)
56 if (ev == std::ios_base::erase_event)
63 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
69 void g1(std::ios_base::event ev, std::ios_base& stream, int index)
71 if (ev == std::ios_base::copyfmt_event)
78 assert(stream.getloc().name() == LOCALE_fr_FR_UTF_8);
84 void g2(std::ios_base::event ev, std::ios_base& stream, int index)
86 if (ev == std::ios_base::copyfmt_event)
93 assert(stream.getloc().name() == LOCALE_fr_FR_UTF_8);
99 void g3(std::ios_base::event ev, std::ios_base& stream, int index)
101 if (ev == std::ios_base::copyfmt_event)
108 assert(stream.getloc().name() == LOCALE_fr_FR_UTF_8);
118 ios1.flags(std::ios::boolalpha | std::ios::dec | std::ios::fixed);
121 ios1.imbue(std::locale(LOCALE_en_US_UTF_8));
122 ios1.exceptions(std::ios::failbit);
123 ios1.setstate(std::ios::eofbit);
124 ios1.register_callback(f1, 4);
125 ios1.register_callback(f2, 5);
133 ios1.tie((std::ostream*)1);
138 ios2.flags(std::ios::showpoint | std::ios::uppercase);
141 ios2.imbue(std::locale(LOCALE_fr_FR_UTF_8));
142 ios2.exceptions(std::ios::eofbit);
143 ios2.setstate(std::ios::goodbit);
144 ios2.register_callback(g1, 7);
145 ios2.register_callback(g2, 8);
146 ios2.register_callback(g3, 9);
156 ios2.tie((std::ostream*)2);
162 #ifndef TEST_HAS_NO_EXCEPTIONS
168 catch (std::ios_base::failure&)
171 assert(ios1.rdstate() == std::ios::eofbit);
172 assert(ios1.rdbuf() == &sb1);
173 assert(ios1.flags() == (std::ios::showpoint | std::ios::uppercase));
174 assert(ios1.precision() == 2);
175 assert(ios1.width() == 12);
176 assert(ios1.getloc().name() == LOCALE_fr_FR_UTF_8);
177 assert(ios1.exceptions() == std::ios::eofbit);
183 assert(ios1.iword(0) == 4);
184 assert(ios1.iword(1) == 5);
185 assert(ios1.iword(2) == 6);
186 assert(ios1.iword(3) == 7);
187 assert(ios1.iword(4) == 8);
188 assert(ios1.iword(5) == 9);
189 assert(ios1.pword(0) == &d1);
190 assert(ios1.pword(1) == &d2);
191 assert(ios1.tie() == (std::ostream*)2);
192 assert(ios1.fill() == '2');