Explorar o código

meta: some tests across boundaries

Michele Caini %!s(int64=6) %!d(string=hai) anos
pai
achega
085a281f8a
Modificáronse 4 ficheiros con 73 adicións e 31 borrados
  1. 6 31
      src/entt/meta/meta.hpp
  2. 13 0
      test/lib/a_module.cpp
  3. 13 0
      test/lib/another_module.cpp
  4. 41 0
      test/lib/lib.cpp

+ 6 - 31
src/entt/meta/meta.hpp

@@ -1742,39 +1742,14 @@ private:
 
 
 /*! @brief Opaque container for a meta context. */
-class meta_ctx {
-    auto ctx() const ENTT_NOEXCEPT {
-        return &internal::meta_info<>::local;
+struct meta_ctx {
+    /*! @brief Sets the context as the current one. */
+    void set() const ENTT_NOEXCEPT {
+        internal::meta_info<>::ctx = ctx;
     }
 
-public:
-    /*! @brief Default constructor. */
-    meta_ctx() ENTT_NOEXCEPT = default;
-
-    /*! @brief Default copy constructor, deleted on purpose. */
-    meta_ctx(const meta_ctx &) = delete;
-    /*! @brief Default move constructor, deleted on purpose. */
-    meta_ctx(meta_ctx &&) = delete;
-
-    /**
-     * @brief Copy assignment operator.
-     * @param other The instance to copy from.
-     * @return This meta object.
-     */
-    meta_ctx & operator=(const meta_ctx &other) {
-        internal::meta_info<>::ctx = other.ctx();
-        return *this;
-    }
-
-    /**
-     * @brief Move assignment operator.
-     * @param other The instance to move from.
-     * @return This meta object.
-     */
-    meta_ctx & operator=(meta_ctx &&other) {
-        internal::meta_info<>::ctx = other.ctx();
-        return *this;
-    }
+private:
+    internal::meta_type_node **ctx{&internal::meta_info<>::local};
 };
 
 

+ 13 - 0
test/lib/a_module.cpp

@@ -1,4 +1,5 @@
 #include <entt/entity/registry.hpp>
+#include <entt/meta/factory.hpp>
 #include <entt/signal/dispatcher.hpp>
 #include <entt/signal/emitter.hpp>
 #include "types.h"
@@ -45,3 +46,15 @@ LIB_EXPORT void trigger_another_event(entt::dispatcher &dispatcher) {
 LIB_EXPORT void emit_another_event(test_emitter &emitter) {
     emitter.publish<another_event>();
 }
+
+LIB_EXPORT void a_module_meta_ctx(entt::meta_ctx context) {
+    context.set();
+}
+
+LIB_EXPORT void a_module_meta_init() {
+    entt::reflect<char>("char"_hs).data<'c'>("c"_hs);
+}
+
+LIB_EXPORT void a_module_meta_deinit() {
+    entt::unregister<char>();
+}

+ 13 - 0
test/lib/another_module.cpp

@@ -1,4 +1,5 @@
 #include <entt/entity/registry.hpp>
+#include <entt/meta/factory.hpp>
 #include <entt/signal/dispatcher.hpp>
 #include <entt/signal/emitter.hpp>
 #include "types.h"
@@ -50,3 +51,15 @@ LIB_EXPORT void trigger_an_event(int payload, entt::dispatcher &dispatcher) {
 LIB_EXPORT void emit_an_event(int payload, test_emitter &emitter) {
     emitter.publish<an_event>(payload);
 }
+
+LIB_EXPORT void another_module_meta_ctx(entt::meta_ctx context) {
+    context.set();
+}
+
+LIB_EXPORT void another_module_meta_init() {
+    entt::reflect<int>("int"_hs).data<0>("0"_hs);
+}
+
+LIB_EXPORT void another_module_meta_deinit() {
+    entt::unregister<int>();
+}

+ 41 - 0
test/lib/lib.cpp

@@ -1,6 +1,7 @@
 #include <gtest/gtest.h>
 #include <entt/entity/entity.hpp>
 #include <entt/entity/registry.hpp>
+#include <entt/meta/factory.hpp>
 #include <entt/signal/dispatcher.hpp>
 #include <entt/signal/emitter.hpp>
 #include "types.h"
@@ -19,6 +20,15 @@ extern void trigger_another_event(entt::dispatcher &);
 extern void emit_an_event(int, test_emitter &);
 extern void emit_another_event(test_emitter &);
 
+extern void a_module_meta_ctx(entt::meta_ctx);
+extern void another_module_meta_ctx(entt::meta_ctx);
+
+extern void a_module_meta_init();
+extern void another_module_meta_init();
+
+extern void a_module_meta_deinit();
+extern void another_module_meta_deinit();
+
 struct listener {
     void on_an_event(an_event event) { value = event.payload; }
     void on_another_event(another_event) {}
@@ -97,3 +107,34 @@ TEST(Lib, Emitter) {
     emit_an_event(42, emitter);
     emit_another_event(emitter);
 }
+
+TEST(Lib, Meta) {
+    ASSERT_FALSE(entt::resolve("double"_hs));
+    ASSERT_FALSE(entt::resolve("char"_hs));
+    ASSERT_FALSE(entt::resolve("int"_hs));
+    ASSERT_FALSE(entt::resolve<int>().data("0"_hs));
+    ASSERT_FALSE(entt::resolve<char>().data("c"_hs));
+
+    a_module_meta_ctx(entt::meta_ctx{});
+    another_module_meta_ctx(entt::meta_ctx{});
+
+    entt::reflect<double>("double"_hs).conv<int>();
+    another_module_meta_init();
+    a_module_meta_init();
+
+    ASSERT_TRUE(entt::resolve("double"_hs));
+    ASSERT_TRUE(entt::resolve("char"_hs));
+    ASSERT_TRUE(entt::resolve("int"_hs));
+    ASSERT_TRUE(entt::resolve<int>().data("0"_hs));
+    ASSERT_TRUE(entt::resolve<char>().data("c"_hs));
+
+    a_module_meta_deinit();
+    another_module_meta_deinit();
+    entt::unregister<double>();
+
+    ASSERT_FALSE(entt::resolve("double"_hs));
+    ASSERT_FALSE(entt::resolve("char"_hs));
+    ASSERT_FALSE(entt::resolve("int"_hs));
+    ASSERT_FALSE(entt::resolve<int>().data("0"_hs));
+    ASSERT_FALSE(entt::resolve<char>().data("c"_hs));
+}