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