]>
Commit | Line | Data |
---|---|---|
85ec4feb | 1 | // Copyright (C) 2016-2018 Free Software Foundation, Inc. |
641cb5a6 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 | ||
18 | // { dg-options "-std=gnu++17 -lstdc++fs" } | |
19 | // { dg-do run { target c++17 } } | |
20 | // { dg-require-filesystem-ts "" } | |
21 | ||
22 | // 15.4 Copy [fs.op.copy_file] | |
23 | ||
24 | #include <filesystem> | |
25 | #include <fstream> | |
26 | #include <testsuite_fs.h> | |
27 | #include <testsuite_hooks.h> | |
28 | ||
29 | void | |
30 | test01() | |
31 | { | |
32 | using std::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}; |
641cb5a6 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} << "Hello, filesystem!"; |
641cb5a6 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( exists(to) ); | |
74 | VERIFY( file_size(to) == file_size(from) ); | |
75 | ||
76 | remove(from); | |
77 | remove(to); | |
78 | } | |
79 | ||
80 | int | |
81 | main() | |
82 | { | |
83 | test01(); | |
84 | } |