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 10 11 // <filesystem> 12 13 // bool is_socket(file_status s) noexcept 14 // bool is_socket(path const& p); 15 // bool is_socket(path const& p, std::error_code& ec) noexcept; 16 17 #include "filesystem_include.h" 18 #include <type_traits> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "rapid-cxx-test.h" 23 #include "filesystem_test_helper.h" 24 25 using namespace fs; 26 27 TEST_SUITE(is_socket_test_suite) 28 29 TEST_CASE(signature_test) 30 { 31 file_status s; ((void)s); 32 const path p; ((void)p); 33 std::error_code ec; ((void)ec); 34 ASSERT_NOEXCEPT(is_socket(s)); 35 ASSERT_NOEXCEPT(is_socket(p, ec)); 36 ASSERT_NOT_NOEXCEPT(is_socket(p)); 37 } 38 39 TEST_CASE(is_socket_status_test) 40 { 41 struct TestCase { 42 file_type type; 43 bool expect; 44 }; 45 const TestCase testCases[] = { 46 {file_type::none, false}, 47 {file_type::not_found, false}, 48 {file_type::regular, false}, 49 {file_type::directory, false}, 50 {file_type::symlink, false}, 51 {file_type::block, false}, 52 {file_type::character, false}, 53 {file_type::fifo, false}, 54 {file_type::socket, true}, 55 {file_type::unknown, false} 56 }; 57 for (auto& TC : testCases) { 58 file_status s(TC.type); 59 TEST_CHECK(is_socket(s) == TC.expect); 60 } 61 } 62 63 TEST_CASE(test_exist_not_found) 64 { 65 static_test_env static_env; 66 const path p = static_env.DNE; 67 TEST_CHECK(is_socket(p) == false); 68 } 69 70 TEST_CASE(test_is_socket_fails) 71 { 72 scoped_test_env env; 73 const path dir = env.create_dir("dir"); 74 const path file = env.create_file("dir/file", 42); 75 permissions(dir, perms::none); 76 77 std::error_code ec; 78 TEST_CHECK(is_socket(file, ec) == false); 79 TEST_CHECK(ec); 80 81 TEST_CHECK_THROW(filesystem_error, is_socket(file)); 82 } 83 84 TEST_SUITE_END() 85