Search in sources :

Example 1 with StringMultipleComparison

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

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

the class RegionMatches 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 = this.getSymbIntegerArgument(0);
    IntegerValue toffsetExpr = this.getSymbIntegerArgument(1);
    ReferenceConstant symb_other = (ReferenceConstant) this.getSymbArgument(2);
    String conc_other = (String) this.getConcArgument(2);
    StringValue otherExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_other, symb_other, conc_other);
    IntegerValue ooffsetExpr = this.getSymbIntegerArgument(3);
    IntegerValue lenExpr = this.getSymbIntegerArgument(4);
    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)

Example 3 with StringMultipleComparison

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

Example 4 with StringMultipleComparison

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

the class TestStringSearch method testStartsWithFalseConstant.

@Test
public void testStartsWithFalseConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "footest";
    String const2 = "test";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    IntegerConstant offs_expr = new IntegerConstant(3);
    ArrayList<Expression<?>> other = new ArrayList<Expression<?>>();
    other.add(offs_expr);
    StringMultipleComparison strComp = new StringMultipleComparison(strVar, Operator.STARTSWITH, strConst, other, 0L);
    constraints.add(new StringConstraint(strComp, Comparator.EQ, new IntegerConstant(0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        assertNotNull(result.get("test1"));
        assertFalse((result.get("test1").toString()).startsWith(const2, 3));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringMultipleComparison(org.evosuite.symbolic.expr.bv.StringMultipleComparison) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) Expression(org.evosuite.symbolic.expr.Expression) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) Test(org.junit.Test)

Example 5 with StringMultipleComparison

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

the class TestStringSearch method testRegionMatchesICTrueConstant.

@Test
public void testRegionMatchesICTrueConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "teXto";
    String const2 = "rtestooo";
    boolean ignore_case = true;
    int offset1 = 0;
    int offset2 = 1;
    int len = 4;
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    IntegerConstant len_expr = new IntegerConstant(len);
    IntegerConstant offs_one = new IntegerConstant(offset1);
    IntegerConstant offs_two = new IntegerConstant(offset2);
    IntegerConstant ign_case = new IntegerConstant(ignore_case ? 1 : 0);
    ArrayList<Expression<?>> other = new ArrayList<Expression<?>>();
    other.add(offs_one);
    other.add(offs_two);
    other.add(len_expr);
    other.add(ign_case);
    StringMultipleComparison strComp = new StringMultipleComparison(strVar, Operator.REGIONMATCHES, strConst, other, 0L);
    constraints.add(new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        assertNotNull(result.get("test1"));
        assertTrue((result.get("test1").toString()).regionMatches(ignore_case, offset1, const2, offset2, len));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringMultipleComparison(org.evosuite.symbolic.expr.bv.StringMultipleComparison) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) Expression(org.evosuite.symbolic.expr.Expression) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) Test(org.junit.Test)

Aggregations

StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)7 ArrayList (java.util.ArrayList)6 Expression (org.evosuite.symbolic.expr.Expression)6 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)5 Constraint (org.evosuite.symbolic.expr.Constraint)4 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)4 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)4 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)4 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)4 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)4 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)4 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)4 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)4 Test (org.junit.Test)4 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)2 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)2 StringValue (org.evosuite.symbolic.expr.str.StringValue)2 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)1 HasMoreTokensExpr (org.evosuite.symbolic.expr.token.HasMoreTokensExpr)1