]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/filesystem/operations/create_symlink.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / operations / create_symlink.cc
CommitLineData
8d9254fc 1// Copyright (C) 2016-2020 Free Software Foundation, Inc.
d17f7088
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" }
d17f7088
JW
19// { dg-do run { target c++11 } }
20// { dg-require-filesystem-ts "" }
21
22#include <experimental/filesystem>
23#include <testsuite_hooks.h>
24#include <testsuite_fs.h>
25
26namespace fs = std::experimental::filesystem;
27
28void
29test01()
30{
31 std::error_code ec, ec2;
32 __gnu_test::scoped_file f;
33 auto tgt = f.path;
34
35 // Test empty path.
36 fs::path p;
37 create_symlink(tgt, p, ec );
38 VERIFY( ec );
39 try
40 {
41 create_symlink(tgt, p);
42 }
43 catch (const std::experimental::filesystem::filesystem_error& ex)
44 {
45 ec2 = ex.code();
46 VERIFY( ex.path1() == tgt );
47 VERIFY( ex.path2() == p );
48 }
49 VERIFY( ec2 == ec );
50}
51
52void
53test02()
54{
55 std::error_code ec, ec2;
56 __gnu_test::scoped_file f;
57 auto tgt = f.path;
58
59 // Test non-existent path
60 auto p = __gnu_test::nonexistent_path();
61 VERIFY( !exists(p) );
62
63 create_symlink(tgt, p, ec); // create the symlink once
64 VERIFY( !ec );
65 VERIFY( exists(p) );
66 VERIFY( is_symlink(p) );
67 remove(p);
68 create_symlink(tgt, p); // create the symlink again
69 VERIFY( exists(p) );
70 VERIFY( is_symlink(p) );
71
72 create_symlink(tgt, p, ec); // Try to create existing symlink
73 VERIFY( ec );
74 try
75 {
76 create_symlink(tgt, p);
77 }
78 catch (const std::experimental::filesystem::filesystem_error& ex)
79 {
80 ec2 = ex.code();
81 VERIFY( ex.path1() == tgt );
82 VERIFY( ex.path2() == p );
83 }
84 VERIFY( ec2 == ec );
85
86 remove(p);
87}
88
89int
90main()
91{
92 test01();
93}