2020-07-31 16:39:47 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
#include "../../extern/catch.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-08-03 15:28:43 +00:00
|
|
|
TEST_CASE("Build and use event hook", "[Battling]") {
|
|
|
|
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>(nullptr, DamageSource::AttackDamage, 0, 0);
|
|
|
|
}
|
|
|
|
REQUIRE(events.size() == 10);
|
|
|
|
REQUIRE(events[0]->GetKind() == EventDataKind::Damage);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Build and use event hook a lot", "[Battling]") {
|
|
|
|
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>(nullptr, DamageSource::AttackDamage, 0, 0);
|
|
|
|
}
|
|
|
|
REQUIRE(events.size() == 10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Build and use event hook with different types", "[Battling]") {
|
|
|
|
auto eventHook = EventHook();
|
|
|
|
std::vector<const EventData*> events;
|
|
|
|
eventHook.RegisterListener([&](const EventData* evt) mutable -> void { events.push_back(evt); });
|
|
|
|
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
|
|
|
eventHook.Trigger<FaintEvent>(nullptr);
|
|
|
|
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
|
|
|
eventHook.Trigger<FaintEvent>(nullptr);
|
|
|
|
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
|
|
|
eventHook.Trigger<FaintEvent>(nullptr);
|
|
|
|
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
|
|
|
|
eventHook.Trigger<FaintEvent>(nullptr);
|
|
|
|
}
|
2020-07-31 16:39:47 +00:00
|
|
|
#endif
|