use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.
the class TestStringSearch method testIndexOfC.
@Test
public void testIndexOfC() {
String var1value = "D<E\u001E";
StringVariable var1 = new StringVariable("var1", var1value);
IntegerConstant colon_code = new IntegerConstant(35);
IntegerConstant numeral_code = new IntegerConstant(58);
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);
IntegerConstraint constr1 = new IntegerConstraint(index_of_colon, Comparator.EQ, minus_one);
IntegerConstraint constr2 = new IntegerConstraint(index_of_numeral, Comparator.NE, minus_one);
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(constr1);
constraints.add(constr2);
EvoSuiteSolver solver = new EvoSuiteSolver();
Map<String, Object> solution;
try {
solution = solve(solver, constraints);
assertNotNull(solution);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.IntegerConstraint 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.expr.IntegerConstraint 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.expr.IntegerConstraint in project evosuite by EvoSuite.
the class ArithmeticVM method zeroViolation.
private boolean zeroViolation(IntegerValue value, long valueConcrete) {
IntegerConstant zero = ExpressionFactory.ICONST_0;
IntegerConstraint zeroCheck;
if (valueConcrete == 0)
zeroCheck = ConstraintFactory.eq(value, zero);
else
zeroCheck = ConstraintFactory.neq(value, zero);
if (zeroCheck.getLeftOperand().containsSymbolicVariable() || zeroCheck.getRightOperand().containsSymbolicVariable())
pathConstraint.addSupportingConstraint(zeroCheck);
if (valueConcrete == 0) {
// JVM will throw an exception
return true;
}
return false;
}
use of org.evosuite.symbolic.expr.IntegerConstraint in project evosuite by EvoSuite.
the class ConstraintNormalizer method normalizeIntegerConstriant.
private static Constraint<?> normalizeIntegerConstriant(IntegerConstraint c) {
if (c.getLeftOperand() instanceof IntegerComparison) {
IntegerComparison cmp = (IntegerComparison) c.getLeftOperand();
int value = ((Number) c.getRightOperand().getConcreteValue()).intValue();
Comparator op = c.getComparator();
Expression<Long> cmp_left = cmp.getLeftOperant();
Expression<Long> cmp_right = cmp.getRightOperant();
return createIntegerConstraint(cmp_left, op, cmp_right, value);
} else {
assert (c.getRightOperand() instanceof IntegerComparison);
IntegerComparison cmp = (IntegerComparison) c.getRightOperand();
int value = ((Number) c.getLeftOperand().getConcreteValue()).intValue();
Comparator op = c.getComparator();
Expression<Long> cmp_left = cmp.getLeftOperant();
Expression<Long> cmp_right = cmp.getRightOperant();
Comparator swap_op = op.swap();
int swap_value = -value;
return createIntegerConstraint(cmp_left, swap_op, cmp_right, swap_value);
}
}
Aggregations