1 from numbers
import Integral
3 from .base
import TestBase
4 from ..object import ObjectFile
5 from ..object import Relocation
6 from ..object import Section
7 from ..object import Symbol
9 class TestObjectFile(TestBase
):
10 def get_object_file(self
):
11 source
= self
.get_test_binary()
12 return ObjectFile(filename
=source
)
14 def test_create_from_file(self
):
15 self
.get_object_file()
17 def test_get_sections(self
):
18 o
= self
.get_object_file()
21 for section
in o
.get_sections():
23 assert isinstance(section
, Section
)
24 assert isinstance(section
.name
, str)
25 assert isinstance(section
.size
, Integral
)
26 assert isinstance(section
.contents
, str)
27 assert isinstance(section
.address
, Integral
)
28 assert len(section
.contents
) == section
.size
30 self
.assertGreater(count
, 0)
32 for section
in o
.get_sections():
35 def test_get_symbols(self
):
36 o
= self
.get_object_file()
39 for symbol
in o
.get_symbols():
41 assert isinstance(symbol
, Symbol
)
42 assert isinstance(symbol
.name
, str)
43 assert isinstance(symbol
.address
, Integral
)
44 assert isinstance(symbol
.size
, Integral
)
46 self
.assertGreater(count
, 0)
48 for symbol
in o
.get_symbols():
51 def test_symbol_section_accessor(self
):
52 o
= self
.get_object_file()
54 for symbol
in o
.get_symbols():
55 section
= symbol
.section
56 assert isinstance(section
, Section
)
60 def test_get_relocations(self
):
61 o
= self
.get_object_file()
62 for section
in o
.get_sections():
63 for relocation
in section
.get_relocations():
64 assert isinstance(relocation
, Relocation
)
65 assert isinstance(relocation
.address
, Integral
)
66 assert isinstance(relocation
.offset
, Integral
)
67 assert isinstance(relocation
.type_number
, Integral
)
68 assert isinstance(relocation
.type_name
, str)
69 assert isinstance(relocation
.value_string
, str)