use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class ConstructorStatement method execute.
// TODO: Handle inner classes (need instance parameter for newInstance)
/**
* {@inheritDoc}
*/
@Override
public Throwable execute(final Scope scope, PrintStream out) throws InvocationTargetException, IllegalArgumentException, InstantiationException, IllegalAccessException {
// PrintStream old_out = System.out;
// PrintStream old_err = System.err;
// System.setOut(out);
// System.setErr(out);
logger.trace("Executing constructor " + constructor.toString());
final Object[] inputs = new Object[parameters.size()];
Throwable exceptionThrown = null;
try {
return super.exceptionHandler(new Executer() {
@Override
public void execute() throws InvocationTargetException, IllegalArgumentException, IllegalAccessException, InstantiationException, CodeUnderTestException {
java.lang.reflect.Type[] parameterTypes = constructor.getParameterTypes();
for (int i = 0; i < parameters.size(); i++) {
VariableReference parameterVar = parameters.get(i);
try {
inputs[i] = parameterVar.getObject(scope);
} catch (CodeUnderTestException e) {
throw e;
// throw new CodeUnderTestException(e.getCause());
// throw CodeUnderTestException.throwException(e.getCause());
} catch (Throwable e) {
// FIXME: this does not seem to propagate to client root. Is this normal behavior?
logger.error("Class " + Properties.TARGET_CLASS + ". Error encountered: " + e);
assert (false);
throw new EvosuiteError(e);
}
if (inputs[i] != null && !TypeUtils.isAssignable(inputs[i].getClass(), parameterTypes[i])) {
// !parameterVar.isAssignableTo(parameterTypes[i])) {
throw new CodeUnderTestException(new UncompilableCodeException("Cannot assign " + parameterVar.getVariableClass().getName() + " to " + parameterTypes[i]));
}
if (inputs[i] == null && constructor.getConstructor().getParameterTypes()[i].isPrimitive()) {
throw new CodeUnderTestException(new NullPointerException());
}
}
// If this is a non-static member class, the first parameter must not be null
if (constructor.getConstructor().getDeclaringClass().isMemberClass() && !Modifier.isStatic(constructor.getConstructor().getDeclaringClass().getModifiers())) {
if (inputs[0] == null) {
// throw new NullPointerException();
throw new CodeUnderTestException(new NullPointerException());
}
}
Object ret = constructor.getConstructor().newInstance(inputs);
try {
// assert(retval.getVariableClass().isAssignableFrom(ret.getClass())) :"we want an " + retval.getVariableClass() + " but got an " + ret.getClass();
retval.setObject(scope, ret);
} catch (CodeUnderTestException e) {
throw e;
// throw CodeUnderTestException.throwException(e);
} catch (Throwable e) {
throw new EvosuiteError(e);
}
}
@Override
public Set<Class<? extends Throwable>> throwableExceptions() {
Set<Class<? extends Throwable>> t = new LinkedHashSet<Class<? extends Throwable>>();
t.add(InvocationTargetException.class);
return t;
}
});
} catch (InvocationTargetException e) {
VM.disableCallBacks();
exceptionThrown = e.getCause();
if (logger.isDebugEnabled()) {
try {
logger.debug("Exception thrown in constructor: " + e.getCause());
}// this can happen if SUT throws exception on toString
catch (Exception ex) {
logger.debug("Exception thrown in constructor and SUT gives issue when calling e.getCause()", ex);
}
}
}
return exceptionThrown;
}
use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class SymbolicObserver method pushDummyValue.
private void pushDummyValue(Type argType) {
if (isBv32(argType)) {
IntegerValue integerExpr = ExpressionFactory.buildNewIntegerConstant(0);
env.topFrame().operandStack.pushBv32(integerExpr);
} else if (isBv64(argType)) {
IntegerValue integerExpr = ExpressionFactory.buildNewIntegerConstant(0);
env.topFrame().operandStack.pushBv64(integerExpr);
} else if (isFp32(argType)) {
RealValue realExpr = ExpressionFactory.buildNewRealConstant(0);
env.topFrame().operandStack.pushFp32(realExpr);
} else if (isFp64(argType)) {
RealValue realExpr = ExpressionFactory.buildNewRealConstant(0);
env.topFrame().operandStack.pushFp64(realExpr);
} else {
throw new EvosuiteError(argType.toString() + " is not a value type!");
}
}
use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(BytePrimitiveStatement statement, Scope scope) {
byte valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Byte.MIN_VALUE, Byte.MAX_VALUE);
symb_expressions.put(varRefName, integerVariable);
Byte byte_instance;
try {
byte_instance = (Byte) varRef.getObject(scope);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
ReferenceConstant byteRef = newByteReference(byte_instance, integerVariable);
symb_references.put(varRefName, byteRef);
}
use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class SymbolicObserver method pushValue.
private void pushValue(Type argType, Expression<?> symb_expr) {
if (isBv32(argType)) {
IntegerValue booleanExpr = (IntegerValue) symb_expr;
env.topFrame().operandStack.pushBv32(booleanExpr);
} else if (isBv64(argType)) {
IntegerValue longExpr = (IntegerValue) symb_expr;
env.topFrame().operandStack.pushBv64(longExpr);
} else if (isFp32(argType)) {
RealValue realExpr = (RealValue) symb_expr;
env.topFrame().operandStack.pushFp32(realExpr);
} else if (isFp64(argType)) {
RealValue realExpr = (RealValue) symb_expr;
env.topFrame().operandStack.pushFp64(realExpr);
} else {
throw new EvosuiteError(argType.toString() + " is not a value type!");
}
}
use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(LongPrimitiveStatement statement, Scope scope) {
long valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
IntegerVariable integerVariable = buildIntegerVariable(varRefName, valueOf, Long.MIN_VALUE, Long.MAX_VALUE);
symb_expressions.put(varRefName, integerVariable);
Long long_instance;
try {
long_instance = (Long) varRef.getObject(scope);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
ReferenceConstant longRef = newLongReference(long_instance, integerVariable);
symb_references.put(varRefName, longRef);
}
Aggregations