summaryrefslogtreecommitdiff
path: root/unittests/SectionDataTest.cpp
blob: e9a929293d97c0473db676818913ab8bc9963a86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//===- SectionDataTest.cpp ------------------------------------------------===//
//
//                     The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "SectionDataTest.h"

#include "mcld/LD/SectionData.h"
#include "mcld/LD/LDFileFormat.h"
#include "mcld/LD/LDSection.h"

using namespace mcld;
using namespace mcldtest;

// Constructor can do set-up work for all test here.
SectionDataTest::SectionDataTest() {
}

// Destructor can do clean-up work that doesn't throw exceptions here.
SectionDataTest::~SectionDataTest() {
}

// SetUp() will be called immediately before each test.
void SectionDataTest::SetUp() {
}

// TearDown() will be called immediately after each test.
void SectionDataTest::TearDown() {
}

//===----------------------------------------------------------------------===//
// Testcases
//===----------------------------------------------------------------------===//

TEST_F(SectionDataTest, constructor_and_trivial_func) {
  LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);

  SectionData* s = SectionData::Create(*test);
  EXPECT_TRUE(s->getSection().name() == "test" &&
              s->getSection().kind() == LDFileFormat::Null);

  LDSection::Destroy(test);
}

TEST_F(SectionDataTest, Fragment_list_and_iterator) {
  LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
  SectionData* s = SectionData::Create(*test);
  EXPECT_TRUE(s->empty());

  new Fragment(Fragment::Alignment, s);
  new Fragment(Fragment::Alignment, s);
  new Fragment(Fragment::Region, s);
  new Fragment(Fragment::Fillment, s);
  new Fragment(Fragment::Target, s);
  EXPECT_TRUE(5 == s->size());

  // iterator
  llvm::iplist<Fragment>::iterator iter = s->begin();
  EXPECT_TRUE(Fragment::Alignment == iter->getKind());
  ++iter;
  EXPECT_TRUE(Fragment::Alignment == iter->getKind());
  ++iter;
  EXPECT_TRUE(Fragment::Region == iter->getKind());
  ++iter;
  EXPECT_TRUE(Fragment::Fillment == iter->getKind());
  ++iter;
  EXPECT_TRUE(Fragment::Target == iter->getKind());
  ++iter;
  EXPECT_TRUE(iter == s->end());

  LDSection::Destroy(test);
}