use of org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression in project evosuite by EvoSuite.
the class Length method executeFunction.
@Override
public Object executeFunction() {
ReferenceConstant symb_str = this.getSymbReceiver();
String conc_str = (String) this.getConcReceiver();
int res = this.getConcIntRetVal();
StringValue string_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_str, symb_str, conc_str);
if (string_expr.containsSymbolicVariable()) {
StringUnaryToIntegerExpression strUnExpr = new StringUnaryToIntegerExpression(string_expr, Operator.LENGTH, (long) res);
return strUnExpr;
}
return this.getSymbIntegerRetVal();
}
use of org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression in project evosuite by EvoSuite.
the class TestIsInteger method testIsInteger.
@Test
public void testIsInteger() throws SolverEmptyQueryException {
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(new StringUnaryToIntegerExpression(new StringVariable("var0", "hello"), Operator.IS_INTEGER, 0L), Comparator.NE, new IntegerConstant(0)));
EvoSuiteSolver solver = new EvoSuiteSolver();
try {
SolverResult result = solver.solve(constraints);
assertTrue(result.isSAT());
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression in project evosuite by EvoSuite.
the class DistanceCalculator method getDistanceStringIsInteger.
private static long getDistanceStringIsInteger(IntegerConstraint n, long leftVal, long rightVal) {
if (n.getLeftOperand() instanceof StringUnaryToIntegerExpression && n.getComparator() == Comparator.NE && n.getRightOperand() instanceof IntegerConstant) {
IntegerConstant right_constant = (IntegerConstant) n.getRightOperand();
StringUnaryToIntegerExpression left_string_expr = (StringUnaryToIntegerExpression) n.getLeftOperand();
if (right_constant.getConcreteValue().longValue() != 0L) {
return -1;
}
if (left_string_expr.getOperator() != Operator.IS_INTEGER) {
return -1;
}
String string = left_string_expr.getOperand().getConcreteValue();
if (string.length() > 0) {
char[] charArray = string.toCharArray();
int maxDistance = 0;
for (int i = 0; i < charArray.length; i++) {
char c = charArray[i];
int distance;
if (!Character.isDigit(c)) {
if (c < '0') {
distance = '0' - c;
} else if (c > '9') {
distance = c - '9';
} else {
throw new RuntimeException("This branch is unreachable!");
}
if (maxDistance < distance) {
maxDistance = distance;
}
}
}
return maxDistance;
} else {
return Long.MAX_VALUE;
}
}
return -1;
}
use of org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression 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;
}
use of org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression in project evosuite by EvoSuite.
the class TestConstraintSolver1 method buildConstraintSystem.
private static Collection<Constraint<?>> buildConstraintSystem() {
StringVariable var0 = new StringVariable("var0", INIT_STRING);
StringUnaryToIntegerExpression length = new StringUnaryToIntegerExpression(var0, Operator.LENGTH, (long) INIT_STRING.length());
IntegerConstant const3 = new IntegerConstant(3);
StringBinaryToIntegerExpression charAt3 = new StringBinaryToIntegerExpression(var0, Operator.CHARAT, const3, (long) INIT_STRING.charAt(3));
IntegerConstant const4 = new IntegerConstant(4);
StringBinaryToIntegerExpression charAt4 = new StringBinaryToIntegerExpression(var0, Operator.CHARAT, const4, (long) INIT_STRING.charAt(4));
IntegerConstant const5 = new IntegerConstant(INIT_STRING.length());
IntegerConstant const95 = new IntegerConstant(EXPECTED_STRING.charAt(3));
IntegerConstant const43 = new IntegerConstant(EXPECTED_STRING.charAt(4));
IntegerConstraint constr1 = new IntegerConstraint(length, Comparator.EQ, const5);
IntegerConstraint constr2 = new IntegerConstraint(charAt3, Comparator.EQ, const95);
IntegerConstraint constr3 = new IntegerConstraint(charAt4, Comparator.EQ, const43);
return Arrays.<Constraint<?>>asList(constr1, constr2, constr3);
}
Aggregations