2020-07-31 16:39:47 +00:00
|
|
|
#ifdef TESTS_BUILD
|
2020-09-25 10:43:08 +00:00
|
|
|
#include "../../extern/doctest.hpp"
|
2020-08-14 11:52:22 +00:00
|
|
|
#include "../../src/Battling/EventHooks/EventDataClasses.hpp"
|
2020-07-31 16:39:47 +00:00
|
|
|
#include "../../src/Battling/EventHooks/EventHook.hpp"
|
|
|
|
#include "../../src/Battling/Models/CreateCreature.hpp"
|
|
|
|
#include "../TestLibrary/TestLibrary.hpp"
|
|
|
|
|
|
|
|
using namespace CreatureLib::Battling;
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Build and use event hook") {
|
2020-08-03 15:28:43 +00:00
|
|
|
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++) {
|
2020-12-12 11:22:48 +00:00
|
|
|
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
|
2020-08-03 15:28:43 +00:00
|
|
|
}
|
|
|
|
REQUIRE(events.size() == 10);
|
|
|
|
REQUIRE(events[0]->GetKind() == EventDataKind::Damage);
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Build and use event hook a lot") {
|
2020-08-03 15:28:43 +00:00
|
|
|
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++) {
|
2020-12-12 11:22:48 +00:00
|
|
|
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
|
2020-08-03 15:28:43 +00:00
|
|
|
}
|
|
|
|
REQUIRE(events.size() == 10000);
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Build and use event hook with different types") {
|
2020-08-03 15:28:43 +00:00
|
|
|
auto eventHook = EventHook();
|
|
|
|
std::vector<const EventData*> events;
|
|
|
|
eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
2020-12-12 11:22:48 +00:00
|
|
|
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);
|
2020-08-03 15:28:43 +00:00
|
|
|
}
|
2020-07-31 16:39:47 +00:00
|
|
|
#endif
|