• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- FragmentTest.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 "FragmentTest.h"
10 
11 #include "mcld/Fragment/Fragment.h"
12 #include "mcld/LD/SectionData.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.
FragmentTest()19 FragmentTest::FragmentTest() {
20 }
21 
22 // Destructor can do clean-up work that doesn't throw exceptions here.
~FragmentTest()23 FragmentTest::~FragmentTest() {
24 }
25 
26 // SetUp() will be called immediately before each test.
SetUp()27 void FragmentTest::SetUp() {
28 }
29 
30 // TearDown() will be called immediately after each test.
TearDown()31 void FragmentTest::TearDown() {
32 }
33 
34 //===----------------------------------------------------------------------===//
35 // Testcases
36 
TEST_F(FragmentTest,Fragment_constructor)37 TEST_F(FragmentTest, Fragment_constructor) {
38   LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
39   SectionData* s = SectionData::Create(*test);
40   new Fragment(Fragment::Alignment, s);
41   EXPECT_TRUE(1 == s->size());
42   new Fragment(Fragment::Alignment, s);
43   new Fragment(Fragment::Region, s);
44   new Fragment(Fragment::Fillment, s);
45   new Fragment(Fragment::Target, s);
46   EXPECT_TRUE(5 == s->size());
47 
48   LDSection::Destroy(test);
49   //  SectionData::Destroy(s);
50 }
51 
TEST_F(FragmentTest,Fragment_trivial_function)52 TEST_F(FragmentTest, Fragment_trivial_function) {
53   LDSection* test = LDSection::Create("test", LDFileFormat::Null, 0, 0);
54   SectionData* s = SectionData::Create(*test);
55   Fragment* f = new Fragment(Fragment::Alignment, s);
56 
57   EXPECT_TRUE(Fragment::Alignment == f->getKind());
58 
59   f->setOffset(5566);
60   EXPECT_TRUE(5566 == f->getOffset());
61 
62   // always return true
63   EXPECT_TRUE(f->classof(new Fragment(Fragment::Region, s)));
64 
65   LDSection::Destroy(test);
66   //  SectionData::Destroy(s);
67 }
68