use of org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression in project evosuite by EvoSuite.
the class CompareToIgnoreCase method executeFunction.
@Override
public Object executeFunction() {
String conc_left = (String) this.getConcReceiver();
ReferenceConstant symb_left = this.getSymbReceiver();
StringValue left_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_left, symb_left, conc_left);
String conc_right = (String) this.getConcArgument(0);
ReferenceConstant symb_right = (ReferenceConstant) this.getSymbArgument(0);
StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right, symb_right, conc_right);
int res = this.getConcIntRetVal();
if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
StringBinaryToIntegerExpression strBExpr = new StringBinaryToIntegerExpression(left_expr, Operator.COMPARETOIGNORECASE, right_expr, (long) res);
return strBExpr;
} else {
return this.getSymbIntegerRetVal();
}
}
use of org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression in project evosuite by EvoSuite.
the class CompareTo method executeFunction.
@Override
public Object executeFunction() {
String conc_left = (String) this.getConcReceiver();
ReferenceConstant symb_left = this.getSymbReceiver();
StringValue left_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_left, symb_left, conc_left);
String conc_right = (String) this.getConcArgument(0);
ReferenceConstant symb_right = (ReferenceConstant) this.getSymbArgument(0);
StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right, symb_right, conc_right);
int res = this.getConcIntRetVal();
if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
StringBinaryToIntegerExpression strBExpr = new StringBinaryToIntegerExpression(left_expr, Operator.COMPARETO, right_expr, (long) res);
return strBExpr;
} else {
return this.getSymbIntegerRetVal();
}
}
use of org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression in project evosuite by EvoSuite.
the class TestIntegerSearch method testEvosuiteExample5.
@Test
public void testEvosuiteExample5() throws SolverEmptyQueryException {
// TestSuiteDSE.setStart();
// Cnstr 0 : var6__SYM(84) != (y charAt 0) dist: 8.0
// Cnstr 1 : var6__SYM(84) != 115 dist: 8.0
// Cnstr 2 : var6__SYM(84) == 108 dist: 8.0
int var1 = 84;
int const1 = 115;
int const2 = 108;
String const3 = "y";
IntegerConstant iconst1 = new IntegerConstant(const1);
IntegerConstant iconst2 = new IntegerConstant(const2);
StringConstant strConst = new StringConstant(const3);
IntegerVariable ivar1 = new IntegerVariable("test1", var1, Integer.MIN_VALUE, Integer.MAX_VALUE);
StringBinaryToIntegerExpression sBExpr = new StringBinaryToIntegerExpression(strConst, Operator.CHARAT, new IntegerConstant(0), (long) "y".charAt(0));
List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
constraints.add(new IntegerConstraint(ivar1, Comparator.NE, sBExpr));
constraints.add(new IntegerConstraint(ivar1, Comparator.NE, iconst1));
constraints.add(new IntegerConstraint(ivar1, Comparator.EQ, iconst2));
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult solverResult = solver.solve(constraints);
assertTrue(solverResult.isSAT());
Map<String, Object> model = solverResult.getModel();
var1 = ((Number) model.get("test1")).intValue();
assertTrue(var1 == 108);
} catch (SolverTimeoutException e) {
fail();
}
}
use of org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression 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.bv.StringBinaryToIntegerExpression 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();
}
}
Aggregations