1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-02 09:02:03 +02:00
vcmi/test/CMapFormatTest.cpp

99 lines
2.3 KiB
C++
Raw Normal View History

2015-07-27 07:33:47 +02:00
/*
* CMapFormatTest.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"
2015-08-08 18:16:33 +02:00
2015-07-27 07:33:47 +02:00
#include <boost/test/unit_test.hpp>
2015-08-08 18:16:33 +02:00
#include "../lib/filesystem/CMemoryBuffer.h"
2015-07-27 07:33:47 +02:00
#include "../lib/mapping/CMap.h"
#include "../lib/rmg/CMapGenOptions.h"
#include "../lib/rmg/CMapGenerator.h"
2015-08-08 21:08:19 +02:00
#include "../lib/mapping/MapFormatJson.h"
2015-08-08 18:16:33 +02:00
2015-08-13 02:29:13 +02:00
#include "../lib/VCMIDirs.h"
2015-08-08 18:16:33 +02:00
#include "MapComparer.h"
2015-07-27 07:33:47 +02:00
2015-08-13 02:29:13 +02:00
2015-07-27 07:33:47 +02:00
static const int TEST_RANDOM_SEED = 1337;
2015-08-08 18:16:33 +02:00
static std::unique_ptr<CMap> initialMap;
2015-07-27 07:33:47 +02:00
class CMapTestFixture
{
2015-08-18 01:21:35 +02:00
public:
2015-07-27 07:33:47 +02:00
CMapTestFixture()
{
CMapGenOptions opt;
2015-08-18 01:21:35 +02:00
2016-02-21 21:13:20 +02:00
opt.setHeight(CMapHeader::MAP_SIZE_MIDDLE);
opt.setWidth(CMapHeader::MAP_SIZE_MIDDLE);
opt.setHasTwoLevels(true);
2016-02-13 16:16:00 +02:00
opt.setPlayerCount(4);
2015-08-18 01:21:35 +02:00
2015-11-15 17:29:00 +02:00
opt.setPlayerTypeForStandardPlayer(PlayerColor(0), EPlayerType::HUMAN);
2016-02-13 16:16:00 +02:00
opt.setPlayerTypeForStandardPlayer(PlayerColor(1), EPlayerType::AI);
opt.setPlayerTypeForStandardPlayer(PlayerColor(2), EPlayerType::AI);
opt.setPlayerTypeForStandardPlayer(PlayerColor(3), EPlayerType::AI);
2015-11-15 17:29:00 +02:00
2015-07-27 07:33:47 +02:00
CMapGenerator gen;
2015-08-18 01:21:35 +02:00
2015-08-08 18:16:33 +02:00
initialMap = gen.generate(&opt, TEST_RANDOM_SEED);
initialMap->name = "Test";
2015-07-27 07:33:47 +02:00
};
~CMapTestFixture()
{
2015-08-08 18:16:33 +02:00
initialMap.reset();
2015-07-27 07:33:47 +02:00
};
};
BOOST_GLOBAL_FIXTURE(CMapTestFixture);
BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
{
logGlobal->info("CMapFormatVCMI_Simple start");
BOOST_TEST_CHECKPOINT("CMapFormatVCMI_Simple start");
CMemoryBuffer serializeBuffer;
2015-07-27 07:33:47 +02:00
{
CMapSaverJson saver(&serializeBuffer);
saver.saveMap(initialMap);
2015-07-27 07:33:47 +02:00
}
BOOST_TEST_CHECKPOINT("CMapFormatVCMI_Simple serialized");
#if 1
2015-07-27 07:33:47 +02:00
{
2016-02-10 07:59:24 +02:00
auto path = VCMIDirs::get().userDataPath()/"test.vmap";
boost::filesystem::remove(path);
boost::filesystem::ofstream tmp(path, boost::filesystem::ofstream::binary);
tmp.write((const char *)serializeBuffer.getBuffer().data(),serializeBuffer.getSize());
tmp.flush();
tmp.close();
2015-11-15 17:29:00 +02:00
2016-08-11 10:06:06 +02:00
logGlobal->info("Test map has been saved to:");
logGlobal->info(path.string());
2015-07-27 07:33:47 +02:00
}
BOOST_TEST_CHECKPOINT("CMapFormatVCMI_Simple saved");
2015-08-18 01:21:35 +02:00
#endif // 1
2015-08-18 01:21:35 +02:00
serializeBuffer.seek(0);
{
CMapLoaderJson loader(&serializeBuffer);
std::unique_ptr<CMap> serialized = loader.loadMap();
MapComparer c;
c(serialized, initialMap);
}
logGlobal->info("CMapFormatVCMI_Simple finish");
2015-07-27 07:33:47 +02:00
}