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

WiP on zip serialization

(-) still not works correctly
This commit is contained in:
AlexVinS 2015-08-14 00:16:31 +03:00 committed by AlexVinS
parent fc2cbc841a
commit 0cc7213a27
7 changed files with 93 additions and 38 deletions

View File

@ -15,7 +15,7 @@
CMemoryBuffer::CMemoryBuffer():
position(0)
{
buffer.reserve(4096);
}
si64 CMemoryBuffer::write(const ui8 * data, si64 size)
@ -48,7 +48,7 @@ si64 CMemoryBuffer::read(ui8 * data, si64 size)
si64 CMemoryBuffer::seek(si64 position)
{
this->position = position;
if (this->position >=getSize())
if (this->position >getSize())
this->position = getSize();
return this->position;
}

View File

@ -65,16 +65,24 @@ long ZCALLBACK CIOApi::seekFileProxy(voidpf opaque, voidpf stream, ZPOS64_T off
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR :
actualStream->skip(offset);//TODO: should we check actual skipped?
if(actualStream->skip(offset) != offset)
ret = -1;
break;
case ZLIB_FILEFUNC_SEEK_END :
actualStream->seek(actualStream->getSize() - offset);
case ZLIB_FILEFUNC_SEEK_END:
{
const si64 pos = actualStream->getSize() - offset;
if(actualStream->seek(pos) != pos)
ret = -1;
}
break;
case ZLIB_FILEFUNC_SEEK_SET :
actualStream->seek(offset);
if(actualStream->seek(offset) != offset)
ret = -1;
break;
default: ret = -1;
}
if(ret == -1)
logGlobal->error("CIOApi::seekFileProxy: seek failed");
return ret;
}

View File

@ -213,6 +213,7 @@ void CMapLoaderJson::readHeader()
static const std::map<std::string, ui8> difficultyMap =
{
{"", 1},
{"EASY", 0},
{"NORMAL", 1},
{"HARD", 2},

View File

@ -55,8 +55,6 @@ BOOST_GLOBAL_FIXTURE(CMapTestFixture);
BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
{
try
{
logGlobal->info("CMapFormatVCMI_Simple start");
CMemoryBuffer serializeBuffer;
{
@ -66,9 +64,10 @@ BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
#if 1
{
std::ofstream tmp((VCMIDirs::get().userDataPath()/"temp.zip").string());
tmp.write((const char *)&serializeBuffer.getBuffer()[0],serializeBuffer.getSize());
tmp.flush();
auto path = VCMIDirs::get().userDataPath()/"temp.zip";
boost::filesystem::remove(path);
boost::filesystem::ofstream tmp(path);
tmp.write((const char *)serializeBuffer.getBuffer().data(),serializeBuffer.getSize());
}
@ -80,14 +79,8 @@ BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
std::unique_ptr<CMap> serialized = loader.loadMap();
MapComparer c;
c(initialMap, serialized);
c(serialized, initialMap);
}
logGlobal->info("CMapFormatVCMI_Simple finish");
}
catch(...)
{
handleException();
BOOST_FAIL("Test case crashed");
}
}

View File

@ -0,0 +1,52 @@
/*
* CMemoryBufferTest.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/filesystem/CMemoryBuffer.h"
struct CMemoryBufferFixture
{
CMemoryBuffer subject;
};
BOOST_FIXTURE_TEST_CASE(CMemoryBuffer_Empty, CMemoryBufferFixture)
{
BOOST_REQUIRE_EQUAL(0, subject.tell());
BOOST_REQUIRE_EQUAL(0, subject.getSize());
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());
}
BOOST_FIXTURE_TEST_CASE(CMemoryBuffer_Write, CMemoryBufferFixture)
{
const si32 initial = 1337;
subject.write((const ui8 *)&initial, sizeof(si32));
BOOST_CHECK_EQUAL(4, subject.tell());
subject.seek(0);
BOOST_CHECK_EQUAL(0, subject.tell());
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());
}

View File

@ -82,7 +82,7 @@ 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(actual != nullptr, "Expected map is not defined");
BOOST_REQUIRE_MESSAGE(expected != nullptr, "Expected map is not defined");
compareHeader();
compareOptions();

View File

@ -60,6 +60,7 @@
</Linker>
<Unit filename="CMapEditManagerTest.cpp" />
<Unit filename="CMapFormatTest.cpp" />
<Unit filename="CMemoryBufferTest.cpp" />
<Unit filename="CVcmiTestConfig.cpp" />
<Unit filename="CVcmiTestConfig.h" />
<Unit filename="MapComparer.cpp" />