Louis Dionne | f7b4323 | 2019-03-19 19:27:29 +0000 | [diff] [blame] | 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 | |
Louis Dionne | 31cbe0f | 2020-06-01 10:38:23 -0400 | [diff] [blame] | 9 | // UNSUPPORTED: c++03 |
Louis Dionne | f7b4323 | 2019-03-19 19:27:29 +0000 | [diff] [blame] | 10 | |
| 11 | // <filesystem> |
| 12 | |
| 13 | // enum class perms; |
| 14 | |
Nico Weber | cc89063 | 2019-08-21 00:14:12 +0000 | [diff] [blame] | 15 | #include "filesystem_include.h" |
Louis Dionne | f7b4323 | 2019-03-19 19:27:29 +0000 | [diff] [blame] | 16 | #include <type_traits> |
| 17 | #include <cassert> |
| 18 | #include <sys/stat.h> |
| 19 | |
| 20 | #include "test_macros.h" |
Nico Weber | 0f3efc4 | 2019-08-21 22:38:38 +0000 | [diff] [blame] | 21 | #include "check_bitmask_types.h" |
Louis Dionne | f7b4323 | 2019-03-19 19:27:29 +0000 | [diff] [blame] | 22 | |
| 23 | |
| 24 | constexpr fs::perms ME(int val) { return static_cast<fs::perms>(val); } |
| 25 | |
| 26 | int main(int, char**) { |
| 27 | typedef fs::perms E; |
| 28 | static_assert(std::is_enum<E>::value, ""); |
| 29 | |
| 30 | // Check that E is a scoped enum by checking for conversions. |
| 31 | typedef std::underlying_type<E>::type UT; |
| 32 | static_assert(!std::is_convertible<E, UT>::value, ""); |
| 33 | |
Martin Storsjö | 66427d7 | 2020-10-16 11:22:33 +0300 | [diff] [blame] | 34 | LIBCPP_ONLY(static_assert(std::is_same<UT, unsigned >::value, "")); // Implementation detail |
Louis Dionne | f7b4323 | 2019-03-19 19:27:29 +0000 | [diff] [blame] | 35 | |
| 36 | typedef check_bitmask_type<E, E::group_all, E::owner_all> BitmaskTester; |
| 37 | assert(BitmaskTester::check()); |
| 38 | |
| 39 | static_assert( |
| 40 | E::none == ME(0) && |
| 41 | |
| 42 | E::owner_read == ME(0400) && |
| 43 | E::owner_write == ME(0200) && |
| 44 | E::owner_exec == ME(0100) && |
| 45 | E::owner_all == ME(0700) && |
| 46 | |
| 47 | E::group_read == ME(040) && |
| 48 | E::group_write == ME(020) && |
| 49 | E::group_exec == ME(010) && |
| 50 | E::group_all == ME(070) && |
| 51 | |
| 52 | E::others_read == ME(04) && |
| 53 | E::others_write == ME(02) && |
| 54 | E::others_exec == ME(01) && |
| 55 | E::others_all == ME(07) && |
| 56 | E::all == ME(0777) && |
| 57 | E::set_uid == ME(04000) && |
| 58 | E::set_gid == ME(02000) && |
| 59 | E::sticky_bit == ME(01000) && |
| 60 | E::mask == ME(07777) && |
| 61 | E::unknown == ME(0xFFFF), |
| 62 | "Expected enumeration values do not match"); |
| 63 | |
| 64 | return 0; |
| 65 | } |