main.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. ASSERT_FALSE(entt::resolve("position"_hs));
  10. userdata ud{};
  11. cr_plugin ctx;
  12. cr_plugin_load(ctx, PLUGIN);
  13. ctx.userdata = &ud;
  14. cr_plugin_update(ctx);
  15. entt::meta<double>().conv<int>();
  16. ASSERT_TRUE(entt::resolve("position"_hs));
  17. ASSERT_TRUE(entt::resolve("velocity"_hs));
  18. auto pos = entt::resolve("position"_hs).construct(42., 3.);
  19. auto vel = entt::resolve("velocity"_hs).ctor<>().invoke();
  20. ASSERT_TRUE(pos && vel);
  21. ASSERT_EQ(pos.type().data("x"_hs).type(), entt::resolve<int>());
  22. ASSERT_NE(pos.type().data("y"_hs).get(pos).try_cast<int>(), nullptr);
  23. ASSERT_EQ(pos.type().data("x"_hs).get(pos).cast<int>(), 42);
  24. ASSERT_EQ(pos.type().data("y"_hs).get(pos).cast<int>(), 3);
  25. ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
  26. ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).convert<double>());
  27. ASSERT_EQ(vel.type().data("dx"_hs).get(vel).cast<double>(), 0.);
  28. ASSERT_EQ(vel.type().data("dy"_hs).get(vel).cast<double>(), 0.);
  29. ASSERT_EQ(ud.any.type(), entt::resolve<int>());
  30. ASSERT_EQ(ud.any.cast<int>(), 42);
  31. // these objects have been initialized from a different context
  32. pos.emplace<void>();
  33. vel.emplace<void>();
  34. ud.any.emplace<void>();
  35. cr_plugin_close(ctx);
  36. ASSERT_FALSE(entt::resolve("position"_hs));
  37. ASSERT_FALSE(entt::resolve("velocity"_hs));
  38. }