]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/filesystem/operations/copy_file.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / operations / copy_file.cc
CommitLineData
7adcbafe 1// Copyright (C) 2016-2022 Free Software Foundation, Inc.
6fe673ad
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
ef0e80d2 18// { dg-options "-DUSE_FILESYSTEM_TS -lstdc++fs" }
52066eae 19// { dg-do run { target c++11 } }
6fe673ad
JW
20// { dg-require-filesystem-ts "" }
21
22// 15.4 Copy [fs.op.copy_file]
23
24#include <experimental/filesystem>
25#include <fstream>
26#include <testsuite_fs.h>
27#include <testsuite_hooks.h>
28
29void
30test01()
31{
6fe673ad
JW
32 using std::experimental::filesystem::copy_options;
33 std::error_code ec;
34
35 auto from = __gnu_test::nonexistent_path();
36 auto to = __gnu_test::nonexistent_path();
37
38 // test non-existent file
39 bool b = copy_file(from, to, ec);
40 VERIFY( !b );
41 VERIFY( ec );
42 VERIFY( !exists(to) );
43
44 // test empty file
9534a5e6 45 std::ofstream{from.c_str()};
6fe673ad
JW
46 VERIFY( exists(from) );
47 VERIFY( file_size(from) == 0 );
48
49 b = copy_file(from, to);
50 VERIFY( b );
51 VERIFY( exists(to) );
52 VERIFY( file_size(to) == 0 );
53 remove(to);
54 VERIFY( !exists(to) );
55 b = copy_file(from, to, copy_options::none, ec);
56 VERIFY( b );
57 VERIFY( !ec );
58 VERIFY( exists(to) );
59 VERIFY( file_size(to) == 0 );
60
9534a5e6 61 std::ofstream{from.c_str()} << "Hello, filesystem!";
6fe673ad
JW
62 VERIFY( file_size(from) != 0 );
63 remove(to);
64 VERIFY( !exists(to) );
65 b = copy_file(from, to);
66 VERIFY( b );
67 VERIFY( exists(to) );
68 VERIFY( file_size(to) == file_size(from) );
69 remove(to);
70 VERIFY( !exists(to) );
71 b = copy_file(from, to);
72 VERIFY( b );
73 VERIFY( !ec );
74 VERIFY( exists(to) );
75 VERIFY( file_size(to) == file_size(from) );
ec04aad7
JW
76
77 remove(from);
78 remove(to);
6fe673ad
JW
79}
80
81int
82main()
83{
84 test01();
85}