aboutsummaryrefslogtreecommitdiff
path: root/test/std/input.output/iostreams.base/ios.base/ios.base.callback/register_callback.pass.cpp
blob: f4d541e2f5277a4ecc8d4edf2b6bc8a5a1371824 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// REQUIRES: locale.en_US.UTF-8

// <ios>

// class ios_base

// void register_callback(event_callback fn, int index);

#include <ios>
#include <string>
#include <locale>
#include <cassert>

#include "platform_support.h" // locale name macros

class test
    : public std::ios
{
public:
    test()
    {
        init(0);
    }
};

int f1_called = 0;

void f1(std::ios_base::event ev, std::ios_base& stream, int index)
{
    if (ev == std::ios_base::imbue_event)
    {
        assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
        assert(index == 4);
        ++f1_called;
    }
}

int main()
{
    test t;
    std::ios_base& b = t;
    b.register_callback(f1, 4);
    b.register_callback(f1, 4);
    b.register_callback(f1, 4);
    std::locale l = b.imbue(std::locale(LOCALE_en_US_UTF_8));
    assert(f1_called == 3);
}