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 // Constructor can do set-up work for all test here.
     21 MCRegionFragmentTest::MCRegionFragmentTest() {
     22 }
     23 
     24 // Destructor can do clean-up work that doesn't throw exceptions here.
     25 MCRegionFragmentTest::~MCRegionFragmentTest() {
     26 }
     27 
     28 // SetUp() will be called immediately before each test.
     29 void MCRegionFragmentTest::SetUp() {
     30 }
     31 
     32 // TearDown() will be called immediately after each test.
     33 void MCRegionFragmentTest::TearDown() {
     34 }
     35 
     36 //==========================================================================//
     37 // Testcases
     38 //
     39 
     40 TEST_F(MCRegionFragmentTest, classof_explicit) {
     41   Path path(TOPDIR);
     42   path.append("unittests/test3.txt");
     43   MemoryAreaFactory* areaFactory = new MemoryAreaFactory(1);
     44   MemoryArea* area = areaFactory->produce(path, MemoryArea::ReadWrite);
     45 
     46   MemoryRegion* region = area->request(0, 4096);
     47   MCRegionFragment* frag = new MCRegionFragment(*region);
     48 
     49   ASSERT_FALSE(llvm::MCDataFragment::classof(frag));
     50   ASSERT_TRUE(MCRegionFragment::classof(frag));
     51   delete frag;
     52   delete areaFactory;
     53 }
     54 
     55 TEST_F(MCRegionFragmentTest, classof_implicit) {
     56   Path path(TOPDIR);
     57   path.append("unittests/test3.txt");
     58   MemoryAreaFactory* areaFactory = new MemoryAreaFactory(1);
     59   MemoryArea* area = areaFactory->produce(path, MemoryArea::ReadWrite);
     60 
     61   MemoryRegion* region = area->request(0, 4096);
     62   llvm::MCFragment* frag = new MCRegionFragment(*region);
     63 
     64   ASSERT_FALSE(llvm::MCDataFragment::classof(frag));
     65   ASSERT_TRUE(MCRegionFragment::classof(frag));
     66   delete frag;
     67   delete areaFactory;
     68 }
     69