diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-03-26 13:44:28 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-03-26 13:44:28 (GMT) |
commit | 78169fc7f8a7150cd22cfe80204cb2faaa991ba5 (patch) | |
tree | ba5bc17f43af044a408dbf07b9f70fffa5ec3bb8 /tests | |
parent | 4319c0ae542b60f225d0f6ce373fe8d2e5f1475d (diff) |
Fixed the conversion of immediate operands to binary strings.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/arch/immediate.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/arch/immediate.py b/tests/arch/immediate.py new file mode 100755 index 0000000..b3ddc6d --- /dev/null +++ b/tests/arch/immediate.py @@ -0,0 +1,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) |