Search in sources :

Example 1 with ReferenceConstant

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

the class SymbolicObserver method readStaticField.

private ReferenceExpressionPair readStaticField(Field field) {
    String owner = field.getDeclaringClass().getName().replace('.', '/');
    String name = field.getName();
    Class<?> fieldClazz = field.getType();
    try {
        if (fieldClazz.equals(int.class)) {
            int conc_value = field.getInt(null);
            IntegerValue expr = env.heap.getStaticField(owner, name, conc_value);
            ReferenceConstant newIntegerRef = newIntegerReference(conc_value, expr);
            return new ReferenceExpressionPair(newIntegerRef, expr);
        } else if (fieldClazz.equals(char.class)) {
            char conc_value = field.getChar(null);
            IntegerValue expr = env.heap.getStaticField(owner, name, conc_value);
            ReferenceConstant newCharacterRef = newCharacterReference(conc_value, expr);
            return new ReferenceExpressionPair(newCharacterRef, expr);
        } else if (fieldClazz.equals(long.class)) {
            long conc_value = field.getLong(null);
            IntegerValue expr = env.heap.getStaticField(owner, name, conc_value);
            ReferenceConstant newLongRef = newLongReference(conc_value, expr);
            return new ReferenceExpressionPair(newLongRef, expr);
        } else if (fieldClazz.equals(short.class)) {
            short conc_value = field.getShort(null);
            IntegerValue expr = env.heap.getStaticField(owner, name, conc_value);
            ReferenceConstant newShortRef = newShortReference(conc_value, expr);
            return new ReferenceExpressionPair(newShortRef, expr);
        } else if (fieldClazz.equals(byte.class)) {
            byte conc_value = field.getByte(null);
            IntegerValue expr = env.heap.getStaticField(owner, name, conc_value);
            ReferenceConstant newByteRef = newByteReference(conc_value, expr);
            return new ReferenceExpressionPair(newByteRef, expr);
        } else if (fieldClazz.equals(boolean.class)) {
            boolean conc_value = field.getBoolean(null);
            IntegerValue expr = env.heap.getStaticField(owner, name, conc_value ? 1 : 0);
            ReferenceConstant newBooleanRef = newBooleanReference(conc_value, expr);
            return new ReferenceExpressionPair(newBooleanRef, expr);
        } else if (fieldClazz.equals(float.class)) {
            float conc_value = field.getFloat(null);
            RealValue expr = env.heap.getStaticField(owner, name, conc_value);
            ReferenceConstant newFloatRef = newFloatReference(conc_value, expr);
            return new ReferenceExpressionPair(newFloatRef, expr);
        } else if (fieldClazz.equals(double.class)) {
            double conc_value = field.getDouble(null);
            RealValue expr = env.heap.getStaticField(owner, name, conc_value);
            ReferenceConstant newDoubleRef = newDoubleReference(conc_value, expr);
            return new ReferenceExpressionPair(newDoubleRef, expr);
        } else {
            Object conc_value = field.get(null);
            if (conc_value instanceof String) {
                String string = (String) conc_value;
                StringValue expr = env.heap.getStaticField(owner, name, string);
                ReferenceConstant newStringRef = newStringReference(string, expr);
                return new ReferenceExpressionPair(newStringRef, expr);
            } else {
                ReferenceExpression ref = env.heap.getReference(conc_value);
                if (conc_value != null && isWrapper(conc_value)) {
                    ReferenceConstant nonNullRef = (ReferenceConstant) ref;
                    Expression<?> expr = findOrCreate(conc_value, nonNullRef);
                    return new ReferenceExpressionPair(ref, expr);
                } else {
                    return new ReferenceExpressionPair(ref, null);
                }
            }
        }
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
Also used : RealValue(org.evosuite.symbolic.expr.fp.RealValue) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) 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) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 2 with ReferenceConstant

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

the class SymbolicObserver method after.

private void after(FloatPrimitiveStatement statement, Scope scope) {
    float valueOf = statement.getValue();
    VariableReference varRef = statement.getReturnValue();
    String varRefName = varRef.getName();
    RealVariable realVariable = buildRealVariable(varRefName, valueOf, -Float.MAX_VALUE, Float.MAX_VALUE);
    symb_expressions.put(varRefName, realVariable);
    Float float_instance;
    try {
        float_instance = (Float) varRef.getObject(scope);
    } catch (CodeUnderTestException e) {
        throw new EvosuiteError(e);
    }
    ReferenceConstant floatRef = newFloatReference(float_instance, realVariable);
    symb_references.put(varRefName, floatRef);
}
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 3 with ReferenceConstant

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

the class SymbolicObserver method newLongReference.

private ReferenceConstant newLongReference(Long conc_long, IntegerValue symb_value) {
    ReferenceConstant longRef = (ReferenceConstant) env.heap.getReference(conc_long);
    env.heap.putField(Types.JAVA_LANG_LONG, SymbolicHeap.$LONG_VALUE, conc_long, longRef, symb_value);
    return longRef;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant)

Example 4 with ReferenceConstant

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

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

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