Browse Source

emitter: updated tests (lib)

Michele Caini 6 năm trước cách đây
mục cha
commit
f68941992a

+ 0 - 2
test/CMakeLists.txt

@@ -115,7 +115,6 @@ if(BUILD_LIB)
     SETUP_LIB_TEST(meta)
     SETUP_LIB_TEST(registry)
 
-    SETUP_LIB_TEST(emitter_std ENTT_STANDARD_CPP)
     SETUP_LIB_TEST(meta_std ENTT_STANDARD_CPP)
     SETUP_LIB_TEST(registry_std ENTT_STANDARD_CPP)
 
@@ -124,7 +123,6 @@ if(BUILD_LIB)
     SETUP_PLUGIN_TEST(meta_plugin)
     SETUP_PLUGIN_TEST(registry_plugin)
 
-    SETUP_PLUGIN_TEST(emitter_plugin_std ENTT_STANDARD_CPP)
     SETUP_PLUGIN_TEST(meta_plugin_std ENTT_STANDARD_CPP)
     SETUP_PLUGIN_TEST(registry_plugin_std ENTT_STANDARD_CPP)
 endif()

+ 4 - 3
test/lib/emitter/types.h

@@ -1,16 +1,17 @@
 #ifndef ENTT_LIB_EMITTER_TYPES_H
 #define ENTT_LIB_EMITTER_TYPES_H
 
+#include <entt/core/attribute.h>
 #include <entt/signal/emitter.hpp>
 
-struct test_emitter
+struct ENTT_API test_emitter
         : entt::emitter<test_emitter>
 {};
 
