use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestStringSearch method testRegionMatchesICFalseConstant.
@Test
public void testRegionMatchesICFalseConstant() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
String var1 = "foTESTo";
String const2 = "rtestooo";
boolean ignore_case = true;
int offset1 = 2;
int offset2 = 1;
int len = 4;
StringVariable strVar = new StringVariable("test1", var1);
StringConstant strConst = new StringConstant(const2);
IntegerConstant len_expr = new IntegerConstant(len);
IntegerConstant offs_two = new IntegerConstant(offset2);
IntegerConstant offs_one = new IntegerConstant(offset1);
IntegerConstant ign_case = new IntegerConstant(ignore_case ? 1 : 0);
ArrayList<Expression<?>> other = new ArrayList<Expression<?>>();
other.add(offs_one);
other.add(offs_two);
other.add(len_expr);
other.add(ign_case);
StringMultipleComparison strComp = new StringMultipleComparison(strVar, Operator.REGIONMATCHES, 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()).regionMatches(ignore_case, offset1, const2, offset2, len));
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestStringSearch method testRegexMatchesFalse.
@Test
public void testRegexMatchesFalse() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
String var1 = "testsomestring";
String const2 = "testsomestring";
StringVariable strVar = new StringVariable("test1", var1);
StringConstant strConst = new StringConstant(const2);
StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.PATTERNMATCHES, 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 should not match TEST: " + result.get("test1").toString(), result.get("test1").toString().matches(const2));
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestStringSearch method testStartsWithTrueConstant.
@Test
public void testStartsWithTrueConstant() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
String var1 = "foo";
String const2 = "test";
StringVariable strVar = new StringVariable("test1", var1);
StringConstant strConst = new StringConstant(const2);
IntegerConstant offs_expr = new IntegerConstant(2);
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.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()).startsWith(const2, 2));
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestConstraintSolver1 method test.
@Test
public void test() throws SolverEmptyQueryException {
// 5000000000000L; TODO - ??
Properties.LOCAL_SEARCH_BUDGET = 100;
Properties.LOCAL_SEARCH_BUDGET_TYPE = LocalSearchBudgetType.FITNESS_EVALUATIONS;
Collection<Constraint<?>> constraints = buildConstraintSystem();
System.out.println("Constraints:");
for (Constraint<?> c : constraints) {
System.out.println(c.toString());
}
EvoSuiteSolver seeker = new EvoSuiteSolver();
try {
SolverResult solverResult = seeker.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
System.out.println(model);
Object var0 = model.get("var0");
System.out.println("Expected: " + EXPECTED_STRING);
System.out.println("Found: " + var0);
assertEquals(EXPECTED_STRING, var0);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestConstraintSolver3 method test.
@Test
public void test() throws SolverEmptyQueryException {
// 5000000000000L; TODO - ??
Properties.LOCAL_SEARCH_BUDGET = 100;
Properties.LOCAL_SEARCH_BUDGET_TYPE = LocalSearchBudgetType.FITNESS_EVALUATIONS;
Collection<Constraint<?>> constraints = buildConstraintSystem();
System.out.println("Constraints:");
for (Constraint<?> c : constraints) {
System.out.println(c.toString());
}
System.out.println("");
System.out.println("Initial: " + INIT_STRING);
EvoSuiteSolver solver = new EvoSuiteSolver();
try {
SolverResult result = solver.solve(constraints);
if (result.isUNSAT()) {
fail("search was unsuccessfull");
} else {
Map<String, Object> model = result.getModel();
Object var0 = model.get("var0");
System.out.println("Expected: " + EXPECTED_INTEGER);
System.out.println("Found: " + var0);
assertEquals(String.valueOf(EXPECTED_INTEGER), var0);
}
} catch (SolverTimeoutException e) {
fail();
}
}
Aggregations