main.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <gtest/gtest.h>
  2. #include <entt/core/attribute.h>
  3. #include <entt/meta/factory.hpp>
  4. #include <entt/meta/meta.hpp>
  5. #include "types.h"
  6. ENTT_API void set_up();
  7. ENTT_API void tear_down();
  8. ENTT_API entt::meta_any wrap_int(int);
  9. TEST(Lib, Meta) {
  10. ASSERT_FALSE(entt::resolve("position"_hs));
  11. set_up();
  12. entt::meta<double>().conv<int>();
  13. ASSERT_TRUE(entt::resolve("position"_hs));
  14. auto pos = entt::resolve("position"_hs).construct(42., 3.);
  15. auto vel = entt::resolve<velocity>().ctor().invoke();
  16. ASSERT_TRUE(pos && vel);
  17. ASSERT_EQ(pos.type().data("x"_hs).type(), entt::resolve<int>());
  18. ASSERT_TRUE(pos.type().data("y"_hs).get(*pos).try_cast<int>());
  19. ASSERT_EQ(pos.type().data("x"_hs).get(*pos).cast<int>(), 42);
  20. ASSERT_EQ(pos.type().data("y"_hs).get(*pos).cast<int>(), 3);
  21. ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
  22. ASSERT_TRUE(vel.type().data("dy"_hs).get(*vel).convert<int>());
  23. ASSERT_EQ(vel.type().data("dx"_hs).get(*vel).cast<double>(), 0.);
  24. ASSERT_EQ(vel.type().data("dy"_hs).get(*vel).cast<double>(), 0.);
  25. ASSERT_EQ(wrap_int(1).type(), entt::resolve<int>());
  26. tear_down();
  27. }