Search in sources :

Example 31 with StringValue

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

the class BigInteger_Ctor method executeFunction.

@Override
public Object executeFunction() {
    String conc_string = (String) this.getConcArgument(0);
    ReferenceConstant str_ref = (ReferenceConstant) this.getSymbArgument(0);
    StringValue symb_string = this.env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_string, str_ref, conc_string);
    if (symb_string.containsSymbolicVariable()) {
        ReferenceConstant symb_big_integer = (ReferenceConstant) env.topFrame().operandStack.peekRef();
        BigInteger bigInteger = new BigInteger(conc_string);
        long concVal = bigInteger.longValue();
        StringToIntegerCast big_integer_value = new StringToIntegerCast(symb_string, concVal);
        env.heap.putField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, null, /* conc_big_integer */
        symb_big_integer, big_integer_value);
    }
    // return void
    return null;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringToIntegerCast(org.evosuite.symbolic.expr.bv.StringToIntegerCast) BigInteger(java.math.BigInteger) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 32 with StringValue

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

the class StringBuffer_ToString method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_str_buffer = this.getSymbReceiver();
    StringBuffer conc_str_buffer = (StringBuffer) this.getConcReceiver();
    // 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, conc_value);
    String conc_ret_val = (String) this.getConcRetVal();
    ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
    env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, symb_ret_val, symb_value);
    // return symbolic value
    return symb_ret_val;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 33 with StringValue

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

the class StringBuilder_Append method executeFunction.

@Override
public final Object executeFunction() {
    // string builder
    StringBuilder conc_str_builder = (StringBuilder) this.getConcReceiver();
    ReferenceConstant symb_str_builder = (ReferenceConstant) this.getSymbReceiver();
    // return value
    StringBuilder res = (StringBuilder) this.getConcRetVal();
    ReferenceConstant symb_res = (ReferenceConstant) this.getSymbRetVal();
    StringValue leftExpr = this.env.heap.getField(Types.JAVA_LANG_STRING_BUILDER, SymbolicHeap.$STRING_BUILDER_CONTENTS, conc_str_builder, symb_str_builder, conc_str_builder_to_string_pre);
    // append string expression
    StringValue newStrExpr = appendExpression(leftExpr, res);
    // store to symbolic heap
    env.heap.putField(Types.JAVA_LANG_STRING_BUILDER, SymbolicHeap.$STRING_BUILDER_CONTENTS, conc_str_builder, symb_res, newStrExpr);
    return symb_res;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 34 with StringValue

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

the class StringBuilder_ToString method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_str_builder = (ReferenceConstant) this.getSymbReceiver();
    // receiver
    StringBuilder conc_str_builder = (StringBuilder) this.getConcReceiver();
    // return value
    String res = (String) this.getConcRetVal();
    if (res != null) {
        ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
        StringValue symb_value = env.heap.getField(Types.JAVA_LANG_STRING_BUILDER, SymbolicHeap.$STRING_BUILDER_CONTENTS, conc_str_builder, symb_str_builder, conc_str_builder.toString());
        String conc_receiver = (String) res;
        env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_receiver, symb_ret_val, symb_value);
    }
    return this.getSymbRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 35 with StringValue

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

the class StringTokenizer_Init method executeFunction.

@Override
public Object executeFunction() {
    // symbolic receiver (new object)
    ReferenceConstant symb_str_tokenizer = (ReferenceConstant) this.getSymbReceiver();
    // string argument
    String conc_str = (String) this.getConcArgument(0);
    ReferenceExpression symb_str = this.getSymbArgument(0);
    // delim argument
    String conc_delim = (String) this.getConcArgument(1);
    ReferenceExpression symb_delim = this.getSymbArgument(1);
    if (symb_str instanceof ReferenceConstant && symb_delim instanceof ReferenceConstant) {
        ReferenceConstant non_null_symb_string = (ReferenceConstant) symb_str;
        assert conc_str != null;
        StringValue strExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_str, non_null_symb_string, conc_str);
        ReferenceConstant non_null_symb_delim = (ReferenceConstant) symb_delim;
        assert conc_delim != null;
        StringValue delimExpr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_delim, non_null_symb_delim, conc_delim);
        NewTokenizerExpr newTokenizerExpr = new NewTokenizerExpr(strExpr, delimExpr);
        // update symbolic heap
        env.heap.putField(Types.JAVA_UTIL_STRING_TOKENIZER, SymbolicHeap.$STRING_TOKENIZER_VALUE, null, symb_str_tokenizer, newTokenizerExpr);
    }
    // constructor returns void
    return null;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) NewTokenizerExpr(org.evosuite.symbolic.expr.token.NewTokenizerExpr) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Aggregations

StringValue (org.evosuite.symbolic.expr.str.StringValue)45 ReferenceConstant (org.evosuite.symbolic.expr.ref.ReferenceConstant)39 ReferenceExpression (org.evosuite.symbolic.expr.ref.ReferenceExpression)16 Expression (org.evosuite.symbolic.expr.Expression)10 IntegerValue (org.evosuite.symbolic.expr.bv.IntegerValue)8 StringBinaryComparison (org.evosuite.symbolic.expr.bv.StringBinaryComparison)8 RealValue (org.evosuite.symbolic.expr.fp.RealValue)4 StringConstant (org.evosuite.symbolic.expr.str.StringConstant)4 CodeUnderTestException (org.evosuite.testcase.execution.CodeUnderTestException)4 PrimitiveExpression (org.evosuite.testcase.statements.PrimitiveExpression)4 ArrayList (java.util.ArrayList)3 StringBinaryToIntegerExpression (org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression)3 StringReaderExpr (org.evosuite.symbolic.expr.reader.StringReaderExpr)3 StringMultipleExpression (org.evosuite.symbolic.expr.str.StringMultipleExpression)3 StringUnaryExpression (org.evosuite.symbolic.expr.str.StringUnaryExpression)3 StringReader (java.io.StringReader)2 Matcher (java.util.regex.Matcher)2 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)2 IntegerConstant (org.evosuite.symbolic.expr.bv.IntegerConstant)2 StringMultipleComparison (org.evosuite.symbolic.expr.bv.StringMultipleComparison)2