1 from .base import TestBase
2 from ..object import ObjectFile
3 from ..object import Relocation
4 from ..object import Section
5 from ..object import Symbol
7 class TestObjectFile(TestBase):
8 def get_object_file(self):
9 source = self.get_test_binary()
10 return ObjectFile(filename=source)
12 def test_create_from_file(self):
13 self.get_object_file()
15 def test_get_sections(self):
16 o = self.get_object_file()
19 for section in o.get_sections():
21 assert isinstance(section, Section)
22 assert isinstance(section.name, str)
23 assert isinstance(section.size, long)
24 assert isinstance(section.contents, str)
25 assert isinstance(section.address, long)
27 self.assertGreater(count, 0)
29 for section in o.get_sections():
32 def test_get_symbols(self):
33 o = self.get_object_file()
36 for symbol in o.get_symbols():
38 assert isinstance(symbol, Symbol)
39 assert isinstance(symbol.name, str)
40 assert isinstance(symbol.address, long)
41 assert isinstance(symbol.size, long)
42 assert isinstance(symbol.file_offset, long)
44 self.assertGreater(count, 0)
46 for symbol in o.get_symbols():
49 def test_symbol_section_accessor(self):
50 o = self.get_object_file()
52 for symbol in o.get_symbols():
53 section = symbol.section
54 assert isinstance(section, Section)
58 def test_get_relocations(self):
59 o = self.get_object_file()
60 for section in o.get_sections():
61 for relocation in section.get_relocations():
62 assert isinstance(relocation, Relocation)
63 assert isinstance(relocation.address, long)
64 assert isinstance(relocation.offset, long)
65 assert isinstance(relocation.type_number, long)
66 assert isinstance(relocation.type_name, str)
67 assert isinstance(relocation.value_string, str)