main.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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(entt::meta_ctx);
  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(entt::meta_ctx{});
  12. entt::meta<double>().conv<int>();
  13. ASSERT_TRUE(entt::resolve("position"_hs));
  14. ASSERT_TRUE(entt::resolve("velocity"_hs));
  15. auto pos = entt::resolve("position"_hs).construct(42., 3.);
  16. auto vel = entt::resolve("velocity"_hs).ctor().invoke();
  17. ASSERT_TRUE(pos && vel);
  18. ASSERT_EQ(pos.type().data("x"_hs).type(), entt::resolve<int>());
  19. ASSERT_TRUE(pos.type().data("y"_hs).get(*pos).try_cast<int>());
  20. ASSERT_EQ(pos.type().data("x"_hs).get(*pos).cast<int>(), 42);
  21. ASSERT_EQ(pos.type().data("y"_hs).get(*pos).cast<int>(), 3);
  22. ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
  23. ASSERT_TRUE(vel.type().data("dy"_hs).get(*vel).convert<double>());
  24. ASSERT_EQ(vel.type().data("dx"_hs).get(*vel).cast<double>(), 0.);
  25. ASSERT_EQ(vel.type().data("dy"_hs).get(*vel).cast<double>(), 0.);
  26. ASSERT_EQ(wrap_int(42).type(), entt::resolve<int>());
  27. ASSERT_EQ(wrap_int(42).cast<int>(), 42);
  28. tear_down();
  29. ASSERT_FALSE(entt::resolve("position"_hs));
  30. ASSERT_FALSE(entt::resolve("velocity"_hs));
  31. }