main.cpp 1.7 KB

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