Search in sources :

Example 1 with ReturnValueAmplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier in project dspot by STAMP-project.

the class ReturnValueAmplifierTest method testStatementAddOnArrayObjects.

@Test
public void testStatementAddOnArrayObjects() throws Exception {
    final String packageName = "fr.inria.statementaddarray";
    final Factory factory = launcher.getFactory();
    RandomHelper.setSeedRandom(32L);
    ReturnValueAmplifier amplifier = new ReturnValueAmplifier();
    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(1, amplifiedMethods.size());
    List<String> expectedCalledMethod = Collections.singletonList("method1");
    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) RandomHelper(eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper) AbstractTestOnSample(eu.stamp_project.dspot.AbstractTestOnSample) 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) ReturnValueAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CtMethod(spoon.reflect.declaration.CtMethod) CtInvocation(spoon.reflect.code.CtInvocation) Factory(spoon.reflect.factory.Factory) ReturnValueAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 2 with ReturnValueAmplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier in project dspot by STAMP-project.

the class ReturnValueAmplifierTest 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);
    ReturnValueAmplifier amplifier = new ReturnValueAmplifier();
    amplifier.reset(factory.Class().get(packageName + ".TestClassTargetAmplify"));
    CtMethod<?> ctMethod = findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
    List<CtMethod> amplifiedMethods = amplifier.amplify(ctMethod, 0).collect(Collectors.toList());
    System.out.println(amplifiedMethods);
    assertEquals(1, amplifiedMethods.size());
    List<String> expectedCalledMethod = Collections.singletonList("method1");
    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) RandomHelper(eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper) AbstractTestOnSample(eu.stamp_project.dspot.AbstractTestOnSample) 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) ReturnValueAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CtMethod(spoon.reflect.declaration.CtMethod) CtInvocation(spoon.reflect.code.CtInvocation) Factory(spoon.reflect.factory.Factory) ReturnValueAmplifier(eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 3 with ReturnValueAmplifier

use of eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier 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

ReturnValueAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.ReturnValueAmplifier)3 Test (org.junit.Test)3 CtMethod (spoon.reflect.declaration.CtMethod)3 AbstractTestOnSample (eu.stamp_project.dspot.AbstractTestOnSample)2 RandomHelper (eu.stamp_project.dspot.amplifier.amplifiers.utils.RandomHelper)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 CtInvocation (spoon.reflect.code.CtInvocation)2 Factory (spoon.reflect.factory.Factory)2 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)2 SimpleInputAmplDistributor (eu.stamp_project.dspot.amplifier.SimpleInputAmplDistributor)1 IterationDecoratorAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.IterationDecoratorAmplifier)1 MethodAdderOnExistingObjectsAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.MethodAdderOnExistingObjectsAmplifier)1 NumberLiteralAmplifier (eu.stamp_project.dspot.amplifier.amplifiers.NumberLiteralAmplifier)1