diff options
Diffstat (limited to 'libcxx/test/std/experimental/filesystem/fs.enum')
5 files changed, 301 insertions, 0 deletions
diff --git a/libcxx/test/std/experimental/filesystem/fs.enum/check_bitmask_types.hpp b/libcxx/test/std/experimental/filesystem/fs.enum/check_bitmask_types.hpp new file mode 100644 index 00000000000..0ad882f24b6 --- /dev/null +++ b/libcxx/test/std/experimental/filesystem/fs.enum/check_bitmask_types.hpp @@ -0,0 +1,75 @@ +#ifndef TEST_BITMASK_TYPE_HPP +#define TEST_BITMASK_TYPE_HPP + +#include <type_traits> +#include <cassert> + +#include "test_macros.h" + + +template <class EnumType, EnumType Val1, EnumType Val2, + class UT = typename std::underlying_type<EnumType>::type, + UT UVal1 = static_cast<UT>(Val1), + UT UVal2 = static_cast<UT>(Val2), + UT UZero = static_cast<UT>(0), + EnumType Zero = static_cast<EnumType>(0) + > +struct check_bitmask_type { + + static constexpr UT dcast(EnumType e) { return static_cast<UT>(e); } + static constexpr UT unpromote(decltype(~UZero) promoted) { return static_cast<UT>(promoted); } + // We need two values that are non-zero and share at least one bit. + static_assert(Val1 != Zero && Val2 != Zero, ""); + static_assert(Val1 != Val2, ""); + static_assert((UVal1 & UVal2) == 0, ""); + + + static bool check() + { + { + EnumType ValRef = Val1; + ASSERT_SAME_TYPE(EnumType, decltype(Val1 & Val2)); + ASSERT_SAME_TYPE(EnumType, decltype(Val1 | Val2)); + ASSERT_SAME_TYPE(EnumType, decltype(Val1 ^ Val2)); + ASSERT_SAME_TYPE(EnumType, decltype(~Val1)); + ASSERT_SAME_TYPE(EnumType&, decltype(ValRef &= Val2)); + ASSERT_SAME_TYPE(EnumType&, decltype(ValRef |= Val2)); + ASSERT_SAME_TYPE(EnumType&, decltype(ValRef ^= Val2)); + } + + static_assert((Val1 & Zero) == Zero, ""); + static_assert((Val1 & Val1) == Val1, ""); + static_assert(dcast(Val1 & Val2) == (UVal1 & UVal2), ""); + + static_assert((Val1 | Zero) == Val1, ""); + static_assert(dcast(Val1 | Val2) == (UVal1 | UVal2), ""); + + static_assert((Val1 ^ Zero) == Val1, ""); + static_assert(dcast(Val1 ^ Val2) == (UVal1 ^ UVal2), ""); + + static_assert(dcast(~Zero) == unpromote(~UZero), ""); + static_assert(dcast(~Val1) == unpromote(~UVal1), ""); + + { + EnumType e = Val1; + EnumType& eref = (e &= Val2); + assert(&eref == &e); + assert(dcast(eref) == (UVal1 & UVal2)); + } + { + EnumType e = Val1; + EnumType& eref = (e |= Val2); + assert(&eref == &e); + assert(dcast(eref) == (UVal1 | UVal2)); + } + { + EnumType e = Val1; + EnumType& eref = (e ^= Val2); + assert(&eref == &e); + assert(dcast(eref) == (UVal1 ^ UVal2)); + } + return true; + } +}; + +#endif // TEST_BITMASK_TYPE diff --git a/libcxx/test/std/experimental/filesystem/fs.enum/enum.copy_options.pass.cpp b/libcxx/test/std/experimental/filesystem/fs.enum/enum.copy_options.pass.cpp new file mode 100644 index 00000000000..22f0cb845a7 --- /dev/null +++ b/libcxx/test/std/experimental/filesystem/fs.enum/enum.copy_options.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/filesystem> + +// enum class copy_options; + +#include <experimental/filesystem> +#include <type_traits> +#include <cassert> + +#include "check_bitmask_types.hpp" +#include "test_macros.h" + +namespace fs = std::experimental::filesystem; + +constexpr fs::copy_options ME(int val) { return static_cast<fs::copy_options>(val); } + +int main() { + typedef fs::copy_options E; + static_assert(std::is_enum<E>::value, ""); + + // Check that E is a scoped enum by checking for conversions. + typedef std::underlying_type<E>::type UT; + static_assert(!std::is_convertible<E, UT>::value, ""); + + static_assert(std::is_same<UT, unsigned short>::value, ""); // Implementation detail + + typedef check_bitmask_type<E, E::skip_existing, E::update_existing> BitmaskTester; + assert(BitmaskTester::check()); + + static_assert( + E::none == ME(0), + "Expected enumeration values do not match"); + // Option group for copy_file + static_assert( + E::skip_existing == ME(1) && + E::overwrite_existing == ME(2) && + E::update_existing == ME(4), + "Expected enumeration values do not match"); + // Option group for copy on directories + static_assert( + E::recursive == ME(8), + "Expected enumeration values do not match"); + // Option group for copy on symlinks + static_assert( + E::copy_symlinks == ME(16) && + E::skip_symlinks == ME(32), + "Expected enumeration values do not match"); + // Option group for changing form of copy + static_assert( + E::directories_only == ME(64) && + E::create_symlinks == ME(128) && + E::create_hard_links == ME(256), + "Expected enumeration values do not match"); +} diff --git a/libcxx/test/std/experimental/filesystem/fs.enum/enum.directory_options.pass.cpp b/libcxx/test/std/experimental/filesystem/fs.enum/enum.directory_options.pass.cpp new file mode 100644 index 00000000000..7dbf7b2887e --- /dev/null +++ b/libcxx/test/std/experimental/filesystem/fs.enum/enum.directory_options.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/filesystem> + +// enum class directory_options; + +#include <experimental/filesystem> +#include <type_traits> +#include <cassert> +#include <sys/stat.h> + +#include "test_macros.h" +#include "check_bitmask_types.hpp" + +namespace fs = std::experimental::filesystem; + +constexpr fs::directory_options ME(int val) { return static_cast<fs::directory_options>(val); } + +int main() { + typedef fs::directory_options E; + static_assert(std::is_enum<E>::value, ""); + + // Check that E is a scoped enum by checking for conversions. + typedef std::underlying_type<E>::type UT; + static_assert(!std::is_convertible<E, UT>::value, ""); + static_assert(std::is_same<UT, unsigned char>::value, ""); + + typedef check_bitmask_type<E, E::follow_directory_symlink, E::skip_permission_denied> BitmaskTester; + assert(BitmaskTester::check()); + + static_assert( + E::none == ME(0) && + E::follow_directory_symlink == ME(1) && + E::skip_permission_denied == ME(2), + "Expected enumeration values do not match"); + +} diff --git a/libcxx/test/std/experimental/filesystem/fs.enum/enum.file_type.pass.cpp b/libcxx/test/std/experimental/filesystem/fs.enum/enum.file_type.pass.cpp new file mode 100644 index 00000000000..ab94ad2877a --- /dev/null +++ b/libcxx/test/std/experimental/filesystem/fs.enum/enum.file_type.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/filesystem> + +// enum class file_type; + +#include <experimental/filesystem> +#include <type_traits> +#include <cassert> + +#include "test_macros.h" + +namespace fs = std::experimental::filesystem; + +constexpr fs::file_type ME(int val) { return static_cast<fs::file_type>(val); } + +int main() { + typedef fs::file_type E; + static_assert(std::is_enum<E>::value, ""); + + // Check that E is a scoped enum by checking for conversions. + typedef std::underlying_type<E>::type UT; + static_assert(!std::is_convertible<E, UT>::value, ""); + + static_assert(std::is_same<UT, signed char>::value, ""); // Implementation detail + + static_assert( + E::none == ME(0) && + E::not_found == ME(-1) && + E::regular == ME(1) && + E::directory == ME(2) && + E::symlink == ME(3) && + E::block == ME(4) && + E::character == ME(5) && + E::fifo == ME(6) && + E::socket == ME(7) && + E::unknown == ME(8), + "Expected enumeration values do not match"); +} diff --git a/libcxx/test/std/experimental/filesystem/fs.enum/enum.perms.pass.cpp b/libcxx/test/std/experimental/filesystem/fs.enum/enum.perms.pass.cpp new file mode 100644 index 00000000000..a3589eb291f --- /dev/null +++ b/libcxx/test/std/experimental/filesystem/fs.enum/enum.perms.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/filesystem> + +// enum class perms; + +#include <experimental/filesystem> +#include <type_traits> +#include <cassert> +#include <sys/stat.h> + +#include "test_macros.h" +#include "check_bitmask_types.hpp" + +namespace fs = std::experimental::filesystem; + +constexpr fs::perms ME(int val) { return static_cast<fs::perms>(val); } + +int main() { + typedef fs::perms E; + static_assert(std::is_enum<E>::value, ""); + + // Check that E is a scoped enum by checking for conversions. + typedef std::underlying_type<E>::type UT; + static_assert(!std::is_convertible<E, UT>::value, ""); + + static_assert(std::is_same<UT, unsigned >::value, ""); // Implementation detail + + typedef check_bitmask_type<E, E::group_all, E::owner_all> BitmaskTester; + assert(BitmaskTester::check()); + + static_assert( + E::none == ME(0) && + + E::owner_read == ME(0400) && + E::owner_write == ME(0200) && + E::owner_exec == ME(0100) && + E::owner_all == ME(0700) && + + E::group_read == ME(040) && + E::group_write == ME(020) && + E::group_exec == ME(010) && + E::group_all == ME(070) && + + E::others_read == ME(04) && + E::others_write == ME(02) && + E::others_exec == ME(01) && + E::others_all == ME(07) && + E::all == ME(0777) && + E::set_uid == ME(04000) && + E::set_gid == ME(02000) && + E::sticky_bit == ME(01000) && + E::mask == ME(07777) && + E::unknown == ME(0xFFFF) && + E::add_perms == ME(0x10000) && + E::remove_perms == ME(0x20000) && + E::resolve_symlinks == ME(0x40000), + "Expected enumeration values do not match"); +} |