Search in sources :

Example 1 with PrimitiveExpression

use of org.evosuite.testcase.PrimitiveExpression in project evosuite by EvoSuite.

the class CompoundTestCase method convertMethod.

/**
 * <p>
 * convertMethod
 * </p>
 *
 * @param methodDef
 *            a {@link org.evosuite.junit.CompoundTestCase.MethodDef}
 *            object.
 * @param params
 *            a {@link java.util.List} object.
 * @param retVal
 *            a {@link org.evosuite.testcase.VariableReference} object.
 */
public void convertMethod(MethodDef methodDef, List<VariableReference> params, VariableReference retVal) {
    assert methodDef.getParams().size() == params.size();
    Map<VariableReference, VariableReference> methodVarsMap = new HashMap<VariableReference, VariableReference>();
    for (StatementInterface statement : methodDef.getCode()) {
        for (int idx = 0; idx < params.size(); idx++) {
            statement.replace(methodDef.getParams().get(idx), params.get(idx));
        }
        if (statement instanceof ReturnStatementPlaceholder) {
            VariableReference resultVal = methodVarsMap.get(statement.getReturnValue());
            if (resultVal == null) {
                throw new IllegalStateException();
            }
            AssignmentStatement assignmentStatement = new AssignmentStatement(delegate, retVal, resultVal);
            addStatement(assignmentStatement);
            return;
        }
        StatementInterface newStmt = statement;
        if (!(statement instanceof PrimitiveExpression)) {
            // Since the delegate code is not yet finished,
            // cloning of PrimitiveExpressions does not work.
            newStmt = statement.clone(delegate);
        }
        addReplacementVariable(statement.getReturnValue(), newStmt.getReturnValue());
        methodVarsMap.put(statement.getReturnValue(), newStmt.getReturnValue());
        addStatement(newStmt);
    }
}
Also used : StatementInterface(org.evosuite.testcase.StatementInterface) VariableReference(org.evosuite.testcase.VariableReference) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AssignmentStatement(org.evosuite.testcase.AssignmentStatement) PrimitiveExpression(org.evosuite.testcase.PrimitiveExpression)

Example 2 with PrimitiveExpression

use of org.evosuite.testcase.PrimitiveExpression in project evosuite by EvoSuite.

the class TestExtractingVisitor method retrieveVariableReference.

private VariableReference retrieveVariableReference(InfixExpression infixExpr, Class<?> exprType) {
    if (exprType == null) {
        exprType = retrieveTypeClass(infixExpr);
    }
    VariableReference ref = new VariableReferenceImpl(testCase.getReference(), exprType);
    VariableReference leftOperand = retrieveVariableReference(infixExpr.getLeftOperand(), null);
    leftOperand.setOriginalCode(infixExpr.getLeftOperand().toString());
    Operator operator = Operator.toOperator(infixExpr.getOperator().toString());
    VariableReference rightOperand = retrieveVariableReference(infixExpr.getRightOperand(), null);
    rightOperand.setOriginalCode(infixExpr.getRightOperand().toString());
    PrimitiveExpression expr = new PrimitiveExpression(testCase.getReference(), ref, leftOperand, operator, rightOperand);
    testCase.addStatement(expr);
    return ref;
}
Also used : Operator(org.evosuite.testcase.PrimitiveExpression.Operator) VariableReference(org.evosuite.testcase.VariableReference) VariableReferenceImpl(org.evosuite.testcase.VariableReferenceImpl) PrimitiveExpression(org.evosuite.testcase.PrimitiveExpression)

Aggregations

PrimitiveExpression (org.evosuite.testcase.PrimitiveExpression)2 VariableReference (org.evosuite.testcase.VariableReference)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 AssignmentStatement (org.evosuite.testcase.AssignmentStatement)1 Operator (org.evosuite.testcase.PrimitiveExpression.Operator)1 StatementInterface (org.evosuite.testcase.StatementInterface)1 VariableReferenceImpl (org.evosuite.testcase.VariableReferenceImpl)1