use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver 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();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestStringSearch method testStartsWithFalseConstant.
@Test
public void testStartsWithFalseConstant() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
String var1 = "footest";
String const2 = "test";
StringVariable strVar = new StringVariable("test1", var1);
StringConstant strConst = new StringConstant(const2);
IntegerConstant offs_expr = new IntegerConstant(3);
ArrayList<Expression<?>> other = new ArrayList<Expression<?>>();
other.add(offs_expr);
StringMultipleComparison strComp = new StringMultipleComparison(strVar, Operator.STARTSWITH, strConst, other, 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()).startsWith(const2, 3));
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestStringSearch method testEndsWithFalseConstant.
@Test
public void testEndsWithFalseConstant() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
String var1 = "footest";
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.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()).endsWith(const2));
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestStringSearch method testIndexOfC2.
@Test
public void testIndexOfC2() {
String var1value = ":cc]#0l";
StringVariable var1 = new StringVariable("var0", var1value);
IntegerConstant colon_code = new IntegerConstant(58);
IntegerConstant numeral_code = new IntegerConstant(35);
IntegerConstant minus_one = new IntegerConstant(-1);
StringBinaryToIntegerExpression index_of_colon = new StringBinaryToIntegerExpression(var1, Operator.INDEXOFC, colon_code, -1L);
StringBinaryToIntegerExpression index_of_numeral = new StringBinaryToIntegerExpression(var1, Operator.INDEXOFC, numeral_code, -1L);
/*
* Here we are trying to modify the string such that the first '#' comes
* before the first ':', and both are present
*/
IntegerConstraint constr1 = new IntegerConstraint(index_of_colon, Comparator.NE, minus_one);
IntegerConstraint constr2 = new IntegerConstraint(index_of_numeral, Comparator.NE, minus_one);
IntegerConstraint constr3 = new IntegerConstraint(index_of_numeral, Comparator.LT, index_of_colon);
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(constr1);
constraints.add(constr2);
constraints.add(constr3);
EvoSuiteSolver solver = new EvoSuiteSolver();
Map<String, Object> solution = null;
try {
/*
* The constraint is not trivial, as there are search plateaus. So
* it is ok if sometimes it fails (tried 10 times, failed 3).
*/
final int TRIES = 20;
for (int i = 0; i < TRIES; i++) {
solution = solve(solver, constraints);
if (solution != null) {
break;
}
}
assertNotNull(solution);
String result = solution.get("var0").toString();
int colonPos = result.indexOf(':');
int numeralPos = result.indexOf('#');
assertTrue("Colon not found in " + result, colonPos >= 0);
assertTrue("Numeral not found in " + result, numeralPos >= 0);
assertTrue(colonPos > numeralPos);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestIntegerSearch method testNEConstant.
@Test
public void testNEConstant() throws SolverEmptyQueryException {
// TODO: Currently, the model returned by the search is null if the
// constraint is already satisfied,
// so in this example the concrete value has to be the target initially
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new IntegerVariable("test1", 235082, -1000000, 1000000), Comparator.NE, new IntegerConstant(235082)));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
assertNotNull(model.get("test1"));
assertTrue(235082 != ((Number) model.get("test1")).intValue());
} catch (SolverTimeoutException e) {
fail();
}
}
Aggregations