Search in sources :

Example 1 with StatementAdd

use of fr.inria.diversify.dspot.amplifier.StatementAdd in project dspot by STAMP-project.

the class AssertGeneratorHelperTest method testNoInstrumentationOnGeneratedObject.

/**
 * this test aims at verifying that dspot does not generate assertion for generated object.
 * To do this, it will check that the instrumentation does not add observation points on those objects.
 * If no observation point is added, any assertion would be generated.
 */
@Test
public void testNoInstrumentationOnGeneratedObject() throws Exception {
    final String packageName = "fr.inria.statementaddarray";
    InputProgram inputProgram = Utils.getInputProgram();
    final Factory factory = inputProgram.getFactory();
    inputProgram.setFactory(factory);
    AmplificationHelper.setSeedRandom(32L);
    StatementAdd amplifier = new StatementAdd(packageName);
    amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));
    CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
    List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);
    final List<CtMethod<?>> instrumentedAmplifiedTests = amplifiedMethods.stream().map(method -> AssertGeneratorHelper.createTestWithLog(method, "fr.inria.statementaddarray")).collect(Collectors.toList());
    assertEquals(5, amplifiedMethods.size());
    final String expectedInstrumentedBodyAfterAmplification_test_sd6_withlog = "{" + AmplificationHelper.LINE_SEPARATOR + "    fr.inria.statementaddarray.ClassTargetAmplify clazz = new fr.inria.statementaddarray.ClassTargetAmplify();" + AmplificationHelper.LINE_SEPARATOR + "    fr.inria.diversify.compare.ObjectLog.log(clazz, \"clazz\", \"test_sd6__1\");" + AmplificationHelper.LINE_SEPARATOR + "    // StatementAdd: generate variable from return value" + AmplificationHelper.LINE_SEPARATOR + "    fr.inria.statementaddarray.ClassParameterAmplify __DSPOT_invoc_3 = clazz.methodWithReturn();" + AmplificationHelper.LINE_SEPARATOR + "    // StatementAdd: add invocation of a method" + AmplificationHelper.LINE_SEPARATOR + "    __DSPOT_invoc_3.method1();" + AmplificationHelper.LINE_SEPARATOR + "    fr.inria.diversify.compare.ObjectLog.log(clazz, \"clazz\", \"test_sd6__1___end\");" + AmplificationHelper.LINE_SEPARATOR + "}";
    assertEquals(expectedInstrumentedBodyAfterAmplification_test_sd6_withlog, instrumentedAmplifiedTests.stream().filter(ctMethod1 -> "test_sd6_withlog".equals(ctMethod1.getSimpleName())).findFirst().get().getBody().toString());
}
Also used : AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) StatementAdd(fr.inria.diversify.dspot.amplifier.StatementAdd) Test(org.junit.Test) Factory(spoon.reflect.factory.Factory) Collectors(java.util.stream.Collectors) List(java.util.List) Utils(fr.inria.Utils) CtClass(spoon.reflect.declaration.CtClass) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AbstractTest(fr.inria.AbstractTest) CtMethod(spoon.reflect.declaration.CtMethod) Factory(spoon.reflect.factory.Factory) StatementAdd(fr.inria.diversify.dspot.amplifier.StatementAdd) CtMethod(spoon.reflect.declaration.CtMethod) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Example 2 with StatementAdd

use of fr.inria.diversify.dspot.amplifier.StatementAdd in project dspot by STAMP-project.

the class JacocoCoverageSelectorTest method testDSpotWithJacocoCoverageSelector.

@Test
public void testDSpotWithJacocoCoverageSelector() throws Exception {
    try {
        FileUtils.deleteDirectory(new File("target/trash"));
    } catch (Exception ignored) {
    // ignored
    }
    AmplificationHelper.setSeedRandom(23L);
    InputConfiguration configuration = new InputConfiguration("src/test/resources/test-projects/test-projects.properties");
    DSpot dspot = new DSpot(configuration, 2, Arrays.asList(new TestDataMutator(), new StatementAdd()), new JacocoCoverageSelector());
    dspot.amplifyTest("example.TestSuiteExample", Collections.singletonList("test2"));
    try (BufferedReader buffer = new BufferedReader(new FileReader(configuration.getOutputDirectory() + "example.TestSuiteExample_jacoco_instr_coverage_report.txt"))) {
        assertEquals(expectedReport, buffer.lines().collect(Collectors.joining(nl)));
    }
}
Also used : DSpot(fr.inria.diversify.dspot.DSpot) BufferedReader(java.io.BufferedReader) StatementAdd(fr.inria.diversify.dspot.amplifier.StatementAdd) FileReader(java.io.FileReader) File(java.io.File) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) TestDataMutator(fr.inria.diversify.dspot.amplifier.TestDataMutator) Test(org.junit.Test)

Example 3 with StatementAdd

use of fr.inria.diversify.dspot.amplifier.StatementAdd in project dspot by STAMP-project.

the class DSpotMockedTest method test.

@Test
public void test() throws Exception {
    /*
			Test the whole dspot procedure.
         */
    ValueCreator.count = 0;
    AmplificationHelper.setSeedRandom(23L);
    InputConfiguration configuration = new InputConfiguration(getPathToPropertiesFile());
    InputProgram program = new InputProgram();
    configuration.setInputProgram(program);
    DSpot dspot = new DSpot(configuration, 1, Arrays.asList(new StatementAdd()));
    try {
        FileUtils.cleanDirectory(new File(configuration.getOutputDirectory()));
    } catch (Exception ignored) {
    }
    assertEquals(6, dspot.getInputProgram().getFactory().Class().get("info.sanaulla.dal.BookDALTest").getMethods().size());
    CtType<?> amplifiedTest = dspot.amplifyTest("info.sanaulla.dal.BookDALTest", Collections.singletonList("testGetBook"));
    assertEquals(1, amplifiedTest.getMethods().stream().filter(AmplificationChecker::isTest).count());
    System.out.println(amplifiedTest);
    assertTrue(!amplifiedTest.getMethodsByName("testGetBook_sd8").isEmpty());
}
Also used : AmplificationChecker(fr.inria.diversify.utils.AmplificationChecker) StatementAdd(fr.inria.diversify.dspot.amplifier.StatementAdd) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) File(java.io.File) InputProgram(fr.inria.diversify.utils.sosiefier.InputProgram) Test(org.junit.Test) AbstractTest(fr.inria.AbstractTest)

Aggregations

StatementAdd (fr.inria.diversify.dspot.amplifier.StatementAdd)3 Test (org.junit.Test)3 AbstractTest (fr.inria.AbstractTest)2 InputConfiguration (fr.inria.diversify.utils.sosiefier.InputConfiguration)2 InputProgram (fr.inria.diversify.utils.sosiefier.InputProgram)2 File (java.io.File)2 Utils (fr.inria.Utils)1 DSpot (fr.inria.diversify.dspot.DSpot)1 TestDataMutator (fr.inria.diversify.dspot.amplifier.TestDataMutator)1 AmplificationChecker (fr.inria.diversify.utils.AmplificationChecker)1 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 CtClass (spoon.reflect.declaration.CtClass)1 CtMethod (spoon.reflect.declaration.CtMethod)1 Factory (spoon.reflect.factory.Factory)1