public void visitMethodStatement(TestCase test, MethodStatement statement) { // The problem is that at this point in the test case the parameters // might have already changed int i = 0; for (VariableReference var : statement.getParameterReferences()) { if (var.isPrimitive() || var.isString()) { if (usedVariables.contains(var) && test.getStatement(var.getStPosition()) instanceof PrimitiveStatement<?>) { // Duplicate and replace VariableReference varCopy = duplicateStatement(test, var); statement.replaceParameterReference(varCopy, i); usedVariables.add(varCopy); } usedVariables.add(var); } i++; } addUnchangedMapping(test, statement.getReturnValue()); }
@Override public void afterStatement(Statement statement, Scope scope, Throwable exception) { if (statement instanceof MethodStatement) { MethodStatement methodStmt = (MethodStatement) statement; VariableReference varRef = methodStmt.getReturnValue(); try { Object returnObject = varRef.getObject(scope); if (exception == null && !methodStmt.getReturnType().equals(Void.TYPE)) { // we don't save anything if there was an exception // we are only interested in methods whose return type != void String className = methodStmt.getDeclaringClassName(); String methodDesc = methodStmt.getDescriptor(); String methodName = methodStmt.getMethodName(); outputCoverage.put(statement.getPosition(), OutputCoverageGoal.createGoalsFromObject(className, methodName, methodDesc, returnObject)); } } catch (CodeUnderTestException e) { // ignore? } } }
/** * * @param callee * <code>null</code> for state methods * @param method * @param parameters * @return <code>void reference</code> for void methods */ public VariableReference appendMethod(VariableReference callee, Method method, VariableReference... parameters) { List<VariableReference> parameter_list = Arrays.asList(parameters); MethodStatement methodStmt = null; if (callee == null) { methodStmt = new MethodStatement(tc, new GenericMethod(method, method.getDeclaringClass()), callee, parameter_list); } else { methodStmt = new MethodStatement(tc, new GenericMethod(method, callee.getType()), callee, parameter_list); } tc.addStatement(methodStmt); return methodStmt.getReturnValue(); }
/** {@inheritDoc} */ @Override public Statement copy(TestCase newTestCase, int offset) { ArrayList<VariableReference> newParams = new ArrayList<VariableReference>(); for (VariableReference r : parameters) { newParams.add(r.copy(newTestCase, offset)); } MethodStatement m; if (isStatic()) { // FIXXME: If callee is an array index, this will return an invalid // copy of the cloned variable! m = new MethodStatement(newTestCase, method.copy(), null, newParams); } else { VariableReference newCallee = callee.copy(newTestCase, offset); m = new MethodStatement(newTestCase, method.copy(), newCallee, newParams); } if (retval instanceof ArrayReference && !(m.getReturnValue() instanceof ArrayReference)) { // logger.info("Copying array retval: " + retval.getGenericClass()); // assert (retval.getGenericClass() != null); // assert (retval.getGenericClass().isArray()) : method.toString(); ArrayReference newRetVal = new ArrayReference(newTestCase, retval.getGenericClass(), ((ArrayReference) retval).getArrayLength()); m.setRetval(newRetVal); } m.getReturnValue().setType(retval.getType()); // Actual type may have changed, e.g. subtype // m.assertions = copyAssertions(newTestCase, offset); return m; }
private void updateMethodCallsOfGenericOwner(VariableReference callee) { for (int pos = callee.getStPosition() + 1; pos < test.size(); pos++) { Statement statement = test.getStatement(pos); if (!(statement instanceof MethodStatement)) continue; MethodStatement ms = (MethodStatement) statement; if (ms.isStatic()) continue; if (!ms.getCallee().equals(callee)) continue; GenericMethod method = ms.getMethod(); logger.info("Updating callee of statement " + statement.getCode()); ms.setMethod(method.copyWithNewOwner(callee.getGenericClass())); ms.getReturnValue().setType(ms.getMethod().getReturnType()); logger.info("Result: " + statement.getCode()); } }
statement.getPosition()); objects.remove(parameter); objects.remove(statement.getReturnValue()); NullStatement nullStatement = new NullStatement(test.getTestCase(), parameter.getType());
VariableReference varRef = statement.getReturnValue(); String varName = varRef.getName(); try {
ms1.getReturnValue(), callParam); test.addStatement(ms2); ms1.getReturnValue(), 0); ms2.addAssertion(assertion);
public void visitMethodStatement(MethodStatement statement) { String result = ""; VariableReference retval = statement.getReturnValue(); GenericMethod method = statement.getMethod(); Throwable exception = getException(statement);