use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class SymbolicObserver method writeArray.
private void writeArray(ArrayIndex lhs, ReferenceExpressionPair readResult, Scope scope) {
ArrayReference arrayReference = lhs.getArray();
int conc_index = lhs.getArrayIndex();
Object conc_array;
try {
conc_array = arrayReference.getObject(scope);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
Type arrayType = Type.getType(conc_array.getClass());
Type elementType = arrayType.getElementType();
if (isValue(elementType) || elementType.equals(Type.getType(String.class))) {
Expression<?> symb_value = readResult.getExpression();
symb_value = castIfNeeded(elementType, symb_value);
String array_name = arrayReference.getName();
ReferenceExpression symb_ref = symb_references.get(array_name);
ReferenceConstant symb_array = (ReferenceConstant) symb_ref;
env.heap.array_store(conc_array, symb_array, conc_index, symb_value);
} else {
/* ignore storing references (we use objects to find them) */
}
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant in project evosuite by EvoSuite.
the class BigInteger_DivideAndRemainder method executeFunction.
@Override
public Object executeFunction() {
BigInteger conc_left_big_integer = (BigInteger) this.getConcReceiver();
ReferenceConstant symb_left_big_integer = this.getSymbReceiver();
BigInteger conc_right_big_integer = (BigInteger) this.getConcArgument(0);
ReferenceConstant symb_right_big_integer = (ReferenceConstant) this.getSymbArgument(0);
Object res = this.getConcRetVal();
ReferenceExpression symb_res = this.getSymbRetVal();
if (res != null && conc_left_big_integer != null && conc_right_big_integer != null) {
IntegerValue left_big_integer_expr = this.env.heap.getField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, conc_left_big_integer, symb_left_big_integer, conc_left_big_integer.longValue());
IntegerValue right_big_integer_expr = this.env.heap.getField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, conc_right_big_integer, symb_right_big_integer, conc_right_big_integer.longValue());
if (left_big_integer_expr.containsSymbolicVariable() || right_big_integer_expr.containsSymbolicVariable()) {
// quotient
BigInteger conc_quotient = (BigInteger) Array.get(res, QUOTIENT_ARRAY_INDEX);
ReferenceConstant symb_quotient = (ReferenceConstant) this.env.heap.getReference(conc_quotient);
IntegerValue symb_div_value = ExpressionFactory.div(left_big_integer_expr, right_big_integer_expr, conc_quotient.longValue());
this.env.heap.putField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, conc_quotient, symb_quotient, symb_div_value);
// remainder
BigInteger conc_remainder = (BigInteger) Array.get(res, REMAINDER_ARRAY_INDEX);
ReferenceConstant symb_remainder = (ReferenceConstant) this.env.heap.getReference(conc_remainder);
IntegerValue symb_rem_value = ExpressionFactory.rem(left_big_integer_expr, right_big_integer_expr, conc_remainder.longValue());
this.env.heap.putField(Types.JAVA_MATH_BIG_INTEGER, SymbolicHeap.$BIG_INTEGER_CONTENTS, conc_remainder, symb_remainder, symb_rem_value);
}
}
return symb_res;
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant 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();
}
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant 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;
}
use of org.evosuite.symbolic.expr.ref.ReferenceConstant 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();
}
}
Aggregations