Search in sources :

Example 16 with StringConstraint

use of org.evosuite.symbolic.expr.StringConstraint in project evosuite by EvoSuite.

the class TestConstraintSolver2 method buildConstraintSystem.

private static Collection<Constraint<?>> buildConstraintSystem() {
    StringVariable var0 = new StringVariable("var0", INIT_STRING);
    StringConstant const0 = new StringConstant(EXPECTED_STRING);
    StringBinaryComparison strEqual = new StringBinaryComparison(var0, Operator.EQUALS, const0, (long) 0);
    IntegerConstant const_zero = new IntegerConstant(0);
    StringConstraint constr1 = new StringConstraint(strEqual, Comparator.NE, const_zero);
    return Arrays.<Constraint<?>>asList(constr1);
}
Also used : StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 17 with StringConstraint

use of org.evosuite.symbolic.expr.StringConstraint in project evosuite by EvoSuite.

the class TestStringDistance method createConstraints.

private Collection<Constraint<?>> createConstraints(final String str1, final String str2) {
    StringVariable var1 = new StringVariable("var0", str1);
    StringConstant const1 = new StringConstant(str2);
    StringBinaryComparison comp = new StringBinaryComparison(var1, Operator.EQUALS, const1, 0L);
    IntegerConstant zero = new IntegerConstant(0);
    StringConstraint stringConstraint = new StringConstraint(comp, Comparator.NE, zero);
    Collection<Constraint<?>> cnstr = Collections.<Constraint<?>>singletonList(stringConstraint);
    return cnstr;
}
Also used : StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 18 with StringConstraint

use of org.evosuite.symbolic.expr.StringConstraint in project evosuite by EvoSuite.

the class TestStringSearch method testEqualsTrueConstant.

@Test
public void testEqualsTrueConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "foo";
    String const2 = "test";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.EQUALS, strConst, 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(const2.equals(result.get("test1").toString()));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) 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) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) Test(org.junit.Test)

Example 19 with StringConstraint

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

Example 20 with StringConstraint

use of org.evosuite.symbolic.expr.StringConstraint in project evosuite by EvoSuite.

the class TestStringSearch method testContainsFalseConstant.

@Test
public void testContainsFalseConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "fotesto";
    String const2 = "test";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.CONTAINS, strConst, 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()).contains(const2));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) 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) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) Test(org.junit.Test)

Aggregations

StringConstraint (org.evosuite.symbolic.expr.StringConstraint)24 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)22 Constraint (org.evosuite.symbolic.expr.Constraint)21 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)21 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)20 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)18 Test (org.junit.Test)18 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)17 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)17 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)17 ArrayList (java.util.ArrayList)16 Expression (org.evosuite.symbolic.expr.Expression)5 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)5 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)4 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)4 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DistanceCalculator (org.evosuite.symbolic.expr.DistanceCalculator)1 RealConstraint (org.evosuite.symbolic.expr.RealConstraint)1