]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/input.output/iostreams.base/ios.base/ios.base.locales/imbue.pass.cpp
Vendor import of libc++ trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / std / input.output / iostreams.base / ios.base / ios.base.locales / imbue.pass.cpp
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 // REQUIRES: locale.en_US.UTF-8
11
12 // <ios>
13
14 // class ios_base
15
16 // locale imbue(const locale& loc);
17
18 #include <ios>
19 #include <string>
20 #include <locale>
21 #include <cassert>
22
23 #include "platform_support.h" // locale name macros
24
25 class test
26     : public std::ios
27 {
28 public:
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
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
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
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
78 int main()
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 }