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());
}
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());
}
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());
}
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();
}
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();
}
Aggregations