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