Search in sources :

Example 1 with MethodAdderOnExistingObjectsAmplifier

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));
}
Also used : TypeFilter(spoon.reflect.visitor.filter.TypeFilter) MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) Arrays(java.util.Arrays) RandomHelper(eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper) AbstractTestOnSample(eu.stamp_project.dspot.AbstractTestOnSample) CtForEach(spoon.reflect.code.CtForEach) CtInvocation(spoon.reflect.code.CtInvocation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Factory(spoon.reflect.factory.Factory) Collectors(java.util.stream.Collectors) List(java.util.List) CtClass(spoon.reflect.declaration.CtClass) CtBlock(spoon.reflect.code.CtBlock) Assert.assertEquals(org.junit.Assert.assertEquals) CtMethod(spoon.reflect.declaration.CtMethod) Factory(spoon.reflect.factory.Factory) MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) CtInvocation(spoon.reflect.code.CtInvocation) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 2 with MethodAdderOnExistingObjectsAmplifier

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));
}
Also used : TypeFilter(spoon.reflect.visitor.filter.TypeFilter) MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) Arrays(java.util.Arrays) RandomHelper(eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper) AbstractTestOnSample(eu.stamp_project.dspot.AbstractTestOnSample) CtForEach(spoon.reflect.code.CtForEach) CtInvocation(spoon.reflect.code.CtInvocation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Factory(spoon.reflect.factory.Factory) Collectors(java.util.stream.Collectors) List(java.util.List) CtClass(spoon.reflect.declaration.CtClass) CtBlock(spoon.reflect.code.CtBlock) Assert.assertEquals(org.junit.Assert.assertEquals) CtMethod(spoon.reflect.declaration.CtMethod) MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) CtInvocation(spoon.reflect.code.CtInvocation) Factory(spoon.reflect.factory.Factory) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 3 with MethodAdderOnExistingObjectsAmplifier

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));
}
Also used : TypeFilter(spoon.reflect.visitor.filter.TypeFilter) MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) Arrays(java.util.Arrays) RandomHelper(eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper) AbstractTestOnSample(eu.stamp_project.dspot.AbstractTestOnSample) CtForEach(spoon.reflect.code.CtForEach) CtInvocation(spoon.reflect.code.CtInvocation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Factory(spoon.reflect.factory.Factory) Collectors(java.util.stream.Collectors) List(java.util.List) CtClass(spoon.reflect.declaration.CtClass) CtBlock(spoon.reflect.code.CtBlock) Assert.assertEquals(org.junit.Assert.assertEquals) CtMethod(spoon.reflect.declaration.CtMethod) MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) CtInvocation(spoon.reflect.code.CtInvocation) Factory(spoon.reflect.factory.Factory) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 4 with MethodAdderOnExistingObjectsAmplifier

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());
}
Also used : TypeFilter(spoon.reflect.visitor.filter.TypeFilter) MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) AbstractTestOnSample(eu.stamp_project.dspot.AbstractTestOnSample) CtInvocation(spoon.reflect.code.CtInvocation) Test(org.junit.Test) Factory(spoon.reflect.factory.Factory) Collectors(java.util.stream.Collectors) AssertionRemover(eu.stamp_project.dspot.assertiongenerator.assertiongenerator.AssertionRemover) List(java.util.List) CtClass(spoon.reflect.declaration.CtClass) AmplificationHelper(eu.stamp_project.dspot.common.miscellaneous.AmplificationHelper) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CtMethod(spoon.reflect.declaration.CtMethod) MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) CtInvocation(spoon.reflect.code.CtInvocation) Factory(spoon.reflect.factory.Factory) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 5 with MethodAdderOnExistingObjectsAmplifier

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());
}
Also used : MethodAdderOnExistingObjectsAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier) SimpleInputAmplDistributor(eu.stamp_project.dspot.amplifier.SimpleInputAmplDistributor) CtMethod(spoon.reflect.declaration.CtMethod) IterationDecoratorAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.IterationDecoratorAmplifier) ReturnValueAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier) NumberLiteralAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier) Test(org.junit.Test)

Aggregations

MethodAdderOnExistingObjectsAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier)7 Test (org.junit.Test)7 CtMethod (spoon.reflect.declaration.CtMethod)6 Factory (spoon.reflect.factory.Factory)6 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)6 AbstractTestOnSample (eu.stamp_project.dspot.AbstractTestOnSample)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 CtBlock (spoon.reflect.code.CtBlock)5 CtInvocation (spoon.reflect.code.CtInvocation)5 CtClass (spoon.reflect.declaration.CtClass)5 RandomHelper (eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper)4 Arrays (java.util.Arrays)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 CtForEach (spoon.reflect.code.CtForEach)4 SimpleInputAmplDistributor (eu.stamp_project.dspot.amplifier.SimpleInputAmplDistributor)1 IterationDecoratorAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.IterationDecoratorAmplifier)1 NumberLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier)1 ReturnValueAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier)1