use of org.evosuite.testcase.PrimitiveStatement in project evosuite by EvoSuite.
the class TestCaseCodeGenerator method createPlainInitStmt.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void createPlainInitStmt(final int logRecNo, final TestCase testCase) {
// NOTE: PLAIN INIT: has always one non-null param
// TODO: use primitives
final int oid = this.log.objectIds.get(logRecNo);
if (this.oidToVarRefMap.containsKey(oid)) {
// TODO this might happen because of Integer.valueOf(), for example. . Is this approach ok?
return;
}
final String type = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
final Object value = this.log.params.get(logRecNo)[0];
if (// Class is a plain type according to log
value instanceof Class) {
// FIXME this code needs to get working
// try
// {
// final VariableReference varRef = new VariableReferenceImpl(testCase, Class.class);
// final VariableReference valueRef = new VariableReferenceImpl(testCase, getClassForName(type));
//
// final AssignmentStatement assign = new AssignmentStatement(testCase, varRef, valueRef);
// this.oidToVarRefMap.put(oid, testCase.addStatement(assign));
// }
// catch(final Exception e)
// {
// throw new RuntimeException(e);
// }
} else {
final PrimitiveStatement primitiveValue = PrimitiveStatement.getPrimitiveStatement(testCase, getClassForName(type));
primitiveValue.setValue(value);
final VariableReference varRef = testCase.addStatement(primitiveValue);
this.oidToVarRefMap.put(oid, varRef);
}
}
use of org.evosuite.testcase.PrimitiveStatement in project evosuite by EvoSuite.
the class TestCaseCodeGenerator method createUnobservedInitStmt.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void createUnobservedInitStmt(final int logRecNo, final TestCase testCase) {
// NOTE: PLAIN INIT: has always one non-null param
// TODO: use primitives
final int oid = this.log.objectIds.get(logRecNo);
final String type = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
try {
// Class.forName("com.thoughtworks.xstream.XStream", true, StaticTestCluster.classLoader);
final Class<?> xStreamType = getClassForName("com.thoughtworks.xstream.XStream");
// Class.forName(type, true, StaticTestCluster.classLoader);
final Class<?> typeClass = getClassForName(type);
final Object value = this.log.params.get(logRecNo)[0];
if (xStreamRef == null) {
final ConstructorStatement constr = new ConstructorStatement(testCase, new GenericConstructor(xStreamType.getConstructor(new Class<?>[0]), xStreamType), Collections.EMPTY_LIST);
xStreamRef = testCase.addStatement(constr);
}
// Class.forName("java.lang.String", true, StaticTestCluster.classLoader);
final Class<?> stringType = getClassForName("java.lang.String");
final PrimitiveStatement stringRep = PrimitiveStatement.getPrimitiveStatement(testCase, stringType);
stringRep.setValue(value);
final VariableReference stringRepRef = testCase.addStatement(stringRep);
final MethodStatement m = new MethodStatement(testCase, new GenericMethod(xStreamType.getMethod("fromXML", stringType), typeClass), xStreamRef, Arrays.asList(stringRepRef));
this.oidToVarRefMap.put(oid, testCase.addStatement(m));
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
Aggregations