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.15 basic_fstream constructors [fstream.cons] 22 23#include <fstream> 24#include <string> 25#include <testsuite_hooks.h> 26 27using namespace std; 28 29std::string const name = "fstream-move.txt"; 30 31void 32test01() 33{ 34 string orig = "Let the whole outside world consist of a long paper tape."; 35 fstream f(name, ios::in|ios::out|ios::trunc); 36 VERIFY( f.is_open() ); 37 f << orig; 38 fstream f1 = std::move(f); 39 VERIFY( f1.is_open() ); 40 VERIFY( !f.is_open() ); 41 f1.seekg(0); 42 string result; 43 getline(f1, result); 44 VERIFY( result == orig ); 45} 46 47void 48test02() 49{ 50#ifdef _GLIBCXX_USE_WCHAR_T 51 wstring orig = L"Let the whole outside world consist of a long paper tape."; 52 wfstream f(name, ios::in|ios::out|ios::trunc); 53 VERIFY( f.is_open() ); 54 f << orig; 55 wfstream f1 = std::move(f); 56 VERIFY( f1.is_open() ); 57 VERIFY( !f.is_open() ); 58 f1.seekg(0); 59 wstring result; 60 getline(f1, result); 61 VERIFY( result == orig ); 62#endif 63} 64 65int 66main() 67{ 68 test01(); 69 test02(); 70} 71