main.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <gtest/gtest.h>
  2. #include <entt/core/attribute.h>
  3. #include <entt/core/hashed_string.hpp>
  4. #include <entt/locator/locator.hpp>
  5. #include <entt/meta/context.hpp>
  6. #include <entt/meta/factory.hpp>
  7. #include <entt/meta/meta.hpp>
  8. #include <entt/meta/resolve.hpp>
  9. #include "../common/types.h"
  10. ENTT_API void share(const entt::locator<entt::meta_ctx>::node_type &);
  11. ENTT_API void set_up();
  12. ENTT_API void tear_down();
  13. ENTT_API entt::meta_any wrap_int(int);
  14. TEST(Lib, Meta) {
  15. using namespace entt::literals;
  16. ASSERT_FALSE(entt::resolve("position"_hs));
  17. ASSERT_FALSE(entt::resolve("velocity"_hs));
  18. share(entt::locator<entt::meta_ctx>::handle());
  19. set_up();
  20. entt::meta<double>().conv<int>();
  21. ASSERT_TRUE(entt::resolve("position"_hs));
  22. ASSERT_TRUE(entt::resolve("velocity"_hs));
  23. ASSERT_EQ(entt::resolve<position>(), entt::resolve("position"_hs));
  24. ASSERT_EQ(entt::resolve<velocity>(), entt::resolve("velocity"_hs));
  25. auto pos = entt::resolve("position"_hs).construct(42., 3.);
  26. auto vel = entt::resolve("velocity"_hs).construct();
  27. ASSERT_TRUE(pos && vel);
  28. ASSERT_EQ(pos.type().data("x"_hs).type(), entt::resolve<int>());
  29. ASSERT_NE(pos.type().data("y"_hs).get(pos).try_cast<int>(), nullptr);
  30. ASSERT_EQ(pos.type().data("x"_hs).get(pos).cast<int>(), 42);
  31. ASSERT_EQ(pos.type().data("y"_hs).get(pos).cast<int>(), 3);
  32. ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
  33. ASSERT_TRUE(vel.type().data("dy"_hs).get(vel).allow_cast<double>());
  34. ASSERT_EQ(vel.type().data("dx"_hs).get(vel).cast<double>(), 0.);
  35. ASSERT_EQ(vel.type().data("dy"_hs).get(vel).cast<double>(), 0.);
  36. pos.reset();
  37. vel.reset();
  38. ASSERT_EQ(wrap_int(42).type(), entt::resolve<int>());
  39. ASSERT_EQ(wrap_int(42).cast<int>(), 42);
  40. tear_down();
  41. ASSERT_FALSE(entt::resolve("position"_hs));
  42. ASSERT_FALSE(entt::resolve("velocity"_hs));
  43. }