test: use common types for lib tests (dispatcher)
This commit is contained in:
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user