Exemplo n.º 1
0
    def test_013_device_id_to_bytes(self):
        """ Test converting a device_id to bytes.
        """
        device_id = [0x00, 0x00]
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id, device_id_bytes)

        device_id = [0xff, 0xff]
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id, device_id_bytes)

        device_id = [0x12, 0x34]
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id, device_id_bytes)
Exemplo n.º 2
0
    def test_019_test_device_id_byte_conversion_03(self):
        """ Test converting a device_id value to its byte array value, then back
        to the device_id value
        """
        device_id = 0x01c4

        did_bytes = device_id_to_bytes(device_id)
        self.assertEqual(did_bytes, [0x01, 0xc4])

        new_device_id = device_id_join_bytes(did_bytes)
        self.assertEqual(new_device_id, device_id)
Exemplo n.º 3
0
    def test_010_device_id_to_bytes(self):
        """ Test converting a device_id to bytes.
        """
        device_id = long(0x00)
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0x00, 0x00])

        device_id = long(0x0f)
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0x00, 0x0f])

        device_id = long(0xffff)
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0xff, 0xff])

        device_id = long(0xa1b)
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0x0a, 0x1b])

        device_id = long(0xbeef)
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0xbe, 0xef])
Exemplo n.º 4
0
    def test_012_device_id_to_bytes(self):
        """ Test converting a device_id to bytes.
        """
        device_id = unicode('{0:04x}'.format(0xf1e2))
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0xf1, 0xe2])

        device_id = unicode('{0:04x}'.format(0x0))
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0x00, 0x00])

        device_id = unicode('{0:04x}'.format(0xffff))
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0xff, 0xff])

        device_id = unicode('{0:04x}'.format(0xabc))
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0x0a, 0xbc])

        device_id = unicode('{0:02x}'.format(0x12))
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0x00, 0x12])
Exemplo n.º 5
0
    def test_009_device_id_to_bytes(self):
        """ Test converting a device_id to bytes.
        """
        device_id = 0xf1e2
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0xf1, 0xe2])

        device_id = 0x1
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0x00, 0x1])

        device_id = 0x0000
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0x00, 0x00])

        device_id = 0xffff
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0xff, 0xff])

        device_id = 0x123
        device_id_bytes = utils.device_id_to_bytes(device_id)
        self.assertEqual(device_id_bytes, [0x01, 0x23])