blob: c0ed3150457c40394f8c9631cb6f7315e921bb22 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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
Marshall Clow83e2c4d2013-01-05 03:21:01 +000021#include "platform_support.h" // locale name macros
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000022
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000023class test
24 : public std::ios
25{
26public:
27 test()
28 {
29 init(0);
30 }
31};
32
33int f1_called = 0;
34
35void f1(std::ios_base::event ev, std::ios_base& stream, int index)
36{
37 if (ev == std::ios_base::imbue_event)
38 {
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000039 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000040 assert(index == 4);
41 ++f1_called;
42 }
43}
44
45int main()
46{
47 test t;
48 std::ios_base& b = t;
49 b.register_callback(f1, 4);
50 b.register_callback(f1, 4);
51 b.register_callback(f1, 4);
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000052 std::locale l = b.imbue(std::locale(LOCALE_en_US_UTF_8));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000053 assert(f1_called == 3);
54}