main.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #define CR_HOST
  2. #include <gtest/gtest.h>
  3. #include <cr.h>
  4. #include <entt/core/hashed_string.hpp>
  5. #include <entt/locator/locator.hpp>
  6. #include <entt/meta/context.hpp>
  7. #include <entt/meta/meta.hpp>
  8. #include <entt/meta/resolve.hpp>
  9. #include "userdata.h"
  10. TEST(Lib, Meta) {
  11. using namespace entt::literals;
  12. ASSERT_FALSE(entt::resolve("boxed_int"_hs));
  13. userdata ud{entt::locator<entt::meta_ctx>::handle(), entt::meta_any{}};
  14. cr_plugin ctx;
  15. ctx.userdata = &ud;
  16. cr_plugin_load(ctx, PLUGIN);
  17. cr_plugin_update(ctx);
  18. ASSERT_TRUE(entt::resolve("boxed_int"_hs));
  19. ASSERT_TRUE(entt::resolve("empty"_hs));
  20. auto boxed_int = entt::resolve("boxed_int"_hs).construct(4.);
  21. auto empty = entt::resolve("empty"_hs).construct();
  22. ASSERT_TRUE(boxed_int);
  23. ASSERT_TRUE(empty);
  24. ASSERT_EQ(boxed_int.type().data("value"_hs).type(), entt::resolve<int>());
  25. ASSERT_NE(boxed_int.get("value"_hs).try_cast<int>(), nullptr);
  26. ASSERT_EQ(boxed_int.get("value"_hs).cast<int>(), 4);
  27. ASSERT_EQ(ud.any.type(), entt::resolve<int>());
  28. ASSERT_EQ(ud.any.cast<int>(), 4);
  29. // these objects have been initialized from a different context
  30. boxed_int.emplace<void>();
  31. empty.emplace<void>();
  32. ud.any.emplace<void>();
  33. cr_plugin_close(ctx);
  34. ASSERT_FALSE(entt::resolve("boxed_int"_hs));
  35. ASSERT_FALSE(entt::resolve("empty"_hs));
  36. }