main.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <gtest/gtest.h>
  2. #include <entt/entity/entity.hpp>
  3. #include <entt/entity/registry.hpp>
  4. #include "types.h"
  5. extern typename entt::component int_type();
  6. extern typename entt::component char_type();
  7. extern void update_position(int, entt::registry &);
  8. extern void assign_velocity(int, entt::registry &);
  9. TEST(Lib, Types) {
  10. entt::registry registry;
  11. ASSERT_EQ(registry.type<int>(), registry.type<const int>());
  12. ASSERT_EQ(registry.type<char>(), registry.type<const char>());
  13. ASSERT_EQ(registry.type<int>(), int_type());
  14. ASSERT_EQ(registry.type<char>(), char_type());
  15. ASSERT_EQ(registry.type<const char>(), char_type());
  16. ASSERT_EQ(registry.type<const int>(), int_type());
  17. }
  18. TEST(Lib, Registry) {
  19. entt::registry registry;
  20. for(auto i = 0; i < 3; ++i) {
  21. const auto entity = registry.create();
  22. registry.assign<position>(entity, i, i+1);
  23. }
  24. assign_velocity(2, registry);
  25. ASSERT_EQ(registry.size<position>(), entt::registry::size_type{3});
  26. ASSERT_EQ(registry.size<velocity>(), entt::registry::size_type{3});
  27. update_position(1, registry);
  28. registry.view<position>().each([](auto entity, auto &position) {
  29. ASSERT_EQ(position.x, entt::to_integer(entity) + 2);
  30. ASSERT_EQ(position.y, entt::to_integer(entity) + 3);
  31. });
  32. }