Search in sources :

Example 11 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.

the class TestStringSearch method testEqualsFalseConstant.

@Test
public void testEqualsFalseConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "foo";
    String const2 = "foo";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.EQUALS, strConst, 0L);
    constraints.add(new StringConstraint(strComp, Comparator.EQ, new IntegerConstant(0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        assertNotNull(result.get("test1"));
        assertTrue(!const2.equals(result.get("test1").toString()));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) 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 12 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.

the class TestStringSearch method testContainsTrueConstant.

@Test
public void testContainsTrueConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "foo";
    String const2 = "test";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.CONTAINS, strConst, 0L);
    constraints.add(new StringConstraint(strComp, Comparator.NE, new IntegerConstant(0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        assertNotNull(result.get("test1"));
        assertTrue((result.get("test1").toString()).contains(const2));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) 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 13 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.

the class TestStringSearch method testEqualsIgnoreCaseFalseConstant.

@Test
public void testEqualsIgnoreCaseFalseConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "foo";
    String const2 = "FOO";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.EQUALSIGNORECASE, strConst, 0L);
    constraints.add(new StringConstraint(strComp, Comparator.EQ, new IntegerConstant(0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        assertNotNull(result.get("test1"));
        assertFalse(const2.equalsIgnoreCase(result.get("test1").toString()));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) 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 14 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.

the class TestStringSearch method testEndsWithFalseConstant.

@Test
public void testEndsWithFalseConstant() {
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    String var1 = "footest";
    String const2 = "test";
    StringVariable strVar = new StringVariable("test1", var1);
    StringConstant strConst = new StringConstant(const2);
    StringBinaryComparison strComp = new StringBinaryComparison(strVar, Operator.ENDSWITH, strConst, 0L);
    constraints.add(new StringConstraint(strComp, Comparator.EQ, new IntegerConstant(0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        assertNotNull(result.get("test1"));
        assertFalse((result.get("test1").toString()).endsWith(const2));
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) Constraint(org.evosuite.symbolic.expr.Constraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) 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 15 with StringBinaryComparison

use of org.evosuite.symbolic.expr.bv.StringBinaryComparison in project evosuite by EvoSuite.

the class Perl5Matcher_Matches method executeFunction.

@Override
public Object executeFunction() {
    // Perl5Matcher conc_matcher = (Perl5Matcher) this.getConcReceiver();
    // NonNullReference symb_matcher = (NonNullReference) this
    // .getSymbReceiver();
    boolean res = this.getConcBooleanRetVal();
    ReferenceConstant symb_string_ref = (ReferenceConstant) this.getSymbArgument(0);
    // Reference symb_pattern_ref = this.getSymbArgument(1);
    String conc_string = (String) this.getConcArgument(0);
    Pattern conc_pattern = (Pattern) this.getConcArgument(1);
    StringValue symb_string_value = env.heap.getField(org.evosuite.symbolic.vm.regex.Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_string, symb_string_ref, conc_string);
    if (symb_string_value != null && symb_string_value.containsSymbolicVariable()) {
        int concrete_value = res ? 1 : 0;
        String pattern_str = conc_pattern.getPattern();
        StringConstant symb_pattern_value = ExpressionFactory.buildNewStringConstant(pattern_str);
        StringBinaryComparison strComp = new StringBinaryComparison(symb_pattern_value, Operator.APACHE_ORO_PATTERN_MATCHES, symb_string_value, (long) concrete_value);
        return strComp;
    } else {
        return this.getSymbIntegerRetVal();
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Pattern(org.apache.oro.text.regex.Pattern) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue) StringConstant(org.evosuite.symbolic.expr.str.StringConstant)

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