tomato-testing/test/entt/core/enum.cpp
Green Sky 5c7231b7a3 Squashed 'external/entt/entt/' content from commit fef92113
git-subtree-dir: external/entt/entt
git-subtree-split: fef921132cae7588213d0f9bcd2fb9c8ffd8b7fc
2023-07-25 11:29:51 +02:00

73 lines
1.9 KiB
C++

#include <cstdint>
#include <type_traits>
#include <gtest/gtest.h>
#include <entt/core/enum.hpp>
enum class detected {
foo = 0x01,
bar = 0x02,
quux = 0x04,
_entt_enum_as_bitmask
};
// small type on purpose
enum class registered : std::uint8_t {
foo = 0x01,
bar = 0x02,
quux = 0x04
};
template<>
struct entt::enum_as_bitmask<registered>
: std::true_type {};
template<typename Type>
struct Enum: testing::Test {
using type = Type;
};
using EnumTypes = ::testing::Types<detected, registered>;
TYPED_TEST_SUITE(Enum, EnumTypes, );
TYPED_TEST(Enum, Functionalities) {
using enum_type = typename TestFixture::type;
ASSERT_TRUE(!!((enum_type::foo | enum_type::bar) & enum_type::foo));
ASSERT_TRUE(!!((enum_type::foo | enum_type::bar) & enum_type::bar));
ASSERT_TRUE(!((enum_type::foo | enum_type::bar) & enum_type::quux));
ASSERT_TRUE(!!((enum_type::foo ^ enum_type::bar) & enum_type::foo));
ASSERT_TRUE(!((enum_type::foo ^ enum_type::foo) & enum_type::foo));
ASSERT_TRUE(!(~enum_type::foo & enum_type::foo));
ASSERT_TRUE(!!(~enum_type::foo & enum_type::bar));
ASSERT_TRUE(enum_type::foo == enum_type::foo);
ASSERT_TRUE(enum_type::foo != enum_type::bar);
enum_type value = enum_type::foo;
ASSERT_TRUE(!!(value & enum_type::foo));
ASSERT_TRUE(!(value & enum_type::bar));
ASSERT_TRUE(!(value & enum_type::quux));
value |= (enum_type::bar | enum_type::quux);
ASSERT_TRUE(!!(value & enum_type::foo));
ASSERT_TRUE(!!(value & enum_type::bar));
ASSERT_TRUE(!!(value & enum_type::quux));
value &= (enum_type::bar | enum_type::quux);
ASSERT_TRUE(!(value & enum_type::foo));
ASSERT_TRUE(!!(value & enum_type::bar));
ASSERT_TRUE(!!(value & enum_type::quux));
value ^= enum_type::bar;
ASSERT_TRUE(!(value & enum_type::foo));
ASSERT_TRUE(!(value & enum_type::bar));
ASSERT_TRUE(!!(value & enum_type::quux));
}