]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_ifstream/cons/move.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ifstream / cons / move.cc
CommitLineData
99dee823 1// Copyright (C) 2014-2021 Free Software Foundation, Inc.
9b817548
JW
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
52066eae 18// { dg-do run { target c++11 } }
9b817548
JW
19// { dg-require-fileio "" }
20
21// 27.9.1.7 basic_ifstream constructors [ifstream.cons]
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 std::ifstream f0(name);
48 std::ifstream f1 = std::move(f0);
49 VERIFY( !f0.is_open() );
50 VERIFY( f1.is_open() );
51 std::ostringstream ss1;
52 read(f1, ss1);
53 VERIFY( ss0.str() == ss1.str() );
54}
55
56void
57test02()
58{
59#ifdef _GLIBCXX_USE_WCHAR_T
60 std::wifstream f0("thirty_years_among_the_dead_preproc.txt");
61 std::wifstream f1 = std::move(f0);
62 VERIFY( f1.is_open() );
63#endif
64}
65
66int
67main()
68{
69 test01();
70 test02();
71}