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