blob: 75fb34c2805f647d0e81c6b21d21895a46d66065 [file] [log] [blame]
Shih-wei Liao5460a1f2012-03-16 22:41:16 -07001//===- implTest.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//===----------------------------------------------------------------------===//
Shih-wei Liao22add6f2012-12-15 17:21:00 -08009#include "StaticResolverTest.h"
Stephen Hines37b74a32014-11-26 18:48:20 -080010#include "mcld/Support/TargetSelect.h"
11#include "mcld/LD/StaticResolver.h"
12#include "mcld/LD/ResolveInfo.h"
13#include "mcld/LinkerConfig.h"
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070014
Stephen Hines37b74a32014-11-26 18:48:20 -080015#include "mcld/Support/FileSystem.h"
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070016
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070017using namespace mcld;
18using namespace mcldtest;
19
Shih-wei Liao67e37f12012-07-27 03:50:34 -070020//===----------------------------------------------------------------------===//
21// StaticResolverTest
22//===----------------------------------------------------------------------===//
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070023// Constructor can do set-up work for all test here.
Stephen Hines37b74a32014-11-26 18:48:20 -080024StaticResolverTest::StaticResolverTest() : m_pResolver(NULL), m_pConfig(NULL) {
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070025 // create testee. modify it if need
26 m_pResolver = new StaticResolver();
Shih-wei Liao67e37f12012-07-27 03:50:34 -070027
Shih-wei Liao22add6f2012-12-15 17:21:00 -080028 m_pConfig = new LinkerConfig("arm-none-linux-gnueabi");
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070029}
30
31// Destructor can do clean-up work that doesn't throw exceptions here.
Stephen Hines37b74a32014-11-26 18:48:20 -080032StaticResolverTest::~StaticResolverTest() {
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070033 delete m_pResolver;
Shih-wei Liao22add6f2012-12-15 17:21:00 -080034 delete m_pConfig;
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070035}
36
37// SetUp() will be called immediately before each test.
Stephen Hines37b74a32014-11-26 18:48:20 -080038void StaticResolverTest::SetUp() {
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070039}
40
41// TearDown() will be called immediately after each test.
Stephen Hines37b74a32014-11-26 18:48:20 -080042void StaticResolverTest::TearDown() {
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070043}
44
45//==========================================================================//
46// Testcases
47//
Stephen Hines37b74a32014-11-26 18:48:20 -080048TEST_F(StaticResolverTest, MDEF) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -080049 ResolveInfo* old_sym = ResolveInfo::Create("abc");
50 ResolveInfo* new_sym = ResolveInfo::Create("abc");
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070051 new_sym->setDesc(ResolveInfo::Define);
52 old_sym->setDesc(ResolveInfo::Define);
Stephen Hines37b74a32014-11-26 18:48:20 -080053 ASSERT_TRUE(mcld::ResolveInfo::Define == new_sym->desc());
54 ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc());
55 ASSERT_TRUE(mcld::ResolveInfo::define_flag == new_sym->info());
56 ASSERT_TRUE(mcld::ResolveInfo::define_flag == old_sym->info());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070057 bool override = true;
Stephen Hines87f34652014-02-14 18:00:16 -080058 bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
Zonr Changaffc1502012-07-16 14:28:23 +080059 ASSERT_TRUE(result);
Stephen Hines37b74a32014-11-26 18:48:20 -080060 ASSERT_FALSE(override);
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070061}
62
Stephen Hines37b74a32014-11-26 18:48:20 -080063TEST_F(StaticResolverTest, DynDefAfterDynUndef) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -080064 ResolveInfo* old_sym = ResolveInfo::Create("abc");
65 ResolveInfo* new_sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -070066
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070067 new_sym->setBinding(ResolveInfo::Global);
68 old_sym->setBinding(ResolveInfo::Global);
69 new_sym->setDesc(ResolveInfo::Undefined);
70 old_sym->setDesc(ResolveInfo::Define);
71 new_sym->setSource(true);
72 old_sym->setSource(true);
73
74 new_sym->setSize(0);
75
76 old_sym->setSize(1);
77
Stephen Hines37b74a32014-11-26 18:48:20 -080078 ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
79 ASSERT_TRUE(mcld::ResolveInfo::Global == old_sym->binding());
80 ASSERT_TRUE(mcld::ResolveInfo::Undefined == new_sym->desc());
81 ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070082
83 bool override = false;
Stephen Hines87f34652014-02-14 18:00:16 -080084 bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
Zonr Changaffc1502012-07-16 14:28:23 +080085 ASSERT_TRUE(result);
Stephen Hines37b74a32014-11-26 18:48:20 -080086 ASSERT_FALSE(override);
Shih-wei Liao22add6f2012-12-15 17:21:00 -080087 ASSERT_TRUE(1 == old_sym->size());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070088}
89
Stephen Hines37b74a32014-11-26 18:48:20 -080090TEST_F(StaticResolverTest, DynDefAfterDynDef) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -080091 ResolveInfo* old_sym = ResolveInfo::Create("abc");
92 ResolveInfo* new_sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -070093
Shih-wei Liao5460a1f2012-03-16 22:41:16 -070094 new_sym->setBinding(ResolveInfo::Global);
95 old_sym->setBinding(ResolveInfo::Global);
96 new_sym->setDesc(ResolveInfo::Define);
97 old_sym->setDesc(ResolveInfo::Define);
98 new_sym->setSource(true);
99 old_sym->setSource(true);
100
101 new_sym->setSize(0);
102
103 old_sym->setSize(1);
104
Stephen Hines37b74a32014-11-26 18:48:20 -0800105 ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
106 ASSERT_TRUE(mcld::ResolveInfo::Global == old_sym->binding());
107 ASSERT_TRUE(mcld::ResolveInfo::Define == new_sym->desc());
108 ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700109
110 bool override = false;
Stephen Hines87f34652014-02-14 18:00:16 -0800111 bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
Zonr Changaffc1502012-07-16 14:28:23 +0800112 ASSERT_TRUE(result);
Stephen Hines37b74a32014-11-26 18:48:20 -0800113 ASSERT_FALSE(override);
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800114 ASSERT_TRUE(1 == old_sym->size());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700115}
116
Stephen Hines37b74a32014-11-26 18:48:20 -0800117TEST_F(StaticResolverTest, DynUndefAfterDynUndef) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800118 ResolveInfo* old_sym = ResolveInfo::Create("abc");
119 ResolveInfo* new_sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -0700120
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700121 new_sym->setBinding(ResolveInfo::Global);
122 old_sym->setBinding(ResolveInfo::Global);
123 new_sym->setDesc(ResolveInfo::Undefined);
124 old_sym->setDesc(ResolveInfo::Undefined);
125 new_sym->setSource(true);
126 old_sym->setSource(true);
127
128 new_sym->setSize(0);
129
130 old_sym->setSize(1);
131
Stephen Hines37b74a32014-11-26 18:48:20 -0800132 ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
133 ASSERT_TRUE(mcld::ResolveInfo::Global == old_sym->binding());
134 ASSERT_TRUE(mcld::ResolveInfo::Undefined == new_sym->desc());
135 ASSERT_TRUE(mcld::ResolveInfo::Undefined == old_sym->desc());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700136
137 bool override = false;
Stephen Hines87f34652014-02-14 18:00:16 -0800138 bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
Zonr Changaffc1502012-07-16 14:28:23 +0800139 ASSERT_TRUE(result);
Stephen Hines37b74a32014-11-26 18:48:20 -0800140 ASSERT_FALSE(override);
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800141 ASSERT_TRUE(1 == old_sym->size());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700142}
143
Stephen Hines37b74a32014-11-26 18:48:20 -0800144TEST_F(StaticResolverTest, OverrideWeakByGlobal) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800145 ResolveInfo* old_sym = ResolveInfo::Create("abc");
146 ResolveInfo* new_sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -0700147
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700148 new_sym->setBinding(ResolveInfo::Global);
149 old_sym->setBinding(ResolveInfo::Weak);
150 new_sym->setSize(0);
151 old_sym->setSize(1);
152
Stephen Hines37b74a32014-11-26 18:48:20 -0800153 ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
154 ASSERT_TRUE(mcld::ResolveInfo::Weak == old_sym->binding());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700155
Stephen Hines37b74a32014-11-26 18:48:20 -0800156 ASSERT_TRUE(mcld::ResolveInfo::global_flag == new_sym->info());
157 ASSERT_TRUE(mcld::ResolveInfo::weak_flag == old_sym->info());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700158 bool override = false;
Stephen Hines87f34652014-02-14 18:00:16 -0800159 bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
Zonr Changaffc1502012-07-16 14:28:23 +0800160 ASSERT_TRUE(result);
Stephen Hines37b74a32014-11-26 18:48:20 -0800161 ASSERT_TRUE(override);
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800162 ASSERT_TRUE(0 == old_sym->size());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700163}
164
Stephen Hines37b74a32014-11-26 18:48:20 -0800165TEST_F(StaticResolverTest, DynWeakAfterDynDef) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800166 ResolveInfo* old_sym = ResolveInfo::Create("abc");
167 ResolveInfo* new_sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -0700168
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700169 old_sym->setBinding(ResolveInfo::Weak);
170 new_sym->setBinding(ResolveInfo::Global);
171
172 new_sym->setSource(true);
173 old_sym->setSource(true);
174
175 old_sym->setDesc(ResolveInfo::Define);
176 new_sym->setDesc(ResolveInfo::Define);
177
178 new_sym->setSize(0);
179
180 old_sym->setSize(1);
181
Stephen Hines37b74a32014-11-26 18:48:20 -0800182 ASSERT_TRUE(mcld::ResolveInfo::Weak == old_sym->binding());
183 ASSERT_TRUE(mcld::ResolveInfo::Global == new_sym->binding());
184 ASSERT_TRUE(mcld::ResolveInfo::Define == old_sym->desc());
185 ASSERT_TRUE(mcld::ResolveInfo::Define == new_sym->desc());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700186
187 bool override = false;
Stephen Hines87f34652014-02-14 18:00:16 -0800188 bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
Zonr Changaffc1502012-07-16 14:28:23 +0800189 ASSERT_TRUE(result);
Stephen Hines37b74a32014-11-26 18:48:20 -0800190 ASSERT_FALSE(override);
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800191 ASSERT_TRUE(1 == old_sym->size());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700192}
193
Stephen Hines37b74a32014-11-26 18:48:20 -0800194TEST_F(StaticResolverTest, MarkByBiggerCommon) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800195 ResolveInfo* old_sym = ResolveInfo::Create("abc");
196 ResolveInfo* new_sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -0700197
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700198 new_sym->setDesc(ResolveInfo::Common);
199 old_sym->setDesc(ResolveInfo::Common);
200 new_sym->setSize(999);
201 old_sym->setSize(0);
202
Stephen Hines37b74a32014-11-26 18:48:20 -0800203 ASSERT_TRUE(mcld::ResolveInfo::Common == new_sym->desc());
204 ASSERT_TRUE(mcld::ResolveInfo::Common == old_sym->desc());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700205
Stephen Hines37b74a32014-11-26 18:48:20 -0800206 ASSERT_TRUE(mcld::ResolveInfo::common_flag == new_sym->info());
207 ASSERT_TRUE(mcld::ResolveInfo::common_flag == old_sym->info());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700208 bool override = true;
Stephen Hines87f34652014-02-14 18:00:16 -0800209 bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
Zonr Changaffc1502012-07-16 14:28:23 +0800210 ASSERT_TRUE(result);
Stephen Hines37b74a32014-11-26 18:48:20 -0800211 ASSERT_FALSE(override);
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800212 ASSERT_TRUE(999 == old_sym->size());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700213}
214
Stephen Hines37b74a32014-11-26 18:48:20 -0800215TEST_F(StaticResolverTest, OverrideByBiggerCommon) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800216 ResolveInfo* old_sym = ResolveInfo::Create("abc");
217 ResolveInfo* new_sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -0700218
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700219 new_sym->setDesc(ResolveInfo::Common);
220 old_sym->setDesc(ResolveInfo::Common);
221 old_sym->setBinding(ResolveInfo::Weak);
222 new_sym->setSize(999);
223 old_sym->setSize(0);
224
Stephen Hines37b74a32014-11-26 18:48:20 -0800225 ASSERT_TRUE(ResolveInfo::Common == new_sym->desc());
226 ASSERT_TRUE(ResolveInfo::Common == old_sym->desc());
227 ASSERT_TRUE(ResolveInfo::Weak == old_sym->binding());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700228
Stephen Hines37b74a32014-11-26 18:48:20 -0800229 ASSERT_TRUE(ResolveInfo::common_flag == new_sym->info());
230 ASSERT_TRUE((ResolveInfo::weak_flag | ResolveInfo::common_flag) ==
231 old_sym->info());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700232
233 bool override = false;
Stephen Hines87f34652014-02-14 18:00:16 -0800234 bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
Zonr Changaffc1502012-07-16 14:28:23 +0800235 ASSERT_TRUE(result);
Stephen Hines37b74a32014-11-26 18:48:20 -0800236 ASSERT_TRUE(override);
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800237 ASSERT_TRUE(999 == old_sym->size());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700238}
239
Stephen Hines37b74a32014-11-26 18:48:20 -0800240TEST_F(StaticResolverTest, OverrideCommonByDefine) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800241 ResolveInfo* old_sym = ResolveInfo::Create("abc");
242 ResolveInfo* new_sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -0700243
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700244 old_sym->setDesc(ResolveInfo::Common);
245 old_sym->setSize(0);
246
247 new_sym->setDesc(ResolveInfo::Define);
248 new_sym->setSize(999);
249
Stephen Hines37b74a32014-11-26 18:48:20 -0800250 ASSERT_TRUE(ResolveInfo::Define == new_sym->desc());
251 ASSERT_TRUE(ResolveInfo::Common == old_sym->desc());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700252
Stephen Hines37b74a32014-11-26 18:48:20 -0800253 ASSERT_TRUE(ResolveInfo::define_flag == new_sym->info());
254 ASSERT_TRUE(ResolveInfo::common_flag == old_sym->info());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700255
256 bool override = false;
Stephen Hines87f34652014-02-14 18:00:16 -0800257 bool result = m_pResolver->resolve(*old_sym, *new_sym, override, 0x0);
Zonr Changaffc1502012-07-16 14:28:23 +0800258 ASSERT_TRUE(result);
Stephen Hines37b74a32014-11-26 18:48:20 -0800259 ASSERT_TRUE(override);
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800260 ASSERT_TRUE(999 == old_sym->size());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700261}
262
Stephen Hines37b74a32014-11-26 18:48:20 -0800263TEST_F(StaticResolverTest, SetUpDesc) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800264 ResolveInfo* sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -0700265
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700266 sym->setIsSymbol(true);
267
Stephen Hines37b74a32014-11-26 18:48:20 -0800268 // ASSERT_FALSE( sym->isSymbol() );
269 ASSERT_TRUE(sym->isSymbol());
270 ASSERT_TRUE(sym->isGlobal());
271 ASSERT_FALSE(sym->isWeak());
272 ASSERT_FALSE(sym->isLocal());
273 ASSERT_FALSE(sym->isDefine());
274 ASSERT_TRUE(sym->isUndef());
275 ASSERT_FALSE(sym->isDyn());
276 ASSERT_FALSE(sym->isCommon());
277 ASSERT_FALSE(sym->isIndirect());
278 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
279 ASSERT_TRUE(0 == sym->desc());
280 ASSERT_TRUE(0 == sym->binding());
281 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700282
283 sym->setIsSymbol(false);
Stephen Hines37b74a32014-11-26 18:48:20 -0800284 ASSERT_FALSE(sym->isSymbol());
285 // ASSERT_TRUE( sym->isSymbol() );
286 ASSERT_TRUE(sym->isGlobal());
287 ASSERT_FALSE(sym->isWeak());
288 ASSERT_FALSE(sym->isLocal());
289 ASSERT_FALSE(sym->isDefine());
290 ASSERT_TRUE(sym->isUndef());
291 ASSERT_FALSE(sym->isDyn());
292 ASSERT_FALSE(sym->isCommon());
293 ASSERT_FALSE(sym->isIndirect());
294 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
295 ASSERT_TRUE(0 == sym->desc());
296 ASSERT_TRUE(0 == sym->binding());
297 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700298
299 sym->setDesc(ResolveInfo::Define);
Stephen Hines37b74a32014-11-26 18:48:20 -0800300 ASSERT_FALSE(sym->isSymbol());
301 // ASSERT_TRUE( sym->isSymbol() );
302 ASSERT_TRUE(sym->isGlobal());
303 ASSERT_FALSE(sym->isWeak());
304 ASSERT_FALSE(sym->isLocal());
305 ASSERT_TRUE(sym->isDefine());
306 ASSERT_FALSE(sym->isUndef());
307 ASSERT_FALSE(sym->isDyn());
308 ASSERT_FALSE(sym->isCommon());
309 ASSERT_FALSE(sym->isIndirect());
310 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
311 ASSERT_TRUE(ResolveInfo::Define == sym->desc());
312 ASSERT_TRUE(0 == sym->binding());
313 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700314
315 sym->setDesc(ResolveInfo::Common);
Stephen Hines37b74a32014-11-26 18:48:20 -0800316 ASSERT_FALSE(sym->isSymbol());
317 // ASSERT_TRUE( sym->isSymbol() );
318 ASSERT_TRUE(sym->isGlobal());
319 ASSERT_FALSE(sym->isWeak());
320 ASSERT_FALSE(sym->isLocal());
321 ASSERT_FALSE(sym->isDyn());
322 ASSERT_FALSE(sym->isDefine());
323 ASSERT_FALSE(sym->isUndef());
324 ASSERT_TRUE(sym->isCommon());
325 ASSERT_FALSE(sym->isIndirect());
326 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
327 ASSERT_TRUE(ResolveInfo::Common == sym->desc());
328 ASSERT_TRUE(0 == sym->binding());
329 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700330
331 sym->setDesc(ResolveInfo::Indirect);
Stephen Hines37b74a32014-11-26 18:48:20 -0800332 ASSERT_FALSE(sym->isSymbol());
333 ASSERT_TRUE(sym->isGlobal());
334 ASSERT_FALSE(sym->isWeak());
335 ASSERT_FALSE(sym->isLocal());
336 ASSERT_FALSE(sym->isDyn());
337 ASSERT_FALSE(sym->isDefine());
338 ASSERT_FALSE(sym->isUndef());
339 ASSERT_FALSE(sym->isCommon());
340 ASSERT_TRUE(sym->isIndirect());
341 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
342 ASSERT_TRUE(ResolveInfo::Indirect == sym->desc());
343 ASSERT_TRUE(0 == sym->binding());
344 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700345
346 sym->setDesc(ResolveInfo::Undefined);
Stephen Hines37b74a32014-11-26 18:48:20 -0800347 ASSERT_FALSE(sym->isSymbol());
348 ASSERT_TRUE(sym->isGlobal());
349 ASSERT_FALSE(sym->isWeak());
350 ASSERT_FALSE(sym->isLocal());
351 ASSERT_FALSE(sym->isDyn());
352 ASSERT_TRUE(sym->isUndef());
353 ASSERT_FALSE(sym->isDefine());
354 ASSERT_FALSE(sym->isCommon());
355 ASSERT_FALSE(sym->isIndirect());
356 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
357 ASSERT_TRUE(0 == sym->desc());
358 ASSERT_TRUE(0 == sym->binding());
359 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700360}
361
Stephen Hines37b74a32014-11-26 18:48:20 -0800362TEST_F(StaticResolverTest, SetUpBinding) {
Shih-wei Liao22add6f2012-12-15 17:21:00 -0800363 ResolveInfo* sym = ResolveInfo::Create("abc");
Stephen Hines551ae4e2014-04-24 14:41:24 -0700364
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700365 sym->setIsSymbol(true);
366
Stephen Hines37b74a32014-11-26 18:48:20 -0800367 // ASSERT_FALSE( sym->isSymbol() );
368 ASSERT_TRUE(sym->isSymbol());
369 ASSERT_TRUE(sym->isGlobal());
370 ASSERT_FALSE(sym->isWeak());
371 ASSERT_FALSE(sym->isLocal());
372 ASSERT_FALSE(sym->isDefine());
373 ASSERT_TRUE(sym->isUndef());
374 ASSERT_FALSE(sym->isDyn());
375 ASSERT_FALSE(sym->isCommon());
376 ASSERT_FALSE(sym->isIndirect());
377 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
378 ASSERT_TRUE(0 == sym->desc());
379 ASSERT_TRUE(0 == sym->binding());
380 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700381
382 sym->setBinding(ResolveInfo::Global);
Stephen Hines37b74a32014-11-26 18:48:20 -0800383 ASSERT_TRUE(sym->isSymbol());
384 ASSERT_TRUE(sym->isGlobal());
385 ASSERT_FALSE(sym->isWeak());
386 ASSERT_FALSE(sym->isLocal());
387 ASSERT_FALSE(sym->isDefine());
388 ASSERT_TRUE(sym->isUndef());
389 ASSERT_FALSE(sym->isDyn());
390 ASSERT_FALSE(sym->isCommon());
391 ASSERT_FALSE(sym->isIndirect());
392 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
393 ASSERT_TRUE(0 == sym->desc());
394 ASSERT_TRUE(ResolveInfo::Global == sym->binding());
395 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700396
397 sym->setBinding(ResolveInfo::Weak);
Stephen Hines37b74a32014-11-26 18:48:20 -0800398 ASSERT_TRUE(sym->isSymbol());
399 ASSERT_FALSE(sym->isGlobal());
400 ASSERT_TRUE(sym->isWeak());
401 ASSERT_FALSE(sym->isLocal());
402 ASSERT_FALSE(sym->isDyn());
403 ASSERT_FALSE(sym->isDefine());
404 ASSERT_TRUE(sym->isUndef());
405 ASSERT_FALSE(sym->isCommon());
406 ASSERT_FALSE(sym->isIndirect());
407 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
408 ASSERT_TRUE(0 == sym->desc());
409 ASSERT_TRUE(ResolveInfo::Weak == sym->binding());
410 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700411
412 sym->setBinding(ResolveInfo::Local);
Stephen Hines37b74a32014-11-26 18:48:20 -0800413 ASSERT_TRUE(sym->isSymbol());
414 ASSERT_FALSE(sym->isGlobal());
415 ASSERT_FALSE(sym->isWeak());
416 ASSERT_TRUE(sym->isLocal());
417 ASSERT_FALSE(sym->isDyn());
418 ASSERT_FALSE(sym->isDefine());
419 ASSERT_TRUE(sym->isUndef());
420 ASSERT_FALSE(sym->isCommon());
421 ASSERT_FALSE(sym->isIndirect());
422 ASSERT_TRUE(ResolveInfo::NoType == sym->type());
423 ASSERT_TRUE(0 == sym->desc());
424 ASSERT_TRUE(ResolveInfo::Local == sym->binding());
425 ASSERT_TRUE(0 == sym->other());
Shih-wei Liao5460a1f2012-03-16 22:41:16 -0700426}