1// Copyright (C) 2014-2015 Free Software Foundation, Inc. 2// 3// This file is part of the GNU ISO C++ Library. This library is free 4// software; you can redistribute it and/or modify it under the 5// terms of the GNU General Public License as published by the 6// Free Software Foundation; either version 3, or (at your option) 7// any later version. 8 9// This library is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13 14// You should have received a copy of the GNU General Public License along 15// with this library; see the file COPYING3. If not see 16// <http://www.gnu.org/licenses/>. 17 18// { dg-options "-std=gnu++11" } 19// { dg-require-fileio "" } 20 21// 27.9.1.8 Assign and swap [ifstream.assign] 22 23#include <fstream> 24#include <sstream> 25#include <testsuite_hooks.h> 26 27void 28read(std::istream& in, std::ostream& out) 29{ 30 std::string s; 31 for (int i=0; i < 10; ++i) 32 { 33 getline(in, s); 34 out << s << '\n'; 35 } 36} 37 38void 39test01() 40{ 41 std::string const name = "thirty_years_among_the_dead_preproc.txt"; 42 std::ostringstream ss0; 43 { 44 std::ifstream f0(name); 45 read(f0, ss0); 46 } 47 { 48 std::ifstream f0(name); 49 std::ifstream f1; 50 f1 = std::move(f0); 51 VERIFY( !f0.is_open() ); 52 VERIFY( f1.is_open() ); 53 std::ostringstream ss1; 54 read(f1, ss1); 55 VERIFY( ss0.str() == ss1.str() ); 56 } 57 { 58 std::ifstream f0(name); 59 std::ifstream f1; 60 f1.swap(f0); 61 VERIFY( !f0.is_open() ); 62 VERIFY( f1.is_open() ); 63 std::ostringstream ss1; 64 read(f1, ss1); 65 VERIFY( ss0.str() == ss1.str() ); 66 } 67} 68 69void 70test02() 71{ 72#ifdef _GLIBCXX_USE_WCHAR_T 73 std::wifstream f, f2; 74 f2 = std::move(f); 75 f2.swap(f); 76 swap(f2, f); 77#endif 78} 79 80int 81main() 82{ 83 test01(); 84 test02(); 85} 86