Quellcode durchsuchen

test: use common types for lib tests (dispatcher)

Michele Caini vor 2 Jahren
Ursprung
Commit
b7622a373b

+ 0 - 10
test/lib/dispatcher/common/types.h

@@ -1,10 +0,0 @@
-#ifndef ENTT_LIB_DISPATCHER_COMMON_TYPES_H
-#define ENTT_LIB_DISPATCHER_COMMON_TYPES_H
-
-struct message {
-    int payload{};
-};
-
-struct event {};
-
-#endif

+ 4 - 4
test/lib/dispatcher/plugin/main.cpp

@@ -1,13 +1,13 @@
 #define CR_HOST
 
 #include <gtest/gtest.h>
+#include <common/boxed_type.h>
 #include <cr.h>
 #include <entt/signal/dispatcher.hpp>
-#include "../common/types.h"
 
 struct listener {
-    void on(message msg) {
-        value = msg.payload;
+    void on(test::boxed_int msg) {
+        value = msg.value;
     }
 
     int value{};
@@ -19,7 +19,7 @@ TEST(Lib, Dispatcher) {
 
     ASSERT_EQ(listener.value, 0);
 
-    dispatcher.sink<message>().connect<&listener::on>(listener);
+    dispatcher.sink<test::boxed_int>().connect<&listener::on>(listener);
 
     cr_plugin ctx;
     cr_plugin_load(ctx, PLUGIN);

+ 4 - 3
test/lib/dispatcher/plugin/plugin.cpp

@@ -1,12 +1,13 @@
+#include <common/boxed_type.h>
+#include <common/empty.h>
 #include <cr.h>
 #include <entt/signal/dispatcher.hpp>
-#include "../common/types.h"
 
 CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {
     switch(operation) {
     case CR_STEP:
-        static_cast<entt::dispatcher *>(ctx->userdata)->trigger<event>();
-        static_cast<entt::dispatcher *>(ctx->userdata)->trigger(message{4});
+        static_cast<entt::dispatcher *>(ctx->userdata)->trigger<test::empty>();
+        static_cast<entt::dispatcher *>(ctx->userdata)->trigger(test::boxed_int{4});
         break;
     case CR_CLOSE:
     case CR_LOAD:

+ 4 - 3
test/lib/dispatcher/shared/lib.cpp

@@ -1,8 +1,9 @@
+#include <common/boxed_type.h>
+#include <common/empty.h>
 #include <entt/core/attribute.h>
 #include <entt/signal/dispatcher.hpp>
-#include "../common/types.h"
 
 ENTT_API void trigger(entt::dispatcher &dispatcher) {
-    dispatcher.trigger<event>();
-    dispatcher.trigger(message{2});
+    dispatcher.trigger<test::empty>();
+    dispatcher.trigger(test::boxed_int{2});
 }

+ 4 - 4
test/lib/dispatcher/shared/main.cpp

@@ -1,14 +1,14 @@
 #include <gtest/gtest.h>
+#include <common/boxed_type.h>
 #include <entt/core/attribute.h>
 #include <entt/core/utility.hpp>
 #include <entt/signal/dispatcher.hpp>
-#include "../common/types.h"
 
 ENTT_API void trigger(entt::dispatcher &);
 
 struct listener {
-    void on(message msg) {
-        value = msg.payload;
+    void on(test::boxed_int msg) {
+        value = msg.value;
     }
 
     int value{};
@@ -20,7 +20,7 @@ TEST(Lib, Dispatcher) {
 
     ASSERT_EQ(listener.value, 0);
 
-    dispatcher.sink<message>().connect<entt::overload<void(message)>(&listener::on)>(listener);
+    dispatcher.sink<test::boxed_int>().connect<entt::overload<void(test::boxed_int)>(&listener::on)>(listener);
     trigger(dispatcher);
 
     ASSERT_EQ(listener.value, 2);