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


from chrysacase import ChrysalideTestCase
from pychrysalide.arch import vmpa
from pychrysalide.glibext import BinPortion


class TestPathNames(ChrysalideTestCase):
    """TestCase for glibext.BinPortion*"""


    def testPortionProperties(self):
        """Validate various binary portion properties."""

        p = BinPortion(BinPortion.BPC_RAW, 0x102, 10)

        p.desc = 'ABC'
        self.assertEqual(p.desc, 'ABC')

        self.assertEqual(p.range.addr.phys, None)
        self.assertEqual(p.range.addr.virt, 0x102)
        self.assertEqual(p.range.length, 10)

        p.continuation = True
        self.assertTrue(p.continuation)

        p.continuation = False
        self.assertFalse(p.continuation)

        p.rights = BinPortion.PAC_ALL
        self.assertEqual(p.rights, BinPortion.PAC_READ | BinPortion.PAC_WRITE | BinPortion.PAC_EXEC)


    def testPortionMethods(self):
        """Validate some binary portion methods."""

        p = BinPortion(BinPortion.BPC_RAW, 0x102, 10)

        self.assertEqual(p.range.length, 10)

        p.limit_range(10)

        self.assertEqual(p.range.length, 10)

        p.limit_range(6)

        self.assertEqual(p.range.length, 6)


    def testPortionComparison(self):
        """Compare different binary portions."""

        p0 = BinPortion(BinPortion.BPC_CODE, 0x102, 10)

        addr = vmpa(vmpa.VMPA_NO_PHYSICAL, 0x102)
        p1 = BinPortion(BinPortion.BPC_CODE, addr, 10)

        self.assertEqual(p0, p1)