emitter: updated tests (lib)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user