-struct message {
+struct ENTT_API message {
     int payload;
 };
 
-struct event {};
+struct ENTT_API event {};
 
 #endif

+ 5 - 14
test/lib/emitter_plugin/main.cpp

@@ -2,25 +2,15 @@
 
 #include <cr.h>
 #include <gtest/gtest.h>
+#include <entt/core/type_info.hpp>
 #include <entt/signal/emitter.hpp>
-#include "proxy.h"
 #include "types.h"
 
-proxy::proxy(test_emitter &ref)
-    : emitter{&ref}
-{}
-
-void proxy::publish(message msg) {
-    emitter->publish<message>(msg);
-}
-
-void proxy::publish(event ev) {
-    emitter->publish<event>(ev);
-}
+template<typename Type>
+struct entt::type_index<Type> {};
 
 TEST(Lib, Emitter) {
     test_emitter emitter;
-    proxy handler{emitter};
     int value{};
 
     ASSERT_EQ(value, 0);
@@ -28,11 +18,12 @@ TEST(Lib, Emitter) {
     emitter.once<message>([&](message msg, test_emitter &) { value = msg.payload; });
 
     cr_plugin ctx;
-    ctx.userdata = &handler;
+    ctx.userdata = &emitter;
     cr_plugin_load(ctx, PLUGIN);
     cr_plugin_update(ctx);
 
     ASSERT_EQ(value, 42);
 
+    emitter = {};
     cr_plugin_close(ctx);
 }

+ 8 - 3
test/lib/emitter_plugin/plugin.cpp

@@ -1,12 +1,17 @@
 #include <cr.h>
+#include <entt/core/type_info.hpp>
+#include <entt/signal/emitter.hpp>
 #include "types.h"
 
+template<typename Type>
+struct entt::type_index<Type> {};
+
 CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
     switch (operation) {
     case CR_STEP:
-        static_cast<emitter_proxy *>(ctx->userdata)->publish(event{});
-        static_cast<emitter_proxy *>(ctx->userdata)->publish(message{42});
-        static_cast<emitter_proxy *>(ctx->userdata)->publish(message{3});
+        static_cast<test_emitter *>(ctx->userdata)->publish<event>();
+        static_cast<test_emitter *>(ctx->userdata)->publish<message>(42);
+        static_cast<test_emitter *>(ctx->userdata)->publish<message>(3);
         break;
     case CR_CLOSE:
     case CR_LOAD:

+ 0 - 15
test/lib/emitter_plugin/proxy.h

@@ -1,15 +0,0 @@
-#ifndef ENTT_LIB_EMITTER_PLUGIN_PROXY_H
-#define ENTT_LIB_EMITTER_PLUGIN_PROXY_H
-
-#include "types.h"
-
-struct proxy: emitter_proxy {
-    proxy(test_emitter &);
-    void publish(message) override;
-    void publish(event) override;
-
-private:
-    test_emitter *emitter;
-};
-
-#endif

+ 0 - 6
test/lib/emitter_plugin/types.h

@@ -13,10 +13,4 @@ struct message {
 
 struct event {};
 
-struct emitter_proxy {
-    virtual ~emitter_proxy() = default;
-    virtual void publish(message) = 0;
-    virtual void publish(event) = 0;
-};
-
 #endif

+ 0 - 38
test/lib/emitter_plugin_std/main.cpp

@@ -1,38 +0,0 @@
-#define CR_HOST
-
-#include <cr.h>
-#include <gtest/gtest.h>
-#include <entt/signal/emitter.hpp>
-#include "proxy.h"
-#include "types.h"
-
-proxy::proxy(test_emitter &ref)
-    : emitter{&ref}
-{}
-
-void proxy::publish(message msg) {
-    emitter->publish<message>(msg);
-}
-
-void proxy::publish(event ev) {
-    emitter->publish<event>(ev);
-}
-
-TEST(Lib, Emitter) {
-    test_emitter emitter;
-    proxy handler{emitter};
-    int value{};
-
-    ASSERT_EQ(value, 0);
-
-    emitter.once<message>([&](message msg, test_emitter &) { value = msg.payload; });
-
-    cr_plugin ctx;
-    ctx.userdata = &handler;
-    cr_plugin_load(ctx, PLUGIN);
-    cr_plugin_update(ctx);
-
-    ASSERT_EQ(value, 42);
-
-    cr_plugin_close(ctx);
-}

+ 0 - 19
test/lib/emitter_plugin_std/plugin.cpp

@@ -1,19 +0,0 @@
-#include <cr.h>
-#include "types.h"
-
-CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
-    switch (operation) {
-    case CR_STEP:
-        static_cast<emitter_proxy *>(ctx->userdata)->publish(event{});
-        static_cast<emitter_proxy *>(ctx->userdata)->publish(message{42});
-        static_cast<emitter_proxy *>(ctx->userdata)->publish(message{3});
-        break;
-    case CR_CLOSE:
-    case CR_LOAD:
-    case CR_UNLOAD:
-        // nothing to do here, this is only a test.
-        break;
-    }
-
-    return 0;
-}

+ 0 - 15
test/lib/emitter_plugin_std/proxy.h

@@ -1,15 +0,0 @@
-#ifndef ENTT_LIB_EMITTER_PLUGIN_STD_PROXY_H
-#define ENTT_LIB_EMITTER_PLUGIN_STD_PROXY_H
-
-#include "types.h"
-
-struct proxy: emitter_proxy {
-    proxy(test_emitter &);
-    void publish(message) override;
-    void publish(event) override;
-
-private:
-    test_emitter *emitter;
-};
-
-#endif

+ 0 - 22
test/lib/emitter_plugin_std/types.h

@@ -1,22 +0,0 @@
-#ifndef ENTT_LIB_EMITTER_PLUGIN_STD_TYPES_H
-#define ENTT_LIB_EMITTER_PLUGIN_STD_TYPES_H
-
-#include <entt/signal/emitter.hpp>
-
-struct test_emitter
-        : entt::emitter<test_emitter>
-{};
-
-struct message {
-    int payload;
-};
-
-struct event {};
-
-struct emitter_proxy {
-    virtual ~emitter_proxy() = default;
-    virtual void publish(message) = 0;
-    virtual void publish(event) = 0;
-};
-
-#endif

+ 0 - 9
test/lib/emitter_std/lib.cpp

@@ -1,9 +0,0 @@
-#include <entt/core/attribute.h>
-#include <entt/signal/emitter.hpp>
-#include "types.h"
-
-ENTT_API void emit(test_emitter &emitter) {
-    emitter.publish<event>();
-    emitter.publish<message>(42);
-    emitter.publish<message>(3);
-}

+ 0 - 18
test/lib/emitter_std/main.cpp

@@ -1,18 +0,0 @@
-#include <gtest/gtest.h>
-#include <entt/core/attribute.h>
-#include <entt/signal/emitter.hpp>
-#include "types.h"
-
-ENTT_API void emit(test_emitter &);
-
-TEST(Lib, Emitter) {
-    test_emitter emitter;
-    int value{};
-
-    ASSERT_EQ(value, 0);
-
-    emitter.once<message>([&](message msg, test_emitter &) { value = msg.payload; });
-    emit(emitter);
-
-    ASSERT_EQ(value, 42);
-}

+ 0 - 17
test/lib/emitter_std/types.h

@@ -1,17 +0,0 @@
-#ifndef ENTT_LIB_EMITTER_STD_TYPES_H
-#define ENTT_LIB_EMITTER_STD_TYPES_H
-
-#include <entt/core/attribute.h>
-#include <entt/signal/emitter.hpp>
-
-struct ENTT_API test_emitter
-        : entt::emitter<test_emitter>
-{};
-
-struct ENTT_API message {
-    int payload;
-};
-
-struct ENTT_API event {};
-
-#endif