Reworks test suite, tweaks to Cmake config for Windows.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2019-12-07 13:45:44 +01:00
parent 8897f2282f
commit 0483e635ea
10 changed files with 90 additions and 68 deletions

View File

@ -39,12 +39,12 @@ target_link_libraries(CreatureLibTests CreatureLibLibrary)
target_link_libraries(CreatureLibTests CreatureLibBattling)
if (WINDOWS)
set (CMAKE_CXX_FLAGS "-Wl,-allow-multiple-definition")
set(CMAKE_CXX_FLAGS "-m64 -Wa,-mbig-obj")
# Statically link libraries we need in Windows.
target_link_libraries(CreatureLibCore -static -static-libgcc -static-libstdc++)
target_link_libraries(CreatureLibLibrary -static -static-libgcc -static-libstdc++)
target_link_libraries(CreatureLibBattling -static -static-libgcc -static-libstdc++)
target_link_libraries(CreatureLibTests -static -static-libgcc -static-libstdc++)
# target_link_libraries(CreatureLibCore -static -static-libgcc -static-libstdc++)
# target_link_libraries(CreatureLibLibrary -static -static-libgcc -static-libstdc++)
# target_link_libraries(CreatureLibBattling -static -static-libgcc -static-libstdc++)
# target_link_libraries(CreatureLibTests -static -static-libgcc -static-libstdc++)
endif(WINDOWS)
# Add a definition for the test library

View File

