Search in sources :

Example 21 with StringBinaryComparison

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

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

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

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

Example 25 with StringBinaryComparison

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

the class TestStringSearch method testEqualsToLowerCase.

@Test
public void testEqualsToLowerCase() {
    // (wed equals var1("f|").toLowerCase()) != 0
    StringVariable var1 = new StringVariable("var1", "f|");
    StringBinaryComparison cmp3 = new StringBinaryComparison(new StringConstant("wed"), Operator.EQUALS, new StringUnaryExpression(var1, Operator.TOLOWERCASE, "f|".toLowerCase()), 0L);
    StringConstraint constr3 = new StringConstraint(cmp3, Comparator.NE, new IntegerConstant(0));
    Collection<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(constr3);
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution;
    try {
        solution = solve(solver, constraints);
        assertNotNull(solution);
    } 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) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) 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

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