Search in sources :

Example 1 with ReferenceExpression

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

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

the class SymbolicObserver method after.

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

Example 3 with ReferenceExpression

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

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

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

Aggregations

ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)73 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)27 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)19 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)18 StringValue (org.evosuite.symbolic.expr.str.StringValue)16 Expression (org.evosuite.symbolic.expr.Expression)13 RealValue (org.evosuite.symbolic.expr.fp.RealValue)13 VariableReference (org.evosuite.testcase.variable.VariableReference)11 Type (org.objectweb.asm.Type)9 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)6 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)5 Field (java.lang.reflect.Field)3 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)3 Method (java.lang.reflect.Method)2 StringMultipleExpression (org.evosuite.symbolic.expr.str.StringMultipleExpression)2 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)2 ArrayReference (org.evosuite.testcase.variable.ArrayReference)2 BigInteger (java.math.BigInteger)1 Matcher (java.util.regex.Matcher)1 EvoSuiteFile (org.evosuite.runtime.testdata.EvoSuiteFile)1