RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
section.cc
1
2#include <cppunit/extensions/HelperMacros.h>
3#include <cppunit/TestFixture.h>
4
5#include "../../src/linker/section.h"
6
7using namespace Linker;
8
9namespace UnitTests
10{
11
12class TestSection : public CppUnit::TestFixture
13{
14 CPPUNIT_TEST_SUITE(TestSection);
15 CPPUNIT_TEST(testSimpleFlags);
16 CPPUNIT_TEST(testZeroFilledFlag);
17 CPPUNIT_TEST(testFixedFlag);
18 CPPUNIT_TEST_SUITE_END();
19private:
20 Section * section;
21 void testSimpleFlags();
22 void testZeroFilledFlag();
23 void testFixedFlag();
24public:
25 void setUp();
26 void tearDown();
27};
28
29void TestSection::testSimpleFlags()
30{
31 CPPUNIT_ASSERT_MESSAGE("Default setting should be Readable", section->GetFlags() == Section::Readable);
32
33 section->SetWritable(true);
34 CPPUNIT_ASSERT(section->IsWritable());
35 section->SetExecable(true);
36 CPPUNIT_ASSERT(section->IsExecable());
37 section->SetMergeable(true);
38 CPPUNIT_ASSERT(section->IsMergeable());
39
40 section->SetReadable(false);
41 CPPUNIT_ASSERT(!section->IsReadable());
42 section->SetExecable(false);
43 CPPUNIT_ASSERT(!section->IsExecable());
44 section->SetWritable(false);
45 CPPUNIT_ASSERT(!section->IsWritable());
46 section->SetMergeable(false);
47 CPPUNIT_ASSERT(!section->IsMergeable());
48}
49
50void TestSection::testZeroFilledFlag()
51{
52 section->SetZeroFilled(true);
53 section->Expand(123);
54 CPPUNIT_ASSERT_EQUAL((offset_t)123, section->Size());
55 section->SetZeroFilled(false);
56 CPPUNIT_ASSERT_EQUAL((offset_t)123, section->Size());
57}
58
59void TestSection::testFixedFlag()
60{
61 CPPUNIT_ASSERT(!section->IsFixed());
62 section->SetAlign(16);
63 CPPUNIT_ASSERT_EQUAL((offset_t)16, section->GetAlign());
64 CPPUNIT_ASSERT_EQUAL((offset_t)0, section->GetStartAddress());
65 section->SetAddress(0x1234);
66 CPPUNIT_ASSERT(section->IsFixed());
67 CPPUNIT_ASSERT_EQUAL((offset_t)0x1240, section->GetStartAddress());
68}
69
70void TestSection::setUp()
71{
72 section = new Section(".test");
73}
74
75void TestSection::tearDown()
76{
77 delete section;
78}
79
80}
81
A section of data as read from an object file.
Definition section.h:25
offset_t SetAddress(offset_t new_address)
For non-fixed segments, sets the starting address and makes the fixed.
Definition section.cc:141
offset_t Expand(offset_t new_size)
Increases the size of the section by the specified amount.
Definition section.cc:173
@ Readable
The data in the section can be read at runtime.
Definition section.h:44
Definition section.cc:13