Search in sources :

Example 21 with ReferenceConstant

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

Example 22 with ReferenceConstant

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

the class BigInteger_DivideAndRemainder method executeFunction.

@Override
public Object executeFunction() {
    BigInteger conc_left_big_integer = (BigInteger) this.getConcReceiver();
    ReferenceConstant symb_left_big_integer = this.getSymbReceiver();
    BigInteger conc_right_big_integer = (BigInteger) this.getConcArgument(0);
    ReferenceConstant symb_right_big_integer = (ReferenceConstant) this.getSymbArgument(0);
    Object res = this.getConcRetVal();
    ReferenceExpression symb_res = this.getSymbRetVal();
    if (res != null && conc_left_big_integer != null && conc_right_big_integer != null) {
        IntegerValue left_big_integer_expr = this.env.heap.getField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, conc_left_big_integer, symb_left_big_integer, conc_left_big_integer.longValue());
        IntegerValue right_big_integer_expr = this.env.heap.getField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, conc_right_big_integer, symb_right_big_integer, conc_right_big_integer.longValue());
        if (left_big_integer_expr.containsSymbolicVariable() || right_big_integer_expr.containsSymbolicVariable()) {
            // quotient
            BigInteger conc_quotient = (BigInteger) Array.get(res, QUOTIENT_ARRAY_INDEX);
            ReferenceConstant symb_quotient = (ReferenceConstant) this.env.heap.getReference(conc_quotient);
            IntegerValue symb_div_value = ExpressionFactory.div(left_big_integer_expr, right_big_integer_expr, conc_quotient.longValue());
            this.env.heap.putField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, conc_quotient, symb_quotient, symb_div_value);
            // remainder
            BigInteger conc_remainder = (BigInteger) Array.get(res, REMAINDER_ARRAY_INDEX);
            ReferenceConstant symb_remainder = (ReferenceConstant) this.env.heap.getReference(conc_remainder);
            IntegerValue symb_rem_value = ExpressionFactory.rem(left_big_integer_expr, right_big_integer_expr, conc_remainder.longValue());
            this.env.heap.putField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, conc_remainder, symb_remainder, symb_rem_value);
        }
    }
    return symb_res;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) BigInteger(java.math.BigInteger) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 23 with ReferenceConstant

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

the class Matcher_Matches method executeFunction.

@Override
public Object executeFunction() {
    Matcher conc_matcher = (Matcher) this.getConcReceiver();
    ReferenceConstant symb_matcher = (ReferenceConstant) this.getSymbReceiver();
    boolean res = this.getConcBooleanRetVal();
    String conc_regex = conc_matcher.pattern().pattern();
    StringValue symb_input = (StringValue) env.heap.getField(Types.JAVA_UTIL_REGEX_MATCHER, SymbolicHeap.$MATCHER_INPUT, conc_matcher, symb_matcher);
    if (symb_input != null && symb_input.containsSymbolicVariable()) {
        int concrete_value = res ? 1 : 0;
        StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(conc_regex);
        StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, symb_input, (long) concrete_value);
        return strComp;
    } else {
        return this.getSymbIntegerRetVal();
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Matcher(java.util.regex.Matcher) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue) StringConstant(org.evosuite.symbolic.expr.str.StringConstant)

Example 24 with ReferenceConstant

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

the class Pattern_Matches method getSymbInput.

private StringValue getSymbInput(CharSequence input_char_seq, ReferenceExpression input_ref) {
    StringValue symb_input;
    if (input_ref instanceof ReferenceConstant) {
        ReferenceConstant input_str_ref = (ReferenceConstant) input_ref;
        assert input_char_seq != null;
        if (input_char_seq instanceof String) {
            String string = (String) input_char_seq;
            symb_input = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, string, input_str_ref, string);
        } else if (input_char_seq instanceof StringBuilder) {
            StringBuilder stringBuffer = (StringBuilder) input_char_seq;
            symb_input = env.heap.getField(Types.JAVA_LANG_STRING_BUILDER, SymbolicHeap.$STRING_BUILDER_CONTENTS, stringBuffer, input_str_ref, stringBuffer.toString());
        } else {
            symb_input = null;
        }
    } else {
        symb_input = null;
    }
    return symb_input;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 25 with ReferenceConstant

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

the class CompareToIgnoreCase method executeFunction.

@Override
public Object executeFunction() {
    String conc_left = (String) this.getConcReceiver();
    ReferenceConstant symb_left = this.getSymbReceiver();
    StringValue left_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_left, symb_left, conc_left);
    String conc_right = (String) this.getConcArgument(0);
    ReferenceConstant symb_right = (ReferenceConstant) this.getSymbArgument(0);
    StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right, symb_right, conc_right);
    int res = this.getConcIntRetVal();
    if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
        StringBinaryToIntegerExpression strBExpr = new StringBinaryToIntegerExpression(left_expr, Operator.COMPARETOIGNORECASE, right_expr, (long) res);
        return strBExpr;
    } else {
        return this.getSymbIntegerRetVal();
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

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