From b0b504d002152376dc3daa8db9df9863c4faa16c Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 10 Jun 2020 15:59:12 +0200 Subject: [PATCH] test: added meta_conv --- test/CMakeLists.txt | 1 + test/entt/meta/meta.cpp | 45 ----------------------- test/entt/meta/meta_conv.cpp | 70 ++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 45 deletions(-) create mode 100644 test/entt/meta/meta_conv.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 07bb1446b..85cddfa0e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -180,6 +180,7 @@ SETUP_BASIC_TEST(locator entt/locator/locator.cpp) SETUP_BASIC_TEST(meta_any entt/meta/meta_any.cpp) SETUP_BASIC_TEST(meta_base entt/meta/meta_base.cpp) SETUP_BASIC_TEST(meta_basic entt/meta/meta_basic.cpp) +SETUP_BASIC_TEST(meta_conv entt/meta/meta_conv.cpp) SETUP_BASIC_TEST(meta_prop entt/meta/meta_prop.cpp) list(APPEND TEST_META_SOURCES entt/meta/meta.cpp entt/meta/fixture.cpp) diff --git a/test/entt/meta/meta.cpp b/test/entt/meta/meta.cpp index 16a9b9598..ba0488aaf 100644 --- a/test/entt/meta/meta.cpp +++ b/test/entt/meta/meta.cpp @@ -9,51 +9,6 @@ #include #include "fixture.h" -TEST_F(Meta, MetaConv) { - auto conv = entt::resolve().conv(); - double value = 3.; - - ASSERT_TRUE(conv); - ASSERT_EQ(conv.parent(), entt::resolve()); - ASSERT_EQ(conv.type(), entt::resolve()); - - auto any = conv.convert(&value); - - ASSERT_TRUE(any); - ASSERT_EQ(any.type(), entt::resolve()); - ASSERT_EQ(any.cast(), 3); -} - -TEST_F(Meta, MetaConvAsFreeFunctions) { - auto conv = entt::resolve().conv(); - derived_type derived{derived_type{}, 42, 'c'}; - - ASSERT_TRUE(conv); - ASSERT_EQ(conv.parent(), entt::resolve()); - ASSERT_EQ(conv.type(), entt::resolve()); - - auto any = conv.convert(&derived); - - ASSERT_TRUE(any); - ASSERT_EQ(any.type(), entt::resolve()); - ASSERT_EQ(any.cast(), 42); -} - -TEST_F(Meta, MetaConvAsMemberFunctions) { - auto conv = entt::resolve().conv(); - derived_type derived{derived_type{}, 42, 'c'}; - - ASSERT_TRUE(conv); - ASSERT_EQ(conv.parent(), entt::resolve()); - ASSERT_EQ(conv.type(), entt::resolve()); - - auto any = conv.convert(&derived); - - ASSERT_TRUE(any); - ASSERT_EQ(any.type(), entt::resolve()); - ASSERT_EQ(any.cast(), 'c'); -} - TEST_F(Meta, MetaCtor) { auto ctor = entt::resolve().ctor(); diff --git a/test/entt/meta/meta_conv.cpp b/test/entt/meta/meta_conv.cpp new file mode 100644 index 000000000..de736f6cc --- /dev/null +++ b/test/entt/meta/meta_conv.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include + +struct clazz_t { + int f() const { + return i; + } + + static char g(const clazz_t &type) { + return type.c; + } + + int i{}; + char c{}; +}; + +struct Meta: ::testing::Test { + static void SetUpTestCase() { + entt::meta().conv(); + entt::meta().conv<&clazz_t::f>().conv<&clazz_t::g>(); + } +}; + +TEST_F(Meta, MetaConv) { + auto conv = entt::resolve().conv(); + double value = 3.; + + ASSERT_TRUE(conv); + ASSERT_EQ(conv.parent(), entt::resolve()); + ASSERT_EQ(conv.type(), entt::resolve()); + + auto any = conv.convert(&value); + + ASSERT_TRUE(any); + ASSERT_EQ(any.type(), entt::resolve()); + ASSERT_EQ(any.cast(), 3); +} + +TEST_F(Meta, MetaConvAsFreeFunctions) { + auto conv = entt::resolve().conv(); + clazz_t clazz{42, 'c'}; + + ASSERT_TRUE(conv); + ASSERT_EQ(conv.parent(), entt::resolve()); + ASSERT_EQ(conv.type(), entt::resolve()); + + auto any = conv.convert(&clazz); + + ASSERT_TRUE(any); + ASSERT_EQ(any.type(), entt::resolve()); + ASSERT_EQ(any.cast(), 42); +} + +TEST_F(Meta, MetaConvAsMemberFunctions) { + auto conv = entt::resolve().conv(); + clazz_t clazz{42, 'c'}; + + ASSERT_TRUE(conv); + ASSERT_EQ(conv.parent(), entt::resolve()); + ASSERT_EQ(conv.type(), entt::resolve()); + + auto any = conv.convert(&clazz); + + ASSERT_TRUE(any); + ASSERT_EQ(any.type(), entt::resolve()); + ASSERT_EQ(any.cast(), 'c'); +}