| 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++03, c++11, c++14 |
| 10 | // UNSUPPORTED: no-filesystem |
| 11 | // UNSUPPORTED: availability-filesystem-missing |
| 12 | |
| 13 | // <filesystem> |
| 14 | |
| 15 | // bool status_known(file_status s) noexcept; |
| 16 | |
| 17 | #include <filesystem> |
| 18 | #include <type_traits> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | #include "filesystem_test_helper.h" |
| 23 | namespace fs = std::filesystem; |
| 24 | using namespace fs; |
| 25 | |
| 26 | static void signature_test() |
| 27 | { |
| 28 | file_status s; ((void)s); |
| 29 | ASSERT_SAME_TYPE(decltype(status_known(s)), bool); |
| 30 | ASSERT_NOEXCEPT(status_known(s: s)); |
| 31 | } |
| 32 | |
| 33 | static void status_known_test() |
| 34 | { |
| 35 | struct TestCase { |
| 36 | file_type type; |
| 37 | bool expect; |
| 38 | }; |
| 39 | const TestCase testCases[] = { |
| 40 | {.type: file_type::none, .expect: false}, |
| 41 | {.type: file_type::not_found, .expect: true}, |
| 42 | {.type: file_type::regular, .expect: true}, |
| 43 | {.type: file_type::directory, .expect: true}, |
| 44 | {.type: file_type::symlink, .expect: true}, |
| 45 | {.type: file_type::block, .expect: true}, |
| 46 | {.type: file_type::character, .expect: true}, |
| 47 | {.type: file_type::fifo, .expect: true}, |
| 48 | {.type: file_type::socket, .expect: true}, |
| 49 | {.type: file_type::unknown, .expect: true} |
| 50 | }; |
| 51 | for (auto& TC : testCases) { |
| 52 | file_status s(TC.type); |
| 53 | assert(status_known(s) == TC.expect); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | int main(int, char**) { |
| 58 | signature_test(); |
| 59 | status_known_test(); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |