Search in sources :

Example 21 with ReferenceExpression

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

the class SymbolicFunctionVM method CALL_RESULT.

@Override
public void CALL_RESULT(Object conc_ret_val, String owner, String name, String desc) {
    if (functionUnderExecution != null) {
        if (!functionUnderExecution.getOwner().equals(owner) || !functionUnderExecution.getName().equals(name) || !functionUnderExecution.getDesc().equals(desc)) {
            functionUnderExecution = null;
        }
    }
    if (functionUnderExecution != null) {
        ReferenceExpression symb_ret_val = this.env.topFrame().operandStack.peekRef();
        functionUnderExecution.setReturnValue(conc_ret_val, symb_ret_val);
        ReferenceExpression new_symb_ret_val = (ReferenceExpression) functionUnderExecution.executeFunction();
        this.replaceTopRef(new_symb_ret_val);
    }
    functionUnderExecution = null;
}
Also used : ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 22 with ReferenceExpression

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

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

the class Pattern_Matcher method executeFunction.

@Override
public Object executeFunction() {
    // receiver
    @SuppressWarnings("unused") ReferenceConstant symb_receiver = this.getSymbReceiver();
    // argument
    CharSequence conc_char_seq = (CharSequence) this.getConcArgument(0);
    ReferenceExpression symb_char_seq = this.getSymbArgument(0);
    // return value
    Matcher conc_matcher = (Matcher) this.getConcRetVal();
    ReferenceConstant symb_matcher = (ReferenceConstant) this.getSymbRetVal();
    if (conc_char_seq != null && conc_char_seq instanceof String) {
        assert symb_char_seq instanceof ReferenceConstant;
        ReferenceConstant symb_string = (ReferenceConstant) symb_char_seq;
        String string = (String) conc_char_seq;
        StringValue symb_input = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, string, symb_string, string);
        env.heap.putField(Types.JAVA_UTIL_REGEX_MATCHER, SymbolicHeap.$MATCHER_INPUT, conc_matcher, symb_matcher, symb_input);
    }
    return symb_matcher;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Matcher(java.util.regex.Matcher) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 24 with ReferenceExpression

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

the class EqualsIgnoreCase method executeFunction.

@Override
public Object executeFunction() {
    String conc_left = (String) this.getConcReceiver();
    ReferenceConstant symb_left = this.getSymbReceiver();
    String conc_right = (String) this.getConcArgument(0);
    ReferenceExpression symb_right = this.getSymbArgument(0);
    boolean res = this.getConcBooleanRetVal();
    StringValue left_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_left, symb_left, conc_left);
    if (symb_right instanceof ReferenceConstant && conc_right != null) {
        ReferenceConstant ref_constant_right = (ReferenceConstant) symb_right;
        StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right, ref_constant_right, conc_right);
        if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
            int conV = res ? 1 : 0;
            StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.EQUALSIGNORECASE, right_expr, (long) conV);
            return strBExpr;
        }
    }
    return this.getSymbIntegerRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 25 with ReferenceExpression

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

the class ReplaceFirst method executeFunction.

@Override
public Object executeFunction() {
    // receiver
    ReferenceConstant symb_receiver = this.getSymbReceiver();
    String conc_receiver = (String) this.getConcReceiver();
    // regex argument
    ReferenceExpression symb_regex = this.getSymbArgument(0);
    String conc_regex = (String) this.getConcArgument(0);
    // replacement argument
    ReferenceExpression symb_replacement = this.getSymbArgument(1);
    String conc_replacement = (String) this.getConcArgument(1);
    // return value
    String conc_ret_val = (String) this.getConcRetVal();
    ReferenceExpression symb_ret_val = this.getSymbRetVal();
    StringValue stringReceiverExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_receiver, conc_receiver);
    if (symb_regex instanceof ReferenceConstant && symb_replacement instanceof ReferenceConstant) {
        ReferenceConstant non_null_symb_regex = (ReferenceConstant) symb_regex;
        StringValue regexExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_regex, non_null_symb_regex, conc_regex);
        ReferenceConstant non_null_symb_replacement = (ReferenceConstant) symb_replacement;
        StringValue replacementExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_replacement, non_null_symb_replacement, conc_replacement);
        if (symb_ret_val instanceof ReferenceConstant) {
            ReferenceConstant non_null_symb_ret_val = (ReferenceConstant) symb_ret_val;
            StringMultipleExpression symb_value = new StringMultipleExpression(stringReceiverExpr, Operator.REPLACEFIRST, regexExpr, new ArrayList<Expression<?>>(Collections.singletonList(replacementExpr)), conc_ret_val);
            env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, non_null_symb_ret_val, symb_value);
        }
    }
    return symb_ret_val;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringMultipleExpression(org.evosuite.symbolic.expr.str.StringMultipleExpression) Expression(org.evosuite.symbolic.expr.Expression) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringMultipleExpression(org.evosuite.symbolic.expr.str.StringMultipleExpression) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

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