use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(FunctionalMockStatement statement, Scope scope) {
Type returnType = Type.getType(statement.getReturnClass());
VariableReference varRef = statement.getReturnValue();
String varName = varRef.getName();
try {
if (varRef.getType().equals(void.class)) {
} else if (returnType.equals(Type.INT_TYPE) || returnType.equals(Type.BOOLEAN_TYPE) || returnType.equals(Type.DOUBLE_TYPE) || returnType.equals(Type.FLOAT_TYPE) || returnType.equals(Type.LONG_TYPE) || returnType.equals(Type.SHORT_TYPE) || returnType.equals(Type.BYTE_TYPE) || returnType.equals(Type.CHAR_TYPE)) {
throw new EvosuiteError("mocking of primitive types is not supported!");
} else {
Object res = varRef.getObject(scope);
ReferenceExpression ref = env.heap.getReference(res);
if (res != null && res instanceof String) {
String string = (String) res;
ReferenceConstant newStringRef = (ReferenceConstant) env.heap.getReference(string);
StringValue str_expr = env.heap.getField(Types.JAVA_LANG_STRING, SymbolicHeap.$STRING_VALUE, string, newStringRef, string);
symb_references.put(varName, newStringRef);
symb_expressions.put(varName, str_expr);
} else {
symb_references.put(varName, ref);
if (res != null && isWrapper(res)) {
ReferenceConstant nonNullRef = (ReferenceConstant) ref;
Expression<?> expr = findOrCreate(res, nonNullRef);
symb_expressions.put(varName, expr);
}
}
}
} catch (CodeUnderTestException e) {
throw new RuntimeException(e);
}
}
use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(StringPrimitiveStatement statement, Scope scope) {
String valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
StringVariable stringVariable = buildStringVariable(varRefName, valueOf);
symb_expressions.put(varRefName, stringVariable);
String string_instance;
try {
String string_interned = (String) varRef.getObject(scope);
string_instance = new String(string_interned);
scope.setObject(varRef, string_instance);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
ReferenceConstant stringRef = newStringReference(string_instance, stringVariable);
symb_references.put(varRefName, stringRef);
}
use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class SymbolicObserver method findOrCreate.
private Expression<?> findOrCreate(Object conc_ref, ReferenceConstant symb_ref) {
if (conc_ref instanceof Boolean) {
Boolean boolean0 = (Boolean) conc_ref;
int conc_val = boolean0.booleanValue() ? 1 : 0;
return env.heap.getField(Types.JAVA_LANG_BOOLEAN, SymbolicHeap.$BOOLEAN_VALUE, boolean0, symb_ref, conc_val);
} else if (conc_ref instanceof Byte) {
Byte byte0 = (Byte) conc_ref;
byte conc_val = byte0.byteValue();
return env.heap.getField(Types.JAVA_LANG_BYTE, SymbolicHeap.$BYTE_VALUE, byte0, symb_ref, conc_val);
} else if (conc_ref instanceof Short) {
Short short0 = (Short) conc_ref;
short conc_val = short0.shortValue();
return env.heap.getField(Types.JAVA_LANG_SHORT, SymbolicHeap.$SHORT_VALUE, short0, symb_ref, conc_val);
} else if (conc_ref instanceof Character) {
Character character0 = (Character) conc_ref;
char conc_val = character0.charValue();
return env.heap.getField(Types.JAVA_LANG_CHARACTER, SymbolicHeap.$CHAR_VALUE, character0, symb_ref, conc_val);
} else if (conc_ref instanceof Integer) {
Integer integer0 = (Integer) conc_ref;
int conc_val = integer0.intValue();
return env.heap.getField(Types.JAVA_LANG_INTEGER, SymbolicHeap.$INT_VALUE, integer0, symb_ref, conc_val);
} else if (conc_ref instanceof Long) {
Long long0 = (Long) conc_ref;
long conc_val = long0.longValue();
return env.heap.getField(Types.JAVA_LANG_LONG, SymbolicHeap.$LONG_VALUE, long0, symb_ref, conc_val);
} else if (conc_ref instanceof Float) {
Float float0 = (Float) conc_ref;
float conc_val = float0.floatValue();
return env.heap.getField(Types.JAVA_LANG_FLOAT, SymbolicHeap.$FLOAT_VALUE, float0, symb_ref, conc_val);
} else if (conc_ref instanceof Double) {
Double double0 = (Double) conc_ref;
double conc_val = double0.doubleValue();
return env.heap.getField(Types.JAVA_LANG_FLOAT, SymbolicHeap.$DOUBLE_VALUE, double0, symb_ref, conc_val);
} else {
throw new EvosuiteError("Unreachable code!");
}
}
use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(IntPrimitiveStatement statement, Scope scope) {
int valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Integer.MIN_VALUE, Integer.MAX_VALUE);
symb_expressions.put(varRefName, integerVariable);
Integer integer_instance;
try {
integer_instance = (Integer) varRef.getObject(scope);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
ReferenceConstant integerRef = newIntegerReference(integer_instance, integerVariable);
symb_references.put(varRefName, integerRef);
}
use of org.evosuite.testcase.execution.EvosuiteError 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) */
}
}
Aggregations