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