Search in sources :

Example 1 with StringVariable

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;
}
Also used : StringVariable(org.evosuite.symbolic.expr.str.StringVariable)

Example 2 with 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);
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) VariableReference(org.evosuite.testcase.variable.VariableReference) EvosuiteError(org.evosuite.testcase.execution.EvosuiteError) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) CodeUnderTestException(org.evosuite.testcase.execution.CodeUnderTestException)

Example 3 with StringVariable

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);
}
Also used : StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) StringAVM(org.evosuite.symbolic.solver.avm.StringAVM) Test(org.junit.Test)

Example 4 with StringVariable

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();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) Pattern(java.util.regex.Pattern) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) Matcher(java.util.regex.Matcher) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) SolverResult(org.evosuite.symbolic.solver.SolverResult) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) Test(org.junit.Test)

Example 5 with StringVariable

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);
}
Also used : IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) StringToIntegerCast(org.evosuite.symbolic.expr.bv.StringToIntegerCast) StringVariable(org.evosuite.symbolic.expr.str.StringVariable) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Aggregations

StringVariable (org.evosuite.symbolic.expr.str.StringVariable)39 Constraint (org.evosuite.symbolic.expr.Constraint)34 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)29 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)28 Test (org.junit.Test)28 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)25 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)24 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)24 ArrayList (java.util.ArrayList)22 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)20 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)16 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)10 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)5 Expression (org.evosuite.symbolic.expr.Expression)4 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)4 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)4 StringUnaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression)4 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)4 StringAVM (org.evosuite.symbolic.solver.avm.StringAVM)4 SolverResult (org.evosuite.symbolic.solver.SolverResult)3