1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Migrating from boost test to google test.

This commit is contained in:
FeniksFire 2017-07-04 13:29:50 +02:00
parent 8314e8234f
commit a71c9d0751
12 changed files with 248 additions and 262 deletions

View File

@ -1,125 +0,0 @@
/*
* Battlefield.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include <boost/test/unit_test.hpp>
#include "../lib/battle/BattleHex.h"
BOOST_AUTO_TEST_SUITE(BattlefieldHex_Suite)
BOOST_AUTO_TEST_CASE(getNeighbouringTiles)
{
BattleHex mainHex;
std::vector<BattleHex> neighbouringTiles;
mainHex.setXY(16,0);
neighbouringTiles = mainHex.neighbouringTiles();
BOOST_TEST(neighbouringTiles.size()==1);
mainHex.setXY(0,0);
neighbouringTiles = mainHex.neighbouringTiles();
BOOST_TEST(neighbouringTiles.size()==2);
mainHex.setXY(15,2);
neighbouringTiles = mainHex.neighbouringTiles();
BOOST_TEST(neighbouringTiles.size()==3);
mainHex.setXY(2,0);
neighbouringTiles = mainHex.neighbouringTiles();
BOOST_TEST(neighbouringTiles.size()==4);
mainHex.setXY(1,2);
neighbouringTiles = mainHex.neighbouringTiles();
BOOST_TEST(neighbouringTiles.size()==5);
mainHex.setXY(8,5);
neighbouringTiles = mainHex.neighbouringTiles();
BOOST_TEST(neighbouringTiles.size()==6);
BOOST_REQUIRE(neighbouringTiles.size()==6 && mainHex==93);
BOOST_TEST(neighbouringTiles.at(0)==75);
BOOST_TEST(neighbouringTiles.at(1)==76);
BOOST_TEST(neighbouringTiles.at(2)==94);
BOOST_TEST(neighbouringTiles.at(3)==110);
BOOST_TEST(neighbouringTiles.at(4)==109);
BOOST_TEST(neighbouringTiles.at(5)==92);
}
BOOST_AUTO_TEST_CASE(getDistance)
{
BattleHex firstHex(0,0), secondHex(16,0);
BOOST_TEST((int)firstHex.getDistance(firstHex,secondHex)==16);
firstHex=0, secondHex=170;
BOOST_TEST((int)firstHex.getDistance(firstHex,secondHex)==10);
firstHex=16, secondHex=181;
BOOST_TEST((int)firstHex.getDistance(firstHex,secondHex)==10);
firstHex=186, secondHex=70;
BOOST_TEST((int)firstHex.getDistance(firstHex,secondHex)==17);
firstHex=166, secondHex=39;
BOOST_TEST((int)firstHex.getDistance(firstHex,secondHex)==11);
firstHex=25, secondHex=103;
BOOST_TEST((int)firstHex.getDistance(firstHex,secondHex)==9);
firstHex=18, secondHex=71;
BOOST_TEST((int)firstHex.getDistance(firstHex,secondHex)==4);
}
BOOST_AUTO_TEST_CASE(mutualPositions)
{
BattleHex firstHex(0,0), secondHex(16,0);
firstHex=86, secondHex=68;
BOOST_TEST((int)firstHex.mutualPosition(firstHex,secondHex)==0);
secondHex=69;
BOOST_TEST((int)firstHex.mutualPosition(firstHex,secondHex)==1);
secondHex=87;
BOOST_TEST((int)firstHex.mutualPosition(firstHex,secondHex)==2);
secondHex=103;
BOOST_TEST((int)firstHex.mutualPosition(firstHex,secondHex)==3);
secondHex=102;
BOOST_TEST((int)firstHex.mutualPosition(firstHex,secondHex)==4);
secondHex=85;
BOOST_TEST((int)firstHex.mutualPosition(firstHex,secondHex)==5);
secondHex=46;
BOOST_TEST((int)firstHex.mutualPosition(firstHex,secondHex)==-1);
}
BOOST_AUTO_TEST_CASE(getClosestTile)
{
BattleHex mainHex(0);
std::set<BattleHex> possibilities;
possibilities.insert(3);
possibilities.insert(170);
possibilities.insert(100);
possibilities.insert(119);
possibilities.insert(186);
BOOST_TEST(mainHex.getClosestTile(0,mainHex,possibilities)==3);
mainHex = 139;
BOOST_TEST(mainHex.getClosestTile(1,mainHex,possibilities)==119);
mainHex = 16;
BOOST_TEST(mainHex.getClosestTile(1,mainHex,possibilities)==100);
mainHex = 166;
BOOST_TEST(mainHex.getClosestTile(0,mainHex,possibilities)==186);
mainHex = 76;
BOOST_TEST(mainHex.getClosestTile(1,mainHex,possibilities)==3);
BOOST_TEST(mainHex.getClosestTile(0,mainHex,possibilities)==100);
}
BOOST_AUTO_TEST_CASE(moveEDir)
{
BattleHex mainHex(20);
mainHex.moveInDirection(BattleHex::EDir::BOTTOM_RIGHT);
BOOST_TEST(mainHex==37);
mainHex.moveInDirection(BattleHex::EDir::RIGHT);
BOOST_TEST(mainHex==38);
mainHex.moveInDirection(BattleHex::EDir::TOP_RIGHT);
BOOST_TEST(mainHex==22);
mainHex.moveInDirection(BattleHex::EDir::TOP_LEFT);
BOOST_TEST(mainHex==4);
mainHex.moveInDirection(BattleHex::EDir::LEFT);
BOOST_TEST(mainHex==3);
mainHex.moveInDirection(BattleHex::EDir::BOTTOM_LEFT);
BOOST_TEST(mainHex==20);
mainHex.moveInDirection(BattleHex::EDir::NONE);
BOOST_TEST(mainHex==20);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -3,28 +3,32 @@ project(test)
enable_testing()
include_directories(${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/include ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_HOME_DIRECTORY}/test)
include_directories(${Boost_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR})
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
set(test_SRCS
StdInc.cpp
Battlefield.cpp
CMapEditManagerTest.cpp
CMapFormatTest.cpp
main.cpp
CMemoryBufferTest.cpp
CVcmiTestConfig.cpp
MapComparer.cpp
battle/BattleHexTest.cpp
battle/CHealthTest.cpp
map/CMapEditManagerTest.cpp
map/CMapFormatTest.cpp
map/MapComparer.cpp
)
set(test_HEADERS
StdInc.h
CVcmiTestConfig.h
MapComparer.h
map/MapComparer.h
)
add_executable(vcmitest ${test_SRCS} ${test_HEADERS})
target_link_libraries(vcmitest vcmi ${Boost_LIBRARIES} ${RT_LIB} ${DL_LIB})
target_link_libraries(vcmitest vcmi gtest ${RT_LIB} ${DL_LIB})
add_test(vcmitest vcmitest)
vcmi_set_output_dir(vcmitest "")

View File

@ -7,46 +7,40 @@
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include <boost/test/unit_test.hpp>
#include "../lib/filesystem/CMemoryBuffer.h"
struct CMemoryBufferFixture
struct CMemoryBufferTest : testing::Test
{
CMemoryBuffer subject;
};
BOOST_AUTO_TEST_SUITE(CMemoryBuffer_Suite)
BOOST_FIXTURE_TEST_CASE(empty, CMemoryBufferFixture)
TEST_F(CMemoryBufferTest, empty)
{
BOOST_REQUIRE_EQUAL(0, subject.tell());
BOOST_REQUIRE_EQUAL(0, subject.getSize());
EXPECT_EQ(subject.tell(), 0);
EXPECT_EQ(subject.getSize(), 0);
si32 dummy = 1337;
auto ret = subject.read((ui8 *)&dummy, sizeof(si32));
BOOST_CHECK_EQUAL(0, ret);
BOOST_CHECK_EQUAL(1337, dummy);
BOOST_CHECK_EQUAL(0, subject.tell());
EXPECT_EQ(ret, 0);
EXPECT_EQ(dummy, 1337);
EXPECT_EQ(subject.tell(), 0);
}
BOOST_FIXTURE_TEST_CASE(write, CMemoryBufferFixture)
TEST_F(CMemoryBufferTest, write)
{
const si32 initial = 1337;
subject.write((const ui8 *)&initial, sizeof(si32));
BOOST_CHECK_EQUAL(4, subject.tell());
EXPECT_EQ(subject.tell(), 4);
subject.seek(0);
BOOST_CHECK_EQUAL(0, subject.tell());
EXPECT_EQ(subject.tell(), 0);
si32 current = 0;
auto ret = subject.read((ui8 *)&current, sizeof(si32));
BOOST_CHECK_EQUAL(sizeof(si32), ret);
BOOST_CHECK_EQUAL(initial, current);
BOOST_CHECK_EQUAL(4, subject.tell());
EXPECT_EQ(ret, sizeof(si32));
EXPECT_EQ(current, initial);
EXPECT_EQ(subject.tell(), 4);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -47,3 +47,4 @@ CVcmiTestConfig::~CVcmiTestConfig()
{
std::cout << "Ending global test tear-down." << std::endl;
}

View File

@ -1,10 +1,12 @@
/*
* StdInc.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
// Creates the precompiled header
#include "StdInc.h"
#ifndef _MSC_VER
// Should be defined only once, before #include of unit test header
#define BOOST_TEST_MODULE VcmiTest
#include <boost/test/unit_test.hpp>
#include "CVcmiTestConfig.h"
BOOST_GLOBAL_FIXTURE(CVcmiTestConfig);
#endif

View File

@ -1,16 +1,13 @@
/*
* StdInc.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../Global.h"
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#define BOOST_TEST_DYN_LINK
#endif
#ifdef _MSC_VER
#define BOOST_TEST_MODULE VcmiTest
#include <boost/test/unit_test.hpp>
#include "CVcmiTestConfig.h"
BOOST_GLOBAL_FIXTURE(CVcmiTestConfig);
#endif
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "Global.h"

View File

@ -0,0 +1,118 @@
/*
* BattleHexTest.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "../lib/battle/BattleHex.h"
TEST(BattleHexTest, getNeighbouringTiles){
BattleHex mainHex;
std::vector<BattleHex> neighbouringTiles;
mainHex.setXY(16,0);
neighbouringTiles = mainHex.neighbouringTiles();
EXPECT_EQ(neighbouringTiles.size(), 1);
mainHex.setXY(0,0);
neighbouringTiles = mainHex.neighbouringTiles();
EXPECT_EQ(neighbouringTiles.size(), 2);
mainHex.setXY(15,2);
neighbouringTiles = mainHex.neighbouringTiles();
EXPECT_EQ(neighbouringTiles.size(), 3);
mainHex.setXY(2,0);
neighbouringTiles = mainHex.neighbouringTiles();
EXPECT_EQ(neighbouringTiles.size(), 4);
mainHex.setXY(1,2);
neighbouringTiles = mainHex.neighbouringTiles();
EXPECT_EQ(neighbouringTiles.size(), 5);
mainHex.setXY(8,5);
neighbouringTiles = mainHex.neighbouringTiles();
EXPECT_EQ(neighbouringTiles.size(), 6);
ASSERT_TRUE(neighbouringTiles.size()==6 && mainHex==93);
EXPECT_EQ(neighbouringTiles.at(0), 75);
EXPECT_EQ(neighbouringTiles.at(1), 76);
EXPECT_EQ(neighbouringTiles.at(2), 94);
EXPECT_EQ(neighbouringTiles.at(3), 110);
EXPECT_EQ(neighbouringTiles.at(4), 109);
EXPECT_EQ(neighbouringTiles.at(5), 92);
}
TEST(BattleHexTest, getDistance){
BattleHex firstHex(0,0), secondHex(16,0);
EXPECT_EQ((int)firstHex.getDistance(firstHex,secondHex), 16);
firstHex=0, secondHex=170;
EXPECT_EQ((int)firstHex.getDistance(firstHex,secondHex), 10);
firstHex=16, secondHex=181;
EXPECT_EQ((int)firstHex.getDistance(firstHex,secondHex), 10);
firstHex=186, secondHex=70;
EXPECT_EQ((int)firstHex.getDistance(firstHex,secondHex), 17);
firstHex=166, secondHex=39;
EXPECT_EQ((int)firstHex.getDistance(firstHex,secondHex), 11);
firstHex=25, secondHex=103;
EXPECT_EQ((int)firstHex.getDistance(firstHex,secondHex), 9);
firstHex=18, secondHex=71;
EXPECT_EQ((int)firstHex.getDistance(firstHex,secondHex), 4);
}
TEST(BattleHexTest, mutualPositions)
{
BattleHex firstHex(0,0), secondHex(16,0);
firstHex=86, secondHex=68;
EXPECT_EQ((int)firstHex.mutualPosition(firstHex,secondHex), BattleHex::EDir::TOP_LEFT);
secondHex=69;
EXPECT_EQ((int)firstHex.mutualPosition(firstHex,secondHex), BattleHex::EDir::TOP_RIGHT);
secondHex=87;
EXPECT_EQ((int)firstHex.mutualPosition(firstHex,secondHex), BattleHex::EDir::RIGHT);
secondHex=103;
EXPECT_EQ((int)firstHex.mutualPosition(firstHex,secondHex), BattleHex::EDir::BOTTOM_RIGHT);
secondHex=102;
EXPECT_EQ((int)firstHex.mutualPosition(firstHex,secondHex), BattleHex::EDir::BOTTOM_LEFT);
secondHex=85;
EXPECT_EQ((int)firstHex.mutualPosition(firstHex,secondHex), BattleHex::EDir::LEFT);
secondHex=46;
EXPECT_EQ((int)firstHex.mutualPosition(firstHex,secondHex), -1);
}
TEST(BattleHexTest, getClosestTile)
{
BattleHex mainHex(0);
std::set<BattleHex> possibilities;
possibilities.insert(3);
possibilities.insert(170);
possibilities.insert(100);
possibilities.insert(119);
possibilities.insert(186);
EXPECT_EQ(mainHex.getClosestTile(0,mainHex,possibilities), 3);
mainHex = 139;
EXPECT_EQ(mainHex.getClosestTile(1,mainHex,possibilities), 119);
mainHex = 16;
EXPECT_EQ(mainHex.getClosestTile(1,mainHex,possibilities), 100);
mainHex = 166;
EXPECT_EQ(mainHex.getClosestTile(0,mainHex,possibilities), 186);
mainHex = 76;
EXPECT_EQ(mainHex.getClosestTile(1,mainHex,possibilities), 3);
EXPECT_EQ(mainHex.getClosestTile(0,mainHex,possibilities), 100);
}
TEST(BattleHexTest, moveEDir)
{
BattleHex mainHex(20);
mainHex.moveInDirection(BattleHex::EDir::BOTTOM_RIGHT);
EXPECT_EQ(mainHex, 37);
mainHex.moveInDirection(BattleHex::EDir::RIGHT);
EXPECT_EQ(mainHex, 38);
mainHex.moveInDirection(BattleHex::EDir::TOP_RIGHT);
EXPECT_EQ(mainHex, 22);
mainHex.moveInDirection(BattleHex::EDir::TOP_LEFT);
EXPECT_EQ(mainHex, 4);
mainHex.moveInDirection(BattleHex::EDir::LEFT);
EXPECT_EQ(mainHex, 3);
mainHex.moveInDirection(BattleHex::EDir::BOTTOM_LEFT);
EXPECT_EQ(mainHex, 20);
}

19
test/main.cpp Normal file
View File

@ -0,0 +1,19 @@
/*
* main.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "CVcmiTestConfig.h"
#include "../lib/filesystem/CMemoryBuffer.h"
int main(int argc, char ** argv){
::testing::InitGoogleTest(&argc, argv);
CVcmiTestConfig test;
return RUN_ALL_TESTS();
}

View File

@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include <boost/test/unit_test.hpp>
#include "../lib/filesystem/ResourceID.h"
#include "../lib/mapping/CMapService.h"
@ -20,9 +19,8 @@
#include "../lib/CRandomGenerator.h"
#include "../lib/VCMI_Lib.h"
BOOST_AUTO_TEST_SUITE(CMapEditManager_Suite)
BOOST_AUTO_TEST_CASE(DrawTerrain_Type)
TEST(MapManager, DrawTerrain_Type)
{
logGlobal->info("CMapEditManager_DrawTerrain_Type start");
try
@ -40,17 +38,17 @@ BOOST_AUTO_TEST_CASE(DrawTerrain_Type)
static const int3 squareCheck[] = { int3(5,5,0), int3(5,4,0), int3(4,4,0), int3(4,5,0) };
for(int i = 0; i < ARRAY_COUNT(squareCheck); ++i)
{
BOOST_CHECK(map->getTile(squareCheck[i]).terType == ETerrainType::GRASS);
EXPECT_EQ(map->getTile(squareCheck[i]).terType, ETerrainType::GRASS);
}
// Concat to square
editManager->getTerrainSelection().select(int3(6, 5, 0));
editManager->drawTerrain(ETerrainType::GRASS);
BOOST_CHECK(map->getTile(int3(6, 4, 0)).terType == ETerrainType::GRASS);
EXPECT_EQ(map->getTile(int3(6, 4, 0)).terType, ETerrainType::GRASS);
editManager->getTerrainSelection().select(int3(6, 5, 0));
editManager->drawTerrain(ETerrainType::LAVA);
BOOST_CHECK(map->getTile(int3(4, 4, 0)).terType == ETerrainType::GRASS);
BOOST_CHECK(map->getTile(int3(7, 4, 0)).terType == ETerrainType::LAVA);
EXPECT_EQ(map->getTile(int3(4, 4, 0)).terType, ETerrainType::GRASS);
EXPECT_EQ(map->getTile(int3(7, 4, 0)).terType, ETerrainType::LAVA);
// Special case water,rock
editManager->getTerrainSelection().selectRange(MapRect(int3(10, 10, 0), 10, 5));
@ -59,7 +57,7 @@ BOOST_AUTO_TEST_CASE(DrawTerrain_Type)
editManager->drawTerrain(ETerrainType::GRASS);
editManager->getTerrainSelection().select(int3(21, 16, 0));
editManager->drawTerrain(ETerrainType::GRASS);
BOOST_CHECK(map->getTile(int3(20, 15, 0)).terType == ETerrainType::GRASS);
EXPECT_EQ(map->getTile(int3(20, 15, 0)).terType, ETerrainType::GRASS);
// Special case non water,rock
static const int3 diagonalCheck[] = { int3(31,42,0), int3(32,42,0), int3(32,43,0), int3(33,43,0), int3(33,44,0),
@ -70,7 +68,7 @@ BOOST_AUTO_TEST_CASE(DrawTerrain_Type)
editManager->getTerrainSelection().select(diagonalCheck[i]);
}
editManager->drawTerrain(ETerrainType::GRASS);
BOOST_CHECK(map->getTile(int3(35, 44, 0)).terType == ETerrainType::WATER);
EXPECT_EQ(map->getTile(int3(35, 44, 0)).terType, ETerrainType::WATER);
// Rock case
editManager->getTerrainSelection().selectRange(MapRect(int3(1, 1, 1), 15, 15));
@ -79,7 +77,7 @@ BOOST_AUTO_TEST_CASE(DrawTerrain_Type)
int3(8, 7, 1), int3(4, 8, 1), int3(5, 8, 1), int3(6, 8, 1)});
editManager->getTerrainSelection().setSelection(vec);
editManager->drawTerrain(ETerrainType::ROCK);
BOOST_CHECK(map->getTile(int3(5, 6, 1)).terType == ETerrainType::ROCK || map->getTile(int3(7, 8, 1)).terType == ETerrainType::ROCK);
EXPECT_TRUE(map->getTile(int3(5, 6, 1)).terType == ETerrainType::ROCK || map->getTile(int3(7, 8, 1)).terType == ETerrainType::ROCK);
//todo: add checks here and enable, also use smaller size
#if 0
@ -111,7 +109,7 @@ BOOST_AUTO_TEST_CASE(DrawTerrain_Type)
logGlobal->info("CMapEditManager_DrawTerrain_Type finish");
}
BOOST_AUTO_TEST_CASE(DrawTerrain_View)
TEST(MapManager, DrawTerrain_View)
{
logGlobal->info("CMapEditManager_DrawTerrain_View start");
try
@ -165,7 +163,7 @@ BOOST_AUTO_TEST_CASE(DrawTerrain_View)
break;
}
}
BOOST_CHECK(isInRange);
EXPECT_TRUE(isInRange);
if(!isInRange)
logGlobal->error("No or invalid pattern found for current position.");
}
@ -179,5 +177,3 @@ BOOST_AUTO_TEST_CASE(DrawTerrain_View)
}
logGlobal->info("CMapEditManager_DrawTerrain_View finish");
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -9,8 +9,6 @@
*/
#include "StdInc.h"
#include <boost/test/unit_test.hpp>
#include "../lib/filesystem/CMemoryBuffer.h"
#include "../lib/filesystem/Filesystem.h"
@ -25,12 +23,11 @@
static const int TEST_RANDOM_SEED = 1337;
BOOST_AUTO_TEST_SUITE(MapFormat_Suite)
BOOST_AUTO_TEST_CASE(Random)
TEST(MapFormat, Random)
{
logGlobal->info("MapFormat_Random start");
BOOST_TEST_CHECKPOINT("MapFormat_Random start");
SCOPED_TRACE("MapFormat_Random start");
std::unique_ptr<CMap> initialMap;
CMapGenOptions opt;
@ -49,14 +46,14 @@ BOOST_AUTO_TEST_CASE(Random)
initialMap = gen.generate(&opt, TEST_RANDOM_SEED);
initialMap->name = "Test";
BOOST_TEST_CHECKPOINT("MapFormat_Random generated");
SCOPED_TRACE("MapFormat_Random generated");
CMemoryBuffer serializeBuffer;
{
CMapSaverJson saver(&serializeBuffer);
saver.saveMap(initialMap);
}
BOOST_TEST_CHECKPOINT("MapFormat_Random serialized");
SCOPED_TRACE("MapFormat_Random serialized");
#if 1
{
auto path = VCMIDirs::get().userDataPath()/"test_random.vmap";
@ -70,8 +67,7 @@ BOOST_AUTO_TEST_CASE(Random)
logGlobal->info("Test map has been saved to:");
logGlobal->info(path.string());
}
BOOST_TEST_CHECKPOINT("MapFormat_Random saved");
SCOPED_TRACE("MapFormat_Random saved");
#endif // 1
serializeBuffer.seek(0);
@ -82,7 +78,7 @@ BOOST_AUTO_TEST_CASE(Random)
MapComparer c;
c(serialized, initialMap);
}
SCOPED_TRACE("MapFormat_Random finish");
logGlobal->info("MapFormat_Random finish");
}
@ -116,7 +112,7 @@ static void addToArchive(CZipSaver & saver, const JsonNode & data, const std::st
}
}
BOOST_AUTO_TEST_CASE(Objects)
TEST(MapFormat, Objects)
{
logGlobal->info("MapFormat_Objects start");
@ -203,5 +199,3 @@ BOOST_AUTO_TEST_CASE(Objects)
logGlobal->info("MapFormat_Objects finish");
}
BOOST_AUTO_TEST_SUITE_END()

