From: John Janus Date: Tue, 13 Aug 2019 22:27:28 +0000 (+0200) Subject: trying to test X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=963d12e9010ed0d859213328f6c1e5e68884194b;p=splittermond-assistant.git trying to test --- diff --git a/splittermond-assistant-tests/splittermond-assistant-tests.pro b/splittermond-assistant-tests/splittermond-assistant-tests.pro index d2d7b7f..6a8fde5 100644 --- a/splittermond-assistant-tests/splittermond-assistant-tests.pro +++ b/splittermond-assistant-tests/splittermond-assistant-tests.pro @@ -5,5 +5,15 @@ CONFIG += qt console warn_on depend_includepath testcase CONFIG -= app_bundle TEMPLATE = app +include(../qmake-destination-path.pri) +include(../qmake-target-platform.pri) +INCLUDEPATH += ../splittermond-assistant/src +DEPENDPATH += ../splittermond-assistant/src SOURCES += tst_test.cpp + +DESTDIR = $$PWD/../binaries/$$DESTINATION_PATH +OBJECTS_DIR = $$PWD/build/$$DESTINATION_PATH/.obj +MOC_DIR = $$PWD/build/$$DESTINATION_PATH/.moc +RCC_DIR = $$PWD/build/$$DESTINATION_PATH/.qrc +UI_DIR = $$PWD/build/$$DESTINATION_PATH/.ui diff --git a/splittermond-assistant-tests/tst_test.cpp b/splittermond-assistant-tests/tst_test.cpp index 91bf4ed..7a0132b 100644 --- a/splittermond-assistant-tests/tst_test.cpp +++ b/splittermond-assistant-tests/tst_test.cpp @@ -1,4 +1,6 @@ #include +#include +#include "character.h" // add necessary includes here @@ -39,9 +41,9 @@ void Test::cleanupTestCase() void Test::test_case1() { - + QVERIFY_EXCEPTION_THROWN (sm::data::Character c{12, 12}, std::invalid_argument); } -QTEST_APPLESS_MAIN(Test) +QTEST_APPLESS_MAIN (Test) #include "tst_test.moc" diff --git a/splittermond-assistant/src/character.cpp b/splittermond-assistant/src/character.cpp index 3e63414..6fbe87d 100644 --- a/splittermond-assistant/src/character.cpp +++ b/splittermond-assistant/src/character.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include namespace sm::data { @@ -14,14 +16,43 @@ public: ~CharacterData() {} unsigned int life = 0; - const std::vector damage; - const std::unordered_map skills; - const std::unordered_map attributes; + std::vector damage; + std::unordered_map skills; + std::unordered_map attributes; }; -Character::Character () : d{new Character::CharacterData} +Character::Character (std::initializer_list list) : d{new Character::CharacterData} { + if (list.size() != 54) throw std::invalid_argument (std::string ("Not exactly 54 arguments!") ); + unsigned int ctr = 0; + for (auto val : list) { + if (ctr < 8) d->attributes.insert ({Attribute{ctr}, val}); + else if (ctr >= 8 && ctr < 53) d->skills.insert ({Skill{ctr - 8}, val}); + else if (ctr == 53) d->life = val; + else throw std::invalid_argument ("Found an argument that should not have been there!"); + ctr++; + } +} + +Character::Character (QFile* file) : d{new Character::CharacterData} +{ + +} + +Character::Character (const Character& other) : d (other.d) {} +Character::Character (Character&& other) : d (other.d) {} + +Character& Character::operator= (const Character& other) +{ + d = other.d; + return *this; +} + +Character& Character::operator= (Character&& other) +{ + d.swap (other.d); + return *this; } Character::~Character() diff --git a/splittermond-assistant/src/character.h b/splittermond-assistant/src/character.h index 2b013a6..d2fb51d 100644 --- a/splittermond-assistant/src/character.h +++ b/splittermond-assistant/src/character.h @@ -3,10 +3,12 @@ #include #include +#include +#include namespace sm::data { -enum Skill { +enum Skill : unsigned int { acrobatics, alchemy, leadership, @@ -55,7 +57,7 @@ enum Skill { windmagic }; -enum Attribute { +enum Attribute : unsigned int { charisma, agility, intuition, @@ -66,7 +68,7 @@ enum Attribute { willpower }; -enum Damage { +enum Damage : unsigned int { canalised, exhausted, used @@ -124,7 +126,14 @@ static const std::unordered_map> skillAtt class Character { public: - explicit Character (); + explicit Character (std::initializer_list); + explicit Character (QFile* file); + Character (const Character&); //Copy Constructor + Character (Character&&); //Move Constructor + + Character& operator= (const Character&); //Copy Assignment + Character& operator= (Character&&); //Move Assignment + virtual ~Character(); unsigned int skill (Skill skill) const; unsigned int attribute (Attribute attribute) const;