Overhaul memory model to new Arbutils memory.
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-12-12 12:22:48 +01:00
parent 1dc3aafd33
commit 5c39694f19
33 changed files with 279 additions and 211 deletions

View File

@@ -1,6 +1,7 @@
#ifdef TESTS_BUILD
#include "../../extern/doctest.hpp"
#include "../../src/Battling/Models/Battle.hpp"
#include "../../src/Battling/Models/BattleSide.hpp"
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
@@ -9,7 +10,9 @@
using namespace CreatureLib::Battling;
TEST_CASE("Set Choice one-sized side") {
auto side = BattleSide(0, nullptr, 1);
auto lib = TestLibrary::Get();
auto battle = Battle(lib, {});
auto side = BattleSide(0, &battle, 1);
auto c = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
side.SetCreature(c, 0);
auto choice = new PassTurnChoice(c);
@@ -18,7 +21,9 @@ TEST_CASE("Set Choice one-sized side") {
}
TEST_CASE("Set Choice one-sized side, validate all choices set") {
auto side = BattleSide(0, nullptr, 1);
auto lib = TestLibrary::Get();
auto battle = Battle(lib, {});
auto side = BattleSide(0, &battle, 1);
auto c = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
side.SetCreature(c, 0);
auto choice = new PassTurnChoice(c);
@@ -29,7 +34,9 @@ TEST_CASE("Set Choice one-sized side, validate all choices set") {
}
TEST_CASE("Set Choice two-sized side") {
auto side = BattleSide(0, nullptr, 2);
auto lib = TestLibrary::Get();
auto battle = Battle(lib, {});
auto side = BattleSide(0, &battle, 2);
auto c1 = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
auto c2 = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
side.SetCreature(c1, 0);
@@ -43,7 +50,9 @@ TEST_CASE("Set Choice two-sized side") {
}
TEST_CASE("Set Choice two-sized side, validate all choices set") {
auto side = BattleSide(0, nullptr, 2);
auto lib = TestLibrary::Get();
auto battle = Battle(lib, {});
auto side = BattleSide(0, &battle, 2);
auto c1 = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
auto c2 = CreateCreature(TestLibrary::Get(), "testSpecies1"_cnc, 5).Create();
side.SetCreature(c1, 0);

View File

@@ -12,7 +12,7 @@ TEST_CASE("Build and use event hook") {
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);
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
}
REQUIRE(events.size() == 10);
REQUIRE(events[0]->GetKind() == EventDataKind::Damage);
@@ -23,7 +23,7 @@ TEST_CASE("Build and use event hook a lot") {
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);
eventHook.Trigger<DamageEvent>((Creature*)1, DamageSource::AttackDamage, 0, 0);
}
REQUIRE(events.size() == 10000);
}
@@ -32,13 +32,13 @@ 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>(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);
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

View File

@@ -26,7 +26,6 @@ TEST_CASE("Script Aggregator properly iterates containing script.") {
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
next.As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 1);
@@ -44,7 +43,6 @@ TEST_CASE("Script Aggregator properly iterates multiple scripts.") {
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
next.As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 3);
@@ -63,8 +61,7 @@ TEST_CASE("Script Aggregator properly iterates Script Set.") {
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
next.As<TestScript>()->TestMethod(ran);
next.value().As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 3);
}
@@ -82,8 +79,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script Set and Script.")
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
next.As<TestScript>()->TestMethod(ran);
next.value().As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 3);
}
@@ -101,8 +97,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.")
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
next.As<TestScript>()->TestMethod(ran);
next.value().As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 3);
}
@@ -122,8 +117,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script, Script Set and Sc
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
next.As<TestScript>()->TestMethod(ran);
next.value().As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 4);
}

View File

