Search in sources :

Example 1 with PrimitiveStatement

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);
    }
}
Also used : PrimitiveStatement(org.evosuite.testcase.PrimitiveStatement) VariableReference(org.evosuite.testcase.VariableReference)

Example 2 with PrimitiveStatement

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);
    }
}
Also used : ConstructorStatement(org.evosuite.testcase.ConstructorStatement) MethodStatement(org.evosuite.testcase.MethodStatement) PrimitiveStatement(org.evosuite.testcase.PrimitiveStatement) VariableReference(org.evosuite.testcase.VariableReference) GenericConstructor(org.evosuite.utils.GenericConstructor) GenericMethod(org.evosuite.utils.GenericMethod)

Aggregations

PrimitiveStatement (org.evosuite.testcase.PrimitiveStatement)2 VariableReference (org.evosuite.testcase.VariableReference)2 ConstructorStatement (org.evosuite.testcase.ConstructorStatement)1 MethodStatement (org.evosuite.testcase.MethodStatement)1 GenericConstructor (org.evosuite.utils.GenericConstructor)1 GenericMethod (org.evosuite.utils.GenericMethod)1