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


# Tests minimalistes pour valider l'intégration des adresses et espaces mémoire
# depuis Python.


from chrysacase import ChrysalideTestCase
from pychrysalide.arch import vmpa


class TestVmpa(ChrysalideTestCase):
    """TestCase for arch.vmpa."""

    def testInit(self):
        """VMPA values are left uninitialized by default."""

        v = vmpa()

        self.assertIsNone(v.phys)
        self.assertIsNone(v.virt)


    def testAdd(self):
        """Verify the commutative property of addition."""

        a = vmpa(0, 0) + 1

        b = 1 + vmpa(0, 0)

        c = vmpa(1, 1)

        self.assertEqual(a, b)
        self.assertEqual(a, c)


    def testCompareWrong(self):
        """Verify unhandled comparisons with VMPA."""

        a = vmpa()

        with self.assertRaisesRegex(Exception, 'Unable to cast object as VMPA.'):

            self.assertLess(a, 'b')


    def testCompareFair(self):
        """Verify right VMPA comparisons."""

        a = vmpa(0)
        b = vmpa()

        self.assertLess(a, b)

        self.assertGreater(b, a)

        a = vmpa()
        b = vmpa()

        self.assertEqual(a, b)