use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class ContainsTraceEntry method getAssertions.
/* (non-Javadoc)
* @see org.evosuite.assertion.OutputTraceEntry#getAssertions()
*/
@Override
public Set<Assertion> getAssertions() {
Set<Assertion> assertions = new HashSet<Assertion>();
for (VariableReference otherVar : containsMap.keySet()) {
if (otherVar == null) {
continue;
}
ContainsAssertion assertion = new ContainsAssertion();
assertion.source = containerVar;
assertion.containedVariable = otherVar;
assertion.value = containsMap.get(otherVar);
assertions.add(assertion);
assert (assertion.isValid());
}
return assertions;
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class MutationAssertionGenerator method primitiveWithoutAssertion.
protected boolean primitiveWithoutAssertion(Statement statement) {
if (!statement.getReturnValue().isPrimitive())
return false;
Set<Assertion> assertions = statement.getAssertions();
if (assertions.isEmpty())
return true;
else {
Iterator<Assertion> iterator = assertions.iterator();
VariableReference ret = statement.getReturnValue();
while (iterator.hasNext()) {
Assertion ass = iterator.next();
if (ass instanceof PrimitiveAssertion) {
if (ass.getReferencedVariables().contains(ret)) {
return false;
}
}
}
return true;
}
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class HashCodeReturnsNormallyContract method check.
/* (non-Javadoc)
* @see org.evosuite.contracts.Contract#check(org.evosuite.testcase.Statement, org.evosuite.testcase.Scope, java.lang.Throwable)
*/
/**
* {@inheritDoc}
*/
@Override
public ContractViolation check(Statement statement, Scope scope, Throwable exception) {
for (VariableReference var : getAllVariables(scope)) {
Object object = scope.getObject(var);
if (object == null)
continue;
// We do not want to call hashCode if it is the default implementation
Class<?>[] parameters = {};
try {
Method equalsMethod = object.getClass().getMethod("hashCode", parameters);
if (equalsMethod.getDeclaringClass().equals(Object.class))
continue;
} catch (SecurityException e1) {
continue;
} catch (NoSuchMethodException e1) {
continue;
}
try {
// hashCode must not throw an exception
object.hashCode();
} catch (Throwable t) {
if (!(t instanceof TimeoutExceeded))
return new ContractViolation(this, statement, t, var);
}
}
return null;
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class ComparisonTraceEntry method getAssertions.
/* (non-Javadoc)
* @see org.evosuite.assertion.OutputTraceEntry#isDetectedBy(org.evosuite.assertion.Assertion)
*/
/**
* {@inheritDoc}
*/
@Override
public Set<Assertion> getAssertions() {
Set<Assertion> assertions = new HashSet<Assertion>();
for (VariableReference otherVar : equalityMap.keySet()) {
if (otherVar == null) {
continue;
}
EqualsAssertion assertion = new EqualsAssertion();
assertion.source = var;
assertion.dest = otherVar;
assertion.value = equalityMap.get(otherVar);
assertions.add(assertion);
assert (assertion.isValid());
}
return assertions;
}
use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.
the class OutputObserver method afterStatement.
/* (non-Javadoc)
* @see org.evosuite.testcase.ExecutionObserver#afterStatement(org.evosuite.testcase.StatementInterface, org.evosuite.testcase.Scope, java.lang.Throwable)
*/
@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?
}
}
}
Aggregations