Search in sources :

Example 6 with EvosuiteError

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

Example 7 with EvosuiteError

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

the class SymbolicObserver method after.

private void after(StringPrimitiveStatement statement, Scope scope) {
    String valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    StringVariable stringVariable = buildStringVariable(varRefName, valueOf);
    symb_expressions.put(varRefName, stringVariable);
    String string_instance;
    try {
        String string_interned = (String) varRef.getObject(scope);
        string_instance = new String(string_interned);
        scope.setObject(varRef, string_instance);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant stringRef = newStringReference(string_instance, stringVariable);
    symb_references.put(varRefName, stringRef);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 8 with EvosuiteError

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

the class SymbolicObserver method findOrCreate.

private Expression<?> findOrCreate(Object conc_ref, ReferenceConstant symb_ref) {
    if (conc_ref instanceof Boolean) {
        Boolean boolean0 = (Boolean) conc_ref;
        int conc_val = boolean0.booleanValue() ? 1 : 0;
        return env.heap.getField(Types.JAVA_LANG_BOOLEAN, SymbolicHeap.$BOOLEAN_VALUE, boolean0, symb_ref, conc_val);
    } else if (conc_ref instanceof Byte) {
        Byte byte0 = (Byte) conc_ref;
        byte conc_val = byte0.byteValue();
        return env.heap.getField(Types.JAVA_LANG_BYTE, SymbolicHeap.$BYTE_VALUE, byte0, symb_ref, conc_val);
    } else if (conc_ref instanceof Short) {
        Short short0 = (Short) conc_ref;
        short conc_val = short0.shortValue();
        return env.heap.getField(Types.JAVA_LANG_SHORT, SymbolicHeap.$SHORT_VALUE, short0, symb_ref, conc_val);
    } else if (conc_ref instanceof Character) {
        Character character0 = (Character) conc_ref;
        char conc_val = character0.charValue();
        return env.heap.getField(Types.JAVA_LANG_CHARACTER, SymbolicHeap.$CHAR_VALUE, character0, symb_ref, conc_val);
    } else if (conc_ref instanceof Integer) {
        Integer integer0 = (Integer) conc_ref;
        int conc_val = integer0.intValue();
        return env.heap.getField(Types.JAVA_LANG_INTEGER, SymbolicHeap.$INT_VALUE, integer0, symb_ref, conc_val);
    } else if (conc_ref instanceof Long) {
        Long long0 = (Long) conc_ref;
        long conc_val = long0.longValue();
        return env.heap.getField(Types.JAVA_LANG_LONG, SymbolicHeap.$LONG_VALUE, long0, symb_ref, conc_val);
    } else if (conc_ref instanceof Float) {
        Float float0 = (Float) conc_ref;
        float conc_val = float0.floatValue();
        return env.heap.getField(Types.JAVA_LANG_FLOAT, SymbolicHeap.$FLOAT_VALUE, float0, symb_ref, conc_val);
    } else if (conc_ref instanceof Double) {
        Double double0 = (Double) conc_ref;
        double conc_val = double0.doubleValue();
        return env.heap.getField(Types.JAVA_LANG_FLOAT, SymbolicHeap.$DOUBLE_VALUE, double0, symb_ref, conc_val);
    } else {
        throw new EvosuiteError("Unreachable code!");
    }
}
Also used : EvosuiteError(org.evosuite.testcase.execution.EvosuiteError)

Example 9 with EvosuiteError

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

the class SymbolicObserver method after.

private void after(IntPrimitiveStatement statement, Scope scope) {
    int valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Integer.MIN_VALUE, Integer.MAX_VALUE);
    symb_expressions.put(varRefName, integerVariable);
    Integer integer_instance;
    try {
        integer_instance = (Integer) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant integerRef = newIntegerReference(integer_instance, integerVariable);
    symb_references.put(varRefName, integerRef);
}
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 EvosuiteError

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

the class SymbolicObserver method writeArray.

private void writeArray(ArrayIndex lhs, ReferenceExpressionPair readResult, Scope scope) {
    ArrayReference arrayReference = lhs.getArray();
    int conc_index = lhs.getArrayIndex();
    Object conc_array;
    try {
        conc_array = arrayReference.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    Type arrayType = Type.getType(conc_array.getClass());
    Type elementType = arrayType.getElementType();
    if (isValue(elementType) || elementType.equals(Type.getType(String.class))) {
        Expression<?> symb_value = readResult.getExpression();
        symb_value = castIfNeeded(elementType, symb_value);
        String array_name = arrayReference.getName();
        ReferenceExpression symb_ref = symb_references.get(array_name);
        ReferenceConstant symb_array = (ReferenceConstant) symb_ref;
        env.heap.array_store(conc_array, symb_array, conc_index, symb_value);
    } else {
    /* ignore storing references (we use objects to find them) */
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) ArrayReference(org.evosuite.testcase.variable.ArrayReference) Type(org.objectweb.asm.Type) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Aggregations

EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)21 VariableReference (org.evosuite.testcase.variable.VariableReference)15 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)14 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)11 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 Set (java.util.Set)3 UncompilableCodeException (org.evosuite.testcase.execution.UncompilableCodeException)3 LinkedHashSet (java.util.LinkedHashSet)2 ConstructionFailedException (org.evosuite.ga.ConstructionFailedException)2 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)2 RealValue (org.evosuite.symbolic.expr.fp.RealValue)2 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)2 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)2 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)2 MethodStatement (org.evosuite.testcase.statements.MethodStatement)2 Statement (org.evosuite.testcase.statements.Statement)2 StringPrimitiveStatement (org.evosuite.testcase.statements.StringPrimitiveStatement)2 GenericMethod (org.evosuite.utils.generic.GenericMethod)2