From 0798ef4b2a107a028d32d55434de318c09aab65e Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Sat, 8 Aug 2015 21:04:07 +0300 Subject: [PATCH] Advance MapComparer --- test/CMapFormatTest.cpp | 5 ++- test/MapComparer.cpp | 72 +++++++++++++++++++++++++++++++++++++++-- test/MapComparer.h | 12 ++++++- 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/test/CMapFormatTest.cpp b/test/CMapFormatTest.cpp index 0ee617ea7..d74288f4f 100644 --- a/test/CMapFormatTest.cpp +++ b/test/CMapFormatTest.cpp @@ -62,9 +62,8 @@ BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple) std::unique_ptr serialized = loader.loadMap(); - MapComparer c; - - BOOST_REQUIRE_MESSAGE(c(initialMap, serialized), "Serialize cycle failed"); + MapComparer c; + c(initialMap, serialized); } catch(const std::exception & e) { diff --git a/test/MapComparer.cpp b/test/MapComparer.cpp index c2806f648..75730b26b 100644 --- a/test/MapComparer.cpp +++ b/test/MapComparer.cpp @@ -13,8 +13,74 @@ #include "MapComparer.h" -bool MapComparer::operator() (const std::unique_ptr& lhs, const std::unique_ptr& rhs) +#define VCMI_CHECK_FIELD_EQUAL(field) BOOST_CHECK_EQUAL(actual->field, expected->field) + +std::ostream& operator<< (std::ostream& os, const PlayerInfo & p) { - BOOST_ERROR(" MapComparer::operator() not implemented"); - return false; + os << "PlayerInfo"; + return os; +} + +bool operator!=(const PlayerInfo & actual, const PlayerInfo & expected) +{ + + + return true; +} + +void MapComparer::compareHeader() +{ + VCMI_CHECK_FIELD_EQUAL(name); + VCMI_CHECK_FIELD_EQUAL(description); + VCMI_CHECK_FIELD_EQUAL(difficulty); + VCMI_CHECK_FIELD_EQUAL(levelLimit); + + VCMI_CHECK_FIELD_EQUAL(victoryMessage); + VCMI_CHECK_FIELD_EQUAL(defeatMessage); + VCMI_CHECK_FIELD_EQUAL(victoryIconIndex); + VCMI_CHECK_FIELD_EQUAL(defeatIconIndex); + + BOOST_CHECK_EQUAL_COLLECTIONS(actual->players.begin(), actual->players.end(), expected->players.begin(), expected->players.end()); + + + //map size parameters are vital for further checks + BOOST_REQUIRE_EQUAL(actual->height, expected->height); + BOOST_REQUIRE_EQUAL(actual->width, expected->width); + BOOST_REQUIRE_EQUAL(actual->twoLevel, expected->twoLevel); + + BOOST_FAIL("Not implemented"); +} + +void MapComparer::compareOptions() +{ + BOOST_FAIL("Not implemented"); +} + +void MapComparer::compareObjects() +{ + BOOST_FAIL("Not implemented"); +} + +void MapComparer::compareTerrain() +{ + BOOST_FAIL("Not implemented"); +} + +void MapComparer::compare() +{ + BOOST_REQUIRE_NE((void *) actual, (void *) expected); //should not point to the same object + BOOST_REQUIRE_MESSAGE(actual != nullptr, "Actual map is not defined"); + BOOST_REQUIRE_MESSAGE(actual != nullptr, "Expected map is not defined"); + + compareHeader(); + compareObjects(); + compareOptions(); + compareTerrain(); +} + +void MapComparer::operator() (const std::unique_ptr& actual, const std::unique_ptr& expected) +{ + this->actual = actual.get(); + this->expected = expected.get(); + compare(); } diff --git a/test/MapComparer.h b/test/MapComparer.h index 9e1e26424..4720a37f1 100644 --- a/test/MapComparer.h +++ b/test/MapComparer.h @@ -14,7 +14,17 @@ struct MapComparer { - bool operator() (const std::unique_ptr& lhs, const std::unique_ptr& rhs); + const CMap * actual; + const CMap * expected; + + void compareHeader(); + void compareOptions(); + void compareObjects(); + void compareTerrain(); + + void compare(); + + void operator() (const std::unique_ptr& actual, const std::unique_ptr& expected); };