main.cpp 1.5 KB

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