use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class TestConstantInliner method testNumericArrayIndexInlining.
@Test
public void testNumericArrayIndexInlining() throws NoSuchMethodException, SecurityException {
DefaultTestCase test = new DefaultTestCase();
PrimitiveStatement<?> primitiveStatement = PrimitiveStatement.getPrimitiveStatement(test, int.class);
VariableReference intVar = test.addStatement(primitiveStatement);
ArrayStatement as = new ArrayStatement(test, int[].class, 3);
test.addStatement(as);
ArrayReference arrayVar = as.getArrayReference();
ArrayIndex ai0 = new ArrayIndex(test, arrayVar, 0);
ArrayIndex ai1 = new ArrayIndex(test, arrayVar, 1);
ArrayIndex ai2 = new ArrayIndex(test, arrayVar, 2);
test.addStatement(new AssignmentStatement(test, ai0, intVar));
test.addStatement(new AssignmentStatement(test, ai1, intVar));
test.addStatement(new AssignmentStatement(test, ai2, intVar));
ConstructorStatement sutCS = new ConstructorStatement(test, new GenericConstructor(TrivialInt.class.getConstructor(), TrivialInt.class), new ArrayList<>());
VariableReference sut = test.addStatement(sutCS);
List<VariableReference> parameters = new ArrayList<VariableReference>();
parameters.add(ai0);
test.addStatement(new MethodStatement(test, new GenericMethod(TrivialInt.class.getMethods()[0], TrivialInt.class), sut, parameters));
parameters = new ArrayList<>();
parameters.add(ai1);
test.addStatement(new MethodStatement(test, new GenericMethod(TrivialInt.class.getMethods()[0], TrivialInt.class), sut, parameters));
parameters = new ArrayList<>();
parameters.add(ai2);
test.addStatement(new MethodStatement(test, new GenericMethod(TrivialInt.class.getMethods()[0], TrivialInt.class), sut, parameters));
System.out.println(test.toCode());
ConstantInliner inliner = new ConstantInliner();
inliner.inline(test);
String code = test.toCode();
System.out.println(test.toCode());
assertFalse(code.contains("trivialInt0.testMe(int"));
}
use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class TestConstantInliner method testStringEndingWithClass.
@Test
public void testStringEndingWithClass() throws NoSuchMethodException, SecurityException {
DefaultTestCase test = new DefaultTestCase();
ConstructorStatement cs = new ConstructorStatement(test, new GenericConstructor(StringConstantInliningExample.class.getConstructor(), StringConstantInliningExample.class), new ArrayList<VariableReference>());
VariableReference objectVar = test.addStatement(cs);
StringPrimitiveStatement stringStatement = new StringPrimitiveStatement(test, "test.class");
VariableReference stringParam = test.addStatement(stringStatement);
List<VariableReference> parameters = new ArrayList<VariableReference>();
parameters.add(stringParam);
test.addStatement(new MethodStatement(test, new GenericMethod(StringConstantInliningExample.class.getMethods()[0], StringConstantInliningExample.class), objectVar, parameters));
System.out.println(test.toCode());
ConstantInliner inliner = new ConstantInliner();
inliner.inline(test);
String code = test.toCode();
System.out.println(code);
assertFalse(code.contains("foo(test.class)"));
assertTrue(code.contains("foo(\"test.class\")"));
}
use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class Archive method ignoreMethodCall.
/**
* Informs {@link org.evosuite.setup.TestCluster} that a particular method of a particular class
* has been fully covered, and therefore no need to generate any solution to cover any of its
* targets.
*
* @param className name of the class which contains the method that has been fully covered and
* can be ignored
* @param methodName name of the method that has been fully covered and can be ignored
*/
protected void ignoreMethodCall(String className, String methodName) {
TestCluster cluster = TestCluster.getInstance();
List<GenericAccessibleObject<?>> calls = cluster.getTestCalls();
for (GenericAccessibleObject<?> call : calls) {
if (!call.getDeclaringClass().getName().equals(className)) {
continue;
}
if (call instanceof GenericMethod) {
GenericMethod genericMethod = (GenericMethod) call;
if (!methodName.startsWith(genericMethod.getName())) {
continue;
}
String desc = Type.getMethodDescriptor(genericMethod.getMethod());
if ((genericMethod.getName() + desc).equals(methodName)) {
logger.info("Removing method " + methodName + " from cluster");
cluster.removeTestCall(call);
logger.info("Testcalls left: " + cluster.getNumTestCalls());
}
} else if (call instanceof GenericConstructor) {
GenericConstructor genericConstructor = (GenericConstructor) call;
if (!methodName.startsWith("<init>")) {
continue;
}
String desc = Type.getConstructorDescriptor(genericConstructor.getConstructor());
if (("<init>" + desc).equals(methodName)) {
logger.info("Removing constructor " + methodName + " from cluster");
cluster.removeTestCall(call);
logger.info("Testcalls left: " + cluster.getNumTestCalls());
}
}
}
}
use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class TestCaseBuilder method appendConstructor.
public VariableReference appendConstructor(Constructor<?> constructor, VariableReference... parameters) {
List<VariableReference> parameter_list = Arrays.asList(parameters);
ConstructorStatement constructorStmt = new ConstructorStatement(tc, new GenericConstructor(constructor, constructor.getDeclaringClass()), parameter_list);
tc.addStatement(constructorStmt);
return constructorStmt.getReturnValue();
}
use of org.evosuite.utils.generic.GenericConstructor in project evosuite by EvoSuite.
the class OverloadSystemTest method testIsOverloadedInstance.
@Test
public void testIsOverloadedInstance() throws NoSuchMethodException, SecurityException {
Method m1 = Overload.class.getMethod("execute", Overload.class, Overload.class);
Method m2 = Overload.class.getMethod("execute", Overload.class, Object.class);
GenericMethod gm1 = new GenericMethod(m1, Overload.class);
GenericMethod gm2 = new GenericMethod(m2, Overload.class);
TestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(Overload.class.getConstructors()[0], Overload.class);
ConstructorStatement cs = new ConstructorStatement(test, gc, new ArrayList<VariableReference>());
VariableReference overloadInstance = test.addStatement(cs);
ConstructorStatement ocs = new ConstructorStatement(test, new GenericConstructor(Object.class.getConstructors()[0], Object.class), new ArrayList<VariableReference>());
VariableReference objectInstance = test.addStatement(ocs);
List<VariableReference> vars1 = new ArrayList<VariableReference>();
vars1.add(overloadInstance);
vars1.add(overloadInstance);
List<VariableReference> vars2 = new ArrayList<VariableReference>();
vars2.add(overloadInstance);
vars2.add(objectInstance);
Assert.assertFalse(gm1.isOverloaded(vars1));
Assert.assertTrue(gm2.isOverloaded(vars1));
Assert.assertTrue(gm1.isOverloaded(vars2));
Assert.assertFalse(gm2.isOverloaded(vars2));
}
Aggregations