2019-10-06 11:50:52 +00:00
|
|
|
#ifdef TESTS_BUILD
|
2020-09-25 10:43:08 +00:00
|
|
|
#include "../../extern/doctest.hpp"
|
2021-08-28 17:05:52 +00:00
|
|
|
#include "../../src/Battling/Models/Battle.hpp"
|
2019-10-24 11:37:55 +00:00
|
|
|
#include "../../src/Battling/Models/CreateCreature.hpp"
|
2019-12-07 12:45:44 +00:00
|
|
|
#include "../TestLibrary/TestLibrary.hpp"
|
2019-10-06 11:50:52 +00:00
|
|
|
|
2020-04-10 18:09:15 +00:00
|
|
|
using namespace CreatureLib::Battling;
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Create basic creature") {
|
2019-12-07 12:45:44 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
2019-10-06 11:50:52 +00:00
|
|
|
delete creature;
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Get creature species") {
|
2019-12-07 12:45:44 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
2020-02-27 17:23:23 +00:00
|
|
|
REQUIRE(creature->GetSpecies()->GetName() == "testSpecies1"_cnc);
|
2019-10-06 11:50:52 +00:00
|
|
|
delete creature;
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Get creature level") {
|
2019-12-07 12:45:44 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
2019-10-06 11:50:52 +00:00
|
|
|
REQUIRE(creature->GetLevel() == 1);
|
|
|
|
delete creature;
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Get creature variant when unset") {
|
2019-12-07 12:45:44 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
2019-10-06 11:50:52 +00:00
|
|
|
REQUIRE(creature->GetVariant()->GetName() == "default");
|
|
|
|
delete creature;
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Get creature nickname when unset") {
|
2019-12-07 12:45:44 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-08-28 10:23:18 +00:00
|
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).WithNickname("foo").Create();
|
|
|
|
REQUIRE(creature->GetNickname() == "foo");
|
2019-10-06 11:50:52 +00:00
|
|
|
delete creature;
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Increase creature stat boost") {
|
2020-01-05 13:25:48 +00:00
|
|
|
auto library = TestLibrary::Get();
|
2020-04-10 14:44:25 +00:00
|
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
2020-03-22 09:11:53 +00:00
|
|
|
creature->ChangeStatBoost(CreatureLib::Library::Statistic::PhysicalAttack, 6);
|
|
|
|
REQUIRE(creature->GetStatBoost(CreatureLib::Library::Statistic::PhysicalAttack) == 6);
|
2020-01-05 13:25:48 +00:00
|
|
|
delete creature;
|
|
|
|
}
|
|
|
|
|
2020-09-25 10:43:08 +00:00
|
|
|
TEST_CASE("Override Creature talent") {
|
2020-08-01 08:27:46 +00:00
|
|
|
auto library = TestLibrary::Get();
|
|
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
|
|
|
creature->OverrideActiveTalent("foobar");
|
|
|
|
REQUIRE(creature->GetActiveTalent() == "foobar");
|
|
|
|
delete creature;
|
|
|
|
}
|
|
|
|
|
2021-08-28 17:05:52 +00:00
|
|
|
TEST_CASE("Creature can be deleted before battle is deleted") {
|
|
|
|
// This should not happen during normal battle executions, but can happen for certain GC solutions. We should not
|
|
|
|
// segfault in this case, but deal with it properly.
|
|
|
|
auto library = TestLibrary::Get();
|
|
|
|
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();
|
|
|
|
auto battle = new Battle(library, {});
|
|
|
|
auto side = battle->GetSides()[0];
|
|
|
|
side->SetCreature(creature, 0);
|
|
|
|
delete creature;
|
|
|
|
delete battle;
|
|
|
|
}
|
|
|
|
|
2019-10-06 11:50:52 +00:00
|
|
|
#endif
|