2#include <cppunit/extensions/HelperMacros.h>
3#include <cppunit/TestFixture.h>
5#include "../../src/linker/symbol.h"
15 CPPUNIT_TEST(testLoadName);
16 CPPUNIT_TEST(testLoadLibraryName);
17 CPPUNIT_TEST(testLoadOrdinalOrHint);
18 CPPUNIT_TEST(testGetLocalName);
19 CPPUNIT_TEST(testGetImportedName);
20 CPPUNIT_TEST(testGetImportedOrdinal);
21 CPPUNIT_TEST(testEquality);
22 CPPUNIT_TEST_SUITE_END();
30 void testLoadLibraryName();
31 void testLoadOrdinalOrHint();
33 void testGetLocalName();
34 void testGetImportedName();
35 void testGetImportedOrdinal();
42void TestSymbolName::testLoadName()
46 CPPUNIT_ASSERT(internalSymbol->
LoadName(result));
47 CPPUNIT_ASSERT_EQUAL(std::string(
"InternalName"), result);
49 CPPUNIT_ASSERT(importedSymbolByName->
LoadName(result));
50 CPPUNIT_ASSERT_EQUAL(std::string(
"ImportedName"), result);
52 CPPUNIT_ASSERT(importedSymbolWithHint->
LoadName(result));
53 CPPUNIT_ASSERT_EQUAL(std::string(
"ImportedName"), result);
55 CPPUNIT_ASSERT(!importedSymbolByOrdinal->
LoadName(result));
58void TestSymbolName::testLoadLibraryName()
65 CPPUNIT_ASSERT_EQUAL(std::string(
"LibraryName"), result);
69 CPPUNIT_ASSERT_EQUAL(std::string(
"LibraryName"), result);
73 CPPUNIT_ASSERT_EQUAL(std::string(
"LibraryName"), result);
76void TestSymbolName::testLoadOrdinalOrHint()
86 CPPUNIT_ASSERT_EQUAL(uint16_t(1234), result);
90 CPPUNIT_ASSERT_EQUAL(uint16_t(1234), result);
93void TestSymbolName::testGetLocalName()
98 CPPUNIT_ASSERT_EQUAL(std::string(
"InternalName"), result);
100 CPPUNIT_ASSERT(!importedSymbolByName->
GetLocalName(result));
102 CPPUNIT_ASSERT(!importedSymbolWithHint->
GetLocalName(result));
104 CPPUNIT_ASSERT(!importedSymbolByOrdinal->
GetLocalName(result));
107void TestSymbolName::testGetImportedName()
109 std::string libraryResult;
110 std::string symbolResult;
113 CPPUNIT_ASSERT(!internalSymbol->
GetImportedName(libraryResult, symbolResult));
115 CPPUNIT_ASSERT(importedSymbolByName->
GetImportedName(libraryResult, symbolResult));
116 CPPUNIT_ASSERT_EQUAL(std::string(
"ImportedName"), symbolResult);
117 CPPUNIT_ASSERT_EQUAL(std::string(
"LibraryName"), libraryResult);
119 symbolResult = libraryResult =
"";
120 CPPUNIT_ASSERT(importedSymbolWithHint->
GetImportedName(libraryResult, symbolResult));
121 CPPUNIT_ASSERT_EQUAL(std::string(
"ImportedName"), symbolResult);
122 CPPUNIT_ASSERT_EQUAL(std::string(
"LibraryName"), libraryResult);
124 CPPUNIT_ASSERT(!importedSymbolByOrdinal->
GetImportedName(libraryResult, symbolResult));
128 CPPUNIT_ASSERT(!internalSymbol->
GetImportedName(libraryResult, symbolResult, hintResult));
130 symbolResult = libraryResult =
"";
131 CPPUNIT_ASSERT(importedSymbolByName->
GetImportedName(libraryResult, symbolResult, hintResult));
132 CPPUNIT_ASSERT_EQUAL(std::string(
"ImportedName"), symbolResult);
133 CPPUNIT_ASSERT_EQUAL(std::string(
"LibraryName"), libraryResult);
135 symbolResult = libraryResult =
"";
137 CPPUNIT_ASSERT(importedSymbolWithHint->
GetImportedName(libraryResult, symbolResult, hintResult));
138 CPPUNIT_ASSERT_EQUAL(std::string(
"ImportedName"), symbolResult);
139 CPPUNIT_ASSERT_EQUAL(std::string(
"LibraryName"), libraryResult);
140 CPPUNIT_ASSERT_EQUAL(uint16_t(1234), hintResult);
142 CPPUNIT_ASSERT(!importedSymbolByOrdinal->
GetImportedName(libraryResult, symbolResult, hintResult));
145void TestSymbolName::testGetImportedOrdinal()
147 std::string libraryResult;
154 CPPUNIT_ASSERT(!importedSymbolWithHint->
GetImportedOrdinal(libraryResult, hintResult));
157 CPPUNIT_ASSERT(importedSymbolByOrdinal->
GetImportedOrdinal(libraryResult, hintResult));
158 CPPUNIT_ASSERT_EQUAL(std::string(
"LibraryName"), libraryResult);
159 CPPUNIT_ASSERT_EQUAL(uint16_t(1234), hintResult);
162void TestSymbolName::testEquality()
164 CPPUNIT_ASSERT_EQUAL(*internalSymbol,
SymbolName(
"InternalName"));
165 CPPUNIT_ASSERT_EQUAL(*importedSymbolByName,
SymbolName(
"LibraryName",
"ImportedName"));
166 CPPUNIT_ASSERT_EQUAL(*importedSymbolWithHint,
SymbolName(
"LibraryName",
"ImportedName", 1234));
167 CPPUNIT_ASSERT_EQUAL(*importedSymbolByOrdinal,
SymbolName(
"LibraryName", 1234));
188void TestSymbolName::setUp()
190 internalSymbol =
new SymbolName(
"InternalName");
191 importedSymbolByName =
new SymbolName(
"LibraryName",
"ImportedName");
192 importedSymbolWithHint =
new SymbolName(
"LibraryName",
"ImportedName", 1234);
193 importedSymbolByOrdinal =
new SymbolName(
"LibraryName", 1234);
196void TestSymbolName::tearDown()
198 delete internalSymbol;
199 delete importedSymbolByName;
200 delete importedSymbolWithHint;
201 delete importedSymbolByOrdinal;
207 CPPUNIT_TEST(testIsExportedByOrdinal);
208 CPPUNIT_TEST(testLoadName);
209 CPPUNIT_TEST(testLoadOrdinalOrHint);
210 CPPUNIT_TEST(testGetExportedByName);
211 CPPUNIT_TEST(testGetExportedByOrdinal);
212 CPPUNIT_TEST(testEquality);
213 CPPUNIT_TEST(testComparison);
214 CPPUNIT_TEST_SUITE_END();
220 void testIsExportedByOrdinal();
222 void testLoadOrdinalOrHint();
223 void testGetExportedByName();
224 void testGetExportedByOrdinal();
228 void testComparison();
234void TestExportedSymbol::testIsExportedByOrdinal()
236 CPPUNIT_ASSERT(!exportedSymbolByName->IsExportedByOrdinal());
237 CPPUNIT_ASSERT(!exportedSymbolWithHint->IsExportedByOrdinal());
238 CPPUNIT_ASSERT(exportedSymbolByOrdinal->IsExportedByOrdinal());
241void TestExportedSymbol::testLoadName()
245 CPPUNIT_ASSERT(exportedSymbolByName->
LoadName(result));
246 CPPUNIT_ASSERT_EQUAL(std::string(
"ExportedName"), result);
249 CPPUNIT_ASSERT(exportedSymbolWithHint->
LoadName(result));
250 CPPUNIT_ASSERT_EQUAL(std::string(
"ExportedName"), result);
253 CPPUNIT_ASSERT(exportedSymbolByOrdinal->
LoadName(result));
254 CPPUNIT_ASSERT_EQUAL(std::string(
"InternalName"), result);
257void TestExportedSymbol::testLoadOrdinalOrHint()
265 CPPUNIT_ASSERT_EQUAL(uint16_t(1234), result);
269 CPPUNIT_ASSERT_EQUAL(uint16_t(1234), result);
272void TestExportedSymbol::testGetExportedByName()
274 std::string nameResult;
278 CPPUNIT_ASSERT_EQUAL(std::string(
"ExportedName"), nameResult);
282 CPPUNIT_ASSERT_EQUAL(std::string(
"ExportedName"), nameResult);
290 CPPUNIT_ASSERT_EQUAL(std::string(
"ExportedName"), nameResult);
294 CPPUNIT_ASSERT(exportedSymbolWithHint->
GetExportedByName(nameResult, hintResult));
295 CPPUNIT_ASSERT_EQUAL(std::string(
"ExportedName"), nameResult);
296 CPPUNIT_ASSERT_EQUAL(uint16_t(1234), hintResult);
298 CPPUNIT_ASSERT(!exportedSymbolByOrdinal->
GetExportedByName(nameResult, hintResult));
301void TestExportedSymbol::testGetExportedByOrdinal()
303 std::string nameResult;
311 CPPUNIT_ASSERT_EQUAL(uint16_t(1234), hintResult);
322 CPPUNIT_ASSERT_EQUAL(uint16_t(1234), hintResult);
323 CPPUNIT_ASSERT_EQUAL(std::string(
"InternalName"), nameResult);
326void TestExportedSymbol::testEquality()
328 CPPUNIT_ASSERT_EQUAL(*exportedSymbolByName,
ExportedSymbol(
"ExportedName"));
329 CPPUNIT_ASSERT_EQUAL(*exportedSymbolWithHint,
ExportedSymbol(
"ExportedName", 1234));
330 CPPUNIT_ASSERT_EQUAL(*exportedSymbolByOrdinal,
ExportedSymbol(1234,
"InternalName"));
347 return a <= b && a >= b;
352 return a < b || a > b;
355void TestExportedSymbol::testComparison()
370void TestExportedSymbol::setUp()
373 exportedSymbolWithHint =
new ExportedSymbol(
"ExportedName", 1234);
374 exportedSymbolByOrdinal =
new ExportedSymbol(1234,
"InternalName");
377void TestExportedSymbol::tearDown()
379 delete exportedSymbolByName;
380 delete exportedSymbolWithHint;
381 delete exportedSymbolByOrdinal;
Represents a symbol to be exported from the module.
Definition symbol.h:119
bool GetExportedByName(std::string &result) const
For symbols exported by name, returns the name.
Definition symbol.cc:167
bool LoadName(std::string &result) const
Returns the name of the symbol.
Definition symbol.cc:148
bool LoadOrdinalOrHint(uint16_t &result) const
Returns the hint or ordinal of the symbol.
Definition symbol.cc:154
bool GetExportedByOrdinal(uint16_t &result) const
For symbols exported by ordinal, returns the ordinal.
Definition symbol.cc:197
Represents an (imported or internal) symbol name, which can be more complex than a string.
Definition symbol.h:18
bool GetImportedOrdinal(std::string &result_library, uint16_t &result_ordinal) const
For symbols imported by ordinal, returns the library and ordinal.
Definition symbol.cc:92
bool GetLocalName(std::string &result) const
For local symbols, returns the name.
Definition symbol.cc:45
bool LoadName(std::string &result) const
Retrieves the name of the symbol, if it has one.
Definition symbol.cc:6
bool LoadOrdinalOrHint(uint16_t &result) const
Retrieves the ordinal of symbols imported by ordinal, or the hint for imported symbols with a hint.
Definition symbol.cc:32
bool LoadLibraryName(std::string &result) const
Retrieves the name of the library, if it is imported.
Definition symbol.cc:19
bool GetImportedName(std::string &result_library, std::string &result_name) const
For symbols imported by name, returns the library and name.
Definition symbol.cc:60