Search in sources :

Example 26 with StringVariable

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

the class StringAVMTests method testInsertRight.

@Test
public void testInsertRight() throws SolverTimeoutException {
    String name = "foo";
    String start = "abc";
    StringVariable var = new StringVariable(name, start);
    String format = start + "\\d\\d\\d";
    List<Constraint<?>> constraints = getPatternConstraint(var, format);
    long start_time = System.currentTimeMillis();
    long timeout = Properties.DSE_CONSTRAINT_SOLVER_TIMEOUT_MILLIS;
    StringAVM avm = new StringAVM(var, constraints, start_time, timeout);
    boolean succeded = avm.applyAVM();
    assertTrue(succeded);
    String result = var.getConcreteValue();
    assertTrue("Length=" + result.length(), result.length() == 6);
    assertTrue(result, result.startsWith(start));
}
Also used : StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) StringAVM(org.evosuite.symbolic.solver.avm.StringAVM) Test(org.junit.Test)

Example 27 with StringVariable

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

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

the class TestSolverStringFunctions method testNegativeLength.

public static Map<String, Object> testNegativeLength(Solver solver) throws SecurityException, NoSuchMethodException, SolverTimeoutException {
    IntegerConstraint newIntegerConstraint = new IntegerConstraint(new StringUnaryToIntegerExpression(new StringVariable("var0", "01234"), Operator.LENGTH, (long) 5), Comparator.LT, new IntegerConstant(0));
    Collection<Constraint<?>> constraints = Collections.<Constraint<?>>singleton(newIntegerConstraint);
    Map<String, Object> solution = solve(solver, constraints);
    return solution;
}
Also used : IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) TestCaseStringAppendString(com.examples.with.different.packagename.solver.TestCaseStringAppendString) TestCaseStringLastIndexOfString(com.examples.with.different.packagename.solver.TestCaseStringLastIndexOfString) TestCaseStringIndexOfString(com.examples.with.different.packagename.solver.TestCaseStringIndexOfString) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 29 with StringVariable

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

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

StringVariable (org.evosuite.symbolic.expr.str.StringVariable)39 Constraint (org.evosuite.symbolic.expr.Constraint)34 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)29 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)28 Test (org.junit.Test)28 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)25 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)24 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)24 ArrayList (java.util.ArrayList)22 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)20 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)16 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)10 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)5 Expression (org.evosuite.symbolic.expr.Expression)4 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)4 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)4 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)4 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)4 StringAVM (org.evosuite.symbolic.solver.avm.StringAVM)4 SolverResult (org.evosuite.symbolic.solver.SolverResult)3