enum.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <gtest/gtest.h>
  2. #include <entt/core/enum.hpp>
  3. #include "../../common/bitmask.h"
  4. template<typename Type>
  5. struct Enum: testing::Test {
  6. using type = Type;
  7. };
  8. using EnumTypes = ::testing::Types<test::enum_is_bitmask, test::enum_as_bitmask>;
  9. TYPED_TEST_SUITE(Enum, EnumTypes, );
  10. TYPED_TEST(Enum, Functionalities) {
  11. using enum_type = typename TestFixture::type;
  12. ASSERT_TRUE(!!((enum_type::foo | enum_type::bar) & enum_type::foo));
  13. ASSERT_TRUE(!!((enum_type::foo | enum_type::bar) & enum_type::bar));
  14. ASSERT_TRUE(!((enum_type::foo | enum_type::bar) & enum_type::quux));
  15. ASSERT_TRUE(!!((enum_type::foo ^ enum_type::bar) & enum_type::foo));
  16. ASSERT_TRUE(!((enum_type::foo ^ enum_type::foo) & enum_type::foo));
  17. ASSERT_TRUE(!(~enum_type::foo & enum_type::foo));
  18. ASSERT_TRUE(!!(~enum_type::foo & enum_type::bar));
  19. ASSERT_TRUE(enum_type::foo == enum_type::foo);
  20. ASSERT_TRUE(enum_type::foo != enum_type::bar);
  21. enum_type value = enum_type::foo;
  22. ASSERT_TRUE(!!(value & enum_type::foo));
  23. ASSERT_TRUE(!(value & enum_type::bar));
  24. ASSERT_TRUE(!(value & enum_type::quux));
  25. value |= (enum_type::bar | enum_type::quux);
  26. ASSERT_TRUE(!!(value & enum_type::foo));
  27. ASSERT_TRUE(!!(value & enum_type::bar));
  28. ASSERT_TRUE(!!(value & enum_type::quux));
  29. value &= (enum_type::bar | enum_type::quux);
  30. ASSERT_TRUE(!(value & enum_type::foo));
  31. ASSERT_TRUE(!!(value & enum_type::bar));
  32. ASSERT_TRUE(!!(value & enum_type::quux));
  33. value ^= enum_type::bar;
  34. ASSERT_TRUE(!(value & enum_type::foo));
  35. ASSERT_TRUE(!(value & enum_type::bar));
  36. ASSERT_TRUE(!!(value & enum_type::quux));
  37. }