Search in sources :

Example 11 with StringValue

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

the class CompareTo 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.COMPARETO, 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)

Example 12 with StringValue

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

the class EndsWith 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);
    boolean res = this.getConcBooleanRetVal();
    if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
        int conV = res ? 1 : 0;
        StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.ENDSWITH, right_expr, (long) conV);
        return strBExpr;
    } else {
        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 13 with StringValue

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

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

the class RegionMatches5 method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_receiver = (ReferenceConstant) this.getSymbReceiver();
    String conc_receiver = (String) this.getConcReceiver();
    StringValue stringReceiverExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_receiver, conc_receiver);
    IntegerValue ignoreCaseExpr = new IntegerConstant(0);
    IntegerValue toffsetExpr = this.getSymbIntegerArgument(0);
    ReferenceConstant symb_other = (ReferenceConstant) this.getSymbArgument(1);
    String conc_other = (String) this.getConcArgument(1);
    StringValue otherExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_other, symb_other, conc_other);
    IntegerValue ooffsetExpr = this.getSymbIntegerArgument(2);
    IntegerValue lenExpr = this.getSymbIntegerArgument(3);
    boolean res = this.getConcBooleanRetVal();
    if (stringReceiverExpr.containsSymbolicVariable() || ignoreCaseExpr.containsSymbolicVariable() || toffsetExpr.containsSymbolicVariable() || otherExpr.containsSymbolicVariable() || ooffsetExpr.containsSymbolicVariable() || lenExpr.containsSymbolicVariable()) {
        ArrayList<Expression<?>> other = new ArrayList<Expression<?>>();
        other.add(toffsetExpr);
        other.add(ooffsetExpr);
        other.add(lenExpr);
        other.add(ignoreCaseExpr);
        int conV = res ? 1 : 0;
        StringMultipleComparison strComp = new StringMultipleComparison(stringReceiverExpr, Operator.REGIONMATCHES, otherExpr, other, (long) conV);
        return strComp;
    }
    return this.getSymbIntegerRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringMultipleComparison(org.evosuite.symbolic.expr.bv.StringMultipleComparison) Expression(org.evosuite.symbolic.expr.Expression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ArrayList(java.util.ArrayList) StringValue(org.evosuite.symbolic.expr.str.StringValue) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 15 with StringValue

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

the class ToUpperCase method executeFunction.

@Override
public Object executeFunction() {
    // object receiver
    ReferenceConstant symb_str = this.getSymbReceiver();
    String conc_str = (String) this.getConcReceiver();
    // return value
    String conc_ret_val = (String) this.getConcRetVal();
    ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
    StringValue string_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_str, symb_str, conc_str);
    StringUnaryExpression symb_value = new StringUnaryExpression(string_expr, Operator.TOUPPERCASE, conc_ret_val);
    env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, symb_ret_val, symb_value);
    return this.getSymbRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) 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