Exemplo n.º 1
0
    def test_core_key_keycmp_boundary(self):
        key0000 = b'\x00' * Key.KEY_OCTETS
        keyffff = b'\xff' * Key.KEY_OCTETS

        key1fff = b'\x1f' + b'\xff' * (Key.KEY_OCTETS - 1)
        key2000 = b'\x20' + b'\x00' * (Key.KEY_OCTETS - 1)
        key2001 = b'\x20' + b'\x00' * (Key.KEY_OCTETS - 2) + b'\x01'

        key5fff = b'\x5f' + b'\xff' * (Key.KEY_OCTETS - 1)
        key6000 = b'\x60' + b'\x00' * (Key.KEY_OCTETS - 1)
        key6001 = b'\x60' + b'\x00' * (Key.KEY_OCTETS - 2) + b'\x01'

        key9fff = b'\x9f' + b'\xff' * (Key.KEY_OCTETS - 1)
        keya000 = b'\xa0' + b'\x00' * (Key.KEY_OCTETS - 1)
        keya001 = b'\xa0' + b'\x00' * (Key.KEY_OCTETS - 2) + b'\x01'

        keydfff = b'\xdf' + b'\xff' * (Key.KEY_OCTETS - 1)
        keye000 = b'\xe0' + b'\x00' * (Key.KEY_OCTETS - 1)
        keye001 = b'\xe0' + b'\x00' * (Key.KEY_OCTETS - 2) + b'\x01'

        self.assertEqual(Key.KEY_OCTETS, 32)
        self.assertEqual(len(key0000), Key.KEY_OCTETS)
        self.assertEqual(len(keyffff), Key.KEY_OCTETS)
        self.assertEqual(len(key1fff), Key.KEY_OCTETS)
        self.assertEqual(len(key2000), Key.KEY_OCTETS)
        self.assertEqual(len(key2001), Key.KEY_OCTETS)
        self.assertEqual(len(key5fff), Key.KEY_OCTETS)
        self.assertEqual(len(key6000), Key.KEY_OCTETS)
        self.assertEqual(len(key6001), Key.KEY_OCTETS)
        self.assertEqual(len(key9fff), Key.KEY_OCTETS)
        self.assertEqual(len(keya000), Key.KEY_OCTETS)
        self.assertEqual(len(keya001), Key.KEY_OCTETS)
        self.assertEqual(len(keydfff), Key.KEY_OCTETS)
        self.assertEqual(len(keye000), Key.KEY_OCTETS)
        self.assertEqual(len(keye001), Key.KEY_OCTETS)

        # Greater means Red, Less means Green, Eq means White

        self.assertEqual(Key.keycmp(key2000, key2000), 0)  # eq     White
        self.assertGreater(Key.keycmp(key2001, key2000), 0)  # + 1    Red
        self.assertGreater(Key.keycmp(key9fff, key2000), 0)  # + 7fff Red
        self.assertLess(Key.keycmp(keya000, key2000), 0)  # + 8000 Green
        self.assertLess(Key.keycmp(key1fff, key2000), 0)  # - 1    Green
        self.assertLess(Key.keycmp(keyffff, key2000), 0)  # end    Green
        self.assertLess(Key.keycmp(key0000, key2000), 0)  # zero   Green

        self.assertEqual(Key.keycmp(key6000, key6000), 0)  # eq     White
        self.assertGreater(Key.keycmp(key6001, key6000), 0)  # + 1    Red
        self.assertGreater(Key.keycmp(keydfff, key6000), 0)  # + 7fff Red
        self.assertLess(Key.keycmp(keye000, key6000), 0)  # + 8000 Green
        self.assertLess(Key.keycmp(key5fff, key6000), 0)  # - 1    Green
        self.assertLess(Key.keycmp(keyffff, key6000), 0)  # end    Green
        self.assertLess(Key.keycmp(key0000, key6000), 0)  # zero   Green

        self.assertEqual(Key.keycmp(keya000, keya000), 0)  # eq     White
        self.assertGreater(Key.keycmp(keya001, keya000), 0)  # + 1    Red
        self.assertGreater(Key.keycmp(key1fff, keya000), 0)  # + 7fff Red
        self.assertLess(Key.keycmp(key2000, keya000), 0)  # + 8000 Green
        self.assertLess(Key.keycmp(key9fff, keya000), 0)  # - 1    Green
        self.assertGreater(Key.keycmp(keyffff, keya000), 0)  # end    Red
        self.assertGreater(Key.keycmp(key0000, keya000), 0)  # zero   Red

        self.assertEqual(Key.keycmp(keye000, keye000), 0)  # eq     White
        self.assertGreater(Key.keycmp(keye001, keye000), 0)  # + 1    Red
        self.assertGreater(Key.keycmp(key5fff, keye000), 0)  # + 7fff Red
        self.assertLess(Key.keycmp(key6000, keye000), 0)  # + 8000 Green
        self.assertLess(Key.keycmp(keydfff, keye000), 0)  # - 1    Green
        self.assertGreater(Key.keycmp(keyffff, keye000), 0)  # end    Red
        self.assertGreater(Key.keycmp(key0000, keye000), 0)  # zero   Red
