Browse Source

meta: fixed meta_factory default constructor

Michele Caini 1 year ago
parent
commit
7052f2ec72
3 changed files with 21 additions and 4 deletions
  1. 1 1
      TODO
  2. 1 1
      src/entt/meta/factory.hpp
  3. 19 2
      test/entt/meta/meta_factory.cpp

+ 1 - 1
TODO

@@ -42,5 +42,5 @@ TODO:
 * dtor, traits and custom should be part of meta descriptor maybe (?)
 * allow attaching const values of non-Type type to meta types
 * built-in no-pagination storage - no_pagination page size as limits::max
-* meta_factory() isn't tested (and is broken too)
 * meta_any ownership construction and from_void
+* meta_factory() isn't fully tested yet

+ 1 - 1
src/entt/meta/factory.hpp

@@ -172,7 +172,7 @@ class meta_factory: private internal::basic_meta_factory {
 public:
     /*! @brief Default constructor. */
     meta_factory() noexcept
-        : internal::basic_meta_factory{type_id<Type>(), locator<meta_ctx>::value_or()} {}
+        : internal::basic_meta_factory{type_id<Type>().hash(), locator<meta_ctx>::value_or()} {}
 
     /**
      * @brief Context aware constructor.

+ 19 - 2
test/entt/meta/meta_factory.cpp

@@ -1,6 +1,23 @@
 #include <gtest/gtest.h>
+#include <entt/core/type_info.hpp>
+#include <entt/locator/locator.hpp>
+#include <entt/meta/context.hpp>
 #include <entt/meta/factory.hpp>
+#include <entt/meta/resolve.hpp>
 
-TEST(MetaFactory, TODO) {
-    // Nothing to see here yet :)
+TEST(MetaFactory, Constructors) {
+    entt::meta_ctx ctx{};
+
+    ASSERT_EQ(entt::resolve(entt::type_id<int>()), entt::meta_type{});
+    ASSERT_EQ(entt::resolve(ctx, entt::type_id<int>()), entt::meta_type{});
+
+    entt::meta_factory<int> factory{};
+
+    ASSERT_NE(entt::resolve(entt::type_id<int>()), entt::meta_type{});
+    ASSERT_EQ(entt::resolve(ctx, entt::type_id<int>()), entt::meta_type{});
+
+    factory = entt::meta_factory<int>{ctx};
+
+    ASSERT_NE(entt::resolve(entt::type_id<int>()), entt::meta_type{});
+    ASSERT_NE(entt::resolve(ctx, entt::type_id<int>()), entt::meta_type{});
 }