Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 9 | #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 Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 13 | #include "UniqueGCFactoryBaseTest.h" |
| 14 | |
| 15 | using namespace mcld; |
| 16 | using namespace mcldtest; |
| 17 | |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 18 | // Constructor can do set-up work for all test here. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 19 | UniqueGCFactoryBaseTest::UniqueGCFactoryBaseTest() { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 20 | m_pConfig = new LinkerConfig("arm-none-linux-gnueabi"); |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | // Destructor can do clean-up work that doesn't throw exceptions here. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 24 | UniqueGCFactoryBaseTest::~UniqueGCFactoryBaseTest() { |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 25 | delete m_pConfig; |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | // SetUp() will be called immediately before each test. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 29 | void UniqueGCFactoryBaseTest::SetUp() { |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | // TearDown() will be called immediately after each test. |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 33 | void UniqueGCFactoryBaseTest::TearDown() { |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | //==========================================================================// |
| 37 | // Testcases |
| 38 | // |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 39 | TEST_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 Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 47 | TEST_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 Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 57 | TEST_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 Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 67 | TEST_F(UniqueGCFactoryBaseTest, iterator) { |
| 68 | sys::fs::Path path1(TOPDIR), path2(TOPDIR); |
| 69 | path1.append("unittests/test.txt"); |
| 70 | path2.append("unittests/test2.txt"); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 71 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 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); |
Zonr Chang | affc150 | 2012-07-16 14:28:23 +0800 | [diff] [blame] | 80 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 81 | MemoryArea* area3 = |
| 82 | memFactory->produce(path1, FileHandle::OpenMode(FileHandle::ReadOnly), |
| 83 | FileHandle::Permission(FileHandle::System)); |
Stephen Hines | 551ae4e | 2014-04-24 14:41:24 -0700 | [diff] [blame] | 84 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 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; |
Shih-wei Liao | 5460a1f | 2012-03-16 22:41:16 -0700 | [diff] [blame] | 96 | } |