• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 using namespace mcld;
16 using namespace mcldtest;
17 
18 // Constructor can do set-up work for all test here.
SectionDataTest()19 SectionDataTest::SectionDataTest() {
20 }
21 
22 // Destructor can do clean-up work that doesn't throw exceptions here.
~SectionDataTest()23 SectionDataTest::~SectionDataTest() {
24 }
25 
26 // SetUp() will be called immediately before each test.
SetUp()27 void SectionDataTest::SetUp() {
28 }
29 
30 // TearDown() will be called immediately after each test.
TearDown()31 void SectionDataTest::TearDown() {
32 }
33 
34 //===----------------------------------------------------------------------===//
35 // Testcases
36 //===----------------------------------------------------------------------===//
37 
TEST_F(SectionDataTest,constructor_and_trivial_func)38 TEST_F(SectionDataTest, constructor_and_trivial_func) {
39   LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
40 
41   SectionData* s = SectionData::Create(*test);
42   EXPECT_TRUE(s->getSection().name() == "test" &&
43               s->getSection().kind() == LDFileFormat::Null);
44 
45   LDSection::Destroy(test);
46 }
47 
TEST_F(SectionDataTest,Fragment_list_and_iterator)48 TEST_F(SectionDataTest, Fragment_list_and_iterator) {
49   LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
50   SectionData* s = SectionData::Create(*test);
51   EXPECT_TRUE(s->empty());
52 
53   new Fragment(Fragment::Alignment, s);
54   new Fragment(Fragment::Alignment, s);
55   new Fragment(Fragment::Region, s);
56   new Fragment(Fragment::Fillment, s);
57   new Fragment(Fragment::Target, s);
58   EXPECT_TRUE(5 == s->size());
59 
60   // iterator
61   llvm::iplist<Fragment>::iterator iter = s->begin();
62   EXPECT_TRUE(Fragment::Alignment == iter->getKind());
63   ++iter;
64   EXPECT_TRUE(Fragment::Alignment == iter->getKind());
65   ++iter;
66   EXPECT_TRUE(Fragment::Region == iter->getKind());
67   ++iter;
68   EXPECT_TRUE(Fragment::Fillment == iter->getKind());
69   ++iter;
70   EXPECT_TRUE(Fragment::Target == iter->getKind());
71   ++iter;
72   EXPECT_TRUE(iter == s->end());
73 
74   LDSection::Destroy(test);
75 }
76