register_callback.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // <ios>
  10. // class ios_base
  11. // void register_callback(event_callback fn, int index);
  12. #include <ios>
  13. #include <string>
  14. #include <locale>
  15. #include <cassert>
  16. #include "../../../../platform_support.h" // locale name macros
  17. class test
  18. : public std::ios
  19. {
  20. public:
  21. test()
  22. {
  23. init(0);
  24. }
  25. };
  26. int f1_called = 0;
  27. void f1(std::ios_base::event ev, std::ios_base& stream, int index)
  28. {
  29. if (ev == std::ios_base::imbue_event)
  30. {
  31. assert(stream.getloc().name() == LOCALE_en_US_UTF_8);
  32. assert(index == 4);
  33. ++f1_called;
  34. }
  35. }
  36. int main()
  37. {
  38. test t;
  39. std::ios_base& b = t;
  40. b.register_callback(f1, 4);
  41. b.register_callback(f1, 4);
  42. b.register_callback(f1, 4);
  43. std::locale l = b.imbue(std::locale(LOCALE_en_US_UTF_8));
  44. assert(f1_called == 3);
  45. }