Search in sources :

Example 1 with StringUnaryExpression

use of org.evosuite.symbolic.expr.str.StringUnaryExpression in project evosuite by EvoSuite.

the class ToUpperCase method executeFunction.

@Override
public Object executeFunction() {
    // object receiver
    ReferenceConstant symb_str = this.getSymbReceiver();
    String conc_str = (String) this.getConcReceiver();
    // return value
    String conc_ret_val = (String) this.getConcRetVal();
    ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
    StringValue string_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_str, symb_str, conc_str);
    StringUnaryExpression symb_value = new StringUnaryExpression(string_expr, Operator.TOUPPERCASE, conc_ret_val);
    env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, symb_ret_val, symb_value);
    return this.getSymbRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 2 with StringUnaryExpression

use of org.evosuite.symbolic.expr.str.StringUnaryExpression in project evosuite by EvoSuite.

the class ToLowerCase method executeFunction.

@Override
public Object executeFunction() {
    // object receiver
    ReferenceConstant symb_str = this.getSymbReceiver();
    String conc_str = (String) this.getConcReceiver();
    // return value
    String conc_ret_val = (String) this.getConcRetVal();
    ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
    StringValue string_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_str, symb_str, conc_str);
    StringUnaryExpression symb_value = new StringUnaryExpression(string_expr, Operator.TOLOWERCASE, conc_ret_val);
    env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, symb_ret_val, symb_value);
    return this.getSymbRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 3 with StringUnaryExpression

use of org.evosuite.symbolic.expr.str.StringUnaryExpression in project evosuite by EvoSuite.

the class Trim method executeFunction.

@Override
public Object executeFunction() {
    // object receiver
    ReferenceConstant symb_str = this.getSymbReceiver();
    String conc_str = (String) this.getConcReceiver();
    // return value
    String conc_ret_val = (String) this.getConcRetVal();
    ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
    StringValue string_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_str, symb_str, conc_str);
    StringUnaryExpression symb_value = new StringUnaryExpression(string_expr, Operator.TRIM, conc_ret_val);
    env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, symb_ret_val, symb_value);
    return this.getSymbRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 4 with StringUnaryExpression

use of org.evosuite.symbolic.expr.str.StringUnaryExpression in project evosuite by EvoSuite.

the class TestStringSearch method testEqualsToLowerCase.

@Test
public void testEqualsToLowerCase() {
    // (wed equals var1("f|").toLowerCase()) != 0
    StringVariable var1 = new StringVariable("var1", "f|");
    StringBinaryComparison cmp3 = new StringBinaryComparison(new StringConstant("wed"), Operator.EQUALS, new StringUnaryExpression(var1, Operator.TOLOWERCASE, "f|".toLowerCase()), 0L);
    StringConstraint constr3 = new StringConstraint(cmp3, Comparator.NE, new IntegerConstant(0));
    Collection<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(constr3);
    EvoSuiteSolver solver = new EvoSuiteSolver();
    Map<String, Object> solution;
    try {
        solution = solve(solver, constraints);
        assertNotNull(solution);
    } 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) StringUnaryExpression(org.evosuite.symbolic.expr.str.StringUnaryExpression) 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)

Aggregations

StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)4 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)3 StringValue (org.evosuite.symbolic.expr.str.StringValue)3 ArrayList (java.util.ArrayList)1 Constraint (org.evosuite.symbolic.expr.Constraint)1 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)1 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)1 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)1 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)1 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)1 StringVariable (org.evosuite.symbolic.expr.str.StringVariable)1 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)1 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)1 Test (org.junit.Test)1