| 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 | // REQUIRES: can-create-symlinks |
| 10 | // UNSUPPORTED: c++03, c++11, c++14 |
| 11 | |
| 12 | // <filesystem> |
| 13 | |
| 14 | // class directory_entry |
| 15 | |
| 16 | // file_status status() const; |
| 17 | // file_status status(error_code const&) const noexcept; |
| 18 | |
| 19 | #include <filesystem> |
| 20 | #include <type_traits> |
| 21 | #include <cassert> |
| 22 | |
| 23 | #include "filesystem_test_helper.h" |
| 24 | #include "test_macros.h" |
| 25 | namespace fs = std::filesystem; |
| 26 | |
| 27 | static void test_basic() { |
| 28 | using namespace fs; |
| 29 | static_test_env static_env; |
| 30 | { |
| 31 | const fs::directory_entry e("foo" ); |
| 32 | std::error_code ec; |
| 33 | static_assert(std::is_same<decltype(e.status()), fs::file_status>::value, "" ); |
| 34 | static_assert(std::is_same<decltype(e.status(ec&: ec)), fs::file_status>::value, "" ); |
| 35 | static_assert(noexcept(e.status()) == false, "" ); |
| 36 | static_assert(noexcept(e.status(ec&: ec)) == true, "" ); |
| 37 | } |
| 38 | path TestCases[] = {static_env.File, static_env.Dir, static_env.SymlinkToFile, |
| 39 | static_env.DNE}; |
| 40 | for (const auto& p : TestCases) { |
| 41 | const directory_entry e(p); |
| 42 | std::error_code pec = GetTestEC(), eec = GetTestEC(1); |
| 43 | file_status ps = fs::status(p, pec); |
| 44 | file_status es = e.status(eec); |
| 45 | assert(ps.type() == es.type()); |
| 46 | assert(ps.permissions() == es.permissions()); |
| 47 | assert(pec.default_error_condition() == eec.default_error_condition()); |
| 48 | } |
| 49 | for (const auto& p : TestCases) { |
| 50 | const directory_entry e(p); |
| 51 | file_status ps = fs::status(p); |
| 52 | file_status es = e.status(); |
| 53 | assert(ps.type() == es.type()); |
| 54 | assert(ps.permissions() == es.permissions()); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | int main(int, char**) { |
| 59 | test_basic(); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |