Search in sources :

Example 1 with VariableReferenceImpl

use of org.evosuite.testcase.VariableReferenceImpl 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)

Example 2 with VariableReferenceImpl

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

the class TestCaseCodeGenerator method createFieldReadAccessStmt.

private void createFieldReadAccessStmt(final int logRecNo, final TestCase testCase) {
    // assumption: all necessary statements are created and there is one variable for reach referenced object
    final int oid = this.log.objectIds.get(logRecNo);
    final int captureId = this.log.captureIds.get(logRecNo);
    final Object returnValue = this.log.returnValues.get(logRecNo);
    if (// TODO necessary?
    !CaptureLog.RETURN_TYPE_VOID.equals(returnValue)) {
        Integer returnValueOID = (Integer) returnValue;
        final String descriptor = this.log.descList.get(logRecNo);
        final org.objectweb.asm.Type fieldTypeType = org.objectweb.asm.Type.getType(descriptor);
        final String typeName = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
        final String fieldName = this.log.namesOfAccessedFields.get(captureId);
        try {
            // Class.forName(fieldTypeName, true, StaticTestCluster.classLoader);
            final Class<?> fieldType = getClassFromType(fieldTypeType);
            // Class.forName(typeName, true, StaticTestCluster.classLoader);
            final Class<?> type = getClassForName(typeName);
            final FieldReference valueRef = new FieldReference(testCase, new GenericField(type.getField(fieldName), type));
            final VariableReference targetVar = new VariableReferenceImpl(testCase, fieldType);
            final AssignmentStatement assignment = new AssignmentStatement(testCase, targetVar, valueRef);
            VariableReference varRef = testCase.addStatement(assignment);
            this.oidToVarRefMap.put(returnValueOID, varRef);
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : FieldReference(org.evosuite.testcase.FieldReference) VariableReference(org.evosuite.testcase.VariableReference) AssignmentStatement(org.evosuite.testcase.AssignmentStatement) VariableReferenceImpl(org.evosuite.testcase.VariableReferenceImpl) GenericField(org.evosuite.utils.GenericField)

Aggregations

VariableReference (org.evosuite.testcase.VariableReference)2 VariableReferenceImpl (org.evosuite.testcase.VariableReferenceImpl)2 AssignmentStatement (org.evosuite.testcase.AssignmentStatement)1 FieldReference (org.evosuite.testcase.FieldReference)1 PrimitiveExpression (org.evosuite.testcase.PrimitiveExpression)1 Operator (org.evosuite.testcase.PrimitiveExpression.Operator)1 GenericField (org.evosuite.utils.GenericField)1