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 // <ios>
11
12 // template <class charT, class traits> class basic_ios
13
14 // locale imbue(const locale& loc);
15
16 #include <ios>
17 #include <streambuf>
18 #include <cassert>
19
20 #include "platform_support.h" // locale name macros
21
22 struct testbuf
23 : public std::streambuf
24 {
25 };
26
27 bool f1_called = false;
28 bool f2_called = false;
29 bool f3_called = false;
30
f1(std::ios_base::event ev,std::ios_base & stream,int index)31 void f1(std::ios_base::event ev, std::ios_base& stream, int index)
32 {
33 if (ev == std::ios_base::imbue_event)
34 {
35 assert(!f1_called);
36 assert( f2_called);
37 assert( f3_called);
38 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
39 assert(index == 4);
40 f1_called = true;
41 }
42 }
43
f2(std::ios_base::event ev,std::ios_base & stream,int index)44 void f2(std::ios_base::event ev, std::ios_base& stream, int index)
45 {
46 if (ev == std::ios_base::imbue_event)
47 {
48 assert(!f1_called);
49 assert(!f2_called);
50 assert( f3_called);
51 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
52 assert(index == 5);
53 f2_called = true;
54 }
55 }
56
f3(std::ios_base::event ev,std::ios_base & stream,int index)57 void f3(std::ios_base::event ev, std::ios_base& stream, int index)
58 {
59 if (ev == std::ios_base::imbue_event)
60 {
61 assert(!f1_called);
62 assert(!f2_called);
63 assert(!f3_called);
64 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
65 assert(index == 6);
66 f3_called = true;
67 }
68 }
69
main()70 int main()
71 {
72 {
73 std::ios ios(0);
74 ios.register_callback(f1, 4);
75 ios.register_callback(f2, 5);
76 ios.register_callback(f3, 6);
77 std::locale l = ios.imbue(std::locale(LOCALE_en_US_UTF_8));
78 assert(l.name() == std::string("C"));
79 assert(ios.getloc().name() == std::string(LOCALE_en_US_UTF_8));
80 assert(f1_called);
81 assert(f2_called);
82 assert(f3_called);
83 }
84 f1_called = false;
85 f2_called = false;
86 f3_called = false;
87 {
88 testbuf sb;
89 std::ios ios(&sb);
90 ios.register_callback(f1, 4);
91 ios.register_callback(f2, 5);
92 ios.register_callback(f3, 6);
93 std::locale l = ios.imbue(std::locale(LOCALE_en_US_UTF_8));
94 assert(l.name() == std::string("C"));
95 assert(ios.getloc().name() == std::string(LOCALE_en_US_UTF_8));
96 assert(sb.getloc().name() == std::string(LOCALE_en_US_UTF_8));
97 assert(f1_called);
98 assert(f2_called);
99 assert(f3_called);
100 }
101 }
102