Search in sources :

Example 11 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class DowncastTest method testDownCastNecessaryForField.

@Test
public void testDownCastNecessaryForField() throws NoSuchMethodException, NoSuchFieldException {
    TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference var = builder.appendConstructor(DowncastExample.class.getConstructor());
    VariableReference num0 = builder.appendMethod(var, DowncastExample.class.getMethod("getAbstractFoo"));
    // This would be set during execution
    num0.setType(ConcreteSubclass.class);
    DefaultTestCase test = builder.getDefaultTestCase();
    PrimitiveFieldAssertion assertion = new PrimitiveFieldAssertion();
    assertion.setValue(true);
    assertion.setSource(num0);
    assertion.setField(ConcreteSubclass.class.getField("fieldInConcreteClass"));
    test.getStatement(num0.getStPosition()).addAssertion(assertion);
    test.removeDownCasts();
    System.out.println(test);
    assertEquals(ConcreteSubclass.class, test.getStatement(1).getReturnClass());
}
Also used : DowncastExample(com.examples.with.different.packagename.test.DowncastExample) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) ConcreteSubclass(com.examples.with.different.packagename.test.ConcreteSubclass) Test(org.junit.Test)

Example 12 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class DowncastTest method testDownCastUnnecessaryForInspectorAssertion.

@Test
public void testDownCastUnnecessaryForInspectorAssertion() throws NoSuchMethodException {
    TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference var = builder.appendConstructor(DowncastExample.class.getConstructor());
    VariableReference num0 = builder.appendMethod(var, DowncastExample.class.getMethod("getAbstractFoo"));
    // This would be set during execution
    num0.setType(ConcreteSubclass.class);
    DefaultTestCase test = builder.getDefaultTestCase();
    Inspector inspector = new Inspector(ConcreteSubclass.class, ConcreteSubclass.class.getMethod("getFoo"));
    InspectorAssertion assertion = new InspectorAssertion(inspector, test.getStatement(num0.getStPosition()), num0, true);
    test.getStatement(num0.getStPosition()).addAssertion(assertion);
    test.removeDownCasts();
    System.out.println(test);
    assertEquals(AbstractSuperclass.class, test.getStatement(1).getReturnClass());
}
Also used : DowncastExample(com.examples.with.different.packagename.test.DowncastExample) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) ConcreteSubclass(com.examples.with.different.packagename.test.ConcreteSubclass) Test(org.junit.Test)

Example 13 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class DowncastTest method testFieldReferenceNeedsDowncast.

@Test
public void testFieldReferenceNeedsDowncast() throws NoSuchMethodException, NoSuchFieldException {
    TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference var = builder.appendConstructor(DowncastExample.class.getConstructor());
    VariableReference num0 = builder.appendMethod(var, DowncastExample.class.getMethod("getAbstractFoo"));
    // This would be set during execution
    num0.setType(ConcreteSubclass.class);
    VariableReference bool0 = builder.appendBooleanPrimitive(true);
    DefaultTestCase test = builder.getDefaultTestCase();
    FieldReference fr = new FieldReference(test, new GenericField(ConcreteSubclass.class.getField("fieldInConcreteClass"), ConcreteSubclass.class), num0);
    AssignmentStatement statement = new AssignmentStatement(test, fr, bool0);
    test.addStatement(statement);
    test.removeDownCasts();
    System.out.println(test);
    FieldReference fr2 = (FieldReference) test.getStatement(3).getReturnValue();
    assertEquals(ConcreteSubclass.class, fr2.getSource().getVariableClass());
}
Also used : DowncastExample(com.examples.with.different.packagename.test.DowncastExample) TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) FieldReference(org.evosuite.testcase.variable.FieldReference) VariableReference(org.evosuite.testcase.variable.VariableReference) AssignmentStatement(org.evosuite.testcase.statements.AssignmentStatement) ConcreteSubclass(com.examples.with.different.packagename.test.ConcreteSubclass) GenericField(org.evosuite.utils.generic.GenericField) Test(org.junit.Test)

Example 14 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class TestDSETestSuiteCookie method buildTestCase0.

/**
 * Creates the test case:
 *
 * <code>
 * int int0 = 10;
 * int int1 = 10;
 * int int2 = 10;
 * Foo.bar(int0,int1,int2);
 * </code>
 *
 * @return
 * @throws NoSuchMethodException
 * @throws SecurityException
 * @throws ClassNotFoundException
 */
private static DefaultTestCase buildTestCase0() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
    TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference int0 = builder.appendIntPrimitive(10);
    VariableReference int1 = builder.appendIntPrimitive(10);
    VariableReference int2 = builder.appendIntPrimitive(10);
    Class<?> fooClass = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
    Method barMethod = fooClass.getMethod("bar", int.class, int.class, int.class);
    builder.appendMethod(null, barMethod, int0, int1, int2);
    return builder.getDefaultTestCase();
}
Also used : TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) Method(java.lang.reflect.Method)

Example 15 with TestCaseBuilder

use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.

the class TestZ3Str2HardConstraints method buildTestCase0.

private DefaultTestCase buildTestCase0() throws NoSuchMethodException, SecurityException {
    TestCaseBuilder tc = new TestCaseBuilder();
    VariableReference int0 = tc.appendIntPrimitive(13075);
    Method method = HardConstraints.class.getMethod("test0", int.class);
    tc.appendMethod(null, method, int0);
    return tc.getDefaultTestCase();
}
Also used : TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) Method(java.lang.reflect.Method)

Aggregations

TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)146 VariableReference (org.evosuite.testcase.variable.VariableReference)143 Method (java.lang.reflect.Method)129 Test (org.junit.Test)16 DowncastExample (com.examples.with.different.packagename.test.DowncastExample)8 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)8 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)7 ArrayReference (org.evosuite.testcase.variable.ArrayReference)7 MIMEType (com.examples.with.different.packagename.concolic.MIMEType)6 ShowMessageDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowMessageDialogExample)6 Field (java.lang.reflect.Field)6 ConcreteSubclass (com.examples.with.different.packagename.test.ConcreteSubclass)4 ShowInternalMessageDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowInternalMessageDialogExample)2 AbstractSuperclass (com.examples.with.different.packagename.test.AbstractSuperclass)2 AssignmentStatement (org.evosuite.testcase.statements.AssignmentStatement)2 FieldReference (org.evosuite.testcase.variable.FieldReference)2 GenericField (org.evosuite.utils.generic.GenericField)2 CBranchExample (com.examples.with.different.packagename.cbranch.CBranchExample)1 ShowConfirmDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowConfirmDialogExample)1 ShowInputDialogExample (com.examples.with.different.packagename.mock.javax.swing.ShowInputDialogExample)1