7ff981b6a2f7ba38cefa2ffc0d2432b50d114146
[oota-llvm.git] / bindings / python / llvm / tests / test_object.py
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
6
7 class TestObjectFile(TestBase):
8     def get_object_file(self):
9         source = self.get_test_binary()
10         return ObjectFile(filename=source)
11
12     def test_create_from_file(self):
13         self.get_object_file()
14
15     def test_get_sections(self):
16         o = self.get_object_file()
17
18         count = 0
19         for section in o.get_sections():
20             count += 1
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)
26
27         self.assertGreater(count, 0)
28
29         for section in o.get_sections():
30             section.cache()
31
32     def test_get_symbols(self):
33         o = self.get_object_file()
34
35         count = 0
36         for symbol in o.get_symbols():
37             count += 1
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)
43
44         self.assertGreater(count, 0)
45
46         for symbol in o.get_symbols():
47             symbol.cache()
48
49     def test_symbol_section_accessor(self):
50         o = self.get_object_file()
51
52         for symbol in o.get_symbols():
53             section = symbol.section
54             assert isinstance(section, Section)
55
56             break
57
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)