Search in sources :

Example 36 with StringValue

use of org.evosuite.symbolic.expr.str.StringValue 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 37 with StringValue

use of org.evosuite.symbolic.expr.str.StringValue in project evosuite by EvoSuite.

the class CharAt method executeFunction.

@Override
public Object executeFunction() {
    String conc_str = (String) this.getConcReceiver();
    ReferenceConstant symb_str = this.getSymbReceiver();
    StringValue string_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_str, symb_str, conc_str);
    IntegerValue index_expr = this.getSymbIntegerArgument(0);
    char res = this.getConcCharRetVal();
    if (string_expr.containsSymbolicVariable() || index_expr.containsSymbolicVariable()) {
        StringBinaryToIntegerExpression strBExpr = new StringBinaryToIntegerExpression(string_expr, Operator.CHARAT, index_expr, (long) res);
        return strBExpr;
    } else {
        return this.getSymbIntegerRetVal();
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 38 with StringValue

use of org.evosuite.symbolic.expr.str.StringValue in project evosuite by EvoSuite.

the class Contains 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);
    CharSequence conc_right = (CharSequence) this.getConcArgument(0);
    ReferenceConstant symb_right = (ReferenceConstant) this.getSymbArgument(0);
    if (conc_right instanceof String) {
        String conc_right_str = (String) conc_right;
        StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right_str, symb_right, conc_right_str);
        boolean res = this.getConcBooleanRetVal();
        if (right_expr != null) {
            if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
                int concrete_value = res ? 1 : 0;
                StringBinaryComparison strComp = new StringBinaryComparison(left_expr, Operator.CONTAINS, right_expr, (long) concrete_value);
                return strComp;
            }
        }
    }
    return this.getSymbIntegerRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 39 with StringValue

use of org.evosuite.symbolic.expr.str.StringValue 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 40 with StringValue

use of org.evosuite.symbolic.expr.str.StringValue in project evosuite by EvoSuite.

the class Concat 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);
    String res = (String) this.getConcRetVal();
    if (res != null) {
        StringBinaryExpression symb_value = new StringBinaryExpression(left_expr, Operator.CONCAT, right_expr, (String) res);
        ReferenceConstant symb_receiver = (ReferenceConstant) env.topFrame().operandStack.peekRef();
        String conc_receiver = (String) res;
        env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_receiver, symb_value);
    }
    return this.getSymbRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringBinaryExpression(org.evosuite.symbolic.expr.str.StringBinaryExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Aggregations

StringValue (org.evosuite.symbolic.expr.str.StringValue)45 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)39 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)16 Expression (org.evosuite.symbolic.expr.Expression)10 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)8 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)8 RealValue (org.evosuite.symbolic.expr.fp.RealValue)4 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)4 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)4 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)4 ArrayList (java.util.ArrayList)3 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)3 StringReaderExpr (org.evosuite.symbolic.expr.reader.StringReaderExpr)3 StringMultipleExpression (org.evosuite.symbolic.expr.str.StringMultipleExpression)3 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)3 StringReader (java.io.StringReader)2 Matcher (java.util.regex.Matcher)2 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)2 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)2 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)2