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