summaryrefslogtreecommitdiff
path: root/tests/glibext/binportion.py
blob: 8d5f3af7faba38a185b1f55e82958990f8f1d228 (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

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.BinaryPortionCode.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.PortionAccessRights.ALL
        self.assertEqual(p.rights, BinPortion.PortionAccessRights.READ | BinPortion.PortionAccessRights.WRITE | BinPortion.PortionAccessRights.EXEC)


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

        p = BinPortion(BinPortion.BinaryPortionCode.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.BinaryPortionCode.CODE, 0x102, 10)

        addr = vmpa(vmpa.VmpaSpecialValue.NO_PHYSICAL, 0x102)
        p1 = BinPortion(BinPortion.BinaryPortionCode.CODE, addr, 10)

        self.assertEqual(p0, p1)