main.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/value_type.h"
  10. #include "lib.h"
  11. TEST(Meta, Shared) {
  12. using namespace entt::literals;
  13. ASSERT_FALSE(entt::resolve("boxed_int"_hs));
  14. ASSERT_FALSE(entt::resolve("empty"_hs));
  15. share(entt::locator<entt::meta_ctx>::handle());
  16. set_up();
  17. ASSERT_TRUE(entt::resolve("boxed_int"_hs));
  18. ASSERT_TRUE(entt::resolve("empty"_hs));
  19. ASSERT_EQ(entt::resolve<test::boxed_int>(), entt::resolve("boxed_int"_hs));
  20. ASSERT_EQ(entt::resolve<test::empty>(), entt::resolve("empty"_hs));
  21. auto boxed_int = entt::resolve("boxed_int"_hs).construct(4.);
  22. auto empty = entt::resolve("empty"_hs).construct();
  23. ASSERT_TRUE(boxed_int);
  24. ASSERT_TRUE(empty);
  25. ASSERT_EQ(boxed_int.type().data("value"_hs).type(), entt::resolve<int>());
  26. ASSERT_NE(boxed_int.get("value"_hs).try_cast<int>(), nullptr);
  27. ASSERT_EQ(boxed_int.get("value"_hs).cast<int>(), 4);
  28. boxed_int.reset();
  29. empty.reset();
  30. ASSERT_EQ(wrap_int(4).type(), entt::resolve<int>());
  31. ASSERT_EQ(wrap_int(4).cast<int>(), 4);
  32. tear_down();
  33. ASSERT_FALSE(entt::resolve("boxed_int"_hs));
  34. ASSERT_FALSE(entt::resolve("empty"_hs));
  35. }