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