Search in sources :

Example 31 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant 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 32 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class StringBuffer_SetLength method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_str_buffer = this.getSymbReceiver();
    StringBuffer conc_str_buffer = (StringBuffer) this.getConcReceiver();
    IntegerValue newSymbLength = this.getSymbIntegerArgument(0);
    int newConcLength = this.getConcIntArgument(0);
    // retrieve symbolic value from heap
    String conc_value = conc_str_buffer.toString();
    StringValue symb_value = env.heap.getField(Types.JAVA_LANG_STRING_BUFFER, SymbolicHeap.$STRING_BUFFER_CONTENTS, conc_str_buffer, symb_str_buffer, pre_conc_value);
    if (symb_value.containsSymbolicVariable() || newSymbLength.containsSymbolicVariable()) {
        StringValue new_symb_value = null;
        if (!newSymbLength.containsSymbolicVariable() && newConcLength == 0) {
            // StringBuffer contents equals to "" string
            new_symb_value = new StringConstant("");
        } else {
            // StringBuffer contents equ
            new_symb_value = new StringMultipleExpression(symb_value, Operator.SUBSTRING, new IntegerConstant(0), new ArrayList<Expression<?>>(Collections.singletonList(newSymbLength)), conc_value);
        }
        env.heap.putField(Types.JAVA_LANG_STRING_BUFFER, SymbolicHeap.$STRING_BUFFER_CONTENTS, conc_str_buffer, symb_str_buffer, new_symb_value);
    }
    // return void
    return null;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringMultipleExpression(org.evosuite.symbolic.expr.str.StringMultipleExpression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ArrayList(java.util.ArrayList) StringValue(org.evosuite.symbolic.expr.str.StringValue) StringConstant(org.evosuite.symbolic.expr.str.StringConstant) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) IntegerConstant(org.evosuite.symbolic.expr.bv.IntegerConstant)

Example 33 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class BigInteger_IntValue method executeFunction.

@Override
public Object executeFunction() {
    BigInteger conc_big_integer = (BigInteger) this.getConcReceiver();
    ReferenceConstant symb_big_integer = this.getSymbReceiver();
    int res = this.getConcIntRetVal();
    IntegerValue integer_expr = this.env.heap.getField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, conc_big_integer, symb_big_integer, res);
    return integer_expr;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) BigInteger(java.math.BigInteger)

Example 34 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class Length method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_str = this.getSymbReceiver();
    String conc_str = (String) this.getConcReceiver();
    int res = this.getConcIntRetVal();
    StringValue string_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_str, symb_str, conc_str);
    if (string_expr.containsSymbolicVariable()) {
        StringUnaryToIntegerExpression strUnExpr = new StringUnaryToIntegerExpression(string_expr, Operator.LENGTH, (long) res);
        return strUnExpr;
    }
    return this.getSymbIntegerRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringUnaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringUnaryToIntegerExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 35 with ReferenceConstant

use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.

the class RegionMatches method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_receiver = (ReferenceConstant) this.getSymbReceiver();
    String conc_receiver = (String) this.getConcReceiver();
    StringValue stringReceiverExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_receiver, conc_receiver);
    IntegerValue ignoreCaseExpr = this.getSymbIntegerArgument(0);
    IntegerValue toffsetExpr = this.getSymbIntegerArgument(1);
    ReferenceConstant symb_other = (ReferenceConstant) this.getSymbArgument(2);
    String conc_other = (String) this.getConcArgument(2);
    StringValue otherExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_other, symb_other, conc_other);
    IntegerValue ooffsetExpr = this.getSymbIntegerArgument(3);
    IntegerValue lenExpr = this.getSymbIntegerArgument(4);
    boolean res = this.getConcBooleanRetVal();
    if (stringReceiverExpr.containsSymbolicVariable() || ignoreCaseExpr.containsSymbolicVariable() || toffsetExpr.containsSymbolicVariable() || otherExpr.containsSymbolicVariable() || ooffsetExpr.containsSymbolicVariable() || lenExpr.containsSymbolicVariable()) {
        ArrayList<Expression<?>> other = new ArrayList<Expression<?>>();
        other.add(toffsetExpr);
        other.add(ooffsetExpr);
        other.add(lenExpr);
        other.add(ignoreCaseExpr);
        int conV = res ? 1 : 0;
        StringMultipleComparison strComp = new StringMultipleComparison(stringReceiverExpr, Operator.REGIONMATCHES, otherExpr, other, (long) conV);
        return strComp;
    }
    return this.getSymbIntegerRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringMultipleComparison(org.evosuite.symbolic.expr.bv.StringMultipleComparison) Expression(org.evosuite.symbolic.expr.Expression) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue) ArrayList(java.util.ArrayList) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Aggregations

ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)99 StringValue (org.evosuite.symbolic.expr.str.StringValue)39 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)32 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)18 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)16 VariableReference (org.evosuite.testcase.variable.VariableReference)14 Type (org.objectweb.asm.Type)12 RealValue (org.evosuite.symbolic.expr.fp.RealValue)11 EvosuiteError (org.evosuite.testcase.execution.EvosuiteError)11 Expression (org.evosuite.symbolic.expr.Expression)9 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)8 IntegerVariable (org.evosuite.symbolic.expr.bv.IntegerVariable)6 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)5 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)4 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)3 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)3 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)3 StringReaderExpr (org.evosuite.symbolic.expr.reader.StringReaderExpr)3