Unit tests for EffectParameters.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-04-10 20:09:15 +02:00
parent e934e13950
commit d2320fde3c
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 28 additions and 4 deletions

View File

@ -14,9 +14,10 @@ namespace CreatureLib::Library {
public:
EffectParameter() : _type(EffectParameterType::None), _val(nullptr){};
EffectParameter(bool b) : _type(EffectParameterType::Bool), _val((void*)b){};
EffectParameter(int64_t i) : _type(EffectParameterType::Int), _val((void*)i){};
EffectParameter(const std::string& s) : _type(EffectParameterType::String), _val(new char[s.size() + 1]) {
explicit EffectParameter(bool b) : _type(EffectParameterType::Bool), _val((void*)b){};
explicit EffectParameter(int64_t i) : _type(EffectParameterType::Int), _val((void*)i){};
explicit EffectParameter(const std::string& s)
: _type(EffectParameterType::String), _val(new char[s.size() + 1]) {
strncpy((char*)_val, s.c_str(), s.size() + 1);
};
EffectParameter(const EffectParameter& other) = delete;

View File

@ -3,7 +3,7 @@
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../TestLibrary/TestLibrary.hpp"
using namespace CreatureLib::Library;
using namespace CreatureLib::Battling;
TEST_CASE("Create basic creature", "[Library]") {
auto library = TestLibrary::Get();
auto creature = CreateCreature(library, "testSpecies1"_cnc, 1).Create();

View File

@ -0,0 +1,23 @@
#ifdef TESTS_BUILD
#include "../../extern/catch.hpp"
#include "../../src/Library/EffectParameter.hpp"
using namespace CreatureLib::Library;
TEST_CASE("Bool EffectParameter", "[Library]") {
auto p = EffectParameter(true);
REQUIRE(p.AsBool());
auto p2 = EffectParameter(false);
REQUIRE_FALSE(p2.AsBool());
}
TEST_CASE("Int EffectParameter", "[Library]") {
auto p = EffectParameter((int64_t)684);
REQUIRE(p.AsInt() == 684);
}
TEST_CASE("String EffectParameter", "[Library]") {
auto p = EffectParameter(std::string("foobar"));
REQUIRE(strcmp(p.AsString(), "foobar") == 0);
}
#endif