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