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 | |
Dan Albert | b4ed5ca | 2014-08-04 18:44:48 +0000 | [diff] [blame] | 10 | // REQUIRES: locale.fr_FR.UTF-8 |
| 11 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 12 | // <ios> |
| 13 | |
| 14 | // template <class charT, class traits> class basic_ios |
| 15 | |
| 16 | // void move(basic_ios&& rhs); |
| 17 | |
| 18 | #include <ios> |
| 19 | #include <streambuf> |
| 20 | #include <cassert> |
| 21 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 22 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 23 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | struct testbuf |
| 25 | : public std::streambuf |
| 26 | { |
| 27 | }; |
| 28 | |
| 29 | struct testios |
| 30 | : public std::ios |
| 31 | { |
| 32 | testios() {} |
| 33 | testios(std::streambuf* p) : std::ios(p) {} |
| 34 | void move(std::ios& x) {std::ios::move(x);} |
| 35 | }; |
| 36 | |
| 37 | bool f1_called = false; |
| 38 | bool f2_called = false; |
| 39 | |
| 40 | bool g1_called = false; |
| 41 | bool g2_called = false; |
| 42 | bool g3_called = false; |
| 43 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 44 | void f1(std::ios_base::event ev, std::ios_base& stream, int index) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | { |
| 46 | f1_called = true; |
| 47 | } |
| 48 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 49 | void f2(std::ios_base::event ev, std::ios_base& stream, int index) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 50 | { |
| 51 | f2_called = true; |
| 52 | } |
| 53 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 54 | void g1(std::ios_base::event ev, std::ios_base& stream, int index) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | { |
| 56 | if (ev == std::ios_base::imbue_event) |
| 57 | { |
| 58 | assert(index == 7); |
| 59 | g1_called = true; |
| 60 | } |
| 61 | } |
| 62 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 63 | void g2(std::ios_base::event ev, std::ios_base& stream, int index) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | { |
| 65 | if (ev == std::ios_base::imbue_event) |
| 66 | { |
| 67 | assert(index == 8); |
| 68 | g2_called = true; |
| 69 | } |
| 70 | } |
| 71 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 72 | void g3(std::ios_base::event ev, std::ios_base& stream, int index) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | { |
| 74 | if (ev == std::ios_base::imbue_event) |
| 75 | { |
| 76 | assert(index == 9); |
| 77 | g3_called = true; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | int main() |
| 82 | { |
| 83 | testios ios1; |
| 84 | testbuf sb2; |
| 85 | std::ios ios2(&sb2); |
| 86 | ios2.flags(std::ios::showpoint | std::ios::uppercase); |
| 87 | ios2.precision(2); |
| 88 | ios2.width(12); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 89 | ios2.imbue(std::locale(LOCALE_fr_FR_UTF_8)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | ios2.exceptions(std::ios::eofbit); |
| 91 | ios2.setstate(std::ios::goodbit); |
| 92 | ios2.register_callback(g1, 7); |
| 93 | ios2.register_callback(g2, 8); |
| 94 | ios2.register_callback(g3, 9); |
| 95 | ios2.iword(0) = 4; |
| 96 | ios2.iword(1) = 5; |
| 97 | ios2.iword(2) = 6; |
| 98 | ios2.iword(3) = 7; |
| 99 | ios2.iword(4) = 8; |
| 100 | ios2.iword(5) = 9; |
| 101 | char d1, d2; |
| 102 | ios2.pword(0) = &d1; |
| 103 | ios2.pword(1) = &d2; |
| 104 | ios2.tie((std::ostream*)2); |
| 105 | ios2.fill('2'); |
| 106 | |
| 107 | ios1.move(ios2); |
| 108 | |
| 109 | assert(ios1.rdstate() == std::ios::goodbit); |
| 110 | assert(ios1.rdbuf() == 0); |
| 111 | assert(ios1.flags() == (std::ios::showpoint | std::ios::uppercase)); |
| 112 | assert(ios1.precision() == 2); |
| 113 | assert(ios1.width() == 12); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 114 | assert(ios1.getloc().name() == LOCALE_fr_FR_UTF_8); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | assert(ios1.exceptions() == std::ios::eofbit); |
| 116 | assert(!f1_called); |
| 117 | assert(!f2_called); |
| 118 | assert(!g1_called); |
| 119 | assert(!g2_called); |
| 120 | assert(!g3_called); |
| 121 | assert(ios1.iword(0) == 4); |
| 122 | assert(ios1.iword(1) == 5); |
| 123 | assert(ios1.iword(2) == 6); |
| 124 | assert(ios1.iword(3) == 7); |
| 125 | assert(ios1.iword(4) == 8); |
| 126 | assert(ios1.iword(5) == 9); |
| 127 | assert(ios1.pword(0) == &d1); |
| 128 | assert(ios1.pword(1) == &d2); |
| 129 | assert(ios1.tie() == (std::ostream*)2); |
| 130 | assert(ios1.fill() == '2'); |
| 131 | ios1.imbue(std::locale("C")); |
| 132 | assert(!f1_called); |
| 133 | assert(!f2_called); |
| 134 | assert(g1_called); |
| 135 | assert(g2_called); |
| 136 | assert(g3_called); |
| 137 | |
| 138 | assert(ios2.rdbuf() == &sb2); |
| 139 | assert(ios2.tie() == 0); |
| 140 | } |