def add_call_for( self, test_case: tc.TestCase, callee: vr.VariableReference, accessible: gao.GenericAccessibleObject, position: int, ) -> bool: """Add a call for the given accessible object. Args: test_case: The test case to add the call to callee: The callee accessible: The accessible object position: The last position Returns: Whether or not the insertion was successful Raises: RuntimeError: in case of an unknown accessible """ previous_length = test_case.size() try: if accessible.is_method(): method = cast(gao.GenericMethod, accessible) self.add_method(test_case, method, position, callee=callee) return True if accessible.is_field(): field = cast(gao.GenericField, accessible) self.add_field(test_case, field, position, callee=callee) return True raise RuntimeError("Unknown accessible object") except ConstructionFailedException: self._rollback_changes(test_case, previous_length, position) return False
def change_call( self, test_case: tc.TestCase, statement: stmt.Statement, call: gao.GenericAccessibleObject, ): """Change the call of the given statement to the one that is given. Args: test_case: The test case statement: The given statement call: The new call """ position = statement.return_value.get_statement_position() return_value = statement.return_value replacement: Optional[stmt.Statement] = None if call.is_method(): method = cast(gao.GenericMethod, call) assert method.owner callee = self._get_random_non_none_object(test_case, method.owner, position) parameters = self._get_reuse_parameters(test_case, method.inferred_signature, position) replacement = par_stmt.MethodStatement(test_case, method, callee, parameters) elif call.is_constructor(): constructor = cast(gao.GenericConstructor, call) parameters = self._get_reuse_parameters( test_case, constructor.inferred_signature, position) replacement = par_stmt.ConstructorStatement( test_case, constructor, parameters) elif call.is_function(): funktion = cast(gao.GenericFunction, call) parameters = self._get_reuse_parameters( test_case, funktion.inferred_signature, position) replacement = par_stmt.FunctionStatement(test_case, funktion, parameters) if replacement is None: assert False, f"Unhandled call type {call}" else: replacement.return_value = return_value test_case.set_statement(replacement, position)
def add_call_for( self, test_case: tc.TestCase, callee: vr.VariableReference, accessible: gao.GenericAccessibleObject, position: int, ) -> bool: """Add a call for the given accessible object.""" previous_length = test_case.size() try: if accessible.is_method(): method = cast(gao.GenericMethod, accessible) self.add_method(test_case, method, position, callee=callee) return True if accessible.is_field(): field = cast(gao.GenericField, accessible) self.add_field(test_case, field, position, callee=callee) return True raise RuntimeError("Unknown accessible object") except ConstructionFailedException: self._rollback_changes(test_case, previous_length, position) return False