2#include <cppunit/extensions/HelperMacros.h>
3#include <cppunit/TestFixture.h>
5#include "../../src/linker/buffer.h"
6#include "../../src/linker/reader.h"
7#include "../../src/linker/writer.h"
17 CPPUNIT_TEST(testCreateBuffer);
18 CPPUNIT_TEST(testReadFile);
19 CPPUNIT_TEST(testWriteFile);
20 CPPUNIT_TEST_SUITE_END();
23 void testCreateBuffer();
28void TestBuffer::testCreateBuffer()
31 CPPUNIT_ASSERT_EQUAL(offset_t(0x1234), buffer.ImageSize());
34void TestBuffer::testReadFile()
38 std::string input =
"\1\2\3\4\5\6\7\x8\x9\xA\xB\xC\xD\xE\xF";
41 std::istringstream iss(input);
42 Reader rd(::LittleEndian, &iss);
44 CPPUNIT_ASSERT_EQUAL(offset_t(input.size()), buffer.
ImageSize());
48 std::istringstream iss(input);
49 Reader rd(::LittleEndian, &iss);
50 buffer.ReadFile(rd, 0);
51 CPPUNIT_ASSERT_EQUAL(offset_t(0), buffer.
ImageSize());
55 std::istringstream iss(input);
56 Reader rd(::LittleEndian, &iss);
57 buffer.ReadFile(rd, input.size() / 2);
58 CPPUNIT_ASSERT_EQUAL(offset_t(input.size() / 2), buffer.
ImageSize());
62 std::istringstream iss(input);
63 Reader rd(::LittleEndian, &iss);
65 size_t offset = input.size() / 2;
66 CPPUNIT_ASSERT_EQUAL(offset_t(input.size()), buffer.
ImageSize());
67 CPPUNIT_ASSERT_EQUAL(
int(input[offset]), buffer.
GetByte(offset));
71void TestBuffer::testWriteFile()
75 std::string input =
"\1\2\3\4\5\6\7\x8\x9\xA\xB\xC\xD\xE\xF";
78 std::istringstream iss(input);
79 Reader rd(::LittleEndian, &iss);
84 std::ostringstream oss;
85 Writer wr(::LittleEndian, &oss);
87 CPPUNIT_ASSERT_EQUAL(oss.str(), input);
91 std::ostringstream oss;
92 Writer wr(::LittleEndian, &oss);
93 offset_t start = input.size() / 5;
94 offset_t length = input.size() / 3;
96 CPPUNIT_ASSERT_EQUAL(oss.str(), input.substr(start, length));
int GetByte(offset_t offset) const
Retrieve byte at a certain offset (optional, might not be defined)
Definition image.cc:62
A buffer that can be used to read and store data from a file.
Definition buffer.h:22
offset_t ImageSize() const override
Retrieves size of stored data.
Definition buffer.cc:9
offset_t WriteFile(Writer &wr, offset_t count, offset_t offset=0) const override
Writes data of non-zero filled sections.
Definition buffer.cc:43
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