summaryrefslogtreecommitdiff
path: root/tests/arch/immediate.py
blob: b3ddc6d5bab3afcf4362b74b2537e48671948860 (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
#!/usr/bin/python3-dbg
# -*- coding: utf-8 -*-


import pychrysalide
from chrysacase import ChrysalideTestCase
from pychrysalide import arch
from pychrysalide.arch import ImmOperand



class TestImmediate(ChrysalideTestCase):
    """TestCase for arch.ImmOperand."""


    def validateValue(self, value, size, padding, syntax, strings):
        """Check all kinds of things with a given immediate operand."""

        display = [
            ImmOperand.IOD_BIN, ImmOperand.IOD_OCT,
            ImmOperand.IOD_DEC,
            ImmOperand.IOD_HEX
        ]

        for d in display:

            op = ImmOperand(size, value)

            self.assertTrue(op.size == size)
            self.assertTrue(op.value == value)

            op.padding = padding
            op.display = d

            string = op.to_string(syntax)
            self.assertEqual(string, strings[d])


    def testByteOne(self):
        """Run sanity checks on immediate operand with value 1."""

        strings = {
            ImmOperand.IOD_BIN: 'b1',
            ImmOperand.IOD_OCT: '01',
            ImmOperand.IOD_DEC: '1',
            ImmOperand.IOD_HEX: '0x1'
        }

        self.validateValue(1, arch.MDS_8_BITS_UNSIGNED, False, arch.ASX_INTEL, strings)


    def testByteOnePadded(self):
        """Run sanity checks on immediate operand with padded value 1."""

        strings = {
            ImmOperand.IOD_BIN: 'b00000001',
            ImmOperand.IOD_OCT: '01',
            ImmOperand.IOD_DEC: '1',
            ImmOperand.IOD_HEX: '0x01'
        }

        self.validateValue(1, arch.MDS_8_BITS_UNSIGNED, True, arch.ASX_INTEL, strings)