Search in sources :

Example 6 with VariableReference

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;
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) HashSet(java.util.HashSet)

Example 7 with VariableReference

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;
    }
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference)

Example 8 with VariableReference

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;
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) TimeoutExceeded(org.evosuite.testcase.execution.TestCaseExecutor.TimeoutExceeded) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method)

Example 9 with VariableReference

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;
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) HashSet(java.util.HashSet)

Example 10 with VariableReference

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?
        }
    }
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Aggregations

VariableReference (org.evosuite.testcase.variable.VariableReference)472 Method (java.lang.reflect.Method)289 TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)143 Test (org.junit.Test)73 GenericMethod (org.evosuite.utils.generic.GenericMethod)68 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)55 MethodStatement (org.evosuite.testcase.statements.MethodStatement)44 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)38 ArrayList (java.util.ArrayList)31 GenericClass (org.evosuite.utils.generic.GenericClass)27 TestCase (org.evosuite.testcase.TestCase)26 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)26 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)25 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)19 Type (java.lang.reflect.Type)17 Statement (org.evosuite.testcase.statements.Statement)17 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)15 ArrayReference (org.evosuite.testcase.variable.ArrayReference)15 VariableReferenceImpl (org.evosuite.testcase.variable.VariableReferenceImpl)15 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)14