• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- MCFragmentRefTest --------------------------------------------------===//
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 
10 #include "mcld/MC/MCFragmentRef.h"
11 #include "mcld/MC/MCRegionFragment.h"
12 #include "mcld/Support/MemoryAreaFactory.h"
13 #include "mcld/Support/Path.h"
14 #include "MCFragmentRefTest.h"
15 
16 using namespace mcld;
17 using namespace mcld::sys::fs;
18 using namespace mcld::sys::fs::detail;
19 using namespace mcldtest;
20 
21 // Constructor can do set-up work for all test here.
MCFragmentRefTest()22 MCFragmentRefTest::MCFragmentRefTest()
23 {
24 }
25 
26 // Destructor can do clean-up work that doesn't throw exceptions here.
~MCFragmentRefTest()27 MCFragmentRefTest::~MCFragmentRefTest()
28 {
29 }
30 
31 // SetUp() will be called immediately before each test.
SetUp()32 void MCFragmentRefTest::SetUp()
33 {
34 }
35 
36 // TearDown() will be called immediately after each test.
TearDown()37 void MCFragmentRefTest::TearDown()
38 {
39 }
40 
41 //==========================================================================//
42 // Testcases
43 //
44 TEST_F( MCFragmentRefTest, ) {
45   Path path(TOPDIR);
46   path.append("unittests/test3.txt");
47   MemoryAreaFactory* areaFactory = new MemoryAreaFactory(1);
48   MemoryArea* area = areaFactory->produce(path, MemoryArea::ReadWrite);
49 
50   MemoryRegion* region = area->request(0, 4096);
51   MCRegionFragment *frag = new MCRegionFragment(*region);
52   MCFragmentRef *ref = new MCFragmentRef(*frag);
53 
54   ASSERT_EQ('H', region->getBuffer()[0]);
55   ASSERT_EQ(4096, region->size());
56   ASSERT_EQ('H', frag->getRegion().getBuffer()[0]);
57   ASSERT_EQ(4096, frag->getRegion().size());
58   ASSERT_EQ(frag, ref->frag());
59   ASSERT_EQ('H', static_cast<MCRegionFragment*>(ref->frag())->getRegion().getBuffer()[0]);
60   ASSERT_EQ(4096, static_cast<MCRegionFragment*>(ref->frag())->getRegion().size());
61   ASSERT_EQ('H', ref->deref()[0]);
62 
63   ASSERT_FALSE(llvm::MCDataFragment::classof(frag));
64   ASSERT_TRUE(MCRegionFragment::classof(frag));
65 
66   delete ref;
67   delete frag;
68   delete areaFactory;
69 }
70 
71