1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

Tests improvement

Delete our logger from tests.
Make correction.
This commit is contained in:
FeniksFire 2017-07-18 21:18:37 +02:00
parent 587f59e93a
commit d84ecb6fb2
6 changed files with 10 additions and 36 deletions

View File

@ -26,7 +26,7 @@ matrix:
compiler: gcc compiler: gcc
env: VCMI_PLATFORM='linux' REAL_CC=gcc-4.8 REAL_CXX=g++-4.8 PACKAGE=g++-4.8 SUPPORT= env: VCMI_PLATFORM='linux' REAL_CC=gcc-4.8 REAL_CXX=g++-4.8 PACKAGE=g++-4.8 SUPPORT=
- os: linux - os: linux
env: VCMI_PLATFORM='mxe' MXE_TARGET=i686-w64-mingw32.shared env: VCMI_PLATFORM='mxe' MXE_TARGET=i686-w64-mingw32.shared VCMI_CMAKE_FLAGS='-DENABLE_TEST=0'
sudo: required sudo: required
- os: osx - os: osx
env: VCMI_PLATFORM='mac' env: VCMI_PLATFORM='mac'

View File

@ -24,13 +24,9 @@
CVcmiTestConfig::CVcmiTestConfig() CVcmiTestConfig::CVcmiTestConfig()
{ {
console = new CConsoleHandler(); console = new CConsoleHandler();
CBasicLogConfigurator logConfig(VCMIDirs::get().userCachePath() / "VCMI_Test_log.txt", console);
logConfig.configureDefault();
preinitDLL(console); preinitDLL(console);
settings.init(); settings.init();
logConfig.configure();
loadDLLClasses(); loadDLLClasses();
logGlobal->info("Initialized global test setup.");
/* TEST_DATA_DIR may be wrong, if yes below test don't run, /* TEST_DATA_DIR may be wrong, if yes below test don't run,
find your test data folder in your build and change TEST_DATA_DIR for it*/ find your test data folder in your build and change TEST_DATA_DIR for it*/

View File

@ -21,9 +21,8 @@ class HealthTest : public ::testing::Test
{ {
public: public:
UnitHealthInfoMock mock; UnitHealthInfoMock mock;
HealthTest() : health(&mock){ HealthTest() : health(&mock)
{}
}
void setDefaultExpectations() void setDefaultExpectations()
{ {
@ -229,8 +228,8 @@ TEST_F(HealthTest, singleUnitStack)
//one Titan //one Titan
EXPECT_CALL(mock, unitMaxHealth()).WillRepeatedly(Return(1)); EXPECT_CALL(mock, unitMaxHealth()).WillRepeatedly(Return(300));
EXPECT_CALL(mock, unitBaseAmount()).WillRepeatedly(Return(300)); EXPECT_CALL(mock, unitBaseAmount()).WillRepeatedly(Return(1));
health.init(); health.init();

View File

@ -12,7 +12,8 @@
#include "CVcmiTestConfig.h" #include "CVcmiTestConfig.h"
#include "../lib/filesystem/CMemoryBuffer.h" #include "../lib/filesystem/CMemoryBuffer.h"
int main(int argc, char ** argv){ int main(int argc, char ** argv)
{
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
CVcmiTestConfig test; CVcmiTestConfig test;
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();

View File

@ -22,7 +22,6 @@
TEST(MapManager, DrawTerrain_Type) TEST(MapManager, DrawTerrain_Type)
{ {
logGlobal->info("CMapEditManager_DrawTerrain_Type start");
try try
{ {
auto map = make_unique<CMap>(); auto map = make_unique<CMap>();
@ -102,23 +101,19 @@ TEST(MapManager, DrawTerrain_Type)
} }
catch(const std::exception & e) catch(const std::exception & e)
{ {
logGlobal->error("CMapEditManager_DrawTerrain_Type crash"); FAIL()<<e.what();
logGlobal->error(e.what());
throw; throw;
} }
logGlobal->info("CMapEditManager_DrawTerrain_Type finish");
} }
TEST(MapManager, DrawTerrain_View) TEST(MapManager, DrawTerrain_View)
{ {
logGlobal->info("CMapEditManager_DrawTerrain_View start");
try try
{ {
const ResourceID testMap("test/TerrainViewTest", EResType::MAP); const ResourceID testMap("test/TerrainViewTest", EResType::MAP);
// Load maps and json config // Load maps and json config
const auto originalMap = CMapService::loadMap(testMap); const auto originalMap = CMapService::loadMap(testMap);
auto map = CMapService::loadMap(testMap); auto map = CMapService::loadMap(testMap);
logGlobal->info("Loaded test map successfully.");
// Validate edit manager // Validate edit manager
auto editManager = map->getEditManager(); auto editManager = map->getEditManager();
@ -146,10 +141,6 @@ TEST(MapManager, DrawTerrain_View)
const auto & posVector = posNode.Vector(); const auto & posVector = posNode.Vector();
if(posVector.size() != 3) throw std::runtime_error("A position should consist of three values x,y,z. Continue with next position."); if(posVector.size() != 3) throw std::runtime_error("A position should consist of three values x,y,z. Continue with next position.");
int3 pos(posVector[0].Float(), posVector[1].Float(), posVector[2].Float()); int3 pos(posVector[0].Float(), posVector[1].Float(), posVector[2].Float());
#if 0
logGlobal->trace("Test pattern '%s' on position x '%d', y '%d', z '%d'.", patternStr, pos.x, pos.y, pos.z);
CTerrainViewPatternUtils::printDebuggingInfoAboutTile(map.get(), pos);
#endif // 0
const auto & originalTile = originalMap->getTile(pos); const auto & originalTile = originalMap->getTile(pos);
editManager->getTerrainSelection().selectRange(MapRect(pos, 1, 1)); editManager->getTerrainSelection().selectRange(MapRect(pos, 1, 1));
editManager->drawTerrain(originalTile.terType, &gen); editManager->drawTerrain(originalTile.terType, &gen);
@ -165,15 +156,13 @@ TEST(MapManager, DrawTerrain_View)
} }
EXPECT_TRUE(isInRange); EXPECT_TRUE(isInRange);
if(!isInRange) if(!isInRange)
logGlobal->error("No or invalid pattern found for current position."); FAIL()<<("No or invalid pattern found for current position.");
} }
} }
} }
catch(const std::exception & e) catch(const std::exception & e)
{ {
logGlobal->info("CMapEditManager_DrawTerrain_View crash"); FAIL()<<e.what();
logGlobal->info(e.what());
throw; throw;
} }
logGlobal->info("CMapEditManager_DrawTerrain_View finish");
} }

View File

@ -26,7 +26,6 @@ static const int TEST_RANDOM_SEED = 1337;
TEST(MapFormat, Random) TEST(MapFormat, Random)
{ {
logGlobal->info("MapFormat_Random start");
SCOPED_TRACE("MapFormat_Random start"); SCOPED_TRACE("MapFormat_Random start");
std::unique_ptr<CMap> initialMap; std::unique_ptr<CMap> initialMap;
@ -63,9 +62,6 @@ TEST(MapFormat, Random)
tmp.write((const char *)serializeBuffer.getBuffer().data(),serializeBuffer.getSize()); tmp.write((const char *)serializeBuffer.getBuffer().data(),serializeBuffer.getSize());
tmp.flush(); tmp.flush();
tmp.close(); tmp.close();
logGlobal->info("Test map has been saved to:");
logGlobal->info(path.string());
} }
SCOPED_TRACE("MapFormat_Random saved"); SCOPED_TRACE("MapFormat_Random saved");
#endif // 1 #endif // 1
@ -79,7 +75,6 @@ TEST(MapFormat, Random)
c(serialized, initialMap); c(serialized, initialMap);
} }
SCOPED_TRACE("MapFormat_Random finish"); SCOPED_TRACE("MapFormat_Random finish");
logGlobal->info("MapFormat_Random finish");
} }
static JsonNode getFromArchive(CZipLoader & archive, const std::string & archiveFilename) static JsonNode getFromArchive(CZipLoader & archive, const std::string & archiveFilename)
@ -114,8 +109,6 @@ static void addToArchive(CZipSaver & saver, const JsonNode & data, const std::st
TEST(MapFormat, Objects) TEST(MapFormat, Objects)
{ {
logGlobal->info("MapFormat_Objects start");
static const std::string MAP_DATA_PATH = "test/ObjectPropertyTest/"; static const std::string MAP_DATA_PATH = "test/ObjectPropertyTest/";
const JsonNode initialHeader(ResourceID(MAP_DATA_PATH+"header.json")); const JsonNode initialHeader(ResourceID(MAP_DATA_PATH+"header.json"));
@ -173,8 +166,6 @@ TEST(MapFormat, Objects)
tmp.write((const char *)serializeBuffer.getBuffer().data(),serializeBuffer.getSize()); tmp.write((const char *)serializeBuffer.getBuffer().data(),serializeBuffer.getSize());
tmp.flush(); tmp.flush();
tmp.close(); tmp.close();
logGlobal->infoStream() << "Test map has been saved to " << path;
} }
{ {
@ -196,6 +187,4 @@ TEST(MapFormat, Objects)
JsonMapComparer c; JsonMapComparer c;
c.compareTerrain("underground", actualUnderground, expectedUnderground); c.compareTerrain("underground", actualUnderground, expectedUnderground);
} }
logGlobal->info("MapFormat_Objects finish");
} }