use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestStringSearch method testInsertIndexOfC.
@Test
public void testInsertIndexOfC() {
String var1value = "D<E\u001Exqaasaksajij1§n";
StringVariable var1 = new StringVariable("var1", var1value);
IntegerConstant colon_code = new IntegerConstant(58);
IntegerConstant minus_one = new IntegerConstant(-1);
int colon_int_code = (int) ':';
int concrete_value = var1value.indexOf(colon_int_code);
StringBinaryToIntegerExpression index_of_colon = new StringBinaryToIntegerExpression(var1, Operator.INDEXOFC, colon_code, (long) concrete_value);
IntegerConstraint constr1 = new IntegerConstraint(index_of_colon, Comparator.NE, minus_one);
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(constr1);
EvoSuiteSolver solver = new EvoSuiteSolver();
Map<String, Object> solution;
try {
solution = solve(solver, constraints);
assertNotNull(solution);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestStringSearch method testEndsWithTrueConstant.
@Test
public void testEndsWithTrueConstant() {
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.ENDSWITH, 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((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 testInversionOfRegex.
@Test
public void testInversionOfRegex() {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
String var = "a+";
String regex = "aaa";
// so we need to solve it
assertFalse(var.matches(regex));
String variableName = "test1";
StringVariable strVar = new StringVariable(variableName, var);
StringConstant strConst = new StringConstant(regex);
StringBinaryComparison strComp = new StringBinaryComparison(strConst, Operator.PATTERNMATCHES, strVar, 0L);
// the constraint should evaluate to true
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(variableName));
String solution = result.get(variableName).toString();
assertTrue(solution.matches(regex));
/*
* as the regex defines only one possible matching string, then the
* solution has to be equal to the regex
*/
assertEquals(regex, solution);
} catch (SolverTimeoutException e) {
fail();
}
// now let's invert them
strVar = new StringVariable(variableName, regex);
strConst = new StringConstant(var);
// the inversion should match immediately
assertTrue(regex.matches(var));
// recreate the same type of constraint
strComp = new StringBinaryComparison(strConst, Operator.PATTERNMATCHES, strVar, 0L);
constraints.clear();
constraints.add(new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0)));
try {
result = solve(skr, constraints);
assertNotNull(result);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.solver.avm.EvoSuiteSolver in project evosuite by EvoSuite.
the class TestStringSearch method testEqualsFalseConstant.
@Test
public void testEqualsFalseConstant() {
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.EQUALS, 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"));
assertTrue(!const2.equals(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 testContainsTrueConstant.
@Test
public void testContainsTrueConstant() {
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.CONTAINS, 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((result.get("test1").toString()).contains(const2));
} catch (SolverTimeoutException e) {
fail();
}
}
Aggregations