Search in sources :

Example 6 with StringValue

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

the class SymbolicHeap method getStaticField.

public StringValue getStaticField(String owner, String name, String conc_value) {
    FieldKey k = new FieldKey(owner, name);
    StringValue symb_value = (StringValue) symb_static_fields.get(k);
    if (symb_value == null || !((String) symb_value.getConcreteValue()).equals(conc_value)) {
        symb_value = ExpressionFactory.buildNewStringConstant(conc_value);
        symb_static_fields.remove(k);
    }
    return symb_value;
}
Also used : StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 7 with StringValue

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

the class Matcher_Matches method executeFunction.

@Override
public Object executeFunction() {
    Matcher conc_matcher = (Matcher) this.getConcReceiver();
    ReferenceConstant symb_matcher = (ReferenceConstant) this.getSymbReceiver();
    boolean res = this.getConcBooleanRetVal();
    String conc_regex = conc_matcher.pattern().pattern();
    StringValue symb_input = (StringValue) env.heap.getField(Types.JAVA_UTIL_REGEX_MATCHER, SymbolicHeap.$MATCHER_INPUT, conc_matcher, symb_matcher);
    if (symb_input != null && symb_input.containsSymbolicVariable()) {
        int concrete_value = res ? 1 : 0;
        StringConstant symb_regex = ExpressionFactory.buildNewStringConstant(conc_regex);
        StringBinaryComparison strComp = new StringBinaryComparison(symb_regex, Operator.PATTERNMATCHES, symb_input, (long) concrete_value);
        return strComp;
    } else {
        return this.getSymbIntegerRetVal();
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Matcher(java.util.regex.Matcher) StringBinaryComparison(org.evosuite.symbolic.expr.bv.StringBinaryComparison) StringValue(org.evosuite.symbolic.expr.str.StringValue) StringConstant(org.evosuite.symbolic.expr.str.StringConstant)

Example 8 with StringValue

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

the class Pattern_Matches method getSymbInput.

private StringValue getSymbInput(CharSequence input_char_seq, ReferenceExpression input_ref) {
    StringValue symb_input;
    if (input_ref instanceof ReferenceConstant) {
        ReferenceConstant input_str_ref = (ReferenceConstant) input_ref;
        assert input_char_seq != null;
        if (input_char_seq instanceof String) {
            String string = (String) input_char_seq;
            symb_input = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, string, input_str_ref, string);
        } else if (input_char_seq instanceof StringBuilder) {
            StringBuilder stringBuffer = (StringBuilder) input_char_seq;
            symb_input = env.heap.getField(Types.JAVA_LANG_STRING_BUILDER, SymbolicHeap.$STRING_BUILDER_CONTENTS, stringBuffer, input_str_ref, stringBuffer.toString());
        } else {
            symb_input = null;
        }
    } else {
        symb_input = null;
    }
    return symb_input;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 9 with StringValue

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

the class CompareToIgnoreCase method executeFunction.

@Override
public Object executeFunction() {
    String conc_left = (String) this.getConcReceiver();
    ReferenceConstant symb_left = this.getSymbReceiver();
    StringValue left_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_left, symb_left, conc_left);
    String conc_right = (String) this.getConcArgument(0);
    ReferenceConstant symb_right = (ReferenceConstant) this.getSymbArgument(0);
    StringValue right_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, conc_right, symb_right, conc_right);
    int res = this.getConcIntRetVal();
    if (left_expr.containsSymbolicVariable() || right_expr.containsSymbolicVariable()) {
        StringBinaryToIntegerExpression strBExpr = new StringBinaryToIntegerExpression(left_expr, Operator.COMPARETOIGNORECASE, right_expr, (long) res);
        return strBExpr;
    } else {
        return this.getSymbIntegerRetVal();
    }
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) StringBinaryToIntegerExpression(org.evosuite.symbolic.expr.bv.StringBinaryToIntegerExpression) StringValue(org.evosuite.symbolic.expr.str.StringValue)

Example 10 with StringValue

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

the class Pattern_Matcher method executeFunction.

@Override
public Object executeFunction() {
    // receiver
    @SuppressWarnings("unused") ReferenceConstant symb_receiver = this.getSymbReceiver();
    // argument
    CharSequence conc_char_seq = (CharSequence) this.getConcArgument(0);
    ReferenceExpression symb_char_seq = this.getSymbArgument(0);
    // return value
    Matcher conc_matcher = (Matcher) this.getConcRetVal();
    ReferenceConstant symb_matcher = (ReferenceConstant) this.getSymbRetVal();
    if (conc_char_seq != null && conc_char_seq instanceof String) {
        assert symb_char_seq instanceof ReferenceConstant;
        ReferenceConstant symb_string = (ReferenceConstant) symb_char_seq;
        String string = (String) conc_char_seq;
        StringValue symb_input = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, string, symb_string, string);
        env.heap.putField(Types.JAVA_UTIL_REGEX_MATCHER, SymbolicHeap.$MATCHER_INPUT, conc_matcher, symb_matcher, symb_input);
    }
    return symb_matcher;
}
Also used : ReferenceConstant(org.evosuite.symbolic.expr.ref.ReferenceConstant) Matcher(java.util.regex.Matcher) 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