register_callback.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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// void register_callback(event_callback fn, int index);
15
16#include <ios>
17#include <string>
18#include <locale>
19#include <cassert>
20
21class test
22    : public std::ios
23{
24public:
25    test()
26    {
27        init(0);
28    }
29};
30
31int f1_called = 0;
32
33void f1(std::ios_base::event ev, std::ios_base& stream, int index)
34{
35    if (ev == std::ios_base::imbue_event)
36    {
37        assert(stream.getloc().name() == "en_US");
38        assert(index == 4);
39        ++f1_called;
40    }
41}
42
43int main()
44{
45    test t;
46    std::ios_base& b = t;
47    b.register_callback(f1, 4);
48    b.register_callback(f1, 4);
49    b.register_callback(f1, 4);
50    std::locale l = b.imbue(std::locale("en_US"));
51    assert(f1_called == 3);
52}
53