diff --git a/test/Battlefield.cpp b/test/Battlefield.cpp deleted file mode 100644 index 2c79967f9..000000000 --- a/test/Battlefield.cpp +++ /dev/null @@ -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 -#include "../lib/battle/BattleHex.h" -BOOST_AUTO_TEST_SUITE(BattlefieldHex_Suite) - -BOOST_AUTO_TEST_CASE(getNeighbouringTiles) -{ - BattleHex mainHex; - std::vector 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 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() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9b37330e2..e695eab35 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 + StdInc.cpp + main.cpp + CMemoryBufferTest.cpp + CVcmiTestConfig.cpp + + battle/BattleHexTest.cpp + battle/CHealthTest.cpp - Battlefield.cpp - CMapEditManagerTest.cpp - CMapFormatTest.cpp - CMemoryBufferTest.cpp - CVcmiTestConfig.cpp - MapComparer.cpp - battle/CHealthTest.cpp + map/CMapEditManagerTest.cpp + map/CMapFormatTest.cpp + map/MapComparer.cpp ) set(test_HEADERS - StdInc.h - - CVcmiTestConfig.h - MapComparer.h + StdInc.h + + CVcmiTestConfig.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 "") @@ -44,7 +48,7 @@ set(vcmitest_FILES ) foreach(file ${vcmitest_FILES}) - add_custom_command(TARGET vcmitestFiles POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${file}" ${CMAKE_CURRENT_BINARY_DIR} - ) + add_custom_command(TARGET vcmitestFiles POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${file}" ${CMAKE_CURRENT_BINARY_DIR} + ) endforeach() diff --git a/test/CMemoryBufferTest.cpp b/test/CMemoryBufferTest.cpp index 4370e0fa3..2df927686 100644 --- a/test/CMemoryBufferTest.cpp +++ b/test/CMemoryBufferTest.cpp @@ -7,46 +7,40 @@ * Full text of license available in license.txt file, in main folder * */ + #include "StdInc.h" -#include #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 *)¤t, 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() diff --git a/test/CVcmiTestConfig.cpp b/test/CVcmiTestConfig.cpp index a9caff9ec..bb22d4920 100644 --- a/test/CVcmiTestConfig.cpp +++ b/test/CVcmiTestConfig.cpp @@ -47,3 +47,4 @@ CVcmiTestConfig::~CVcmiTestConfig() { std::cout << "Ending global test tear-down." << std::endl; } + diff --git a/test/StdInc.cpp b/test/StdInc.cpp index c1b797eb8..201d9a246 100644 --- a/test/StdInc.cpp +++ b/test/StdInc.cpp @@ -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 - #include "CVcmiTestConfig.h" - BOOST_GLOBAL_FIXTURE(CVcmiTestConfig); -#endif diff --git a/test/StdInc.h b/test/StdInc.h index ac257b5f0..0ea466cd6 100644 --- a/test/StdInc.h +++ b/test/StdInc.h @@ -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 - #include "CVcmiTestConfig.h" - BOOST_GLOBAL_FIXTURE(CVcmiTestConfig); -#endif - - +#include +#include +#include "Global.h" diff --git a/test/battle/BattleHexTest.cpp b/test/battle/BattleHexTest.cpp new file mode 100644 index 000000000..e41809d6a --- /dev/null +++ b/test/battle/BattleHexTest.cpp @@ -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 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 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); +} diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 000000000..b1fe2f444 --- /dev/null +++ b/test/main.cpp @@ -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(); +} diff --git a/test/CMapEditManagerTest.cpp b/test/map/CMapEditManagerTest.cpp similarity index 87% rename from test/CMapEditManagerTest.cpp rename to test/map/CMapEditManagerTest.cpp index d05803ef3..3bcff96f4 100644 --- a/test/CMapEditManagerTest.cpp +++ b/test/map/CMapEditManagerTest.cpp @@ -9,7 +9,6 @@ */ #include "StdInc.h" -#include #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,18 +57,18 @@ 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), - int3(34,44,0), int3(34,45,0), int3(35,45,0), int3(35,46,0), int3(36,46,0), - int3(36,47,0), int3(37,47,0)}; + int3(34,44,0), int3(34,45,0), int3(35,45,0), int3(35,46,0), int3(36,46,0), + int3(36,47,0), int3(37,47,0)}; for(int i = 0; i < ARRAY_COUNT(diagonalCheck); ++i) { 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() diff --git a/test/CMapFormatTest.cpp b/test/map/CMapFormatTest.cpp similarity index 93% rename from test/CMapFormatTest.cpp rename to test/map/CMapFormatTest.cpp index 82b454f20..5c186dde4 100644 --- a/test/CMapFormatTest.cpp +++ b/test/map/CMapFormatTest.cpp @@ -9,8 +9,6 @@ */ #include "StdInc.h" -#include - #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 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() diff --git a/test/MapComparer.cpp b/test/map/MapComparer.cpp similarity index 82% rename from test/MapComparer.cpp rename to test/map/MapComparer.cpp index 6b8692e78..1e2fb6ffe 100644 --- a/test/MapComparer.cpp +++ b/test/map/MapComparer.cpp @@ -9,29 +9,27 @@ */ #include "StdInc.h" -#include - #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 void checkEqual(const T & actual, const T & expected) { - BOOST_CHECK_EQUAL(actual, expected) ; + EXPECT_EQ(actual, expected) ; } void checkEqual(const std::vector & actual, const std::vector & 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 & actual, const std::vector & expe template void checkEqual(const std::vector & actual, const std::vector & 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 & actual, const std::vector template void checkEqual(const std::set & actual, const std::set & 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); } } @@ -91,12 +89,12 @@ void checkEqual(const PlayerInfo & actual, const PlayerInfo & expected) VCMI_CHECK_FIELD_EQUAL(hasRandomHero); } -void checkEqual(const EventExpression & actual, const EventExpression & expected) +void checkEqual(const EventExpression & actual, const EventExpression & expected) { //todo: checkEventExpression } -void checkEqual(const TriggeredEvent & actual, const TriggeredEvent & expected) +void checkEqual(const TriggeredEvent & actual, const TriggeredEvent & expected) { VCMI_CHECK_FIELD_EQUAL(identifier); VCMI_CHECK_FIELD_EQUAL(description); @@ -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); @@ -179,7 +177,7 @@ void MapComparer::compareHeader() auto sortByIdentifier = [](const TriggeredEvent & lhs, const TriggeredEvent & rhs) -> bool { - return lhs.identifier < rhs.identifier; + return lhs.identifier < rhs.identifier; }; boost::sort (actualEvents, sortByIdentifier); boost::sort (expectedEvents, sortByIdentifier); @@ -197,18 +195,18 @@ void MapComparer::compareOptions() checkEqual(actual->allowedArtifact, expected->allowedArtifact); checkEqual(actual->allowedSpell, expected->allowedSpell); - //todo: compareOptions events + //todo: compareOptions events } 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(); @@ -269,7 +266,7 @@ void MapComparer::compare() compareTerrain(); } -void MapComparer::operator() (const std::unique_ptr& actual, const std::unique_ptr& expected) +void MapComparer::operator() (const std::unique_ptr& actual, const std::unique_ptr& expected) { this->actual = actual.get(); this->expected = expected.get(); @@ -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()<