blob: ca990cb2d3bb20c24b0e56f72a078cb30535fa00 [file] [log] [blame]
Louis Dionnef7b43232019-03-19 19:27:29 +00001//===----------------------------------------------------------------------===//
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 Dionne31cbe0f2020-06-01 10:38:23 -04009// UNSUPPORTED: c++03
Louis Dionnef7b43232019-03-19 19:27:29 +000010
11// <filesystem>
12
13// enum class perms;
14
Nico Webercc890632019-08-21 00:14:12 +000015#include "filesystem_include.h"
Louis Dionnef7b43232019-03-19 19:27:29 +000016#include <type_traits>
17#include <cassert>
18#include <sys/stat.h>
19
20#include "test_macros.h"
Nico Weber0f3efc42019-08-21 22:38:38 +000021#include "check_bitmask_types.h"
Louis Dionnef7b43232019-03-19 19:27:29 +000022
23
24constexpr fs::perms ME(int val) { return static_cast<fs::perms>(val); }
25
26int 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ö66427d72020-10-16 11:22:33 +030034 LIBCPP_ONLY(static_assert(std::is_same<UT, unsigned >::value, "")); // Implementation detail
Louis Dionnef7b43232019-03-19 19:27:29 +000035
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}