Fixes for EventHook corruptions, unit tests for EventHooks.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
30
tests/BattleTests/EventHookTests.cpp
Normal file
30
tests/BattleTests/EventHookTests.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include "../../extern/catch.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", "[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);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user