main.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #define ENTT_API_IMPORT
  2. #include <gtest/gtest.h>
  3. #include <entt/lib/attribute.h>
  4. #include <entt/meta/factory.hpp>
  5. #include <entt/meta/meta.hpp>
  6. #include "types.h"
  7. ENTT_IMPORT void meta_set_up();
  8. ENTT_IMPORT void meta_tear_down();
  9. ENTT_IMPORT entt::meta_any wrap_int(int);
  10. TEST(Lib, Meta) {
  11. ASSERT_FALSE(entt::resolve("position"_hs));
  12. meta_set_up();
  13. entt::meta<double>().conv<int>();
  14. ASSERT_TRUE(entt::resolve("position"_hs));
  15. auto pos = entt::resolve("position"_hs).construct(42., 3.);
  16. auto vel = entt::resolve<velocity>().ctor().invoke();
  17. ASSERT_TRUE(pos && vel);
  18. ASSERT_EQ(pos.type().data("x"_hs).type(), entt::resolve<int>());
  19. ASSERT_TRUE(pos.type().data("y"_hs).get(*pos).try_cast<int>());
  20. ASSERT_EQ(pos.type().data("x"_hs).get(*pos).cast<int>(), 42);
  21. ASSERT_EQ(pos.type().data("y"_hs).get(*pos).cast<int>(), 3);
  22. ASSERT_EQ(vel.type().data("dx"_hs).type(), entt::resolve<double>());
  23. ASSERT_TRUE(vel.type().data("dy"_hs).get(*vel).convert<int>());
  24. ASSERT_EQ(vel.type().data("dx"_hs).get(*vel).cast<double>(), 0.);
  25. ASSERT_EQ(vel.type().data("dy"_hs).get(*vel).cast<double>(), 0.);
  26. ASSERT_EQ(wrap_int(1).type(), entt::resolve<int>());
  27. meta_tear_down();
  28. }