mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-17 20:58:07 +02:00
Advance map format simple test
This commit is contained in:
parent
7d16585f89
commit
0cc47f00c5
@ -110,10 +110,9 @@ CMapLoaderJson::CMapLoaderJson(CInputStream * stream):
|
||||
std::unique_ptr<CMap> CMapLoaderJson::loadMap()
|
||||
{
|
||||
map = new CMap();
|
||||
mapHeader.reset(map);
|
||||
mapHeader = std::unique_ptr<CMapHeader>(dynamic_cast<CMapHeader *>(map));
|
||||
readMap();
|
||||
mapHeader.reset();
|
||||
return std::unique_ptr<CMap>(map);
|
||||
return std::unique_ptr<CMap>(dynamic_cast<CMap *>(mapHeader.release()));
|
||||
}
|
||||
|
||||
std::unique_ptr<CMapHeader> CMapLoaderJson::loadMapHeader()
|
||||
@ -167,7 +166,7 @@ JsonNode eventToJson(const EventCondition & cond)
|
||||
void CMapLoaderJson::readMap()
|
||||
{
|
||||
readHeader();
|
||||
assert(0); // Not implemented, vcmi does not have its own map format right now
|
||||
//TODO:readMap
|
||||
}
|
||||
|
||||
void CMapLoaderJson::readHeader()
|
||||
@ -175,12 +174,12 @@ void CMapLoaderJson::readHeader()
|
||||
//TODO: read such data like map name & size
|
||||
// readTriggeredEvents();
|
||||
readPlayerInfo();
|
||||
assert(0); // Not implemented
|
||||
//TODO: readHeader
|
||||
}
|
||||
|
||||
void CMapLoaderJson::readPlayerInfo()
|
||||
{
|
||||
assert(0); // Not implemented
|
||||
//TODO: readPlayerInfo
|
||||
}
|
||||
|
||||
///CMapSaverJson
|
||||
@ -193,6 +192,6 @@ CMapSaverJson::CMapSaverJson(COutputStream * stream):
|
||||
|
||||
void CMapSaverJson::saveMap(const std::unique_ptr<CMap>& map)
|
||||
{
|
||||
assert(0); // Not implemented
|
||||
//TODO: saveMap
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
|
||||
/*
|
||||
* MapFormatH3M.h, part of VCMI engine
|
||||
* MapFormatJSON.h, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
|
@ -8,6 +8,8 @@ set(test_SRCS
|
||||
StdInc.cpp
|
||||
CVcmiTestConfig.cpp
|
||||
CMapEditManagerTest.cpp
|
||||
MapComparer.cpp
|
||||
CMapFormatTest.cpp
|
||||
)
|
||||
|
||||
add_executable(vcmitest ${test_SRCS})
|
||||
|
@ -8,18 +8,22 @@
|
||||
* 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"
|
||||
|
||||
#include "../lib/mapping/CMap.h"
|
||||
#include "../lib/rmg/CMapGenOptions.h"
|
||||
#include "../lib/rmg/CMapGenerator.h"
|
||||
#include "../lib/mapping/MapFormatJSON.h"
|
||||
|
||||
#include "MapComparer.h"
|
||||
|
||||
static const int TEST_RANDOM_SEED = 1337;
|
||||
|
||||
static CMap * initialMap;
|
||||
static std::unique_ptr<CMap> initialMap;
|
||||
|
||||
class CMapTestFixture
|
||||
{
|
||||
@ -35,11 +39,11 @@ public:
|
||||
|
||||
CMapGenerator gen;
|
||||
|
||||
initialMap = gen.generate(&opt, TEST_RANDOM_SEED).release();
|
||||
initialMap = gen.generate(&opt, TEST_RANDOM_SEED);
|
||||
};
|
||||
~CMapTestFixture()
|
||||
{
|
||||
delete initialMap;
|
||||
initialMap.reset();
|
||||
};
|
||||
};
|
||||
|
||||
@ -49,11 +53,18 @@ BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
//TODO: serialize map
|
||||
//TODO: deserialize map
|
||||
//TODO: compare results
|
||||
CMemoryBuffer serializeBuffer;
|
||||
CMapSaverJson saver(&serializeBuffer);
|
||||
saver.saveMap(initialMap);
|
||||
|
||||
CMapLoaderJson loader(&serializeBuffer);
|
||||
serializeBuffer.seek(0);
|
||||
std::unique_ptr<CMap> serialized = loader.loadMap();
|
||||
|
||||
|
||||
MapComparer c;
|
||||
|
||||
BOOST_REQUIRE_MESSAGE(c(initialMap, serialized), "Serialize cycle failed");
|
||||
}
|
||||
catch(const std::exception & e)
|
||||
{
|
||||
|
20
test/MapComparer.cpp
Normal file
20
test/MapComparer.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* MapComparer.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 "MapComparer.h"
|
||||
|
||||
bool MapComparer::operator() (const std::unique_ptr<CMap>& lhs, const std::unique_ptr<CMap>& rhs)
|
||||
{
|
||||
BOOST_ERROR(" MapComparer::operator() not implemented");
|
||||
return false;
|
||||
}
|
20
test/MapComparer.h
Normal file
20
test/MapComparer.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* MapComparer.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 "../lib/mapping/CMap.h"
|
||||
|
||||
struct MapComparer
|
||||
{
|
||||
bool operator() (const std::unique_ptr<CMap>& lhs, const std::unique_ptr<CMap>& rhs);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user