Home | History | Annotate | Download | only in tests
      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             assert len(section.contents) == section.size
     27 
     28         self.assertGreater(count, 0)
     29 
     30         for section in o.get_sections():
     31             section.cache()
     32 
     33     def test_get_symbols(self):
     34         o = self.get_object_file()
     35 
     36         count = 0
     37         for symbol in o.get_symbols():
     38             count += 1
     39             assert isinstance(symbol, Symbol)
     40             assert isinstance(symbol.name, str)
     41             assert isinstance(symbol.address, long)
     42             assert isinstance(symbol.size, 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)
     68