Search in sources :

Example 26 with ReferenceConstant

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

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

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

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

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

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