main.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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(Meta, PluginStd) {
  11. using namespace entt::literals;
  12. ASSERT_FALSE(entt::resolve("boxed_int"_hs));
  13. userdata ud{};
  14. ud.ctx = entt::locator<entt::meta_ctx>::handle();
  15. cr_plugin ctx;
  16. ctx.userdata = &ud;
  17. cr_plugin_load(ctx, PLUGIN);
  18. cr_plugin_update(ctx);
  19. ASSERT_TRUE(entt::resolve("boxed_int"_hs));
  20. ASSERT_TRUE(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. ASSERT_EQ(ud.any.type(), entt::resolve<int>());
  29. ASSERT_EQ(ud.any.cast<int>(), 4);
  30. // these objects have been initialized from a different context
  31. boxed_int.emplace<void>();
  32. empty.emplace<void>();
  33. ud.any.emplace<void>();
  34. cr_plugin_close(ctx);
  35. ASSERT_FALSE(entt::resolve("boxed_int"_hs));
  36. ASSERT_FALSE(entt::resolve("empty"_hs));
  37. }