Eric Fiselier | c797958 | 2016-06-17 19:46:40 +0000 | [diff] [blame^] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // UNSUPPORTED: c++98, c++03 |
| 11 | |
| 12 | // <experimental/filesystem> |
| 13 | |
| 14 | // enum class perms; |
| 15 | |
| 16 | #include <experimental/filesystem> |
| 17 | #include <type_traits> |
| 18 | #include <cassert> |
| 19 | #include <sys/stat.h> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | #include "check_bitmask_types.hpp" |
| 23 | |
| 24 | namespace fs = std::experimental::filesystem; |
| 25 | |
| 26 | constexpr fs::perms ME(int val) { return static_cast<fs::perms>(val); } |
| 27 | |
| 28 | int main() { |
| 29 | typedef fs::perms E; |
| 30 | static_assert(std::is_enum<E>::value, ""); |
| 31 | |
| 32 | // Check that E is a scoped enum by checking for conversions. |
| 33 | typedef std::underlying_type<E>::type UT; |
| 34 | static_assert(!std::is_convertible<E, UT>::value, ""); |
| 35 | |
| 36 | static_assert(std::is_same<UT, unsigned >::value, ""); // Implementation detail |
| 37 | |
| 38 | typedef check_bitmask_type<E, E::group_all, E::owner_all> BitmaskTester; |
| 39 | assert(BitmaskTester::check()); |
| 40 | |
| 41 | static_assert( |
| 42 | E::none == ME(0) && |
| 43 | |
| 44 | E::owner_read == ME(0400) && |
| 45 | E::owner_write == ME(0200) && |
| 46 | E::owner_exec == ME(0100) && |
| 47 | E::owner_all == ME(0700) && |
| 48 | |
| 49 | E::group_read == ME(040) && |
| 50 | E::group_write == ME(020) && |
| 51 | E::group_exec == ME(010) && |
| 52 | E::group_all == ME(070) && |
| 53 | |
| 54 | E::others_read == ME(04) && |
| 55 | E::others_write == ME(02) && |
| 56 | E::others_exec == ME(01) && |
| 57 | E::others_all == ME(07) && |
| 58 | E::all == ME(0777) && |
| 59 | E::set_uid == ME(04000) && |
| 60 | E::set_gid == ME(02000) && |
| 61 | E::sticky_bit == ME(01000) && |
| 62 | E::mask == ME(07777) && |
| 63 | E::unknown == ME(0xFFFF) && |
| 64 | E::add_perms == ME(0x10000) && |
| 65 | E::remove_perms == ME(0x20000) && |
| 66 | E::resolve_symlinks == ME(0x40000), |
| 67 | "Expected enumeration values do not match"); |
| 68 | } |