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/LD/Fragment.h>
12#include <mcld/LD/SectionData.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.
20FragmentTest::FragmentTest()
21{
22}
23
24// Destructor can do clean-up work that doesn't throw exceptions here.
25FragmentTest::~FragmentTest()
26{
27}
28
29// SetUp() will be called immediately before each test.
30void FragmentTest::SetUp()
31{
32}
33
34// TearDown() will be called immediately after each test.
35void FragmentTest::TearDown()
36{
37}
38
39//===----------------------------------------------------------------------===//
40// Testcases
41
42TEST_F( FragmentTest, Fragment_constructor ) {
43  LDSection test("test", LDFileFormat::Null, 0, 0);
44  SectionData* s = new SectionData(test);
45  Fragment* f1 = new Fragment(Fragment::Alignment, s);
46  EXPECT_TRUE(1 == s->size());
47  Fragment* f2 = new Fragment(Fragment::Alignment, s);
48  Fragment* f3 = new Fragment(Fragment::Region, s);
49  Fragment* f4 = new Fragment(Fragment::Fillment, s);
50  Fragment* f5 = new Fragment(Fragment::Relocation, s);
51  Fragment* f6 = new Fragment(Fragment::Target, s);
52  EXPECT_TRUE(6 == s->size());
53
54  delete s;
55}
56
57TEST_F( FragmentTest, Fragment_trivial_function ) {
58  LDSection test("test", LDFileFormat::Null, 0, 0);
59  SectionData* s = new SectionData(test);
60  Fragment* f = new Fragment(Fragment::Alignment, s);
61
62  EXPECT_TRUE(Fragment::Alignment == f->getKind());
63
64  EXPECT_TRUE(~uint64_t(0) == f->getOffset());
65  EXPECT_TRUE(~(0U) == f->getLayoutOrder());
66
67  f->setOffset(5566);
68  EXPECT_TRUE(5566 == f->getOffset());
69
70  f->setLayoutOrder(5566);
71  EXPECT_TRUE(5566 == f->getLayoutOrder());
72
73  //always return true
74  EXPECT_TRUE(f->classof(new Fragment(Fragment::Region, s)) );
75
76  delete s;
77}
78
79
80