Search in sources :

Example 66 with ReferenceExpression

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

the class Pattern_Matches method executeFunction.

@Override
public Object executeFunction() {
    // argument 0
    String regex_str = (String) this.getConcArgument(0);
    ReferenceConstant regex_ref = (ReferenceConstant) this.getSymbArgument(0);
    // argument 1
    CharSequence input_char_seq = (CharSequence) this.getConcArgument(1);
    ReferenceExpression input_ref = this.getSymbArgument(1);
    // return value
    boolean res = this.getConcBooleanRetVal();
    // symbolic execution
    StringValue symb_regex = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, regex_str, regex_ref, regex_str);
    StringValue symb_input = getSymbInput(input_char_seq, input_ref);
    if (symb_input != null && symb_input.containsSymbolicVariable()) {
        int concrete_value = res ? 1 : 0;
        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) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 67 with ReferenceExpression

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

the class Equals method executeFunction.

@Override
public Object executeFunction() {
    String conc_left = (String) this.getConcReceiver();
    ReferenceConstant symb_left = this.getSymbReceiver();
    Object conc_right = 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 instanceof String) {
        ReferenceConstant non_null_symb_right = (ReferenceConstant) symb_right;
        String conc_right_str = (String) conc_right;
        StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right_str, non_null_symb_right, conc_right_str);
        if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
            int conV = res ? 1 : 0;
            StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.EQUALS, 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 68 with ReferenceExpression

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

the class ReplaceAll 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.REPLACEALL, 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)

Example 69 with ReferenceExpression

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

the class SymbolicObserver method after.

private void after(EnumPrimitiveStatement<?> s, Scope scope) {
    VariableReference varRef = s.getReturnValue();
    String varName = varRef.getName();
    Object conc_value = s.getValue();
    ReferenceExpression symb_value = env.heap.getReference(conc_value);
    symb_references.put(varName, symb_value);
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression)

Example 70 with ReferenceExpression

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

the class SymbolicObserver method readVariable.

/**
 * Reads a VariableReference from the stored symbolic references and
 * symbolic expressions.
 *
 * @throws IllegalArgumentException
 *             if no value was found
 *
 * @param rhs
 * @param scope
 * @return
 */
private ReferenceExpressionPair readVariable(VariableReference rhs, Scope scope) {
    String rhs_name = rhs.getName();
    ReferenceExpression symb_ref = symb_references.get(rhs_name);
    Expression<?> symb_expr = symb_expressions.get(rhs_name);
    return new ReferenceExpressionPair(symb_ref, symb_expr);
}
Also used : 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