Search in sources :

Example 16 with VariableReference

use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(UrlPrimitiveStatement s, Scope scope) {
    EvoSuiteURL conc_url = s.getValue();
    VariableReference varRef = s.getReturnValue();
    String varRefName = varRef.getName();
    ReferenceExpression urlRef;
    if (conc_url == null) {
        urlRef = env.heap.getReference(null);
        if (urlRef.getConcreteValue() != null) {
            throw new IllegalStateException("Expected null concrete value");
        }
    } else {
        urlRef = (ReferenceConstant) env.heap.getReference(conc_url);
        if (urlRef.getConcreteValue() == null) {
            throw new IllegalStateException("Expected non-null concrete value");
        }
    }
    symb_references.put(varRefName, urlRef);
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) EvoSuiteURL(org.evosuite.runtime.testdata.EvoSuiteURL) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 17 with VariableReference

use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(RemoteAddressPrimitiveStatement s, Scope scope) {
    EvoSuiteRemoteAddress conc_remote_address = s.getValue();
    VariableReference varRef = s.getReturnValue();
    String varRefName = varRef.getName();
    ReferenceExpression addressRef;
    if (conc_remote_address == null) {
        addressRef = env.heap.getReference(null);
        if (addressRef.getConcreteValue() != null) {
            throw new IllegalStateException("Expected null concrete value");
        }
    } else {
        addressRef = env.heap.getReference(conc_remote_address);
        if (addressRef.getConcreteValue() == null) {
            throw new IllegalStateException("Expected non-null concrete value");
        }
    }
    symb_references.put(varRefName, addressRef);
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) EvoSuiteRemoteAddress(org.evosuite.runtime.testdata.EvoSuiteRemoteAddress) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 18 with VariableReference

use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(NullStatement s, Scope scope) {
    VariableReference lhs = s.getReturnValue();
    String lhs_name = lhs.getName();
    ReferenceExpression nullConstant = ExpressionFactory.buildNewNullExpression();
    symb_references.put(lhs_name, nullConstant);
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 19 with VariableReference

use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.

the class SymbolicObserver method writeField.

private void writeField(FieldReference lhs, ReferenceExpressionPair readResult, Scope scope) {
    Field field = lhs.getField().getField();
    String className = field.getDeclaringClass().getName().replace('.', '/');
    String fieldName = field.getName();
    Class<?> fieldClass = field.getType();
    Type fieldType = Type.getType(fieldClass);
    if (isValue(fieldType) || fieldType.equals(Type.getType(String.class))) {
        Expression<?> symb_value = readResult.getExpression();
        symb_value = castIfNeeded(fieldType, symb_value);
        VariableReference source = lhs.getSource();
        if (source != null) {
            /* write symbolic expression to instance field */
            String source_name = source.getName();
            Object conc_receiver;
            try {
                conc_receiver = source.getObject(scope);
            } catch (CodeUnderTestException e) {
                throw new RuntimeException(e);
            }
            ReferenceConstant symb_receiver = (ReferenceConstant) symb_references.get(source_name);
            env.heap.putField(className, fieldName, conc_receiver, symb_receiver, symb_value);
        } else {
            /* write symbolic expression to static field */
            env.heap.putStaticField(className, fieldName, symb_value);
        }
    } else {
    /*
			 * ignore writing of references (DSE does not store Reference
			 * fields)
			 */
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Field(java.lang.reflect.Field) Type(org.objectweb.asm.Type) VariableReference(org.evosuite.testcase.variable.VariableReference) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 20 with VariableReference

use of org.evosuite.testcase.variable.VariableReference in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(ShortPrimitiveStatement statement, Scope scope) {
    short valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Short.MIN_VALUE, Short.MAX_VALUE);
    symb_expressions.put(varRefName, integerVariable);
    Short short_instance;
    try {
        short_instance = (Short) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant shortRef = newShortReference(short_instance, integerVariable);
    symb_references.put(varRefName, shortRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) IntegerVariable(org.evosuite.symbolic.expr.bv.IntegerVariable) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) 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