test: reuse types if possible
This commit is contained in:
@@ -2,37 +2,34 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <gtest/gtest.h>
|
||||
#include <common/boxed_type.h>
|
||||
#include <common/emitter.h>
|
||||
#include <common/linter.hpp>
|
||||
#include <entt/signal/emitter.hpp>
|
||||
|
||||
struct foo_event {
|
||||
int i;
|
||||
};
|
||||
|
||||
struct bar_event {};
|
||||
struct quux_event {};
|
||||
|
||||
TEST(Emitter, Move) {
|
||||
test::emitter emitter{};
|
||||
emitter.on<foo_event>([](auto &, const auto &) {});
|
||||
emitter.on<test::boxed_int>([](auto &, const auto &) {});
|
||||
|
||||
ASSERT_FALSE(emitter.empty());
|
||||
ASSERT_TRUE(emitter.contains<foo_event>());
|
||||
ASSERT_TRUE(emitter.contains<test::boxed_int>());
|
||||
|
||||
test::emitter other{std::move(emitter)};
|
||||
|
||||
test::is_initialized(emitter);
|
||||
|
||||
ASSERT_FALSE(other.empty());
|
||||
ASSERT_TRUE(other.contains<foo_event>());
|
||||
ASSERT_TRUE(other.contains<test::boxed_int>());
|
||||
ASSERT_TRUE(emitter.empty());
|
||||
|
||||
emitter = std::move(other);
|
||||
test::is_initialized(other);
|
||||
|
||||
ASSERT_FALSE(emitter.empty());
|
||||
ASSERT_TRUE(emitter.contains<foo_event>());
|
||||
ASSERT_TRUE(emitter.contains<test::boxed_int>());
|
||||
ASSERT_TRUE(other.empty());
|
||||
}
|
||||
|
||||
@@ -41,21 +38,21 @@ TEST(Emitter, Swap) {
|
||||
test::emitter other{};
|
||||
int value{};
|
||||
|
||||
emitter.on<foo_event>([&value](auto &event, const auto &) {
|
||||
value = event.i;
|
||||
emitter.on<test::boxed_int>([&value](auto &event, const auto &) {
|
||||
value = event.value;
|
||||
});
|
||||
|
||||
ASSERT_FALSE(emitter.empty());
|
||||
ASSERT_TRUE(other.empty());
|
||||
|
||||
emitter.swap(other);
|
||||
emitter.publish(foo_event{1});
|
||||
emitter.publish(test::boxed_int{1});
|
||||
|
||||
ASSERT_EQ(value, 0);
|
||||
ASSERT_TRUE(emitter.empty());
|
||||
ASSERT_FALSE(other.empty());
|
||||
|
||||
other.publish(foo_event{1});
|
||||
other.publish(test::boxed_int{1});
|
||||
|
||||
ASSERT_EQ(value, 1);
|
||||
}
|
||||
@@ -65,40 +62,40 @@ TEST(Emitter, Clear) {
|
||||
|
||||
ASSERT_TRUE(emitter.empty());
|
||||
|
||||
emitter.on<foo_event>([](auto &, const auto &) {});
|
||||
emitter.on<test::boxed_int>([](auto &, const auto &) {});
|
||||
emitter.on<quux_event>([](const auto &, const auto &) {});
|
||||
|
||||
ASSERT_FALSE(emitter.empty());
|
||||
ASSERT_TRUE(emitter.contains<foo_event>());
|
||||
ASSERT_TRUE(emitter.contains<test::boxed_int>());
|
||||
ASSERT_TRUE(emitter.contains<quux_event>());
|
||||
ASSERT_FALSE(emitter.contains<bar_event>());
|
||||
|
||||
emitter.erase<bar_event>();
|
||||
|
||||
ASSERT_FALSE(emitter.empty());
|
||||
ASSERT_TRUE(emitter.contains<foo_event>());
|
||||
ASSERT_TRUE(emitter.contains<test::boxed_int>());
|
||||
ASSERT_TRUE(emitter.contains<quux_event>());
|
||||
ASSERT_FALSE(emitter.contains<bar_event>());
|
||||
|
||||
emitter.erase<foo_event>();
|
||||
emitter.erase<test::boxed_int>();
|
||||
|
||||
ASSERT_FALSE(emitter.empty());
|
||||
ASSERT_FALSE(emitter.contains<foo_event>());
|
||||
ASSERT_FALSE(emitter.contains<test::boxed_int>());
|
||||
ASSERT_TRUE(emitter.contains<quux_event>());
|
||||
ASSERT_FALSE(emitter.contains<bar_event>());
|
||||
|
||||
emitter.on<foo_event>([](auto &, const auto &) {});
|
||||
emitter.on<test::boxed_int>([](auto &, const auto &) {});
|
||||
emitter.on<bar_event>([](const auto &, const auto &) {});
|
||||
|
||||
ASSERT_FALSE(emitter.empty());
|
||||
ASSERT_TRUE(emitter.contains<foo_event>());
|
||||
ASSERT_TRUE(emitter.contains<test::boxed_int>());
|
||||
ASSERT_TRUE(emitter.contains<quux_event>());
|
||||
ASSERT_TRUE(emitter.contains<bar_event>());
|
||||
|
||||
emitter.clear();
|
||||
|
||||
ASSERT_TRUE(emitter.empty());
|
||||
ASSERT_FALSE(emitter.contains<foo_event>());
|
||||
ASSERT_FALSE(emitter.contains<test::boxed_int>());
|
||||
ASSERT_FALSE(emitter.contains<bar_event>());
|
||||
}
|
||||
|
||||
@@ -107,9 +104,9 @@ TEST(Emitter, ClearFromCallback) {
|
||||
|
||||
ASSERT_TRUE(emitter.empty());
|
||||
|
||||
emitter.on<foo_event>([](auto &, auto &owner) {
|
||||
owner.template on<foo_event>([](auto &, auto &) {});
|
||||
owner.template erase<foo_event>();
|
||||
emitter.on<test::boxed_int>([](auto &, auto &owner) {
|
||||
owner.template on<test::boxed_int>([](auto &, auto &) {});
|
||||
owner.template erase<test::boxed_int>();
|
||||
});
|
||||
|
||||
emitter.on<bar_event>([](const auto &, auto &owner) {
|
||||
@@ -119,7 +116,7 @@ TEST(Emitter, ClearFromCallback) {
|
||||
|
||||
ASSERT_FALSE(emitter.empty());
|
||||
|
||||
emitter.publish(foo_event{});
|
||||
emitter.publish(test::boxed_int{});
|
||||
emitter.publish(bar_event{});
|
||||
|
||||
ASSERT_TRUE(emitter.empty());
|
||||
@@ -129,15 +126,15 @@ TEST(Emitter, On) {
|
||||
test::emitter emitter{};
|
||||
int value{};
|
||||
|
||||
emitter.on<foo_event>([&value](auto &event, const auto &) {
|
||||
value = event.i;
|
||||
emitter.on<test::boxed_int>([&value](auto &event, const auto &) {
|
||||
value = event.value;
|
||||
});
|
||||
|
||||
ASSERT_FALSE(emitter.empty());
|
||||
ASSERT_TRUE(emitter.contains<foo_event>());
|
||||
ASSERT_TRUE(emitter.contains<test::boxed_int>());
|
||||
ASSERT_EQ(value, 0);
|
||||
|
||||
emitter.publish(foo_event{1});
|
||||
emitter.publish(test::boxed_int{1});
|
||||
|
||||
ASSERT_EQ(value, 1);
|
||||
}
|
||||
@@ -164,7 +161,7 @@ TEST(Emitter, CustomAllocator) {
|
||||
ASSERT_EQ(emitter.get_allocator(), allocator);
|
||||
ASSERT_FALSE(emitter.get_allocator() != allocator);
|
||||
|
||||
emitter.on<foo_event>([](auto &, const auto &) {});
|
||||
emitter.on<test::boxed_int>([](auto &, const auto &) {});
|
||||
const decltype(emitter) other{std::move(emitter), allocator};
|
||||
|
||||
test::is_initialized(emitter);
|
||||
|
||||
Reference in New Issue
Block a user