use of org.evosuite.testcase.VariableReference 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);
}
}
}
use of org.evosuite.testcase.VariableReference in project evosuite by EvoSuite.
the class CompoundTestCase method getVariableReferenceInternally.
private VariableReference getVariableReferenceInternally(IVariableBinding varBinding) {
VariableReference varRef = currentMethodVars.get(varBinding.toString());
if (varRef != null) {
return varRef;
}
varRef = fieldVars.get(varBinding.toString());
if (varRef != null) {
return varRef;
}
if (parent != null) {
return parent.getVariableReferenceInternally(varBinding);
}
return null;
}
use of org.evosuite.testcase.VariableReference in project evosuite by EvoSuite.
the class TestExtractingVisitor method endVisit.
/**
* {@inheritDoc}
*/
@Override
public void endVisit(ClassInstanceCreation instanceCreation) {
if (instanceCreation.getParent() instanceof ThrowStatement) {
logger.warn("Ignoring throw statements!");
return;
}
List<?> paramTypes = Arrays.asList(instanceCreation.resolveConstructorBinding().getParameterTypes());
List<?> paramValues = instanceCreation.arguments();
Constructor<?> constructor = retrieveConstructor(instanceCreation.getType(), paramTypes, paramValues);
List<VariableReference> params = convertParams(instanceCreation.arguments(), paramTypes);
VariableReference retVal = retrieveVariableReference(instanceCreation, null);
retVal.setOriginalCode(instanceCreation.toString());
ConstructorStatement statement = new ValidConstructorStatement(testCase.getReference(), constructor, retVal, params);
testCase.addStatement(statement);
}
use of org.evosuite.testcase.VariableReference in project evosuite by EvoSuite.
the class TestExtractingVisitor method endVisit.
/**
* {@inheritDoc}
*/
@Override
public void endVisit(Assignment assignment) {
if ((assignment.getRightHandSide() instanceof MethodInvocation) || (assignment.getRightHandSide() instanceof ClassInstanceCreation)) {
// treated in respective endVisit methods
return;
}
VariableReference varRef = retrieveVariableReference(assignment.getLeftHandSide(), null);
varRef.setOriginalCode(assignment.getLeftHandSide().toString());
VariableReference newAssignment = retrieveVariableReference(assignment.getRightHandSide(), null);
newAssignment.setOriginalCode(assignment.getRightHandSide().toString());
if (varRef instanceof ArrayIndex) {
AssignmentStatement assignmentStatement = new AssignmentStatement(testCase.getReference(), varRef, newAssignment);
testCase.addStatement(assignmentStatement);
return;
}
testCase.variableAssignment(varRef, newAssignment);
}
use of org.evosuite.testcase.VariableReference in project evosuite by EvoSuite.
the class TestExtractingVisitor method visit.
/**
* {@inheritDoc}
*/
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
if (Modifier.isStatic(fieldDeclaration.getModifiers())) {
testCase.setCurrentScope(TestScope.STATICFIELDS);
}
VariableDeclarationFragment varDeclFrgmnt = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0);
Expression expression = varDeclFrgmnt.getInitializer();
VariableReference varRef;
if (expression == null) {
varRef = retrieveDefaultValueAssignment(retrieveTypeClass(varDeclFrgmnt));
} else {
varRef = retrieveVariableReference(expression, null);
}
varRef.setOriginalCode(fieldDeclaration.toString());
// TODO Use the name here as well?
// String name = varDeclFrgmt.getName().getIdentifier();
// new BoundVariableReferenceImpl(testCase, varType, name);
testCase.addVariable(varDeclFrgmnt.resolveBinding(), varRef);
testCase.setCurrentScope(TestScope.FIELDS);
return true;
}
Aggregations