1
0

main.cpp 1.7 KB

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