main.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #define CR_HOST
  2. #include <cr.h>
  3. #include <gtest/gtest.h>
  4. #include <entt/meta/factory.hpp>
  5. #include <entt/meta/meta.hpp>
  6. #include <entt/meta/resolve.hpp>
  7. #include "types.h"
  8. TEST(Lib, Meta) {
  9. using namespace entt::literals;
  10. ASSERT_FALSE(entt::resolve("position"_hs));
  11. userdata ud{};
  12. cr_plugin ctx;
  13. cr_plugin_load(ctx, PLUGIN);
  14. ctx.userdata = &ud;
  15. cr_plugin_update(ctx);
  16. entt::meta<double>().conv<int>();
  17. ASSERT_TRUE(entt::resolve("position"_hs));
  18. ASSERT_TRUE(entt::resolve("velocity"_hs));
  19. auto pos = entt::resolve("position"_hs).construct(42., 3.);
  20. auto vel = entt::resolve("velocity"_hs).ctor<>().invoke();
  21. ASSERT_TRUE(pos && vel);
  22. ASSERT_EQ(pos.type().data("x"_hs).type(), entt::resolve<int>());
  23. ASSERT_NE(pos.type().data("y"_hs).get(pos).try_cast<int>(), nullptr);
  24. ASSERT_EQ(pos.type().data("x"_hs).get(pos).cast<int>(), 42);
  25. ASSERT_EQ(pos.type().data("y"_hs).get(pos).cast<int>(), 3);
  26. ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
  27. ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).allow_cast<double>());
  28. ASSERT_EQ(vel.type().data("dx"_hs).get(vel).cast<double>(), 0.);
  29. ASSERT_EQ(vel.type().data("dy"_hs).get(vel).cast<double>(), 0.);
  30. ASSERT_EQ(ud.any.type(), entt::resolve<int>());
  31. ASSERT_EQ(ud.any.cast<int>(), 42);
  32. // these objects have been initialized from a different context
  33. pos.emplace<void>();
  34. vel.emplace<void>();
  35. ud.any.emplace<void>();
  36. cr_plugin_close(ctx);
  37. ASSERT_FALSE(entt::resolve("position"_hs));
  38. ASSERT_FALSE(entt::resolve("velocity"_hs));
  39. }