1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++98, c++03
10
11 // <filesystem>
12
13 // class directory_entry
14
15 // file_status status() const;
16 // file_status status(error_code const&) const noexcept;
17
18 #include "filesystem_include.h"
19 #include <type_traits>
20 #include <cassert>
21
22 #include "filesystem_test_helper.h"
23 #include "rapid-cxx-test.h"
24
25 #include "test_macros.h"
26
27 TEST_SUITE(directory_entry_status_testsuite)
28
TEST_CASE(test_basic)29 TEST_CASE(test_basic) {
30 using namespace fs;
31 {
32 const fs::directory_entry e("foo");
33 std::error_code ec;
34 static_assert(std::is_same<decltype(e.status()), fs::file_status>::value, "");
35 static_assert(std::is_same<decltype(e.status(ec)), fs::file_status>::value, "");
36 static_assert(noexcept(e.status()) == false, "");
37 static_assert(noexcept(e.status(ec)) == true, "");
38 }
39 path TestCases[] = {StaticEnv::File, StaticEnv::Dir, StaticEnv::SymlinkToFile,
40 StaticEnv::DNE};
41 for (const auto& p : TestCases) {
42 const directory_entry e(p);
43 std::error_code pec = GetTestEC(), eec = GetTestEC(1);
44 file_status ps = fs::status(p, pec);
45 file_status es = e.status(eec);
46 TEST_CHECK(ps.type() == es.type());
47 TEST_CHECK(ps.permissions() == es.permissions());
48 TEST_CHECK(pec == eec);
49 }
50 for (const auto& p : TestCases) {
51 const directory_entry e(p);
52 file_status ps = fs::status(p);
53 file_status es = e.status();
54 TEST_CHECK(ps.type() == es.type());
55 TEST_CHECK(ps.permissions() == es.permissions());
56 }
57 }
58
59 TEST_SUITE_END()
60