component.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <gtest/gtest.h>
  2. #include <entt/config/config.h>
  3. #include <entt/entity/component.hpp>
  4. #include "../common/boxed_int.h"
  5. #include "../common/non_movable.h"
  6. struct empty {};
  7. struct self_contained {
  8. static constexpr auto in_place_delete = true;
  9. static constexpr auto page_size = 4u;
  10. };
  11. struct traits_based {};
  12. template<>
  13. struct entt::component_traits<traits_based> {
  14. using type = traits_based;
  15. static constexpr auto in_place_delete = false;
  16. static constexpr auto page_size = 8u;
  17. };
  18. TEST(Component, VoidType) {
  19. using traits_type = entt::component_traits<void>;
  20. ASSERT_FALSE(traits_type::in_place_delete);
  21. ASSERT_EQ(traits_type::page_size, 0u);
  22. }
  23. TEST(Component, Empty) {
  24. using traits_type = entt::component_traits<empty>;
  25. ASSERT_FALSE(traits_type::in_place_delete);
  26. ASSERT_EQ(traits_type::page_size, 0u);
  27. }
  28. TEST(Component, NonEmpty) {
  29. using traits_type = entt::component_traits<test::boxed_int>;
  30. ASSERT_FALSE(traits_type::in_place_delete);
  31. ASSERT_EQ(traits_type::page_size, ENTT_PACKED_PAGE);
  32. }
  33. TEST(Component, NonMovable) {
  34. using traits_type = entt::component_traits<test::non_movable>;
  35. ASSERT_TRUE(traits_type::in_place_delete);
  36. ASSERT_EQ(traits_type::page_size, ENTT_PACKED_PAGE);
  37. }
  38. TEST(Component, SelfContained) {
  39. using traits_type = entt::component_traits<self_contained>;
  40. ASSERT_TRUE(traits_type::in_place_delete);
  41. ASSERT_EQ(traits_type::page_size, 4u);
  42. }
  43. TEST(Component, TraitsBased) {
  44. using traits_type = entt::component_traits<traits_based>;
  45. ASSERT_TRUE(!traits_type::in_place_delete);
  46. ASSERT_EQ(traits_type::page_size, 8u);
  47. }