Search in sources :

Example 96 with GenericMethod

use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.

the class EvoTestCaseCodeGenerator method createUnobservedInitStmt.

@SuppressWarnings({ "rawtypes" })
@Override
public void createUnobservedInitStmt(CaptureLog log, int logRecNo) {
    // NOTE: PLAIN INIT: has always one non-null param
    // TODO: use primitives
    final int oid = log.objectIds.get(logRecNo);
    try {
        final Object value = log.params.get(logRecNo)[0];
        final PrimitiveStatement stringRep = new ImmutableStringPrimitiveStatement(testCase, (String) value);
        final VariableReference stringRepRef = testCase.addStatement(stringRep);
        final MethodStatement m = new MethodStatement(testCase, new GenericMethod(EvoSuiteXStream.class.getMethod("fromString", new Class<?>[] { String.class }), EvoSuiteXStream.class), null, Arrays.asList(stringRepRef));
        this.oidToVarRefMap.put(oid, testCase.addStatement(m));
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) ClassPrimitiveStatement(org.evosuite.testcase.statements.ClassPrimitiveStatement) PrimitiveStatement(org.evosuite.testcase.statements.PrimitiveStatement) ImmutableStringPrimitiveStatement(org.evosuite.testcase.statements.ImmutableStringPrimitiveStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) ImmutableStringPrimitiveStatement(org.evosuite.testcase.statements.ImmutableStringPrimitiveStatement) GenericMethod(org.evosuite.utils.generic.GenericMethod)

Example 97 with GenericMethod

use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.

the class ConstraintHelper method countNumberOfMethodCalls.

/**
 * This ignores the input parameters
 *
 * @param test
 * @param klass
 * @param methodName
 * @return
 * @throws IllegalArgumentException
 */
public static int countNumberOfMethodCalls(TestCase test, Class<?> klass, String methodName) throws IllegalArgumentException {
    Inputs.checkNull(test, klass);
    int counter = 0;
    for (int i = 0; i < test.size(); i++) {
        Statement st = test.getStatement(i);
        if (st instanceof MethodStatement) {
            MethodStatement ms = (MethodStatement) st;
            GenericMethod gm = ms.getMethod();
            if (gm.getDeclaringClass().equals(klass) && gm.getName().equals(methodName)) {
                counter++;
            }
        }
    }
    return counter;
}
Also used : GenericMethod(org.evosuite.utils.generic.GenericMethod)

Example 98 with GenericMethod

use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.

the class ConstraintHelper method getLastPositionOfMethodCall.

/**
 * @param test
 * @param className
 * @param methodName
 * @return a negative value if it is not present
 */
public static int getLastPositionOfMethodCall(TestCase test, String className, String methodName, int lastPosition) {
    Inputs.checkNull(test, className, methodName);
    int pos = -1;
    for (int i = 0; i < lastPosition; i++) {
        Statement st = test.getStatement(i);
        if (st instanceof MethodStatement) {
            MethodStatement ms = (MethodStatement) st;
            GenericMethod gm = ms.getMethod();
            if (gm.getDeclaringClass().getCanonicalName().equals(className) && gm.getName().equals(methodName)) {
                pos = i;
            }
        }
    }
    return pos;
}
Also used : GenericMethod(org.evosuite.utils.generic.GenericMethod)

Example 99 with GenericMethod

use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.

the class ChangeMutationSystemTest method getIntTest.

private TestCase getIntTest(int x) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
    Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
    GenericClass clazz = new GenericClass(sut);
    DefaultTestCase test = new DefaultTestCase();
    GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
    TestFactory testFactory = TestFactory.getInstance();
    VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
    VariableReference intVar = test.addStatement(new IntPrimitiveStatement(test, x));
    Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class });
    GenericMethod method = new GenericMethod(m, sut);
    MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar }));
    test.addStatement(ms);
    return test;
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) GenericClass(org.evosuite.utils.generic.GenericClass) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)

Example 100 with GenericMethod

use of org.evosuite.utils.generic.GenericMethod in project evosuite by EvoSuite.

the class ChangeMutationSystemTest method getTwoIntTest.

private TestCase getTwoIntTest(int x, int y) throws NoSuchMethodException, SecurityException, ConstructionFailedException, ClassNotFoundException {
    Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
    GenericClass clazz = new GenericClass(sut);
    DefaultTestCase test = new DefaultTestCase();
    GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
    TestFactory testFactory = TestFactory.getInstance();
    VariableReference callee = testFactory.addConstructor(test, gc, 0, 0);
    VariableReference intVar1 = test.addStatement(new IntPrimitiveStatement(test, x));
    VariableReference intVar2 = test.addStatement(new IntPrimitiveStatement(test, y));
    Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class, int.class });
    GenericMethod method = new GenericMethod(m, sut);
    MethodStatement ms = new MethodStatement(test, method, callee, Arrays.asList(new VariableReference[] { intVar1, intVar2 }));
    test.addStatement(ms);
    return test;
}
Also used : MethodStatement(org.evosuite.testcase.statements.MethodStatement) VariableReference(org.evosuite.testcase.variable.VariableReference) GenericClass(org.evosuite.utils.generic.GenericClass) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) GenericMethod(org.evosuite.utils.generic.GenericMethod) Method(java.lang.reflect.Method) GenericMethod(org.evosuite.utils.generic.GenericMethod) IntPrimitiveStatement(org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)

Aggregations

GenericMethod (org.evosuite.utils.generic.GenericMethod)110 Test (org.junit.Test)68 VariableReference (org.evosuite.testcase.variable.VariableReference)64 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)60 Method (java.lang.reflect.Method)57 GenericClass (org.evosuite.utils.generic.GenericClass)40 MethodStatement (org.evosuite.testcase.statements.MethodStatement)29 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)19 ArrayList (java.util.ArrayList)18 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)17 ConstructorStatement (org.evosuite.testcase.statements.ConstructorStatement)15 TestCase (org.evosuite.testcase.TestCase)12 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)11 Injector (org.evosuite.runtime.javaee.injection.Injector)10 Type (java.lang.reflect.Type)9 ConstructionFailedException (org.evosuite.ga.ConstructionFailedException)8 EvoServletState (org.evosuite.runtime.javaee.javax.servlet.EvoServletState)8 GenericAccessibleObject (org.evosuite.utils.generic.GenericAccessibleObject)8 GenericField (org.evosuite.utils.generic.GenericField)8 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)7