@@ -76,8 +76,8 @@ TEST_CASE("Script source with single item script set.") {
source.Set.Add(s);
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNextNotNull();
CHECK(first != nullptr);
CHECK(first->GetName() == "foobar");
REQUIRE(first.has_value());
CHECK(first.value()->GetName() == "foobar");
}
TEST_CASE("Script source with multiple item script set.") {
@@ -88,11 +88,11 @@ TEST_CASE("Script source with multiple item script set.") {
source.Set.Add(s2);
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNextNotNull();
REQUIRE(first != nullptr);
CHECK(first->GetName() == "foobar");
REQUIRE(first.has_value());
CHECK(first.value()->GetName() == "foobar");
auto second = scripts.GetNextNotNull();
REQUIRE(second != nullptr);
CHECK(second->GetName() == "foobar2");
REQUIRE(second.has_value());
CHECK(second.value()->GetName() == "foobar2");
}
#endif

View File

@@ -2,6 +2,7 @@
#include "../../extern/doctest.hpp"
#include "../../src/Battling/Flow/TurnOrdering.hpp"
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.hpp"
@@ -13,8 +14,10 @@ TEST_CASE("Turn ordering: Attack before pass") {
auto lib = TestLibrary::Get();
auto learnedAttack =
LearnedAttack(lib->GetAttackLibrary()->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto choice1 = std::make_shared<PassTurnChoice>(nullptr);
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, &learnedAttack, CreatureIndex(0, 0));
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto choice1 = std::make_shared<PassTurnChoice>(creature);
auto choice2 = std::make_shared<AttackTurnChoice>(creature, &learnedAttack, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
@@ -23,14 +26,18 @@ TEST_CASE("Turn ordering: Attack before pass") {
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
CHECK(vec[1] == choice1);
delete creature;
}
TEST_CASE("Turn ordering: High priority goes before no priority") {
const auto& l = TestLibrary::Get()->GetAttackLibrary();
auto lib = TestLibrary::Get();
const auto& l = lib->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto choice1 = std::make_shared<AttackTurnChoice>(creature, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(creature, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
@@ -42,14 +49,17 @@ TEST_CASE("Turn ordering: High priority goes before no priority") {
delete a1;
delete a2;
delete creature;
}
TEST_CASE("Turn ordering: Higher priority goes before high priority") {
const auto& l = TestLibrary::Get()->GetAttackLibrary();
auto lib = TestLibrary::Get();
const auto& l = lib->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto choice1 = std::make_shared<AttackTurnChoice>(creature, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(creature, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
@@ -60,14 +70,18 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority") {
CHECK(vec[1] == choice1);
delete a1;
delete a2;
delete creature;
}
TEST_CASE("Turn ordering: High priority goes before low priority") {
const auto& l = TestLibrary::Get()->GetAttackLibrary();
auto lib = TestLibrary::Get();
const auto& l = lib->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto choice1 = std::make_shared<AttackTurnChoice>(creature, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(creature, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
@@ -79,14 +93,17 @@ TEST_CASE("Turn ordering: High priority goes before low priority") {
delete a1;
delete a2;
delete creature;
}
TEST_CASE("Turn ordering: No priority goes before low priority") {
const auto& l = TestLibrary::Get()->GetAttackLibrary();
auto lib = TestLibrary::Get();
const auto& l = lib->GetAttackLibrary();
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->Get("standard"_cnc.GetHash()), AttackLearnMethod::Unknown);
auto choice1 = std::make_shared<AttackTurnChoice>(nullptr, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(nullptr, a2, CreatureIndex(0, 0));
auto creature = CreateCreature(lib, "testSpecies1"_cnc, 1).Create();
auto choice1 = std::make_shared<AttackTurnChoice>(creature, a1, CreatureIndex(0, 0));
auto choice2 = std::make_shared<AttackTurnChoice>(creature, a2, CreatureIndex(0, 0));
auto vec = std::vector<std::shared_ptr<BaseTurnChoice>>{choice1, choice2};
TurnOrdering::OrderChoices(vec);
CHECK(vec[0] == choice2);
@@ -98,6 +115,7 @@ TEST_CASE("Turn ordering: No priority goes before low priority") {
delete a1;
delete a2;
delete creature;
}
#endif