meta_handle.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <gtest/gtest.h>
  2. #include <entt/core/hashed_string.hpp>
  3. #include <entt/meta/factory.hpp>
  4. #include <entt/meta/meta.hpp>
  5. #include <entt/meta/resolve.hpp>
  6. struct clazz_t {
  7. clazz_t(): value{} {}
  8. void incr() { ++value; }
  9. void decr() { --value; }
  10. int value;
  11. };
  12. struct MetaHandle: ::testing::Test {
  13. static void SetUpTestCase() {
  14. using namespace entt::literals;
  15. entt::meta<clazz_t>()
  16. .func<&clazz_t::incr>("incr"_hs)
  17. .func<&clazz_t::decr>("decr"_hs);
  18. }
  19. };
  20. TEST_F(MetaHandle, Functionalities) {
  21. using namespace entt::literals;
  22. clazz_t instance{};
  23. entt::meta_handle handle{};
  24. ASSERT_FALSE(handle);
  25. handle = entt::meta_handle{instance};
  26. ASSERT_TRUE(handle);
  27. ASSERT_TRUE(handle->invoke("incr"_hs));
  28. ASSERT_EQ(instance.value, 1);
  29. entt::meta_any any{std::ref(instance)};
  30. handle = entt::meta_handle{any};
  31. ASSERT_FALSE(std::as_const(handle)->invoke("decr"_hs));
  32. ASSERT_TRUE(handle->invoke("decr"_hs));
  33. ASSERT_EQ(instance.value, 0);
  34. }