Search in sources :

Example 1 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.

the class Matcher_Matches method executeFunction.

@Override
public Object executeFunction() {
    Matcher conc_matcher = (Matcher) this.getConcReceiver();
    ReferenceConstant symb_matcher = (ReferenceConstant) this.getSymbReceiver();
    boolean res = this.getConcBooleanRetVal();
    String conc_regex = conc_matcher.pattern().pattern();
    StringValue symb_input = (StringValue) env.heap.getField(Types.JAVA_UTIL_REGEX_MATCHER, SymbolicHeap.$MATCHER_INPUT, conc_matcher, symb_matcher);
    if (symb_input != null && symb_input.containsSymbolicVariable()) {
        int concrete_value = res ? 1 : 0;
        StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(conc_regex);
        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) Matcher(java.util.regex.Matcher) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue) StringConstant(org.evosuite.symbolic.expr.str.StringConstant)

Example 2 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison 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 3 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison 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 4 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.

the class Matches method executeFunction.

@Override
public Object executeFunction() {
    // receiver
    ReferenceConstant symb_receiver = this.getSymbReceiver();
    String conc_receiver = (String) this.getConcReceiver();
    // argument
    String conc_argument = (String) this.getConcArgument(0);
    StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_receiver, conc_receiver);
    // return val
    boolean res = this.getConcBooleanRetVal();
    if (right_expr.containsSymbolicVariable()) {
        StringConstant left_expr = ExpressionFactory.buildNewStringConstant(conc_argument);
        int conV = res ? 1 : 0;
        StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.PATTERNMATCHES, right_expr, (long) conV);
        return strBExpr;
    }
    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) StringConstant(org.evosuite.symbolic.expr.str.StringConstant)

Example 5 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.

the class DistanceCalculator method visit.

@Override
public Object visit(StringConstraint n, Void arg) {
    Expression<?> exprLeft = n.getLeftOperand();
    Comparator cmpr = n.getComparator();
    double distance = 0.0;
    if (exprLeft instanceof StringBinaryComparison) {
        StringBinaryComparison scTarget = (StringBinaryComparison) exprLeft;
        distance = getStringDistance(scTarget);
        log.debug("Calculating distance of constraint " + n);
    } else if (exprLeft instanceof StringMultipleComparison) {
        StringMultipleComparison scTarget = (StringMultipleComparison) exprLeft;
        distance = getStringDistance(scTarget);
        log.debug("Calculating distance of constraint " + n);
    } else if (exprLeft instanceof HasMoreTokensExpr) {
        HasMoreTokensExpr hasMoreTokensExpr = (HasMoreTokensExpr) exprLeft;
        distance = getStringDistance(hasMoreTokensExpr);
        log.debug("Calculating distance of constraint " + n);
    } else {
        assert (false) : "Invalid string comparison";
    }
    assert (((Long) n.getRightOperand().getConcreteValue()).intValue() == 0);
    if (cmpr == Comparator.NE) {
        return distance;
    } else {
        // if not satisfied Long.MAX_VALUE else
        return distance > 0 ? 0.0 : Double.MAX_VALUE;
    }
}
Also used : StringMultipleComparison(org.evosuite.symbolic.expr.bv.StringMultipleComparison) HasMoreTokensExpr(org.evosuite.symbolic.expr.token.HasMoreTokensExpr) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison)

Aggregations

StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)26 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)20 Constraint (org.evosuite.symbolic.expr.Constraint)17 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)17 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)17 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)16 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)14 Test (org.junit.Test)14 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)13 ArrayList (java.util.ArrayList)12 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)12 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)8 StringValue (org.evosuite.symbolic.expr.str.StringValue)8 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)1 Pattern (org.apache.oro.text.regex.Pattern)1 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)1 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)1 HasMoreTokensExpr (org.evosuite.symbolic.expr.token.HasMoreTokensExpr)1