예제 #1
0
    def testPackifyUnpackify(self):
        """
        Test the packbits
        """
        console.terse("{0}\n".format(self.testPackifyUnpackify.__doc__))

        fmt = u"3 2 1 1"
        fields = [6, 2, True, False]
        size = 1
        packed = aiding.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([212]))
        self.assertEqual(aiding.binize(aiding.unbytify(packed), size * 8), "11010100")

        fmt = u""
        fields = []
        size = 0
        packed = aiding.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([]))

        fmt = u"3 1"
        fields = [5, True]
        size = 1
        packed = aiding.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([0xB0]))
        self.assertEqual(aiding.binize(aiding.unbytify(packed), size * 8), "10110000")

        fmt = u"8 6 7 3"
        fields = [0xA5, 0x38, 0x08, 0x01]
        size = 3
        packed = aiding.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([0xA5, 0xE0, 0x41]))
        self.assertEqual(aiding.binize(aiding.unbytify(packed), size * 8), "101001011110000001000001")
        # 0xa5e040

        fmt = u"3 2 1 1"
        packed = bytearray([212])
        fields = aiding.unpackify(fmt=fmt, b=packed, boolean=True)
        self.assertEqual(fields, (6, 2, True, False, False))
        fields = aiding.unpackify(fmt=fmt, b=packed, boolean=False)
        self.assertEqual(fields, (6, 2, 1, 0, 0))

        fmt = u""
        packed = bytearray([])
        fields = aiding.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, tuple())

        fmt = u"3 1"
        packed = [0xB0]
        fields = aiding.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, (5, 1, 0))

        fmt = u"4 3 1"
        packed = [0x0B]
        fields = aiding.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, (0, 5, 1))

        fmt = u"8 6 7 3"
        packed = bytearray([0xA5, 0xE0, 0x41])
        fields = aiding.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, (0xA5, 0x38, 0x08, 0x01))
예제 #2
0
    def testBinizeUnbinize(self):
        """
        Test the binize unbinize functions
        """
        console.terse("{0}\n".format(self.testBinizeUnbinize.__doc__))

        n = 5
        u = aiding.binize(n, 8)
        self.assertEqual(u, "00000101")
        n = aiding.unbinize(u)
        self.assertEqual(n, 5)
예제 #3
0
    def testBinizeUnbinize(self):
        """
        Test the binize unbinize functions
        """
        console.terse("{0}\n".format(self.testBinizeUnbinize.__doc__))

        n = 5
        u = aiding.binize(n, 8)
        self.assertEqual(u, '00000101')
        n = aiding.unbinize(u)
        self.assertEqual(n, 5)
예제 #4
0
    def testPackifyUnpackify(self):
        """
        Test the packbits
        """
        console.terse("{0}\n".format(self.testPackifyUnpackify.__doc__))

        fmt = u'3 2 1 1'
        fields = [6, 2, True, False]
        size = 1
        packed = aiding.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([212]))
        self.assertEqual(aiding.binize(aiding.unbytify(packed), size * 8),
                         '11010100')

        fmt = u''
        fields = []
        size = 0
        packed = aiding.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([]))

        fmt = u'3 1'
        fields = [5, True]
        size = 1
        packed = aiding.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([0xb0]))
        self.assertEqual(aiding.binize(aiding.unbytify(packed), size * 8),
                         '10110000')

        fmt = u'8 6 7 3'
        fields = [0xA5, 0x38, 0x08, 0x01]
        size = 3
        packed = aiding.packify(fmt=fmt, fields=fields, size=size)
        self.assertEqual(packed, bytearray([0xa5, 0xe0, 0x41]))
        self.assertEqual(aiding.binize(aiding.unbytify(packed), size * 8),
                         '101001011110000001000001')
        # 0xa5e040

        fmt = u'3 2 1 1'
        packed = bytearray([212])
        fields = aiding.unpackify(fmt=fmt, b=packed, boolean=True)
        self.assertEqual(fields, (6, 2, True, False, False))
        fields = aiding.unpackify(fmt=fmt, b=packed, boolean=False)
        self.assertEqual(fields, (6, 2, 1, 0, 0))

        fmt = u''
        packed = bytearray([])
        fields = aiding.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, tuple())

        fmt = u'3 1'
        packed = [0xb0]
        fields = aiding.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, (5, 1, 0))

        fmt = u'4 3 1'
        packed = [0x0b]
        fields = aiding.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, (0, 5, 1))

        fmt = u'8 6 7 3'
        packed = bytearray([0xa5, 0xe0, 0x41])
        fields = aiding.unpackify(fmt=fmt, b=packed)
        self.assertEqual(fields, (0xA5, 0x38, 0x08, 0x01))