use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.
the class TestDefaultValue method testCharacter.
@Test
public void testCharacter() throws SecurityException, NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
ArrayReference characterArray0 = builder.appendArrayStmt(Character[].class, 10);
VariableReference character0 = builder.appendNull(Character.class);
builder.appendAssignment(characterArray0, 0, character0);
builder.appendAssignment(character0, characterArray0, 0);
builder.appendMethod(character0, Character.class.getMethod("toString"));
DefaultTestCase tc = builder.getDefaultTestCase();
ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
assertNotNull(ret_val);
assertFalse(ret_val.explicitExceptions.isEmpty());
}
use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.
the class TestDefaultValue method testDouble.
@Test
public void testDouble() throws SecurityException, NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
ArrayReference doubleArray0 = builder.appendArrayStmt(Double[].class, 10);
VariableReference double0 = builder.appendNull(Double.class);
builder.appendAssignment(doubleArray0, 0, double0);
builder.appendAssignment(double0, doubleArray0, 0);
builder.appendMethod(double0, Double.class.getMethod("floatValue"));
DefaultTestCase tc = builder.getDefaultTestCase();
ExecutionResult ret_val = TestCaseExecutor.runTest(tc);
assertNotNull(ret_val);
assertFalse(ret_val.explicitExceptions.isEmpty());
}
use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.
the class TestDSETestCaseLocalSearch 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 DowncastTest method testUnnecessaryDownCast.
@Test
public void testUnnecessaryDownCast() throws NoSuchMethodException {
TestCaseBuilder builder = new TestCaseBuilder();
VariableReference var = builder.appendConstructor(DowncastExample.class.getConstructor());
VariableReference int0 = builder.appendIntPrimitive(42);
VariableReference num0 = builder.appendMethod(var, DowncastExample.class.getMethod("getANumber", new Class<?>[] { int.class }), int0);
// This would be set during execution
num0.setType(Integer.class);
VariableReference boolean0 = builder.appendMethod(var, DowncastExample.class.getMethod("testMe", new Class<?>[] { Number.class }), num0);
PrimitiveAssertion assertion = new PrimitiveAssertion();
assertion.setSource(boolean0);
assertion.setValue(false);
DefaultTestCase test = builder.getDefaultTestCase();
test.getStatement(boolean0.getStPosition()).addAssertion(assertion);
test.removeDownCasts();
assertEquals(Number.class, test.getStatement(2).getReturnClass());
}
use of org.evosuite.symbolic.TestCaseBuilder in project evosuite by EvoSuite.
the class DowncastTest method testDownCastNecessaryForInspectorAssertion.
@Test
public void testDownCastNecessaryForInspectorAssertion() 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("getBar"));
InspectorAssertion assertion = new InspectorAssertion(inspector, test.getStatement(num0.getStPosition()), num0, true);
test.getStatement(num0.getStPosition()).addAssertion(assertion);
test.removeDownCasts();
System.out.println(test);
assertEquals(ConcreteSubclass.class, test.getStatement(1).getReturnClass());
}
Aggregations