]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / operations / exists.cc
CommitLineData
a5544970 1// Copyright (C) 2015-2019 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#include <filesystem>
23#include <testsuite_hooks.h>
24#include <testsuite_fs.h>
25
26using std::filesystem::path;
27
28void
29test01()
30{
31 const std::error_code bad_ec = make_error_code(std::errc::invalid_argument);
9534a5e6 32 const path root = __gnu_test::root_path();
641cb5a6 33
9534a5e6
JW
34 VERIFY( exists(root) );
35 VERIFY( exists(root/".") );
641cb5a6
JW
36 VERIFY( exists(path{"."}) );
37 VERIFY( exists(path{".."}) );
38 VERIFY( exists(std::filesystem::current_path()) );
39
40 std::error_code ec;
41 ec = bad_ec;
9534a5e6 42 VERIFY( exists(root, ec) );
641cb5a6
JW
43 VERIFY( !ec );
44 ec = bad_ec;
9534a5e6 45 VERIFY( exists(root/".", ec) );
641cb5a6
JW
46 VERIFY( !ec );
47 ec = bad_ec;
48 VERIFY( exists(path{"."}, ec) );
49 VERIFY( !ec );
50 ec = bad_ec;
51 VERIFY( exists(path{".."}, ec) );
52 VERIFY( !ec );
53 ec = bad_ec;
54 VERIFY( exists(std::filesystem::current_path(), ec) );
55 VERIFY( !ec );
56}
57
58void
59test02()
60{
61 path rel = __gnu_test::nonexistent_path();
62 VERIFY( !exists(rel) );
63
64 std::error_code ec = std::make_error_code(std::errc::invalid_argument);
65 VERIFY( !exists(rel, ec) );
66 VERIFY( !ec ); // DR 2725
67}
68
69void
70test03()
71{
72 path abs = absolute(__gnu_test::nonexistent_path());
73 VERIFY( !exists(abs) );
74
75 std::error_code ec = std::make_error_code(std::errc::invalid_argument);
76 VERIFY( !exists(abs, ec) );
77 VERIFY( !ec ); // DR 2725
78}
79
80void
81test04()
82{
83 using std::filesystem::perms;
84 using std::filesystem::perm_options;
85 path p = __gnu_test::nonexistent_path();
86 create_directory(p);
87 permissions(p, perms::all, perm_options::remove);
88
89 auto unr = p / "unreachable";
90 std::error_code ec;
91 VERIFY( !exists(unr, ec) );
92 VERIFY( ec == std::errc::permission_denied );
93 ec.clear();
94 try
95 {
96 exists(unr);
97 }
98 catch(const std::filesystem::filesystem_error& ex)
99 {
100 ec = ex.code();
101 VERIFY( ex.path1() == unr );
102 }
103 VERIFY( ec == std::errc::permission_denied );
104
105 permissions(p, perms::owner_all);
106 remove(p);
107}
108
109int
110main()
111{
112 test01();
113 test02();
114 test03();
115 test04();
116}