Search in sources :

Example 6 with CodeUnderTestException

use of org.evosuite.testcase.execution.CodeUnderTestException in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(BooleanPrimitiveStatement statement, Scope scope) {
    boolean valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf ? 1 : 0, 0, 1);
    Boolean boolean_instance;
    try {
        boolean_instance = (Boolean) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    symb_expressions.put(varRefName, integerVariable);
    ReferenceConstant booleanRef = newBooleanReference(boolean_instance, integerVariable);
    symb_references.put(varRefName, booleanRef);
}
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)

Example 7 with CodeUnderTestException

use of org.evosuite.testcase.execution.CodeUnderTestException in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(DoublePrimitiveStatement statement, Scope scope) {
    double valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    RealVariable realVariable = buildRealVariable(varRefName, valueOf, -Double.MAX_VALUE, Double.MAX_VALUE);
    symb_expressions.put(varRefName, realVariable);
    Double double_instance;
    try {
        double_instance = (Double) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant doubleRef = newDoubleReference(double_instance, realVariable);
    symb_references.put(varRefName, doubleRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 8 with CodeUnderTestException

use of org.evosuite.testcase.execution.CodeUnderTestException 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 9 with CodeUnderTestException

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

Example 10 with CodeUnderTestException

use of org.evosuite.testcase.execution.CodeUnderTestException in project evosuite by EvoSuite.

the class SymbolicObserver method after.

private void after(FunctionalMockStatement statement, Scope scope) {
    Type returnType = Type.getType(statement.getReturnClass());
    VariableReference varRef = statement.getReturnValue();
    String varName = varRef.getName();
    try {
        if (varRef.getType().equals(void.class)) {
        } else if (returnType.equals(Type.INT_TYPE) || returnType.equals(Type.BOOLEAN_TYPE) || returnType.equals(Type.DOUBLE_TYPE) || returnType.equals(Type.FLOAT_TYPE) || returnType.equals(Type.LONG_TYPE) || returnType.equals(Type.SHORT_TYPE) || returnType.equals(Type.BYTE_TYPE) || returnType.equals(Type.CHAR_TYPE)) {
            throw new EvosuiteError("mocking of primitive types is not supported!");
        } else {
            Object res = varRef.getObject(scope);
            ReferenceExpression ref = env.heap.getReference(res);
            if (res != null && res instanceof String) {
                String string = (String) res;
                ReferenceConstant newStringRef = (ReferenceConstant) env.heap.getReference(string);
                StringValue str_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, string, newStringRef, string);
                symb_references.put(varName, newStringRef);
                symb_expressions.put(varName, str_expr);
            } else {
                symb_references.put(varName, ref);
                if (res != null && isWrapper(res)) {
                    ReferenceConstant nonNullRef = (ReferenceConstant) ref;
                    Expression<?> expr = findOrCreate(res, nonNullRef);
                    symb_expressions.put(varName, expr);
                }
            }
        }
    } catch (CodeUnderTestException e) {
        throw new RuntimeException(e);
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Type(org.objectweb.asm.Type) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) PrimitiveExpression(org.evosuite.testcase.statements.PrimitiveExpression) Expression(org.evosuite.symbolic.expr.Expression) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Aggregations

CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)33 VariableReference (org.evosuite.testcase.variable.VariableReference)25 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)16 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)14 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)6 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)6 MethodStatement (org.evosuite.testcase.statements.MethodStatement)5 Type (org.objectweb.asm.Type)5 StringValue (org.evosuite.symbolic.expr.str.StringValue)4 UncompilableCodeException (org.evosuite.testcase.execution.UncompilableCodeException)4 PrimitiveStatement (org.evosuite.testcase.statements.PrimitiveStatement)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 LinkedHashSet (java.util.LinkedHashSet)3 Expression (org.evosuite.symbolic.expr.Expression)3 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)3 RealValue (org.evosuite.symbolic.expr.fp.RealValue)3 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)3 ArrayReference (org.evosuite.testcase.variable.ArrayReference)3 ConstantValue (org.evosuite.testcase.variable.ConstantValue)3 Field (java.lang.reflect.Field)2