diff --git a/TODO b/TODO index dd70f141b..6fb4cda78 100644 --- a/TODO +++ b/TODO @@ -42,3 +42,4 @@ TODO: * fix cmake warning about FetchContent_Populate * deprecate meta properties in favor of custom data * make meta objects safe to use with null nodes +* natvis for meta_custom diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bd6ca9c83..88ef0a89f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -272,6 +272,7 @@ SETUP_BASIC_TEST(meta_container entt/meta/meta_container.cpp) SETUP_BASIC_TEST(meta_context entt/meta/meta_context.cpp) SETUP_BASIC_TEST(meta_conv entt/meta/meta_conv.cpp) SETUP_BASIC_TEST(meta_ctor entt/meta/meta_ctor.cpp) +SETUP_BASIC_TEST(meta_custom entt/meta/meta_custom.cpp) SETUP_BASIC_TEST(meta_data entt/meta/meta_data.cpp) SETUP_BASIC_TEST(meta_dtor entt/meta/meta_dtor.cpp) SETUP_BASIC_TEST(meta_func entt/meta/meta_func.cpp) diff --git a/test/entt/meta/meta_custom.cpp b/test/entt/meta/meta_custom.cpp new file mode 100644 index 000000000..9f46be583 --- /dev/null +++ b/test/entt/meta/meta_custom.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../common/config.h" + +struct clazz { + int i{0}; + char j{1}; + + void f(int) {} + void g(char) {} +}; + +struct MetaCustom: ::testing::Test { + void SetUp() override { + using namespace entt::literals; + + entt::meta() + .type("clazz"_hs) + .custom('c') + .data<&clazz::i>("i"_hs) + .custom(2) + .data<&clazz::j>("j"_hs) + .func<&clazz::f>("f"_hs) + .custom(3) + .func<&clazz::g>("g"_hs); + } + + void TearDown() override { + entt::meta_reset(); + } +}; + +using MetaCustomDeathTest = MetaCustom; + +TEST_F(MetaCustom, Functionalities) { + entt::meta_custom custom{}; + + ASSERT_EQ(static_cast(custom), nullptr); + + custom = entt::resolve().custom(); + + ASSERT_NE(static_cast(custom), nullptr); + + ASSERT_EQ(*static_cast(custom), 'c'); + ASSERT_EQ(static_cast(custom), 'c'); +} + +ENTT_DEBUG_TEST_F(MetaCustomDeathTest, Functionalities) { + entt::meta_custom custom{}; + + ASSERT_DEATH([[maybe_unused]] const char &value = custom, ""); + + custom = entt::resolve().custom(); + + ASSERT_DEATH([[maybe_unused]] const int &value = custom, ""); +} + +TEST_F(MetaCustom, Type) { + ASSERT_NE(static_cast(entt::resolve().custom()), nullptr); + ASSERT_EQ(*static_cast(entt::resolve().custom()), 'c'); + ASSERT_EQ(static_cast(entt::resolve().custom()), 'c'); + + ASSERT_EQ(static_cast(entt::resolve().custom()), nullptr); + ASSERT_EQ(static_cast(entt::resolve().custom()), nullptr); +} + +TEST_F(MetaCustom, Data) { + using namespace entt::literals; + + ASSERT_NE(static_cast(entt::resolve().data("i"_hs).custom()), nullptr); + ASSERT_EQ(*static_cast(entt::resolve().data("i"_hs).custom()), 2); + ASSERT_EQ(static_cast(entt::resolve().data("i"_hs).custom()), 2); + + ASSERT_EQ(static_cast(entt::resolve().data("i"_hs).custom()), nullptr); + ASSERT_EQ(static_cast(entt::resolve().data("j"_hs).custom()), nullptr); +} + +TEST_F(MetaCustom, Func) { + using namespace entt::literals; + + ASSERT_NE(static_cast(entt::resolve().func("f"_hs).custom()), nullptr); + ASSERT_EQ(*static_cast(entt::resolve().func("f"_hs).custom()), 3); + ASSERT_EQ(static_cast(entt::resolve().func("f"_hs).custom()), 3); + + ASSERT_EQ(static_cast(entt::resolve().func("f"_hs).custom()), nullptr); + ASSERT_EQ(static_cast(entt::resolve().func("g"_hs).custom()), nullptr); +} + +TEST_F(MetaCustom, ReRegistration) { + using namespace entt::literals; + + SetUp(); + + auto type = entt::resolve(); + + ASSERT_EQ(static_cast(type.custom()), nullptr); + ASSERT_NE(static_cast(type.custom()), nullptr); + ASSERT_EQ(*static_cast(type.custom()), 'c'); + + entt::meta().custom(1); + type = entt::resolve(); + + ASSERT_NE(static_cast(type.custom()), nullptr); + ASSERT_EQ(static_cast(type.custom()), nullptr); + ASSERT_EQ(*static_cast(type.custom()), 1); +}