use of org.evosuite.testcase.execution.CodeUnderTestException in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(BooleanPrimitiveStatement statement, Scope scope) {
boolean valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf ? 1 : 0, 0, 1);
Boolean boolean_instance;
try {
boolean_instance = (Boolean) varRef.getObject(scope);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
symb_expressions.put(varRefName, integerVariable);
ReferenceConstant booleanRef = newBooleanReference(boolean_instance, integerVariable);
symb_references.put(varRefName, booleanRef);
}
use of org.evosuite.testcase.execution.CodeUnderTestException in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(DoublePrimitiveStatement statement, Scope scope) {
double valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
RealVariable realVariable = buildRealVariable(varRefName, valueOf, -Double.MAX_VALUE, Double.MAX_VALUE);
symb_expressions.put(varRefName, realVariable);
Double double_instance;
try {
double_instance = (Double) varRef.getObject(scope);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
ReferenceConstant doubleRef = newDoubleReference(double_instance, realVariable);
symb_references.put(varRefName, doubleRef);
}
use of org.evosuite.testcase.execution.CodeUnderTestException in project evosuite by EvoSuite.
the class SymbolicObserver method writeField.
private void writeField(FieldReference lhs, ReferenceExpressionPair readResult, Scope scope) {
Field field = lhs.getField().getField();
String className = field.getDeclaringClass().getName().replace('.', '/');
String fieldName = field.getName();
Class<?> fieldClass = field.getType();
Type fieldType = Type.getType(fieldClass);
if (isValue(fieldType) || fieldType.equals(Type.getType(String.class))) {
Expression<?> symb_value = readResult.getExpression();
symb_value = castIfNeeded(fieldType, symb_value);
VariableReference source = lhs.getSource();
if (source != null) {
/* write symbolic expression to instance field */
String source_name = source.getName();
Object conc_receiver;
try {
conc_receiver = source.getObject(scope);
} catch (CodeUnderTestException e) {
throw new RuntimeException(e);
}
ReferenceConstant symb_receiver = (ReferenceConstant) symb_references.get(source_name);
env.heap.putField(className, fieldName, conc_receiver, symb_receiver, symb_value);
} else {
/* write symbolic expression to static field */
env.heap.putStaticField(className, fieldName, symb_value);
}
} else {
/*
* ignore writing of references (DSE does not store Reference
* fields)
*/
}
}
use of org.evosuite.testcase.execution.CodeUnderTestException in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(ShortPrimitiveStatement statement, Scope scope) {
short valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Short.MIN_VALUE, Short.MAX_VALUE);
symb_expressions.put(varRefName, integerVariable);
Short short_instance;
try {
short_instance = (Short) varRef.getObject(scope);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
ReferenceConstant shortRef = newShortReference(short_instance, integerVariable);
symb_references.put(varRefName, shortRef);
}
use of org.evosuite.testcase.execution.CodeUnderTestException 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);
}
}
Aggregations