def test_unary_decrement_strings_02(self):
        # test the flip to max char 0x10FFFF
        input = ''.join(chr(c) for c in range(0, 31))
        expect = chr(0x10FFFF) + ''.join(chr(c - 1) for c in range(1, 31))

        result = UnaryOperation.decrement(input)
        self.assertEqual(result, expect, 'INCREMENT({}) = {} != expected {}'.format(input, result, expect))
    def test_unary_decrement_strings_03(self):
        # test at large ranges
        input = ''.join(chr(c) for c in range(200, 300))
        expect = ''.join(chr(c - 1) for c in range(200, 300))

        result = UnaryOperation.decrement(input)
        self.assertEqual(result, expect, 'DECREMENT({}) = {} != expected {}'.format(input, result, expect))
예제 #3
0
    def mutate(self, message: AbstractMessage):
        field_value = message.message_get_field(self.field)

        if field_value is not None:
            if self.operation_type is UnaryOperation.UNARY_INVERT:
                mutated_value = UnaryOperation.invert(field_value)
            elif self.operation_type is UnaryOperation.UNARY_INCR:
                mutated_value = UnaryOperation.increment(field_value)
            elif self.operation_type is UnaryOperation.UNARY_DECR:
                mutated_value = UnaryOperation.decrement(field_value)
            else:
                raise Exception(
                    'UnaryMutator does not support operation {}'.format(
                        self.operation_type))

            message.message_set_field(self.field, mutated_value)

            return '{}({})={}->{}'.format(self._operation_type, self.field,
                                          field_value, mutated_value)
        else:
            # TODO: how to handle such cases properly?
            raise Exception('Message {} has no field "{}"'.format(
                message.message, self.field))
    def test_unary_decrement_bytes(self):
        value = b'\xFF\x00\x55\xAA'
        expect = b'\xFE\xFF\x54\xA9'

        result = UnaryOperation.decrement(value)
        self.assertEqual(result, expect, 'DECREMENT({}) = {} != expected {}'.format(value, result, expect))
    def test_unary_decrement_strings_01(self):
        input = 'bcd'
        expect = 'abc'

        result = UnaryOperation.decrement(input)
        self.assertEqual(result, expect, 'DECREMENT({}) = {} != expected {}'.format(input, result, expect))