main.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <gtest/gtest.h>
  2. #include <entt/config/config.h>
  3. #include <entt/core/hashed_string.hpp>
  4. #include <entt/locator/locator.hpp>
  5. #include <entt/meta/context.hpp>
  6. #include <entt/meta/meta.hpp>
  7. #include <entt/meta/resolve.hpp>
  8. #include "../../../common/boxed_type.h"
  9. #include "../../../common/empty.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("boxed_int"_hs));
  17. ASSERT_FALSE(entt::resolve("empty"_hs));
  18. share(entt::locator<entt::meta_ctx>::handle());
  19. set_up();
  20. ASSERT_TRUE(entt::resolve("boxed_int"_hs));
  21. ASSERT_TRUE(entt::resolve("empty"_hs));
  22. ASSERT_EQ(entt::resolve<test::boxed_int>(), entt::resolve("boxed_int"_hs));
  23. ASSERT_EQ(entt::resolve<test::empty>(), entt::resolve("empty"_hs));
  24. auto boxed_int = entt::resolve("boxed_int"_hs).construct(4.);
  25. auto empty = entt::resolve("empty"_hs).construct();
  26. ASSERT_TRUE(boxed_int);
  27. ASSERT_TRUE(empty);
  28. ASSERT_EQ(boxed_int.type().data("value"_hs).type(), entt::resolve<int>());
  29. ASSERT_NE(boxed_int.get("value"_hs).try_cast<int>(), nullptr);
  30. ASSERT_EQ(boxed_int.get("value"_hs).cast<int>(), 4);
  31. boxed_int.reset();
  32. empty.reset();
  33. ASSERT_EQ(wrap_int(4).type(), entt::resolve<int>());
  34. ASSERT_EQ(wrap_int(4).cast<int>(), 4);
  35. tear_down();
  36. ASSERT_FALSE(entt::resolve("boxed_int"_hs));
  37. ASSERT_FALSE(entt::resolve("empty"_hs));
  38. }