1//===- UniqueGCFactoryBaseTest.cpp ----------------------------------------===// 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 "mcld/MC/ContextFactory.h" 10#include "mcld/Support/MemoryAreaFactory.h" 11#include "mcld/Support/TargetSelect.h" 12#include "mcld/Support/Path.h" 13#include "UniqueGCFactoryBaseTest.h" 14 15using namespace mcld; 16using namespace mcldtest; 17 18// Constructor can do set-up work for all test here. 19UniqueGCFactoryBaseTest::UniqueGCFactoryBaseTest() { 20 m_pConfig = new LinkerConfig("arm-none-linux-gnueabi"); 21} 22 23// Destructor can do clean-up work that doesn't throw exceptions here. 24UniqueGCFactoryBaseTest::~UniqueGCFactoryBaseTest() { 25 delete m_pConfig; 26} 27 28// SetUp() will be called immediately before each test. 29void UniqueGCFactoryBaseTest::SetUp() { 30} 31 32// TearDown() will be called immediately after each test. 33void UniqueGCFactoryBaseTest::TearDown() { 34} 35 36//==========================================================================// 37// Testcases 38// 39TEST_F(UniqueGCFactoryBaseTest, number_constructor) { 40 ContextFactory* contextFactory = new ContextFactory(10); 41 contextFactory->produce("/"); 42 contextFactory->produce("ab/c"); 43 ASSERT_TRUE(2 == contextFactory->size()); 44 delete contextFactory; 45} 46 47TEST_F(UniqueGCFactoryBaseTest, unique_produce) { 48 ContextFactory* contextFactory = new ContextFactory(10); 49 LDContext* context1 = contextFactory->produce("/"); 50 contextFactory->produce("ab/c"); 51 ASSERT_TRUE(2 == contextFactory->size()); 52 LDContext* context2 = contextFactory->produce("/"); 53 ASSERT_EQ(context1, context2); 54 delete contextFactory; 55} 56 57TEST_F(UniqueGCFactoryBaseTest, unique_produce2) { 58 ContextFactory* contextFactory = new ContextFactory(10); 59 LDContext* context1 = contextFactory->produce("abc/def"); 60 contextFactory->produce("ab/c"); 61 ASSERT_TRUE(2 == contextFactory->size()); 62 LDContext* context2 = contextFactory->produce("ttt/../abc/def"); 63 ASSERT_EQ(context1, context2); 64 delete contextFactory; 65} 66 67TEST_F(UniqueGCFactoryBaseTest, iterator) { 68 sys::fs::Path path1(TOPDIR), path2(TOPDIR); 69 path1.append("unittests/test.txt"); 70 path2.append("unittests/test2.txt"); 71 72 MemoryAreaFactory* memFactory = new MemoryAreaFactory(10); 73 MemoryArea* area1 = 74 memFactory->produce(path1, FileHandle::OpenMode(FileHandle::ReadOnly), 75 FileHandle::Permission(FileHandle::System)); 76 MemoryArea* area2 = 77 memFactory->produce(path2, FileHandle::OpenMode(FileHandle::ReadOnly), 78 FileHandle::Permission(FileHandle::System)); 79 ASSERT_NE(area1, area2); 80 81 MemoryArea* area3 = 82 memFactory->produce(path1, FileHandle::OpenMode(FileHandle::ReadOnly), 83 FileHandle::Permission(FileHandle::System)); 84 85 ASSERT_EQ(area1, area3); 86 ASSERT_FALSE(memFactory->empty()); 87 ASSERT_TRUE(2 == memFactory->size()); 88 MemoryAreaFactory::iterator aIter = memFactory->begin(); 89 ASSERT_EQ(area1, &(*aIter)); 90 ++aIter; 91 ASSERT_EQ(area2, &(*aIter)); 92 ++aIter; 93 MemoryAreaFactory::iterator aEnd = memFactory->end(); 94 ASSERT_TRUE(aEnd == aIter); 95 delete memFactory; 96} 97