1cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao//===- FragmentTest.cpp -------------------------------------------------------===//
2cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao//
3cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao//                     The MCLinker Project
4cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao//
5cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao// This file is distributed under the University of Illinois Open Source
6cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao// License. See LICENSE.TXT for details.
7cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao//
8cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao//===----------------------------------------------------------------------===//
9cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao#include "FragmentTest.h"
10cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
11cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao#include <mcld/LD/Fragment.h>
12cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao#include <mcld/LD/SectionData.h>
13cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao#include <mcld/LD/LDSection.h>
14cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
15cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liaousing namespace mcld;
16cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liaousing namespace mcldtest;
17cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
18cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
19cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao// Constructor can do set-up work for all test here.
20cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei LiaoFragmentTest::FragmentTest()
21cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao{
22cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao}
23cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
24cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao// Destructor can do clean-up work that doesn't throw exceptions here.
25cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei LiaoFragmentTest::~FragmentTest()
26cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao{
27cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao}
28cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
29cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao// SetUp() will be called immediately before each test.
30cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liaovoid FragmentTest::SetUp()
31cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao{
32cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao}
33cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
34cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao// TearDown() will be called immediately after each test.
35cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liaovoid FragmentTest::TearDown()
36cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao{
37cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao}
38cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
39cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao//===----------------------------------------------------------------------===//
40cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao// Testcases
41cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
42cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei LiaoTEST_F( FragmentTest, Fragment_constructor ) {
43cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  LDSection test("test", LDFileFormat::Null, 0, 0);
44cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  SectionData* s = new SectionData(test);
45cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  Fragment* f1 = new Fragment(Fragment::Alignment, s);
46cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  EXPECT_TRUE(1 == s->size());
47cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  Fragment* f2 = new Fragment(Fragment::Alignment, s);
48cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  Fragment* f3 = new Fragment(Fragment::Region, s);
49cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  Fragment* f4 = new Fragment(Fragment::Fillment, s);
50cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  Fragment* f5 = new Fragment(Fragment::Relocation, s);
51cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  Fragment* f6 = new Fragment(Fragment::Target, s);
52cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  EXPECT_TRUE(6 == s->size());
53cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
54cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  delete s;
55cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao}
56cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
57cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei LiaoTEST_F( FragmentTest, Fragment_trivial_function ) {
58cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  LDSection test("test", LDFileFormat::Null, 0, 0);
59cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  SectionData* s = new SectionData(test);
60cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  Fragment* f = new Fragment(Fragment::Alignment, s);
61cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
62cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  EXPECT_TRUE(Fragment::Alignment == f->getKind());
63cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
64cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  EXPECT_TRUE(~uint64_t(0) == f->getOffset());
65cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  EXPECT_TRUE(~(0U) == f->getLayoutOrder());
66cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
67cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  f->setOffset(5566);
68cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  EXPECT_TRUE(5566 == f->getOffset());
69cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
70cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  f->setLayoutOrder(5566);
71cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  EXPECT_TRUE(5566 == f->getLayoutOrder());
72cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
73cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  //always return true
74cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  EXPECT_TRUE(f->classof(new Fragment(Fragment::Region, s)) );
75cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
76cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  delete s;
77cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao}
78cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
79cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao
80