1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // REQUIRES: locale.en_US.UTF-8
10
11 // <ios>
12
13 // class ios_base
14
15 // void register_callback(event_callback fn, int index);
16
17 #include <ios>
18 #include <string>
19 #include <locale>
20 #include <cassert>
21
22 #include "test_macros.h"
23 #include "platform_support.h" // locale name macros
24
25 class test
26 : public std::ios
27 {
28 public:
test()29 test()
30 {
31 init(0);
32 }
33 };
34
35 int f1_called = 0;
36
f1(std::ios_base::event ev,std::ios_base & stream,int index)37 void f1(std::ios_base::event ev, std::ios_base& stream, int index)
38 {
39 if (ev == std::ios_base::imbue_event)
40 {
41 assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
42 assert(index == 4);
43 ++f1_called;
44 }
45 }
46
main(int,char **)47 int main(int, char**)
48 {
49 test t;
50 std::ios_base& b = t;
51 b.register_callback(f1, 4);
52 b.register_callback(f1, 4);
53 b.register_callback(f1, 4);
54 std::locale l = b.imbue(std::locale(LOCALE_en_US_UTF_8));
55 assert(f1_called == 3);
56
57 return 0;
58 }
59