Michele Caini 5 роки тому
батько
коміт
b0b504d002
3 змінених файлів з 71 додано та 45 видалено
  1. 1 0
      test/CMakeLists.txt
  2. 0 45
      test/entt/meta/meta.cpp
  3. 70 0
      test/entt/meta/meta_conv.cpp

+ 1 - 0
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)

+ 0 - 45
test/entt/meta/meta.cpp

@@ -9,51 +9,6 @@
 #include <entt/meta/resolve.hpp>
 #include "fixture.h"
 
-TEST_F(Meta, MetaConv) {
-    auto conv = entt::resolve<double>().conv<int>();
-    double value = 3.;
-
-    ASSERT_TRUE(conv);
-    ASSERT_EQ(conv.parent(), entt::resolve<double>());
-    ASSERT_EQ(conv.type(), entt::resolve<int>());
-
-    auto any = conv.convert(&value);
-
-    ASSERT_TRUE(any);
-    ASSERT_EQ(any.type(), entt::resolve<int>());
-    ASSERT_EQ(any.cast<int>(), 3);
-}
-
-TEST_F(Meta, MetaConvAsFreeFunctions) {
-    auto conv = entt::resolve<derived_type>().conv<int>();
-    derived_type derived{derived_type{}, 42, 'c'};
-
-    ASSERT_TRUE(conv);
-    ASSERT_EQ(conv.parent(), entt::resolve<derived_type>());
-    ASSERT_EQ(conv.type(), entt::resolve<int>());
-
-    auto any = conv.convert(&derived);
-
-    ASSERT_TRUE(any);
-    ASSERT_EQ(any.type(), entt::resolve<int>());
-    ASSERT_EQ(any.cast<int>(), 42);
-}
-
-TEST_F(Meta, MetaConvAsMemberFunctions) {
-    auto conv = entt::resolve<derived_type>().conv<char>();
-    derived_type derived{derived_type{}, 42, 'c'};
-
-    ASSERT_TRUE(conv);
-    ASSERT_EQ(conv.parent(), entt::resolve<derived_type>());
-    ASSERT_EQ(conv.type(), entt::resolve<char>());
-
-    auto any = conv.convert(&derived);
-
-    ASSERT_TRUE(any);
-    ASSERT_EQ(any.type(), entt::resolve<char>());
-    ASSERT_EQ(any.cast<char>(), 'c');
-}
-
 TEST_F(Meta, MetaCtor) {
     auto ctor = entt::resolve<derived_type>().ctor<const base_type &, int, char>();
 

+ 70 - 0
test/entt/meta/meta_conv.cpp

@@ -0,0 +1,70 @@
+#include <gtest/gtest.h>
+#include <entt/core/hashed_string.hpp>
+#include <entt/meta/factory.hpp>
+#include <entt/meta/meta.hpp>
+#include <entt/meta/resolve.hpp>
+
+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<double>().conv<int>();
+        entt::meta<clazz_t>().conv<&clazz_t::f>().conv<&clazz_t::g>();
+    }
+};
+
+TEST_F(Meta, MetaConv) {
+    auto conv = entt::resolve<double>().conv<int>();
+    double value = 3.;
+
+    ASSERT_TRUE(conv);
+    ASSERT_EQ(conv.parent(), entt::resolve<double>());
+    ASSERT_EQ(conv.type(), entt::resolve<int>());
+
+    auto any = conv.convert(&value);
+
+    ASSERT_TRUE(any);
+    ASSERT_EQ(any.type(), entt::resolve<int>());
+    ASSERT_EQ(any.cast<int>(), 3);
+}
+
+TEST_F(Meta, MetaConvAsFreeFunctions) {
+    auto conv = entt::resolve<clazz_t>().conv<int>();
+    clazz_t clazz{42, 'c'};
+
+    ASSERT_TRUE(conv);
+    ASSERT_EQ(conv.parent(), entt::resolve<clazz_t>());
+    ASSERT_EQ(conv.type(), entt::resolve<int>());
+
+    auto any = conv.convert(&clazz);
+
+    ASSERT_TRUE(any);
+    ASSERT_EQ(any.type(), entt::resolve<int>());
+    ASSERT_EQ(any.cast<int>(), 42);
+}
+
+TEST_F(Meta, MetaConvAsMemberFunctions) {
+    auto conv = entt::resolve<clazz_t>().conv<char>();
+    clazz_t clazz{42, 'c'};
+
+    ASSERT_TRUE(conv);
+    ASSERT_EQ(conv.parent(), entt::resolve<clazz_t>());
+    ASSERT_EQ(conv.type(), entt::resolve<char>());
+
+    auto any = conv.convert(&clazz);
+
+    ASSERT_TRUE(any);
+    ASSERT_EQ(any.type(), entt::resolve<char>());
+    ASSERT_EQ(any.cast<char>(), 'c');
+}