44 lines
1.9 KiB
C++
44 lines
1.9 KiB
C++
#ifdef TESTS_BUILD
|
|
#include "../../extern/doctest.hpp"
|
|
#include "../../src/Battling/EventHooks/EventDataClasses.hpp"
|
|
#include "../../src/Battling/EventHooks/EventHook.hpp"
|
|
#include "../../src/Battling/Models/CreateCreature.hpp"
|
|
#include "../TestLibrary/TestLibrary.hpp"
|
|
|
|
using namespace CreatureLib::Battling;
|
|
|
|
TEST_CASE("Build and use event hook") {
|
|
auto eventHook = EventHook();
|
|
std::vector<const EventData*> events;
|
|
eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
|
for (size_t i = 0; i < 10; i++) {
|
|
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
|
|
}
|
|
REQUIRE(events.size() == 10);
|
|
REQUIRE(events[0]->GetKind() == EventDataKind::Damage);
|
|
}
|
|
|
|
TEST_CASE("Build and use event hook a lot") {
|
|
auto eventHook = EventHook();
|
|
std::vector<const EventData*> events;
|
|
eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
|
for (size_t i = 0; i < 10000; i++) {
|
|
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
|
|
}
|
|
REQUIRE(events.size() == 10000);
|
|
}
|
|
|
|
TEST_CASE("Build and use event hook with different types") {
|
|
auto eventHook = EventHook();
|
|
std::vector<const EventData*> events;
|
|
eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
|
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
|
|
eventHook.Trigger<FaintEvent>((Creature*)1);
|
|
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
|
|
eventHook.Trigger<FaintEvent>((Creature*)1);
|
|
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
|
|
eventHook.Trigger<FaintEvent>((Creature*)1);
|
|
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
|
|
eventHook.Trigger<FaintEvent>((Creature*)1);
|
|
}
|
|
#endif |