1//===- SectionDataTest.cpp ------------------------------------------------===//
2//
3//                     The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#include "SectionDataTest.h"
10
11#include <mcld/LD/SectionData.h>
12#include <mcld/LD/LDFileFormat.h>
13#include <mcld/LD/LDSection.h>
14
15using namespace mcld;
16using namespace mcldtest;
17
18
19// Constructor can do set-up work for all test here.
20SectionDataTest::SectionDataTest()
21{
22}
23
24// Destructor can do clean-up work that doesn't throw exceptions here.
25SectionDataTest::~SectionDataTest()
26{
27}
28
29// SetUp() will be called immediately before each test.
30void SectionDataTest::SetUp()
31{
32}
33
34// TearDown() will be called immediately after each test.
35void SectionDataTest::TearDown()
36{
37}
38
39//===----------------------------------------------------------------------===//
40// Testcases
41//===----------------------------------------------------------------------===//
42
43TEST_F( SectionDataTest, constructor_and_trivial_func ) {
44  LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
45
46  SectionData* s = SectionData::Create(*test);
47  EXPECT_TRUE(s->getSection().name() == "test" && \
48              s->getSection().kind() == LDFileFormat::Null);
49
50
51  LDSection::Destroy(test);
52}
53
54TEST_F( SectionDataTest, Fragment_list_and_iterator ) {
55  LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
56  SectionData* s = SectionData::Create(*test);
57  EXPECT_TRUE(s->empty());
58
59  new Fragment(Fragment::Alignment, s);
60  new Fragment(Fragment::Alignment, s);
61  new Fragment(Fragment::Region, s);
62  new Fragment(Fragment::Fillment, s);
63  new Fragment(Fragment::Target, s);
64  EXPECT_TRUE(5 == s->size());
65
66  //iterator
67  llvm::iplist<Fragment>::iterator iter=s->begin();
68  EXPECT_TRUE(Fragment::Alignment == iter->getKind());
69  ++iter;
70  EXPECT_TRUE(Fragment::Alignment == iter->getKind());
71  ++iter;
72  EXPECT_TRUE(Fragment::Region == iter->getKind());
73  ++iter;
74  EXPECT_TRUE(Fragment::Fillment == iter->getKind());
75  ++iter;
76  EXPECT_TRUE(Fragment::Target == iter->getKind());
77  ++iter;
78  EXPECT_TRUE(iter == s->end());
79
80  LDSection::Destroy(test);
81}
82