summaryrefslogtreecommitdiff
path: root/tests/format/program.py
blob: 7a649b8347e982ec9963128e1aac71c28b9194fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

from chrysacase import ChrysalideTestCase
from pychrysalide import SourceEndian
#from pychrysalide.arch import vmpa, mrange
from pychrysalide.format import ProgramFormat
#from pychrysalide.format import BinSymbol


# class SimpleFormat(BinFormat):
#     pass


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)






    # 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."""

    #     sf = SimpleFormat()

    #     self.assertTrue(len(list(sf.symbols)) == 0)

    #     symbols = [ self.create_fake_symbol(i) for i in range(4) ]
    #     s0, s1, s2, s3 = symbols

    #     for s in symbols:
    #         sf.add_symbol(s)

    #     self.assertTrue(len(list(sf.symbols)) == len(symbols))

    #     sf.remove_symbol(s2)

    #     self.assertTrue(list(sf.symbols) == [s0, s1, s3])


    # def testBadParamsForAdding(self):
    #     """Check if bad parameters fail for adding a new symbol."""

    #     sf = SimpleFormat()

    #     with self.assertRaises(TypeError):
    #         sf.add_symbol('s')


    # def testWrongRemoval(self):
    #     """Try to remove a wrong symbol from a format."""

    #     sf = SimpleFormat()

    #     s23 = self.create_fake_symbol(23)
    #     sf.remove_symbol(s23)