blob: 5480eab171af1aa7cb59873723984ef69324f184 [file] [log] [blame]
Shih-wei Liao5460a1f2012-03-16 22:41:16 -07001//===- 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//===----------------------------------------------------------------------===//
Stephen Hines37b74a32014-11-26 18:48:20 -08009#include "mcld/MC/ContextFactory.h"
10#include "mcld/Support/MemoryAreaFactory.h"
11#include "mcld/Support/TargetSelect.h"
12#include "mcld/Support/Path.h"
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070013#include "UniqueGCFactoryBaseTest.h"
14
15using namespace mcld;
16using namespace mcldtest;
17
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070018// Constructor can do set-up work for all test here.
Stephen Hines37b74a32014-11-26 18:48:20 -080019UniqueGCFactoryBaseTest::UniqueGCFactoryBaseTest() {
Shih-wei Liao22add6f2012-12-15 17:21:00 -080020 m_pConfig = new LinkerConfig("arm-none-linux-gnueabi");
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070021}
22
23// Destructor can do clean-up work that doesn't throw exceptions here.
Stephen Hines37b74a32014-11-26 18:48:20 -080024UniqueGCFactoryBaseTest::~UniqueGCFactoryBaseTest() {
Shih-wei Liao22add6f2012-12-15 17:21:00 -080025 delete m_pConfig;
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070026}
27
28// SetUp() will be called immediately before each test.
Stephen Hines37b74a32014-11-26 18:48:20 -080029void UniqueGCFactoryBaseTest::SetUp() {
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070030}
31
32// TearDown() will be called immediately after each test.
Stephen Hines37b74a32014-11-26 18:48:20 -080033void UniqueGCFactoryBaseTest::TearDown() {
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070034}
35
36//==========================================================================//
37// Testcases
38//
Stephen Hines37b74a32014-11-26 18:48:20 -080039TEST_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;
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070045}
46
Stephen Hines37b74a32014-11-26 18:48:20 -080047TEST_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;
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070055}
56
Stephen Hines37b74a32014-11-26 18:48:20 -080057TEST_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;
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070065}
66
Stephen Hines37b74a32014-11-26 18:48:20 -080067TEST_F(UniqueGCFactoryBaseTest, iterator) {
68 sys::fs::Path path1(TOPDIR), path2(TOPDIR);
69 path1.append("unittests/test.txt");
70 path2.append("unittests/test2.txt");
Zonr Changaffc1502012-07-16 14:28:23 +080071
Stephen Hines37b74a32014-11-26 18:48:20 -080072 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);
Zonr Changaffc1502012-07-16 14:28:23 +080080
Stephen Hines37b74a32014-11-26 18:48:20 -080081 MemoryArea* area3 =
82 memFactory->produce(path1, FileHandle::OpenMode(FileHandle::ReadOnly),
83 FileHandle::Permission(FileHandle::System));
Stephen Hines551ae4e2014-04-24 14:41:24 -070084
Stephen Hines37b74a32014-11-26 18:48:20 -080085 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;
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070096}