use of org.evosuite.symbolic.expr.str.StringConstant in project evosuite by EvoSuite.
the class Matcher_Matches method executeFunction.
@Override
public Object executeFunction() {
Matcher conc_matcher = (Matcher) this.getConcReceiver();
ReferenceConstant symb_matcher = (ReferenceConstant) this.getSymbReceiver();
boolean res = this.getConcBooleanRetVal();
String conc_regex = conc_matcher.pattern().pattern();
StringValue symb_input = (StringValue) env.heap.getField(Types.JAVA_UTIL_REGEX_MATCHER, SymbolicHeap.$MATCHER_INPUT, conc_matcher, symb_matcher);
if (symb_input != null && symb_input.containsSymbolicVariable()) {
int concrete_value = res ? 1 : 0;
StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(conc_regex);
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.str.StringConstant in project evosuite by EvoSuite.
the class StringBuffer_SetLength method executeFunction.
@Override
public Object executeFunction() {
ReferenceConstant symb_str_buffer = this.getSymbReceiver();
StringBuffer conc_str_buffer = (StringBuffer) this.getConcReceiver();
IntegerValue newSymbLength = this.getSymbIntegerArgument(0);
int newConcLength = this.getConcIntArgument(0);
// retrieve symbolic value from heap
String conc_value = conc_str_buffer.toString();
StringValue symb_value = env.heap.getField(Types.JAVA_LANG_STRING_BUFFER, SymbolicHeap.$STRING_BUFFER_CONTENTS, conc_str_buffer, symb_str_buffer, pre_conc_value);
if (symb_value.containsSymbolicVariable() || newSymbLength.containsSymbolicVariable()) {
StringValue new_symb_value = null;
if (!newSymbLength.containsSymbolicVariable() && newConcLength == 0) {
// StringBuffer contents equals to "" string
new_symb_value = new StringConstant("");
} else {
// StringBuffer contents equ
new_symb_value = new StringMultipleExpression(symb_value, Operator.SUBSTRING, new IntegerConstant(0), new ArrayList<Expression<?>>(Collections.singletonList(newSymbLength)), conc_value);
}
env.heap.putField(Types.JAVA_LANG_STRING_BUFFER, SymbolicHeap.$STRING_BUFFER_CONTENTS, conc_str_buffer, symb_str_buffer, new_symb_value);
}
// return void
return null;
}
use of org.evosuite.symbolic.expr.str.StringConstant in project evosuite by EvoSuite.
the class Matches method executeFunction.
@Override
public Object executeFunction() {
// receiver
ReferenceConstant symb_receiver = this.getSymbReceiver();
String conc_receiver = (String) this.getConcReceiver();
// argument
String conc_argument = (String) this.getConcArgument(0);
StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_receiver, conc_receiver);
// return val
boolean res = this.getConcBooleanRetVal();
if (right_expr.containsSymbolicVariable()) {
StringConstant left_expr = ExpressionFactory.buildNewStringConstant(conc_argument);
int conV = res ? 1 : 0;
StringBinaryComparison strBExpr = new StringBinaryComparison(left_expr, Operator.PATTERNMATCHES, right_expr, (long) conV);
return strBExpr;
}
return this.getSymbIntegerRetVal();
}
use of org.evosuite.symbolic.expr.str.StringConstant 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.str.StringConstant in project evosuite by EvoSuite.
the class TestPatternSearch method testMatcherMatches.
@Test
public void testMatcherMatches() throws SolverEmptyQueryException {
String input = "random_value";
String format = "(\\d+)-(\\d\\d)-(\\d)";
// String format = "^(\\d+)-(\\d\\d)-(\\d)$";
StringVariable var0 = new StringVariable("var0", input);
StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(format);
StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, var0, 0L);
StringConstraint constraint = new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0));
List<Constraint<?>> constraints = Collections.<Constraint<?>>singletonList(constraint);
try {
EvoSuiteSolver solver = new EvoSuiteSolver();
SolverResult result = solver.solve(constraints);
assertTrue(result.isSAT());
Map<String, Object> model = result.getModel();
String var0_value = (String) model.get("var0");
Pattern pattern = Pattern.compile(format);
Matcher matcher = pattern.matcher(var0_value);
assertTrue(matcher.matches());
} catch (SolverTimeoutException e) {
fail();
}
}
Aggregations