libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

enum.perms.pass.cpp (1906B)


      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 // <filesystem>
     13 
     14 // enum class perms;
     15 
     16 #include "filesystem_include.hpp"
     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 
     25 constexpr fs::perms ME(int val) { return static_cast<fs::perms>(val); }
     26 
     27 int main() {
     28   typedef fs::perms E;
     29   static_assert(std::is_enum<E>::value, "");
     30 
     31   // Check that E is a scoped enum by checking for conversions.
     32   typedef std::underlying_type<E>::type UT;
     33   static_assert(!std::is_convertible<E, UT>::value, "");
     34 
     35   static_assert(std::is_same<UT, unsigned >::value, ""); // Implementation detail
     36 
     37   typedef check_bitmask_type<E, E::group_all, E::owner_all> BitmaskTester;
     38   assert(BitmaskTester::check());
     39 
     40   static_assert(
     41         E::none         == ME(0) &&
     42 
     43         E::owner_read   == ME(0400) &&
     44         E::owner_write  == ME(0200) &&
     45         E::owner_exec   == ME(0100) &&
     46         E::owner_all    == ME(0700) &&
     47 
     48         E::group_read   == ME(040) &&
     49         E::group_write  == ME(020) &&
     50         E::group_exec   == ME(010) &&
     51         E::group_all    == ME(070) &&
     52 
     53         E::others_read  == ME(04) &&
     54         E::others_write == ME(02) &&
     55         E::others_exec  == ME(01) &&
     56         E::others_all   == ME(07) &&
     57         E::all          == ME(0777) &&
     58         E::set_uid      == ME(04000) &&
     59         E::set_gid      == ME(02000) &&
     60         E::sticky_bit   == ME(01000) &&
     61         E::mask         == ME(07777) &&
     62         E::unknown      == ME(0xFFFF),
     63         "Expected enumeration values do not match");
     64 }