def test_unary_increment_strings_03(self):
        # test at large ranges with a flip to smallest char
        input = ''.join(chr(c) for c in range(1114100, 1114112))
        expect = ''.join(chr(c + 1) for c in range(1114100, 1114111)) + chr(0)

        result = UnaryOperation.increment(input)
        self.assertEqual(result, expect, 'INCREMENT({}) = {} != expected {}'.format(input, result, expect))
    def test_unary_increment_strings_02(self):
        # test non-printable and special characters
        input = ''.join(chr(c) for c in range(0, 31))
        expect = ''.join(chr(c + 1) for c in range(0, 31))

        result = UnaryOperation.increment(input)
        self.assertEqual(result, expect, 'INCREMENT({}) = {} != expected {}'.format(input, result, expect))
    def test_unary_increment_floats(self):
        values = range(-5, 5)

        for v in values:
            expect = v + 1.0
            result = UnaryOperation.increment(v)
            self.assertEqual(result, expect, 'INCREMENT({}) = {} != expected {}'.format(input, result, expect))
예제 #4
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_increment_bytes(self):
        value = b'\xFF\x00\x55\xAA'
        expect = b'\x00\x01\x56\xAB'

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

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