🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

  1. #define CR_HOST
  2. #include <gtest/gtest.h>
  3. #include <cr.h>
  4. #include <entt/core/hashed_string.hpp>
  5. #include <entt/meta/factory.hpp>
  6. #include <entt/meta/meta.hpp>
  7. #include <entt/meta/resolve.hpp>
  8. #include "types.h"
  9. TEST(Lib, Meta) {
  10. using namespace entt::literals;
  11. ASSERT_FALSE(entt::resolve("position"_hs));
  12. userdata ud{};
  13. cr_plugin ctx;
  14. cr_plugin_load(ctx, PLUGIN);
  15. ctx.userdata = &ud;
  16. cr_plugin_update(ctx);
  17. entt::meta<double>().conv<int>();
  18. ASSERT_TRUE(entt::resolve("position"_hs));
  19. ASSERT_TRUE(entt::resolve("velocity"_hs));
  20. auto pos = entt::resolve("position"_hs).construct(42., 3.);
  21. auto vel = entt::resolve("velocity"_hs).construct();
  22. ASSERT_TRUE(pos && vel);
  23. ASSERT_EQ(pos.type().data("x"_hs).type(), entt::resolve<int>());
  24. ASSERT_NE(pos.type().data("y"_hs).get(pos).try_cast<int>(), nullptr);
  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).allow_cast<double>());
  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. }