use of eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier in project dspot by STAMP-project.
the class MethodAdderOnExistingObjectsAmplifierTest method testStatementAddOnUnderTest.
@Test
public void testStatementAddOnUnderTest() throws Exception {
Factory factory = launcher.getFactory();
CtClass<Object> ctClass = factory.Class().get("fr.inria.mutation.ClassUnderTestTest");
RandomHelper.setSeedRandom(23L);
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(ctClass);
CtMethod originalMethod = ctClass.getMethodsByName("testLit").get(0);
List<CtMethod> amplifiedMethods = amplifier.amplify(originalMethod, 0).collect(Collectors.toList());
System.out.println(amplifiedMethods);
assertEquals(2, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("plusOne", "minusOne");
assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
}
}).first() != null));
}
use of eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier in project dspot by STAMP-project.
the class MethodAdderOnExistingObjectsAmplifierTest method testStatementAdd.
@Test
public void testStatementAdd() throws Exception {
/*
Test the StatementAdd amplifier. It reuse existing object to add method call of accessible method.
It can reuse return value to add method call. It results here with 7 new test cases.
*/
final String packageName = "fr.inria.statementadd";
final Factory factory = launcher.getFactory();
RandomHelper.setSeedRandom(42L);
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".TestClassTargetAmplify"));
CtMethod<?> ctMethod = factory.Class().get(packageName + ".TestClassTargetAmplify").getMethodsByName("test").get(0);
List<CtMethod> amplifiedMethods = amplifier.amplify(ctMethod, 0).collect(Collectors.toList());
System.out.println(amplifiedMethods);
assertEquals(5, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("method", "methodWithDomainParameter", "methodWithPrimitifParameters", "methodWithPrimitifParameters", "methodWithReturn");
assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
}
}).first() != null));
}
use of eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier in project dspot by STAMP-project.
the class MethodAdderOnExistingObjectsAmplifierTest method testStatementAddOnArrayObjects.
@Test
public void testStatementAddOnArrayObjects() throws Exception {
final String packageName = "fr.inria.statementaddarray";
final Factory factory = launcher.getFactory();
RandomHelper.setSeedRandom(32L);
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));
CtMethod<?> ctMethod = factory.Class().get(packageName + ".TestClassTargetAmplify").getMethodsByName("test").get(0);
List<CtMethod> amplifiedMethods = amplifier.amplify(ctMethod, 0).collect(Collectors.toList());
assertEquals(4, amplifiedMethods.size());
List<String> expectedCalledMethod = Arrays.asList("methodWithArrayParatemeter", "methodWithArrayParatemeterFromDomain", "methodWithDomainParameter", "methodWithReturn");
assertTrue(amplifiedMethods.stream().allMatch(amplifiedMethod -> amplifiedMethod.filterChildren(new TypeFilter<CtInvocation<?>>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation<?> element) {
return expectedCalledMethod.contains(element.getExecutable().getSimpleName());
}
}).first() != null));
}
use of eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier in project dspot by STAMP-project.
the class TestWithLogGeneratorTest method testNoInstrumentationOnGeneratedObject.
@Test
public void testNoInstrumentationOnGeneratedObject() throws Exception {
/*
* This test aims at verifying that dspot does not generate assertion for generated object.
* To do this, it will checkEnum that the instrumentation does not add observation points on those objects.
* If no observation point is added, any assertion would be generated.
* We verify the number of ObjectLog.log statement inside the instrumented tests
*/
final String packageName = "fr.inria.statementaddarray";
final Factory factory = this.launcher.getFactory();
MethodAdderOnExistingObjectsAmplifier amplifier = new MethodAdderOnExistingObjectsAmplifier();
amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));
CtMethod<?> ctMethod = findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
List<CtMethod> amplifiedMethods = amplifier.amplify(ctMethod, 0).collect(Collectors.toList());
assertEquals(4, amplifiedMethods.size());
final List<CtMethod<?>> instrumentedAmplifiedTests = amplifiedMethods.stream().map(method -> eu.stamp_project.dspot.assertiongenerator.assertiongenerator.methodreconstructor.observer.TestWithLogGenerator.createTestWithLog(method, "fr.inria.statementaddarray", Collections.emptyList())).collect(Collectors.toList());
assertEquals(4, instrumentedAmplifiedTests.size());
assertEquals(17, instrumentedAmplifiedTests.parallelStream().mapToInt(instrumentedAmplifiedTest -> instrumentedAmplifiedTest.getElements(new TypeFilter<CtInvocation>(CtInvocation.class) {
@Override
public boolean matches(CtInvocation element) {
return "eu.stamp_project.dspot.assertiongenerator.assertiongenerator.methodreconstructor.observer.testwithloggenerator.objectlogsyntaxbuilder_constructs.ObjectLog".equals(element.getTarget().toString()) && "log".equals(element.getExecutable().getSimpleName());
}
}).size()).sum());
}
use of eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier in project dspot by STAMP-project.
the class SimpleInputAmplDistributorTest method test.
@Test
public void test() throws Exception {
/*
Test the simple input_ampl_distributor with different amplifier.
The SimpleBudget should always provide a specific number of test Methods
*/
final CtClass<?> testClass = findClass("fr.inria.statementadd.TestClassTargetAmplify");
List<CtMethod<?>> ctMethods = TestFramework.getAllTest(testClass);
final SimpleInputAmplDistributor simpleBudgetizer = new SimpleInputAmplDistributor(6, Arrays.asList(new IterationDecoratorAmplifier(new ReturnValueAmplifier(), 3), new IterationDecoratorAmplifier(new MethodAdderOnExistingObjectsAmplifier(), 2), new NumberLiteralAmplifier()));
for (int i = 0; i < 3; i++) {
// !
ctMethods = simpleBudgetizer.inputAmplify(ctMethods, i);
}
assertEquals(6, ctMethods.size());
}
Aggregations