From a3c3f935b911a9f36adab2d1d44c3d85faf0643c Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sat, 15 Aug 2015 20:25:40 +0300 Subject: [PATCH] Advance map checks --- test/MapComparer.cpp | 83 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/test/MapComparer.cpp b/test/MapComparer.cpp index da47ba757..6afb570b2 100644 --- a/test/MapComparer.cpp +++ b/test/MapComparer.cpp @@ -19,25 +19,73 @@ #define VCMI_REQUIRE_FIELD_EQUAL(field) BOOST_REQUIRE_EQUAL(actual->field, expected->field) -std::ostream& operator<< (std::ostream& os, const PlayerInfo & value) +template +void checkEqual(const T & actual, const T & expected) { - os << "PlayerInfo"; - return os; + BOOST_CHECK_EQUAL(actual, expected) ; } -//std::ostream& operator<< (std::ostream& os, const std::set & value) -//{ -// os << "'Set'"; -// return os; -//} +template +void checkEqual(const std::vector & actual, const std::vector & expected) +{ + BOOST_CHECK_EQUAL(actual.size(), expected.size()); + + for(auto actualIt = actual.begin(), expectedIt = expected.begin(); actualIt != actual.end() && expectedIt != expected.end(); actualIt++, expectedIt++) + { + checkEqual(*actualIt, *expectedIt); + } +} -bool operator!=(const PlayerInfo & actual, const PlayerInfo & expected) +template +void checkEqual(const std::set & actual, const std::set & expected) +{ + BOOST_CHECK_EQUAL(actual.size(), expected.size()); + + for(auto elem : expected) + { + if(!vstd::contains(actual, elem)) + BOOST_ERROR("Required element not found "+boost::to_string(elem)); + } +} + +void checkEqual(const PlayerInfo & actual, const PlayerInfo & expected) { VCMI_CHECK_FIELD_EQUAL(canHumanPlay); VCMI_CHECK_FIELD_EQUAL(canComputerPlay); VCMI_CHECK_FIELD_EQUAL(aiTactic); - //VCMI_CHECK_FIELD_EQUAL(allowedFactions); - return false; + + checkEqual(actual.allowedFactions, expected.allowedFactions); + + VCMI_CHECK_FIELD_EQUAL(isFactionRandom); + VCMI_CHECK_FIELD_EQUAL(mainCustomHeroPortrait); + VCMI_CHECK_FIELD_EQUAL(mainCustomHeroName); + + VCMI_CHECK_FIELD_EQUAL(mainCustomHeroId); + + //todo:heroesNames + + VCMI_CHECK_FIELD_EQUAL(hasMainTown); + VCMI_CHECK_FIELD_EQUAL(generateHeroAtMainTown); + VCMI_CHECK_FIELD_EQUAL(posOfMainTown); + VCMI_CHECK_FIELD_EQUAL(team); + VCMI_CHECK_FIELD_EQUAL(hasRandomHero); + +} + +void checkEqual(const EventExpression & actual, const EventExpression & expected) +{ + //todo: checkEventExpression +} + +void checkEqual(const TriggeredEvent & actual, const TriggeredEvent & expected) +{ + VCMI_CHECK_FIELD_EQUAL(identifier); + VCMI_CHECK_FIELD_EQUAL(description); + VCMI_CHECK_FIELD_EQUAL(onFulfill); + VCMI_CHECK_FIELD_EQUAL(effect.type); + VCMI_CHECK_FIELD_EQUAL(effect.toOtherMessage); + + checkEqual(actual.trigger, expected.trigger); } void MapComparer::compareHeader() @@ -57,13 +105,22 @@ void MapComparer::compareHeader() VCMI_CHECK_FIELD_EQUAL_P(victoryIconIndex); VCMI_CHECK_FIELD_EQUAL_P(defeatIconIndex); - BOOST_CHECK_EQUAL_COLLECTIONS(actual->players.begin(), actual->players.end(), expected->players.begin(), expected->players.end()); + checkEqual(actual->players, expected->players); + + //todo: allowedHeroes, placeholdedHeroes - BOOST_ERROR("Not implemented"); + checkEqual(actual->triggeredEvents, expected->triggeredEvents); } void MapComparer::compareOptions() { + //rumors + //disposedHeroes + //predefinedHeroes + //allowedSpell + //allowedArtifact + //allowedAbilities + BOOST_ERROR("Not implemented"); }