Search in sources :

Example 16 with StringConstant

use of org.evosuite.symbolic.expr.str.StringConstant in project evosuite by EvoSuite.

the class TestStringEqualsIgnoreCase method testStringEqualsIgnoreCase.

@Test
public void testStringEqualsIgnoreCase() throws SecurityException, NoSuchMethodException, SolverTimeoutException {
    IntegerConstant zero = new IntegerConstant(0);
    StringVariable stringVar0 = new StringVariable("var0", "");
    StringConstant strConst = new StringConstant("bar");
    StringBinaryComparison cmp1 = new StringBinaryComparison(stringVar0, Operator.EQUALS, strConst, 0L);
    StringConstraint constr1 = new StringConstraint(cmp1, Comparator.EQ, zero);
    StringBinaryComparison cmp2 = new StringBinaryComparison(stringVar0, Operator.EQUALSIGNORECASE, strConst, 1L);
    StringConstraint constr2 = new StringConstraint(cmp2, Comparator.NE, zero);
    Collection<Constraint<?>> constraints = Arrays.<Constraint<?>>asList(constr1, constr2);
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution = solve(solver, constraints);
    assertNotNull(solution);
    String var0 = (String) solution.get("var0");
    assertNotNull(var0);
    assertTrue(!var0.equals("bar"));
    assertTrue(var0.equalsIgnoreCase("bar"));
}
Also used : StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) 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) Test(org.junit.Test)

Example 17 with StringConstant

use of org.evosuite.symbolic.expr.str.StringConstant in project evosuite by EvoSuite.

the class StringAVMTests method getPatternConstraint.

private List<Constraint<?>> getPatternConstraint(StringVariable var, String format) {
    StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(format);
    StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, var, 0L);
    StringConstraint constraint = new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0));
    List<Constraint<?>> constraints = Collections.<Constraint<?>>singletonList(constraint);
    return constraints;
}
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) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 18 with StringConstant

use of org.evosuite.symbolic.expr.str.StringConstant 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 19 with StringConstant

use of org.evosuite.symbolic.expr.str.StringConstant 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 20 with StringConstant

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

Aggregations

StringConstant (org.evosuite.symbolic.expr.str.StringConstant)26 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)23 Constraint (org.evosuite.symbolic.expr.Constraint)22 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)21 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)20 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)20 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)19 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)18 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)18 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)18 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)5 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)5 Expression (org.evosuite.symbolic.expr.Expression)4 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)4 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)4 StringValue (org.evosuite.symbolic.expr.str.StringValue)4 Matcher (java.util.regex.Matcher)2 SolverResult (org.evosuite.symbolic.solver.SolverResult)2 Pattern (java.util.regex.Pattern)1