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