From 085a281f8acf1c057b6aac877caa491a32a96344 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 9 Oct 2019 23:07:51 +0200 Subject: [PATCH] meta: some tests across boundaries --- src/entt/meta/meta.hpp | 37 ++++++--------------------------- test/lib/a_module.cpp | 13 ++++++++++++ test/lib/another_module.cpp | 13 ++++++++++++ test/lib/lib.cpp | 41 +++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 31 deletions(-) diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 6b1f2e687..c19a9beb1 100644 --- a/src/entt/meta/meta.hpp +++ b/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}; }; diff --git a/test/lib/a_module.cpp b/test/lib/a_module.cpp index 69dbef17a..1d7cffa54 100644 --- a/test/lib/a_module.cpp +++ b/test/lib/a_module.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #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(); } + +LIB_EXPORT void a_module_meta_ctx(entt::meta_ctx context) { + context.set(); +} + +LIB_EXPORT void a_module_meta_init() { + entt::reflect("char"_hs).data<'c'>("c"_hs); +} + +LIB_EXPORT void a_module_meta_deinit() { + entt::unregister(); +} diff --git a/test/lib/another_module.cpp b/test/lib/another_module.cpp index 2d4bd61d9..2473f669f 100644 --- a/test/lib/another_module.cpp +++ b/test/lib/another_module.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #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(payload); } + +LIB_EXPORT void another_module_meta_ctx(entt::meta_ctx context) { + context.set(); +} + +LIB_EXPORT void another_module_meta_init() { + entt::reflect("int"_hs).data<0>("0"_hs); +} + +LIB_EXPORT void another_module_meta_deinit() { + entt::unregister(); +} diff --git a/test/lib/lib.cpp b/test/lib/lib.cpp index 4bb800637..9fffcd4c7 100644 --- a/test/lib/lib.cpp +++ b/test/lib/lib.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #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().data("0"_hs)); + ASSERT_FALSE(entt::resolve().data("c"_hs)); + + a_module_meta_ctx(entt::meta_ctx{}); + another_module_meta_ctx(entt::meta_ctx{}); + + entt::reflect("double"_hs).conv(); + 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().data("0"_hs)); + ASSERT_TRUE(entt::resolve().data("c"_hs)); + + a_module_meta_deinit(); + another_module_meta_deinit(); + entt::unregister(); + + ASSERT_FALSE(entt::resolve("double"_hs)); + ASSERT_FALSE(entt::resolve("char"_hs)); + ASSERT_FALSE(entt::resolve("int"_hs)); + ASSERT_FALSE(entt::resolve().data("0"_hs)); + ASSERT_FALSE(entt::resolve().data("c"_hs)); +}