use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class TestSuiteGenerator method buildLoadTargetClassTestCase.
/**
* Creates a single Test Case that only loads the target class.
* <code>
* Thread currentThread = Thread.currentThread();
* ClassLoader classLoader = currentThread.getClassLoader();
* classLoader.load(className);
* </code>
* @param className the class to be loaded
* @return
* @throws EvosuiteError if a reflection error happens while creating the test case
*/
private static DefaultTestCase buildLoadTargetClassTestCase(String className) throws EvosuiteError {
DefaultTestCase test = new DefaultTestCase();
StringPrimitiveStatement stmt0 = new StringPrimitiveStatement(test, className);
VariableReference string0 = test.addStatement(stmt0);
try {
Method currentThreadMethod = Thread.class.getMethod("currentThread");
Statement currentThreadStmt = new MethodStatement(test, new GenericMethod(currentThreadMethod, currentThreadMethod.getDeclaringClass()), null, Collections.emptyList());
VariableReference currentThreadVar = test.addStatement(currentThreadStmt);
Method getContextClassLoaderMethod = Thread.class.getMethod("getContextClassLoader");
Statement getContextClassLoaderStmt = new MethodStatement(test, new GenericMethod(getContextClassLoaderMethod, getContextClassLoaderMethod.getDeclaringClass()), currentThreadVar, Collections.emptyList());
VariableReference contextClassLoaderVar = test.addStatement(getContextClassLoaderStmt);
// Method loadClassMethod = ClassLoader.class.getMethod("loadClass", String.class);
// Statement loadClassStmt = new MethodStatement(test,
// new GenericMethod(loadClassMethod, loadClassMethod.getDeclaringClass()), contextClassLoaderVar,
// Collections.singletonList(string0));
// test.addStatement(loadClassStmt);
BooleanPrimitiveStatement stmt1 = new BooleanPrimitiveStatement(test, true);
VariableReference boolean0 = test.addStatement(stmt1);
Method forNameMethod = Class.class.getMethod("forName", String.class, boolean.class, ClassLoader.class);
Statement forNameStmt = new MethodStatement(test, new GenericMethod(forNameMethod, forNameMethod.getDeclaringClass()), null, Arrays.<VariableReference>asList(string0, boolean0, contextClassLoaderVar));
test.addStatement(forNameStmt);
return test;
} catch (NoSuchMethodException | SecurityException e) {
throw new EvosuiteError("Unexpected exception while creating Class Initializer Test Case");
}
}
use of org.evosuite.testcase.execution.EvosuiteError in project evosuite by EvoSuite.
the class SymbolicObserver method after.
private void after(FloatPrimitiveStatement statement, Scope scope) {
float valueOf = statement.getValue();
VariableReference varRef = statement.getReturnValue();
String varRefName = varRef.getName();
RealVariable realVariable = buildRealVariable(varRefName, valueOf, -Float.MAX_VALUE, Float.MAX_VALUE);
symb_expressions.put(varRefName, realVariable);
Float float_instance;
try {
float_instance = (Float) varRef.getObject(scope);
} catch (CodeUnderTestException e) {
throw new EvosuiteError(e);
}
ReferenceConstant floatRef = newFloatReference(float_instance, realVariable);
symb_references.put(varRefName, floatRef);
}
use of org.evosuite.testcase.execution.EvosuiteError 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.EvosuiteError 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.EvosuiteError 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);
}
Aggregations