@ -81,13 +81,13 @@ bool Battle::CreatureInField(const Creature* creature) const {
void Battle::ForceRecall(uint8_t side, uint8_t index) { _sides[side]->SetCreature(nullptr, index); }
void Battle::FillEmptySlot(uint8_t side, uint8_t index, Creature* c) { _sides[side]->SetCreature(c, index); }
void Battle::GetActiveScripts(std::vector<ScriptWrapper>& scripts) { scripts.emplace_back(&_volatile); }
void Battle::SwitchCreature(uint8_t sideIndex, uint8_t index, Creature* c) {
auto side = this->_sides[sideIndex];
side->SetCreature(c, index);
}
bool Battle::CanSlotBeFilled(uint8_t side, uint8_t index) const {
for (const auto& party : _parties) {
if (party.IsResponsibleForIndex(side, index)) {

View File

@ -54,7 +54,6 @@ namespace CreatureLib::Battling {
}
void ForceRecall(uint8_t side, uint8_t index);
void FillEmptySlot(uint8_t side, uint8_t index, Creature* c);
void SwitchCreature(uint8_t side, uint8_t index, Creature* c);
bool CanSlotBeFilled(uint8_t side, uint8_t index) const;

View File

@ -1,15 +1,16 @@
#ifdef TESTS_BUILD
#include "../../extern/catch.hpp"
#include "../TestLibrary/TestLibrary.hpp"
#include "../../src/Battling/Models/BattleSide.hpp"
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.cpp"
using namespace CreatureLib::Battling;
TEST_CASE("Set Choice one-sized side", "[Battling]") {
auto side = BattleSide(0, nullptr, 1);
auto c = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
auto c = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
side.SetCreature(c, 0);
auto choice = new PassTurnChoice(c);
side.SetChoice(choice);
@ -19,7 +20,7 @@ TEST_CASE("Set Choice one-sized side", "[Battling]") {
TEST_CASE("Set Choice one-sized side, validate all choices set", "[Battling]") {
auto side = BattleSide(0, nullptr, 1);
auto c = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
auto c = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
side.SetCreature(c, 0);
auto choice = new PassTurnChoice(c);
REQUIRE_FALSE(side.AllChoicesSet());
@ -31,8 +32,8 @@ TEST_CASE("Set Choice one-sized side, validate all choices set", "[Battling]") {
TEST_CASE("Set Choice two-sized side", "[Battling]") {
auto side = BattleSide(0, nullptr, 2);
auto c1 = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
auto c2 = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
auto c1 = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
auto c2 = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
side.SetCreature(c1, 0);
side.SetCreature(c2, 1);
auto choice1 = new PassTurnChoice(c1);
@ -47,8 +48,8 @@ TEST_CASE("Set Choice two-sized side", "[Battling]") {
TEST_CASE("Set Choice two-sized side, validate all choices set", "[Battling]") {
auto side = BattleSide(0, nullptr, 2);
auto c1 = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
auto c2 = CreateCreature(GetLibrary(), "testSpecies1", 5).Create();
auto c1 = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
auto c2 = CreateCreature(TestLibrary::Get(), "testSpecies1", 5).Create();
side.SetCreature(c1, 0);
side.SetCreature(c2, 1);
auto choice1 = new PassTurnChoice(c1);

View File

@ -1,9 +1,10 @@
#ifdef TESTS_BUILD
#include "../../extern/catch.hpp"
#include "../../src/Battling/Flow/TurnOrdering.hpp"
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.cpp"
#include "../TestLibrary/TestLibrary.hpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
@ -26,7 +27,7 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
}
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
auto l = GetLibrary()->GetAttackLibrary();
auto l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
@ -48,7 +49,7 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]")
}
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
auto l = GetLibrary()->GetAttackLibrary();
auto l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->GetAttack("highPriority"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
@ -70,7 +71,7 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling
}
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
auto l = GetLibrary()->GetAttackLibrary();
auto l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->GetAttack("higherPriority"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
@ -92,7 +93,7 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]")
}
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
auto l = GetLibrary()->GetAttackLibrary();
auto l = TestLibrary::Get()->GetAttackLibrary();
auto a1 = new LearnedAttack(l->GetAttack("lowPriority"), AttackLearnMethod::Unknown);
auto a2 = new LearnedAttack(l->GetAttack("standard"), AttackLearnMethod::Unknown);
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));

View File

@ -5,13 +5,13 @@
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.cpp"
#include "../TestLibrary/TestLibrary.hpp"
using namespace CreatureLib;
using namespace Battling;
TEST_CASE("Create Party", "[Integrations]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty = BattleParty(&party1, {CreatureIndex(0, 0)});
@ -19,7 +19,7 @@ TEST_CASE("Create Party", "[Integrations]") {
}
TEST_CASE("Create Battle", "[Integrations]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
@ -31,7 +31,7 @@ TEST_CASE("Create Battle", "[Integrations]") {
}
TEST_CASE("Use damaging move", "[Integrations]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto c1 = CreateCreature(library, "testSpecies1", 50).WithAttack("standard", AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
@ -41,8 +41,8 @@ TEST_CASE("Use damaging move", "[Integrations]") {
auto battle = Battle(library, {battleParty1, battleParty2});
battle.FillEmptySlot(0, 0, c1);
battle.FillEmptySlot(1, 0, c2);
battle.SwitchCreature(0, 0, c1);
battle.SwitchCreature(1, 0, c2);
battle.TrySetChoice(new AttackTurnChoice(c1, c1->GetAttacks()[0], CreatureIndex(1, 0)));
battle.TrySetChoice(new PassTurnChoice(c2));

View File

@ -1,44 +1,45 @@
#ifdef TESTS_BUILD
#include "../../extern/catch.hpp"
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../TestLibrary/TestLibrary.cpp"
#include "../TestLibrary/TestLibrary.hpp"
using namespace CreatureLib::Library;
TEST_CASE("Create basic creature", "[Library]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
delete creature;
}
TEST_CASE("Get creature species", "[Library]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1");
delete creature;
}
TEST_CASE("Get creature level", "[Library]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
REQUIRE(creature->GetLevel() == 1);
delete creature;
}
TEST_CASE("Get creature variant when unset", "[Library]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
REQUIRE(creature->GetVariant()->GetName() == "default");
delete creature;
}
TEST_CASE("Get creature nickname when unset", "[Library]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
REQUIRE(creature->GetNickname() == "testSpecies1");
delete creature;
}
TEST_CASE("Get creature stat potentials when unset", "[Library]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto potentials = creature->GetStatPotential();
REQUIRE(potentials.GetHealth() == 0);
@ -51,7 +52,7 @@ TEST_CASE("Get creature stat potentials when unset", "[Library]") {
}
TEST_CASE("Get creature stat experience when unset", "[Library]") {
auto library = GetLibrary();
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1", 1).Create();
auto experiences = creature->GetStatExperience();
REQUIRE(experiences.GetHealth() == 0);

View File

@ -2,36 +2,35 @@
#define CATCH_CONFIG_MAIN
#include "../../extern/catch.hpp"
#include "../TestLibrary/TestLibrary.cpp"
#include "../TestLibrary/TestLibrary.hpp"
TEST_CASE("Can Create Species Library", "[Library]") {
auto l = BuildSpeciesLibrary();
auto l = TestLibrary::BuildSpeciesLibrary();
REQUIRE(l != nullptr);
delete l;
}
TEST_CASE("Can Create Attack Library", "[Library]") {
auto l = BuildAttackLibrary();
auto l = TestLibrary::BuildAttackLibrary();
REQUIRE(l != nullptr);
delete l;
}
TEST_CASE("Can Create Item Library", "[Library]") {
auto l = BuildItemLibrary();
auto l = TestLibrary::BuildItemLibrary();
REQUIRE(l != nullptr);
delete l;
}
TEST_CASE("Can Create Growthrate Library", "[Library]") {
auto l = BuildGrowthRateLibrary();
TEST_CASE("Can Create Growth Rate Library", "[Library]") {
auto l = TestLibrary::BuildGrowthRateLibrary();
REQUIRE(l != nullptr);
delete l;
}
TEST_CASE("Can Create Data Library", "[Library]") {
auto l = BuildLibrary();
auto l = TestLibrary::Get();
REQUIRE(l != nullptr);
delete l;
}
#endif

View File

@ -1,24 +1,35 @@
#ifdef TESTS_BUILD
#include "../../extern/catch.hpp"
#include "../../src/Battling/Library/BattleLibrary.hpp"
#include "TestLibrary.hpp"
using namespace CreatureLib::Core;
using namespace CreatureLib::Library;
using namespace CreatureLib::Battling;
static BattleLibrary* __library = nullptr;
BattleLibrary* TestLibrary::_library = nullptr;
static SpeciesLibrary* BuildSpeciesLibrary() {
BattleLibrary *TestLibrary::Get() {
if (TestLibrary::_library == nullptr){
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(), BuildItemLibrary(),
BuildGrowthRateLibrary(), BuildTypeLibrary());
auto statCalc = new BattleStatCalculator();
auto battleLib = new BattleLibrary(l, statCalc, new DamageLibrary(), new CriticalLibrary(), new ScriptResolver());
TestLibrary::_library = battleLib;
}
return TestLibrary::_library;
}
SpeciesLibrary *TestLibrary::BuildSpeciesLibrary() {
auto l = new SpeciesLibrary();
l->LoadSpecies("testSpecies1",
new CreatureSpecies(
0, "testSpecies1",
new SpeciesVariant("default", 1, 1, 10, {0, 1}, StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10),
{"testTalent"}, {"testSecretTalent"}, new LearnableAttacks(100)),
0.5f, "testGrowthRate", 5, 100));
0, "testSpecies1",
new SpeciesVariant("default", 1, 1, 10, {0, 1}, StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10),
{"testTalent"}, {"testSecretTalent"}, new LearnableAttacks(100)),
0.5f, "testGrowthRate", 5, 100));
return l;
}
static AttackLibrary* BuildAttackLibrary() {
AttackLibrary *TestLibrary::BuildAttackLibrary() {
auto l = new AttackLibrary();
l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 0, {}));
@ -31,17 +42,17 @@ static AttackLibrary* BuildAttackLibrary() {
return l;
}
static ItemLibrary* BuildItemLibrary() {
ItemLibrary *TestLibrary::BuildItemLibrary() {
auto l = new ItemLibrary();
return l;
}
static GrowthRateLibrary* BuildGrowthRateLibrary() {
GrowthRateLibrary *TestLibrary::BuildGrowthRateLibrary() {
auto l = new GrowthRateLibrary();
return l;
}
static TypeLibrary* BuildTypeLibrary() {
TypeLibrary *TestLibrary::BuildTypeLibrary() {
auto l = new TypeLibrary();
l->RegisterType("testType1");
l->RegisterType("testType2");
@ -49,18 +60,4 @@ static TypeLibrary* BuildTypeLibrary() {
return l;
}
static BattleLibrary* BuildLibrary() {
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(), BuildItemLibrary(),
BuildGrowthRateLibrary(), BuildTypeLibrary());
auto statCalc = new BattleStatCalculator();
auto battleLib = new BattleLibrary(l, statCalc, new DamageLibrary(), new CriticalLibrary(), new ScriptResolver());
return battleLib;
}
[[maybe_unused]] static BattleLibrary* GetLibrary() {
if (__library == nullptr) {
__library = BuildLibrary();
}
return __library;
}
#endif

View File

@ -0,0 +1,24 @@
#ifndef CREATURELIB_TESTLIBRARY_HPP
#define CREATURELIB_TESTLIBRARY_HPP
#include "../../src/Battling/Library/BattleLibrary.hpp"
using namespace CreatureLib::Core;
using namespace CreatureLib::Library;
using namespace CreatureLib::Battling;
class TestLibrary{
static BattleLibrary* _library;
public:
static SpeciesLibrary* BuildSpeciesLibrary();
static AttackLibrary* BuildAttackLibrary();
static ItemLibrary* BuildItemLibrary();
static GrowthRateLibrary* BuildGrowthRateLibrary();
static TypeLibrary* BuildTypeLibrary();
static BattleLibrary* Get();
};
#endif //CREATURELIB_TESTLIBRARY_HPP