2015-08-13 23:16:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
};
|
|
|
|
|
2017-06-14 10:56:35 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE(CMemoryBuffer_Suite)
|
|
|
|
|
|
|
|
BOOST_FIXTURE_TEST_CASE(empty, CMemoryBufferFixture)
|
2015-08-13 23:16:31 +02:00
|
|
|
{
|
|
|
|
BOOST_REQUIRE_EQUAL(0, subject.tell());
|
|
|
|
BOOST_REQUIRE_EQUAL(0, subject.getSize());
|
2017-06-14 10:56:35 +02:00
|
|
|
|
2015-08-13 23:16:31 +02:00
|
|
|
si32 dummy = 1337;
|
2017-06-14 10:56:35 +02:00
|
|
|
|
2015-08-13 23:16:31 +02:00
|
|
|
auto ret = subject.read((ui8 *)&dummy, sizeof(si32));
|
2017-06-14 10:56:35 +02:00
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(0, ret);
|
2015-08-13 23:16:31 +02:00
|
|
|
BOOST_CHECK_EQUAL(1337, dummy);
|
|
|
|
BOOST_CHECK_EQUAL(0, subject.tell());
|
|
|
|
}
|
|
|
|
|
2017-06-14 10:56:35 +02:00
|
|
|
BOOST_FIXTURE_TEST_CASE(write, CMemoryBufferFixture)
|
2015-08-13 23:16:31 +02:00
|
|
|
{
|
|
|
|
const si32 initial = 1337;
|
2017-06-14 10:56:35 +02:00
|
|
|
|
2015-08-13 23:16:31 +02:00
|
|
|
subject.write((const ui8 *)&initial, sizeof(si32));
|
2017-06-14 10:56:35 +02:00
|
|
|
|
2015-08-13 23:16:31 +02:00
|
|
|
BOOST_CHECK_EQUAL(4, subject.tell());
|
|
|
|
subject.seek(0);
|
|
|
|
BOOST_CHECK_EQUAL(0, subject.tell());
|
2017-06-14 10:56:35 +02:00
|
|
|
|
2015-08-13 23:16:31 +02:00
|
|
|
si32 current = 0;
|
|
|
|
auto ret = subject.read((ui8 *)¤t, sizeof(si32));
|
2017-06-14 10:56:35 +02:00
|
|
|
BOOST_CHECK_EQUAL(sizeof(si32), ret);
|
2015-08-13 23:16:31 +02:00
|
|
|
BOOST_CHECK_EQUAL(initial, current);
|
2017-06-14 10:56:35 +02:00
|
|
|
BOOST_CHECK_EQUAL(4, subject.tell());
|
2015-08-13 23:16:31 +02:00
|
|
|
}
|
2017-06-14 10:56:35 +02:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|