1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00
vcmi/test/CMemoryBufferTest.cpp

54 lines
1.2 KiB
C++
Raw Normal View History

/*
* 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)
{
BOOST_REQUIRE_EQUAL(0, subject.tell());
BOOST_REQUIRE_EQUAL(0, subject.getSize());
2017-06-14 10:56:35 +02:00
si32 dummy = 1337;
2017-06-14 10:56:35 +02:00
auto ret = subject.read((ui8 *)&dummy, sizeof(si32));
2017-06-14 10:56:35 +02:00
BOOST_CHECK_EQUAL(0, ret);
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)
{
const si32 initial = 1337;
2017-06-14 10:56:35 +02:00
subject.write((const ui8 *)&initial, sizeof(si32));
2017-06-14 10:56:35 +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
si32 current = 0;
auto ret = subject.read((ui8 *)&current, sizeof(si32));
2017-06-14 10:56:35 +02:00
BOOST_CHECK_EQUAL(sizeof(si32), ret);
BOOST_CHECK_EQUAL(initial, current);
2017-06-14 10:56:35 +02:00
BOOST_CHECK_EQUAL(4, subject.tell());
}
2017-06-14 10:56:35 +02:00
BOOST_AUTO_TEST_SUITE_END()