Search in sources :

Example 16 with StringBinaryComparison

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();
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 17 with StringBinaryComparison

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();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 18 with StringBinaryComparison

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();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 19 with StringBinaryComparison

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

Example 20 with StringBinaryComparison

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

Aggregations

StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)26 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)20 Constraint (org.evosuite.symbolic.expr.Constraint)17 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)17 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)17 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)16 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)14 Test (org.junit.Test)14 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)13 ArrayList (java.util.ArrayList)12 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)12 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)8 StringValue (org.evosuite.symbolic.expr.str.StringValue)8 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)1 Pattern (org.apache.oro.text.regex.Pattern)1 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)1 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)1 HasMoreTokensExpr (org.evosuite.symbolic.expr.token.HasMoreTokensExpr)1