use of org.evosuite.symbolic.expr.str.StringVariable in project evosuite by EvoSuite.
the class SymbolicObserver method buildStringVariable.
private StringVariable buildStringVariable(String name, String concVal) {
StringVariable stringVariable;
if (stringVariables.containsKey(name)) {
stringVariable = stringVariables.get(name);
stringVariable.setConcreteValue(concVal);
} else {
stringVariable = new StringVariable(name, concVal);
stringVariables.put(name, stringVariable);
}
return stringVariable;
}
use of org.evosuite.symbolic.expr.str.StringVariable in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(StringPrimitiveStatement statement, Scope scope) {
String valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
StringVariable stringVariable = buildStringVariable(varRefName, valueOf);
symb_expressions.put(varRefName, stringVariable);
String string_instance;
try {
String string_interned = (String) varRef.getObject(scope);
string_instance = new String(string_interned);
scope.setObject(varRef, string_instance);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
ReferenceConstant stringRef = newStringReference(string_instance, stringVariable);
symb_references.put(varRefName, stringRef);
}
use of org.evosuite.symbolic.expr.str.StringVariable in project evosuite by EvoSuite.
the class StringAVMTests method testSimpleRegexThreeDigits.
@Test
public void testSimpleRegexThreeDigits() throws SolverTimeoutException {
String name = "foo";
StringVariable var = new StringVariable(name, "");
String format = "\\d\\d\\d";
List<Constraint<?>> constraints = getPatternConstraint(var, format);
long start_time = System.currentTimeMillis();
long timeout = Properties.DSE_CONSTRAINT_SOLVER_TIMEOUT_MILLIS;
StringAVM avm = new StringAVM(var, constraints, start_time, timeout);
boolean succeded = avm.applyAVM();
assertTrue(succeded);
String result = var.getConcreteValue();
Integer value = Integer.parseInt(result);
assertTrue("Value=" + result, value >= 0 && value <= 999);
}
use of org.evosuite.symbolic.expr.str.StringVariable 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();
}
}
use of org.evosuite.symbolic.expr.str.StringVariable in project evosuite by EvoSuite.
the class TestConstraintSolver3 method buildConstraintSystem.
private static Collection<Constraint<?>> buildConstraintSystem() {
StringVariable var0 = new StringVariable("var0", INIT_STRING);
StringToIntegerCast castStr = new StringToIntegerCast(var0, (long) Integer.parseInt(INIT_STRING));
IntegerConstant const126 = new IntegerConstant(EXPECTED_INTEGER);
IntegerConstraint constr1 = new IntegerConstraint(castStr, Comparator.EQ, const126);
return Arrays.<Constraint<?>>asList(constr1);
}
Aggregations