Search in sources :

Example 46 with ReferenceConstant

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

the class StringReader_Read method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_str_reader = this.getSymbReceiver();
    StringReader conc_str_reader = (StringReader) this.getConcReceiver();
    StringReaderExpr stringReaderExpr = (StringReaderExpr) env.heap.getField(Types.JAVA_IO_STRING_READER, SymbolicHeap.$STRING_READER_VALUE, conc_str_reader, symb_str_reader);
    if (stringReaderExpr != null && stringReaderExpr.containsSymbolicVariable()) {
        StringValue symb_string = stringReaderExpr.getString();
        String conc_string = symb_string.getConcreteValue();
        int currPosition = stringReaderExpr.getReaderPosition();
        if (currPosition < conc_string.length()) {
            // update symbolic string reader
            currPosition++;
            int conc_string_reader_value;
            if (currPosition >= conc_string.length()) {
                conc_string_reader_value = -1;
            } else {
                conc_string_reader_value = conc_string.charAt(currPosition);
            }
            StringReaderExpr newStringReaderExpr = new StringReaderExpr((long) conc_string_reader_value, symb_string, currPosition);
            env.heap.putField(Types.JAVA_IO_STRING_READER, SymbolicHeap.$STRING_READER_VALUE, conc_str_reader, symb_str_reader, newStringReaderExpr);
        }
        // returns STRING_READER(string,currPosition)
        return stringReaderExpr;
    }
    return this.getSymbIntegerRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringReaderExpr(org.evosuite.symbolic.expr.reader.StringReaderExpr) StringReader(java.io.StringReader) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 47 with ReferenceConstant

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

the class NextToken method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_receiver = this.getSymbReceiver();
    StringTokenizer conc_receiver = (StringTokenizer) this.getConcReceiver();
    TokenizerExpr tokenizerExpr = (TokenizerExpr) env.heap.getField(Types.JAVA_UTIL_STRING_TOKENIZER, SymbolicHeap.$STRING_TOKENIZER_VALUE, conc_receiver, symb_receiver);
    if (tokenizerExpr != null && tokenizerExpr.containsSymbolicVariable()) {
        ReferenceConstant symb_ret_val = (ReferenceConstant) this.getSymbRetVal();
        String conc_ret_val = (String) this.getConcRetVal();
        // create new NEXT_TOKEN string expression
        StringNextTokenExpr string_next_token_expr = new StringNextTokenExpr(tokenizerExpr, conc_ret_val);
        env.heap.putField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_ret_val, symb_ret_val, string_next_token_expr);
        // update StringTokenizer's symbolic state
        NextTokenizerExpr nextTokenizerExpr = new NextTokenizerExpr(tokenizerExpr);
        env.heap.putField(Types.JAVA_UTIL_STRING_TOKENIZER, SymbolicHeap.$STRING_TOKENIZER_VALUE, conc_receiver, symb_receiver, nextTokenizerExpr);
    }
    return this.getSymbRetVal();
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) NextTokenizerExpr(org.evosuite.symbolic.expr.token.NextTokenizerExpr) StringTokenizer(java.util.StringTokenizer) StringNextTokenExpr(org.evosuite.symbolic.expr.token.StringNextTokenExpr) NextTokenizerExpr(org.evosuite.symbolic.expr.token.NextTokenizerExpr) TokenizerExpr(org.evosuite.symbolic.expr.token.TokenizerExpr)

Example 48 with ReferenceConstant

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

the class B_ByteValue method executeFunction.

@Override
public Object executeFunction() {
    ReferenceConstant symb_byte = this.getSymbReceiver();
    Byte conc_byte = (Byte) this.getConcReceiver();
    int conc_byte_value = this.getConcByteRetVal();
    IntegerValue symb_byte_value = env.heap.getField(Types.JAVA_LANG_BYTE, SymbolicHeap.$BYTE_VALUE, conc_byte, symb_byte, conc_byte_value);
    return symb_byte_value;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

Example 49 with ReferenceConstant

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

the class StringReader_Init method executeFunction.

@Override
public Object executeFunction() {
    // symbolic receiver (new object)
    ReferenceConstant symb_str_reader = (ReferenceConstant) this.getSymbReceiver();
    // string argument
    String conc_str = (String) this.getConcArgument(0);
    ReferenceExpression symb_str = this.getSymbArgument(0);
    if (symb_str 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);
        if (strExpr.containsSymbolicVariable()) {
            int conc_string_reader_value;
            if (conc_str.length() == 0) {
                conc_string_reader_value = -1;
            } else {
                conc_string_reader_value = conc_str.charAt(0);
            }
            StringReaderExpr newStringReaderExpr = new StringReaderExpr((long) conc_string_reader_value, strExpr);
            // update symbolic heap
            env.heap.putField(Types.JAVA_IO_STRING_READER, SymbolicHeap.$STRING_READER_VALUE, null, symb_str_reader, newStringReaderExpr);
        }
    }
    // constructor returns void
    return null;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringReaderExpr(org.evosuite.symbolic.expr.reader.StringReaderExpr) ReferenceExpression(org.evosuite.symbolic.expr.ref.ReferenceExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 50 with ReferenceConstant

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

the class C_ValueOf method executeFunction.

@Override
public Object executeFunction() {
    IntegerValue int_value = this.getSymbIntegerArgument(0);
    ReferenceConstant symb_character = (ReferenceConstant) this.getSymbRetVal();
    Character conc_character = (Character) this.getConcRetVal();
    env.heap.putField(Types.JAVA_LANG_CHARACTER, SymbolicHeap.$CHAR_VALUE, conc_character, symb_character, int_value);
    return symb_character;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) IntegerValue(org.evosuite.symbolic.expr.bv.IntegerValue)

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