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