Search in sources :

Example 11 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class SymbolicObserver method newDoubleReference.

private ReferenceConstant newDoubleReference(Double conc_double, RealValue symb_value) {
    ReferenceConstant doubleRef = (ReferenceConstant) env.heap.getReference(conc_double);
    env.heap.putField(Types.JAVA_LANG_DOUBLE, SymbolicHeap.$DOUBLE_VALUE, conc_double, doubleRef, symb_value);
    return doubleRef;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant)

Example 12 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant 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 13 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant 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 14 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class SymbolicObserver method newCharacterReference.

private ReferenceConstant newCharacterReference(Character conc_char, IntegerValue symb_value) {
    ReferenceConstant charRef = (ReferenceConstant) env.heap.getReference(conc_char);
    env.heap.putField(Types.JAVA_LANG_CHARACTER, SymbolicHeap.$CHAR_VALUE, conc_char, charRef, symb_value);
    return charRef;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant)

Example 15 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class SymbolicObserver method newFloatReference.

private ReferenceConstant newFloatReference(Float conc_float, RealValue symb_value) {
    ReferenceConstant floatRef = (ReferenceConstant) env.heap.getReference(conc_float);
    env.heap.putField(Types.JAVA_LANG_FLOAT, SymbolicHeap.$FLOAT_VALUE, conc_float, floatRef, symb_value);
    return floatRef;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant)

Aggregations

ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)99 StringValue (org.evosuite.symbolic.expr.str.StringValue)39 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)32 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)18 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)16 VariableReference (org.evosuite.testcase.variable.VariableReference)14 Type (org.objectweb.asm.Type)12 RealValue (org.evosuite.symbolic.expr.fp.RealValue)11 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)11 Expression (org.evosuite.symbolic.expr.Expression)9 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)8 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)6 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)5 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)4 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)3 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)3 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)3 StringReaderExpr (org.evosuite.symbolic.expr.reader.StringReaderExpr)3