main.cpp 1.7 KB

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