use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class Pattern_Matches method executeFunction.
@Override
public Object executeFunction() {
// argument 0
String regex_str = (String) this.getConcArgument(0);
ReferenceConstant regex_ref = (ReferenceConstant) this.getSymbArgument(0);
// argument 1
CharSequence input_char_seq = (CharSequence) this.getConcArgument(1);
ReferenceExpression input_ref = this.getSymbArgument(1);
// return value
boolean res = this.getConcBooleanRetVal();
// symbolic execution
StringValue symb_regex = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, regex_str, regex_ref, regex_str);
StringValue symb_input = getSymbInput(input_char_seq, input_ref);
if (symb_input != null && symb_input.containsSymbolicVariable()) {
int concrete_value = res ? 1 : 0;
StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, symb_input, (long) concrete_value);
return strComp;
} else {
return this.getSymbIntegerRetVal();
}
}
use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class Contains 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);
CharSequence conc_right = (CharSequence) this.getConcArgument(0);
ReferenceConstant symb_right = (ReferenceConstant) this.getSymbArgument(0);
if (conc_right instanceof String) {
String conc_right_str = (String) conc_right;
StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right_str, symb_right, conc_right_str);
boolean res = this.getConcBooleanRetVal();
if (right_expr != null) {
if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
int concrete_value = res ? 1 : 0;
StringBinaryComparison strComp = new StringBinaryComparison(left_expr, Operator.CONTAINS, right_expr, (long) concrete_value);
return strComp;
}
}
}
return this.getSymbIntegerRetVal();
}
use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class Equals method executeFunction.
@Override
public Object executeFunction() {
String conc_left = (String) this.getConcReceiver();
ReferenceConstant symb_left = this.getSymbReceiver();
Object conc_right = this.getConcArgument(0);
ReferenceExpression symb_right = this.getSymbArgument(0);
boolean res = this.getConcBooleanRetVal();
StringValue left_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_left, symb_left, conc_left);
if (symb_right instanceof ReferenceConstant && conc_right instanceof String) {
ReferenceConstant non_null_symb_right = (ReferenceConstant) symb_right;
String conc_right_str = (String) conc_right;
StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right_str, non_null_symb_right, conc_right_str);
if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
int conV = res ? 1 : 0;
StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.EQUALS, right_expr, (long) conV);
return strBExpr;
}
}
return this.getSymbIntegerRetVal();
}
use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class TestStringEqualsIgnoreCase method testStringEqualsIgnoreCase.
@Test
public void testStringEqualsIgnoreCase() throws SecurityException, NoSuchMethodException, SolverTimeoutException {
IntegerConstant zero = new IntegerConstant(0);
StringVariable stringVar0 = new StringVariable("var0", "");
StringConstant strConst = new StringConstant("bar");
StringBinaryComparison cmp1 = new StringBinaryComparison(stringVar0, Operator.EQUALS, strConst, 0L);
StringConstraint constr1 = new StringConstraint(cmp1, Comparator.EQ, zero);
StringBinaryComparison cmp2 = new StringBinaryComparison(stringVar0, Operator.EQUALSIGNORECASE, strConst, 1L);
StringConstraint constr2 = new StringConstraint(cmp2, Comparator.NE, zero);
Collection<Constraint<?>> constraints = Arrays.<Constraint<?>>asList(constr1, constr2);
EvoSuiteSolver solver = new EvoSuiteSolver();
Map<String, Object> solution = solve(solver, constraints);
assertNotNull(solution);
String var0 = (String) solution.get("var0");
assertNotNull(var0);
assertTrue(!var0.equals("bar"));
assertTrue(var0.equalsIgnoreCase("bar"));
}
use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.
the class StringAVMTests method getPatternConstraint.
private List<Constraint<?>> getPatternConstraint(StringVariable var, String format) {
StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(format);
StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, var, 0L);
StringConstraint constraint = new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0));
List<Constraint<?>> constraints = Collections.<Constraint<?>>singletonList(constraint);
return constraints;
}
Aggregations