🛠️🐜 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.

50 lines
1.6 KiB

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