Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <ios> |
| 11 | |
| 12 | // class ios_base |
| 13 | |
| 14 | // locale imbue(const locale& loc); |
| 15 | |
| 16 | #include <ios> |
| 17 | #include <string> |
| 18 | #include <locale> |
| 19 | #include <cassert> |
| 20 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 21 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 22 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | class test |
| 24 | : public std::ios |
| 25 | { |
| 26 | public: |
| 27 | test() |
| 28 | { |
| 29 | init(0); |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | bool f1_called = false; |
| 34 | bool f2_called = false; |
| 35 | bool f3_called = false; |
| 36 | |
| 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(!f1_called); |
| 42 | assert( f2_called); |
| 43 | assert( f3_called); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 44 | assert(stream.getloc().name() == LOCALE_en_US_UTF_8); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | assert(index == 4); |
| 46 | f1_called = true; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void f2(std::ios_base::event ev, std::ios_base& stream, int index) |
| 51 | { |
| 52 | if (ev == std::ios_base::imbue_event) |
| 53 | { |
| 54 | assert(!f1_called); |
| 55 | assert(!f2_called); |
| 56 | assert( f3_called); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 57 | assert(stream.getloc().name() == LOCALE_en_US_UTF_8); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | assert(index == 5); |
| 59 | f2_called = true; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void f3(std::ios_base::event ev, std::ios_base& stream, int index) |
| 64 | { |
| 65 | if (ev == std::ios_base::imbue_event) |
| 66 | { |
| 67 | assert(!f1_called); |
| 68 | assert(!f2_called); |
| 69 | assert(!f3_called); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 70 | assert(stream.getloc().name() == LOCALE_en_US_UTF_8); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 71 | assert(index == 6); |
| 72 | f3_called = true; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | int main() |
| 77 | { |
| 78 | test t; |
| 79 | std::ios_base& b = t; |
| 80 | b.register_callback(f1, 4); |
| 81 | b.register_callback(f2, 5); |
| 82 | b.register_callback(f3, 6); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 83 | std::locale l = b.imbue(std::locale(LOCALE_en_US_UTF_8)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | assert(l.name() == std::string("C")); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 85 | assert(b.getloc().name() == std::string(LOCALE_en_US_UTF_8)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | assert(f1_called); |
| 87 | assert(f2_called); |
| 88 | assert(f3_called); |
| 89 | } |