Search in sources :

Example 6 with StringConstraint

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

the class TestStringSearch method testEndsWithTrueConstant.

@Test
public void testEndsWithTrueConstant() {
    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.ENDSWITH, 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((result.get("test1").toString()).endsWith(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)

Example 7 with StringConstraint

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

the class TestStringSearch method testInversionOfRegex.

@Test
public void testInversionOfRegex() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var = "a+";
    String regex = "aaa";
    // so we need to solve it
    assertFalse(var.matches(regex));
    String variableName = "test1";
    StringVariable strVar = new StringVariable(variableName, var);
    StringConstant strConst = new StringConstant(regex);
    StringBinaryComparison strComp = new StringBinaryComparison(strConst, Operator.PATTERNMATCHES, strVar, 0L);
    // the constraint should evaluate to true
    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(variableName));
        String solution = result.get(variableName).toString();
        assertTrue(solution.matches(regex));
        /*
			 * as the regex defines only one possible matching string, then the
			 * solution has to be equal to the regex
			 */
        assertEquals(regex, solution);
    } catch (SolverTimeoutException e) {
        fail();
    }
    // now let's invert them
    strVar = new StringVariable(variableName, regex);
    strConst = new StringConstant(var);
    // the inversion should match immediately
    assertTrue(regex.matches(var));
    // recreate the same type of constraint
    strComp = new StringBinaryComparison(strConst, Operator.PATTERNMATCHES, strVar, 0L);
    constraints.clear();
    constraints.add(new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0)));
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
    } 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 8 with StringConstraint

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

the class TestStringSearch method testEqualsFalseConstant.

@Test
public void testEqualsFalseConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "foo";
    String const2 = "foo";
    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.EQ, 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 9 with StringConstraint

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

the class TestStringSearch method testContainsTrueConstant.

@Test
public void testContainsTrueConstant() {
    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.CONTAINS, 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((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)

Example 10 with StringConstraint

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

the class TestStringSearch method testEqualsIgnoreCaseFalseConstant.

@Test
public void testEqualsIgnoreCaseFalseConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "foo";
    String const2 = "FOO";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.EQUALSIGNORECASE, 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(const2.equalsIgnoreCase(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)

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