test: rework lib stuff to share common files
This commit is contained in:
8
test/lib/emitter/shared/lib.cpp
Normal file
8
test/lib/emitter/shared/lib.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <entt/core/attribute.h>
|
||||
#include "types.h"
|
||||
|
||||
ENTT_API void emit(test_emitter &emitter) {
|
||||
emitter.publish(event{});
|
||||
emitter.publish(message{42});
|
||||
emitter.publish(message{3});
|
||||
}
|
||||
21
test/lib/emitter/shared/main.cpp
Normal file
21
test/lib/emitter/shared/main.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/attribute.h>
|
||||
#include "types.h"
|
||||
|
||||
ENTT_API void emit(test_emitter &);
|
||||
|
||||
TEST(Lib, Emitter) {
|
||||
test_emitter emitter;
|
||||
int value{};
|
||||
|
||||
ASSERT_EQ(value, 0);
|
||||
|
||||
emitter.on<message>([&](message msg, test_emitter &owner) {
|
||||
value = msg.payload;
|
||||
owner.erase<message>();
|
||||
});
|
||||
|
||||
emit(emitter);
|
||||
|
||||
ASSERT_EQ(value, 42);
|
||||
}
|
||||
15
test/lib/emitter/shared/types.h
Normal file
15
test/lib/emitter/shared/types.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef ENTT_LIB_EMITTER_TYPES_H
|
||||
#define ENTT_LIB_EMITTER_TYPES_H
|
||||
|
||||
#include <entt/signal/emitter.hpp>
|
||||
|
||||
struct test_emitter
|
||||
: entt::emitter<test_emitter> {};
|
||||
|
||||
struct message {
|
||||
int payload;
|
||||
};
|
||||
|
||||
struct event {};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user