diff options
Diffstat (limited to 'tests/format/program.py')
-rw-r--r-- | tests/format/program.py | 96 |
1 files changed, 57 insertions, 39 deletions
diff --git a/tests/format/program.py b/tests/format/program.py index b6aad8f..7a649b8 100644 --- a/tests/format/program.py +++ b/tests/format/program.py @@ -1,66 +1,84 @@ -#!/usr/bin/python3-dbg -# -*- coding: utf-8 -*- +from chrysacase import ChrysalideTestCase +from pychrysalide import SourceEndian +#from pychrysalide.arch import vmpa, mrange +from pychrysalide.format import ProgramFormat +#from pychrysalide.format import BinSymbol -# Tests minimalistes pour valider la gestion des erreurs relevées. +# class SimpleFormat(BinFormat): +# pass -from chrysacase import ChrysalideTestCase -from pychrysalide.arch import vmpa, mrange -from pychrysalide.format import BinFormat -from pychrysalide.format import BinSymbol -import os -import sys + +class TestProgramFormat(ChrysalideTestCase): + """TestCase for format.ProgramFormat.""" + + + def testCustomInstance(self): + """Validate a full custom ProgramFormat implementation.""" + + class CustomFormat(ProgramFormat): + + def _get_endianness(self): + return SourceEndian.BIG + + cf = CustomFormat() + + self.assertEqual(cf.endianness, SourceEndian.BIG) + + + class EmptyCustomFormat(ProgramFormat): + pass + + cf = EmptyCustomFormat() + + self.assertEqual(cf.endianness, SourceEndian.LITTLE) -class SimpleFormat(BinFormat): - pass -class TestFormatErrors(ChrysalideTestCase): - """TestCase for format.BinFormat.""" - def create_fake_symbol(self, index): - saddr = vmpa(index * 0x10, vmpa.VMPA_NO_VIRTUAL) - srange = mrange(saddr, 0x3) - symbol = BinSymbol(BinSymbol.STP_ENTRY_POINT, srange) - return symbol + # def create_fake_symbol(self, index): + # saddr = vmpa(index * 0x10, vmpa.VMPA_NO_VIRTUAL) + # srange = mrange(saddr, 0x3) + # symbol = BinSymbol(BinSymbol.STP_ENTRY_POINT, srange) + # return symbol - def testBasicSymbolOperations(self): - """Deal with the basic operations related to symbols in a binary format.""" + # def testBasicSymbolOperations(self): + # """Deal with the basic operations related to symbols in a binary format.""" - sf = SimpleFormat() + # sf = SimpleFormat() - self.assertTrue(len(list(sf.symbols)) == 0) + # self.assertTrue(len(list(sf.symbols)) == 0) - symbols = [ self.create_fake_symbol(i) for i in range(4) ] - s0, s1, s2, s3 = symbols + # symbols = [ self.create_fake_symbol(i) for i in range(4) ] + # s0, s1, s2, s3 = symbols - for s in symbols: - sf.add_symbol(s) + # for s in symbols: + # sf.add_symbol(s) - self.assertTrue(len(list(sf.symbols)) == len(symbols)) + # self.assertTrue(len(list(sf.symbols)) == len(symbols)) - sf.remove_symbol(s2) + # sf.remove_symbol(s2) - self.assertTrue(list(sf.symbols) == [s0, s1, s3]) + # self.assertTrue(list(sf.symbols) == [s0, s1, s3]) - def testBadParamsForAdding(self): - """Check if bad parameters fail for adding a new symbol.""" + # def testBadParamsForAdding(self): + # """Check if bad parameters fail for adding a new symbol.""" - sf = SimpleFormat() + # sf = SimpleFormat() - with self.assertRaises(TypeError): - sf.add_symbol('s') + # with self.assertRaises(TypeError): + # sf.add_symbol('s') - def testWrongRemoval(self): - """Try to remove a wrong symbol from a format.""" + # def testWrongRemoval(self): + # """Try to remove a wrong symbol from a format.""" - sf = SimpleFormat() + # sf = SimpleFormat() - s23 = self.create_fake_symbol(23) - sf.remove_symbol(s23) + # s23 = self.create_fake_symbol(23) + # sf.remove_symbol(s23) |