2#include <cppunit/extensions/HelperMacros.h>
3#include <cppunit/TestFixture.h>
5#include "../../src/linker/buffer.h"
15 CPPUNIT_TEST(testCreateBuffer);
16 CPPUNIT_TEST(testReadFile);
17 CPPUNIT_TEST(testWriteFile);
18 CPPUNIT_TEST_SUITE_END();
21 void testCreateBuffer();
26void TestBuffer::testCreateBuffer()
29 CPPUNIT_ASSERT_EQUAL(offset_t(0x1234), buffer.ActualDataSize());
32void TestBuffer::testReadFile()
36 std::string input =
"\1\2\3\4\5\6\7\x8\x9\xA\xB\xC\xD\xE\xF";
39 std::istringstream iss(input);
40 Reader rd(::LittleEndian, &iss);
42 CPPUNIT_ASSERT_EQUAL(offset_t(input.size()), buffer.
ActualDataSize());
46 std::istringstream iss(input);
47 Reader rd(::LittleEndian, &iss);
48 buffer.ReadFile(rd, 0);
53 std::istringstream iss(input);
54 Reader rd(::LittleEndian, &iss);
55 buffer.ReadFile(rd, input.size() / 2);
56 CPPUNIT_ASSERT_EQUAL(offset_t(input.size() / 2), buffer.
ActualDataSize());
60 std::istringstream iss(input);
61 Reader rd(::LittleEndian, &iss);
63 size_t offset = input.size() / 2;
64 CPPUNIT_ASSERT_EQUAL(offset_t(input.size()), buffer.
ActualDataSize());
65 CPPUNIT_ASSERT_EQUAL(
int(input[offset]), buffer.
GetByte(offset));
69void TestBuffer::testWriteFile()
73 std::string input =
"\1\2\3\4\5\6\7\x8\x9\xA\xB\xC\xD\xE\xF";
76 std::istringstream iss(input);
77 Reader rd(::LittleEndian, &iss);
82 std::ostringstream oss;
83 Writer wr(::LittleEndian, &oss);
85 CPPUNIT_ASSERT_EQUAL(oss.str(), input);
89 std::ostringstream oss;
90 Writer wr(::LittleEndian, &oss);
91 offset_t start = input.size() / 5;
92 offset_t length = input.size() / 3;
94 CPPUNIT_ASSERT_EQUAL(oss.str(), input.substr(start, length));
A buffer that can be used to read and store data from a file.
Definition buffer.h:22
offset_t ActualDataSize() override
Retrieves size of stored data.
Definition buffer.cc:6
offset_t WriteFile(Writer &wr, offset_t count, offset_t offset=0) override
Writes data of non-zero filled sections.
Definition buffer.cc:40
int GetByte(offset_t offset) override
Retrieve byte at a certain offset (optional, might not be defined)
Definition buffer.cc:45
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15