1 //===- 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 //===----------------------------------------------------------------------===// 9 #include <mcld/MC/SymbolCategory.h> 10 #include <mcld/LD/ResolveInfo.h> 11 #include <mcld/LD/LDSymbol.h> 12 #include <iostream> 13 #include "SymbolCategoryTest.h" 14 15 using namespace std; 16 using namespace mcld; 17 using namespace mcldtest; 18 19 20 // Constructor can do set-up work for all test here. 21 SymbolCategoryTest::SymbolCategoryTest() 22 { 23 // create testee. modify it if need 24 m_pTestee = new SymbolCategory(); 25 } 26 27 // Destructor can do clean-up work that doesn't throw exceptions here. 28 SymbolCategoryTest::~SymbolCategoryTest() 29 { 30 delete m_pTestee; 31 } 32 33 // SetUp() will be called immediately before each test. 34 void SymbolCategoryTest::SetUp() 35 { 36 } 37 38 // TearDown() will be called immediately after each test. 39 void SymbolCategoryTest::TearDown() 40 { 41 } 42 43 //==========================================================================// 44 // Testcases 45 // 46 47 TEST_F(SymbolCategoryTest, upward_test) { 48 ResolveInfo* a = m_InfoFactory.produce("a"); 49 ResolveInfo* b = m_InfoFactory.produce("b"); 50 ResolveInfo* c = m_InfoFactory.produce("c"); 51 ResolveInfo* d = m_InfoFactory.produce("d"); 52 ResolveInfo* e = m_InfoFactory.produce("e"); 53 e->setBinding(ResolveInfo::Global); 54 d->setBinding(ResolveInfo::Weak); 55 c->setDesc(ResolveInfo::Common); 56 c->setBinding(ResolveInfo::Global); 57 b->setBinding(ResolveInfo::Local); 58 a->setType(ResolveInfo::File); 59 60 LDSymbol aa; 61 LDSymbol bb; 62 LDSymbol cc; 63 LDSymbol dd; 64 LDSymbol ee; 65 66 aa.setResolveInfo(*a); 67 bb.setResolveInfo(*b); 68 cc.setResolveInfo(*c); 69 dd.setResolveInfo(*d); 70 ee.setResolveInfo(*e); 71 72 m_pTestee->add(ee); 73 m_pTestee->add(dd); 74 m_pTestee->add(cc); 75 m_pTestee->add(bb); 76 m_pTestee->add(aa); 77 78 SymbolCategory::iterator sym = m_pTestee->begin(); 79 ASSERT_STREQ("a", (*sym)->name()); 80 ++sym; 81 ASSERT_STREQ("b", (*sym)->name()); 82 ++sym; 83 ASSERT_STREQ("c", (*sym)->name()); 84 ++sym; 85 ASSERT_STREQ("d", (*sym)->name()); 86 ++sym; 87 ASSERT_STREQ("e", (*sym)->name()); 88 89 ASSERT_EQ(2, m_pTestee->numOfLocals()); 90 ASSERT_EQ(1, m_pTestee->numOfCommons()); 91 ASSERT_EQ(2, m_pTestee->numOfRegulars()); 92 ASSERT_EQ(5, m_pTestee->numOfSymbols()); 93 } 94 95