View File

@ -9,29 +9,27 @@
*/
#include "StdInc.h"
#include <boost/test/unit_test.hpp>
#include "MapComparer.h"
#include "../lib/ScopeGuard.h"
#include "../lib/mapping/CMap.h"
#define VCMI_CHECK_FIELD_EQUAL_P(field) BOOST_CHECK_EQUAL(actual->field, expected->field)
#define VCMI_CHECK_FIELD_EQUAL_P(field) EXPECT_EQ(actual->field, expected->field)
#define VCMI_CHECK_FIELD_EQUAL(field) BOOST_CHECK_EQUAL(actual.field, expected.field)
#define VCMI_CHECK_FIELD_EQUAL(field) EXPECT_EQ(actual.field, expected.field)
#define VCMI_REQUIRE_FIELD_EQUAL_P(field) BOOST_REQUIRE_EQUAL(actual->field, expected->field)
#define VCMI_REQUIRE_FIELD_EQUAL(field) BOOST_REQUIRE_EQUAL(actual.field, expected.field)
#define VCMI_REQUIRE_FIELD_EQUAL_P(field) ASSERT_EQ(actual->field, expected->field)
#define VCMI_REQUIRE_FIELD_EQUAL(field) ASSERT_EQ(actual.field, expected.field)
template <class T>
void checkEqual(const T & actual, const T & expected)
{
BOOST_CHECK_EQUAL(actual, expected) ;
EXPECT_EQ(actual, expected) ;
}
void checkEqual(const std::vector<bool> & actual, const std::vector<bool> & expected)
{
BOOST_CHECK_EQUAL(actual.size(), expected.size());
EXPECT_EQ(actual.size(), expected.size());
for(auto actualIt = actual.begin(), expectedIt = expected.begin(); actualIt != actual.end() && expectedIt != expected.end(); actualIt++, expectedIt++)
{
@ -42,7 +40,7 @@ void checkEqual(const std::vector<bool> & actual, const std::vector<bool> & expe
template <class Element>
void checkEqual(const std::vector<Element> & actual, const std::vector<Element> & expected)
{
BOOST_CHECK_EQUAL(actual.size(), expected.size());
EXPECT_EQ(actual.size(), expected.size());
for(auto actualIt = actual.begin(), expectedIt = expected.begin(); actualIt != actual.end() && expectedIt != expected.end(); actualIt++, expectedIt++)
{
@ -53,12 +51,12 @@ void checkEqual(const std::vector<Element> & actual, const std::vector<Element>
template <class Element>
void checkEqual(const std::set<Element> & actual, const std::set<Element> & expected)
{
BOOST_CHECK_EQUAL(actual.size(), expected.size());
EXPECT_EQ(actual.size(), expected.size());
for(auto elem : expected)
{
if(!vstd::contains(actual, elem))
BOOST_ERROR("Required element not found "+boost::to_string(elem));
FAIL() << "Required element not found "+boost::to_string(elem);
}
}
@ -142,8 +140,8 @@ void checkEqual(const TerrainTile & actual, const TerrainTile & expected)
VCMI_REQUIRE_FIELD_EQUAL(roadDir);
VCMI_REQUIRE_FIELD_EQUAL(extTileFlags);
BOOST_REQUIRE_EQUAL(actual.blockingObjects.size(), expected.blockingObjects.size());
BOOST_REQUIRE_EQUAL(actual.visitableObjects.size(), expected.visitableObjects.size());
ASSERT_EQ(actual.blockingObjects.size(), expected.blockingObjects.size());
ASSERT_EQ(actual.visitableObjects.size(), expected.visitableObjects.size());
VCMI_REQUIRE_FIELD_EQUAL(visitable);
VCMI_REQUIRE_FIELD_EQUAL(blocked);
@ -202,13 +200,13 @@ void MapComparer::compareOptions()
void MapComparer::compareObject(const CGObjectInstance * actual, const CGObjectInstance * expected)
{
BOOST_CHECK_EQUAL(actual->instanceName, expected->instanceName);
BOOST_CHECK_EQUAL(typeid(actual).name(), typeid(expected).name());//todo: remove and use just comparison
EXPECT_EQ(actual->instanceName, expected->instanceName);
EXPECT_EQ(typeid(actual).name(), typeid(expected).name());//todo: remove and use just comparison
std::string actualFullID = boost::to_string(boost::format("%s(%d)|%s(%d) %d") % actual->typeName % actual->ID % actual->subTypeName % actual->subID % actual->tempOwner);
std::string expectedFullID = boost::to_string(boost::format("%s(%d)|%s(%d) %d") % expected->typeName % expected->ID % expected->subTypeName % expected->subID % expected->tempOwner);
BOOST_CHECK_EQUAL(actualFullID, expectedFullID);
EXPECT_EQ(actualFullID, expectedFullID);
VCMI_CHECK_FIELD_EQUAL_P(pos);
checkEqual(actual->appearance, expected->appearance);
@ -216,24 +214,24 @@ void MapComparer::compareObject(const CGObjectInstance * actual, const CGObjectI
void MapComparer::compareObjects()
{
BOOST_CHECK_EQUAL(actual->objects.size(), expected->objects.size());
EXPECT_EQ(actual->objects.size(), expected->objects.size());
for(size_t idx = 0; idx < expected->objects.size(); idx++)
{
auto expectedObject = expected->objects[idx];
BOOST_REQUIRE_EQUAL(idx, expectedObject->id.getNum());
ASSERT_EQ(idx, expectedObject->id.getNum());
{
auto it = expected->instanceNames.find(expectedObject->instanceName);
BOOST_REQUIRE(it != expected->instanceNames.end());
ASSERT_NE(it, expected->instanceNames.end());
}
{
auto it = actual->instanceNames.find(expectedObject->instanceName);
BOOST_REQUIRE(it != actual->instanceNames.end());
ASSERT_NE(it, actual->instanceNames.end());
auto actualObject = it->second;
@ -251,17 +249,16 @@ void MapComparer::compareTerrain()
for(int y = 0; y < expected->height; y++)
{
int3 coord(x,y,0);
BOOST_TEST_CHECKPOINT(coord);
SCOPED_TRACE(coord);
checkEqual(actual->getTile(coord), expected->getTile(coord));
}
}
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(expected != nullptr, "Expected map is not defined");
ASSERT_NE((void *) actual, (void *) expected); //should not point to the same object
ASSERT_TRUE(actual != nullptr) << "Actual map is not defined";
ASSERT_TRUE(expected != nullptr) << "Expected map is not defined";
compareHeader();
compareOptions();
@ -301,12 +298,7 @@ std::string JsonMapComparer::buildMessage(const std::string & message)
void JsonMapComparer::addError(const std::string & message)
{
BOOST_ERROR(buildMessage(message));
}
void JsonMapComparer::addWarning(const std::string & message)
{
BOOST_WARN_MESSAGE(false, buildMessage(message));
FAIL()<<buildMessage(message);
}
bool JsonMapComparer::isEmpty(const JsonNode & value)
@ -327,7 +319,7 @@ bool JsonMapComparer::isEmpty(const JsonNode & value)
return value.Struct().empty();
break;
default:
BOOST_FAIL("Unknown Json type");
EXPECT_TRUE(false) << "Unknown Json type";
return false;
}
}
@ -335,9 +327,9 @@ bool JsonMapComparer::isEmpty(const JsonNode & value)
void JsonMapComparer::check(const bool condition, const std::string & message)
{
if(strict)
BOOST_REQUIRE_MESSAGE(condition, buildMessage(message));
ASSERT_TRUE(condition) << buildMessage(message);
else
BOOST_CHECK_MESSAGE(condition, buildMessage(message));
EXPECT_TRUE(condition) << buildMessage(message);
}
void JsonMapComparer::checkEqualInteger(const si64 actual, const si64 expected)
@ -421,7 +413,7 @@ void JsonMapComparer::checkEqualJson(const JsonNode & actual, const JsonNode & e
checkEqualInteger(actual.Integer(), expected.Integer());
break;
default:
BOOST_FAIL("Unknown Json type");
FAIL() << "Unknown Json type";
break;
}
}
@ -433,9 +425,7 @@ void JsonMapComparer::checkExcessStructField(const JsonNode & actualValue, const
if(!vstd::contains(expected, name))
{
if(isEmpty(actualValue))
addWarning("excess");
else
if(!isEmpty(actualValue))
addError("excess");
}
}
@ -443,12 +433,9 @@ void JsonMapComparer::checkExcessStructField(const JsonNode & actualValue, const
void JsonMapComparer::checkStructField(const JsonMap & actual, const std::string & name, const JsonNode & expectedValue)
{
auto guard = pushName(name);
if(!vstd::contains(actual, name))
{
if(isEmpty(expectedValue))
addWarning("missing");
else
if(!isEmpty(expectedValue))
addError("missing");
}
else

View File

@ -52,7 +52,6 @@ struct JsonMapComparer
std::string buildMessage(const std::string & message);
void addError(const std::string & message);
void addWarning(const std::string & message);
bool isEmpty(const JsonNode & value);