xref: /llvm-project/libcxx/test/std/input.output/filesystems/fs.enum/enum.perms.pass.cpp (revision 0f3efc4aab9748ea4791ed47530a9ea7174b97e3)
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++98, c++03
10 
11 // <filesystem>
12 
13 // enum class perms;
14 
15 #include "filesystem_include.h"
16 #include <type_traits>
17 #include <cassert>
18 #include <sys/stat.h>
19 
20 #include "test_macros.h"
21 #include "check_bitmask_types.h"
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 
34   static_assert(std::is_same<UT, unsigned >::value, ""); // Implementation detail
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 }
66