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