Exemplo n.º 2
0
    def test_core_key_keycmp_simple(self):
        # b'\xff' * 16
        # int.to_bytes(255, 1, 'big')
        # int.to_bytes(0, 1, 'big')
        keyffff = b'\xff' * Key.KEY_OCTETS
        keyfffe = b'\xff' * (Key.KEY_OCTETS - 1) + b'\xfe'
        key7fff = b'\x7f' + b'\xff' * (Key.KEY_OCTETS - 1)
        key7ffe = b'\x7f' + b'\xff' * (Key.KEY_OCTETS - 2) + b'\xfe'

        key0000 = b'\x00' * Key.KEY_OCTETS
        key0001 = b'\x00' * (Key.KEY_OCTETS - 1) + b'\x01'
        key8000 = b'\x80' + b'\x00' * (Key.KEY_OCTETS - 1)
        key8001 = b'\x80' + b'\x00' * (Key.KEY_OCTETS - 2) + b'\x01'

        self.assertEqual(Key.KEY_OCTETS, 32)
        self.assertEqual(len(keyffff), Key.KEY_OCTETS)
        self.assertEqual(len(keyfffe), Key.KEY_OCTETS)
        self.assertEqual(len(key7fff), Key.KEY_OCTETS)
        self.assertEqual(len(key7ffe), Key.KEY_OCTETS)
        self.assertEqual(len(key0000), Key.KEY_OCTETS)
        self.assertEqual(len(key0001), Key.KEY_OCTETS)
        self.assertEqual(len(key8000), Key.KEY_OCTETS)
        self.assertEqual(len(key8001), Key.KEY_OCTETS)

        # Greater means Red, Less means Green, Eq means White

        self.assertEqual(Key.keycmp(key0000, key0000), 0)  # eq     White
        self.assertGreater(Key.keycmp(key0001, key0000), 0)  # + 1    Red
        self.assertGreater(Key.keycmp(key7fff, key0000), 0)  # + 7fff Red
        self.assertLess(Key.keycmp(key8000, key0000), 0)  # + 8000 Green
        self.assertLess(Key.keycmp(keyffff, key0000), 0)  # - 1    Green

        self.assertEqual(Key.keycmp(key7fff, key7fff), 0)  # eq
        self.assertGreater(Key.keycmp(key8000, key7fff), 0)  # + 1
        self.assertGreater(Key.keycmp(keyfffe, key7fff), 0)  # + 7fff
        self.assertLess(Key.keycmp(keyffff, key7fff), 0)  # + 8000
        self.assertLess(Key.keycmp(key7ffe, key7fff), 0)  # -1
        self.assertLess(Key.keycmp(key0000, key7fff), 0)  # zero

        self.assertEqual(Key.keycmp(key8000, key8000), 0)  # eq
        self.assertGreater(Key.keycmp(key8001, key8000), 0)  # + 1
        self.assertGreater(Key.keycmp(keyffff, key8000), 0)  # + 7fff
        self.assertLess(Key.keycmp(key0000, key8000), 0)  # + 8000
        self.assertLess(Key.keycmp(key7fff, key8000), 0)  # -1

        self.assertEqual(Key.keycmp(keyffff, keyffff), 0)  # eq
        self.assertGreater(Key.keycmp(key0000, keyffff), 0)  # + 1
        self.assertGreater(Key.keycmp(key7ffe, keyffff), 0)  # + 7fff
        self.assertLess(Key.keycmp(key7fff, keyffff), 0)  # + 8000
        self.assertLess(Key.keycmp(keyfffe, keyffff), 0)  # -1