-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test StatementAdd amplificator (#12)
- Loading branch information
Showing
10 changed files
with
164 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package fr.inria.diversify.dspot; | ||
|
||
import fr.inria.diversify.factories.DiversityCompiler; | ||
import fr.inria.diversify.runner.InputProgram; | ||
import spoon.reflect.declaration.CtClass; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.factory.Factory; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Created by Benjamin DANGLOT | ||
* benjamin.danglot@inria.fr | ||
* on 12/7/16 | ||
*/ | ||
public class Utils { | ||
|
||
public static CtMethod getCtMethod(CtClass testClass, final String simpleNameMethod) { | ||
return (CtMethod) testClass.getMethods().stream().filter(method -> simpleNameMethod.equals(((CtMethod) method).getSimpleName())).findFirst().get(); | ||
} | ||
|
||
public static Factory getFactory(InputProgram inputProgram) throws IOException, InterruptedException { | ||
DiversityCompiler diversityCompiler = DSpotUtils.initDiversityCompiler(inputProgram, true); | ||
Factory factory = diversityCompiler.getFactory(); | ||
factory.getEnvironment().setNoClasspath(true); | ||
return factory; | ||
} | ||
|
||
public static InputProgram getInputProgram() { | ||
InputProgram inputProgram = new InputProgram(); | ||
inputProgram.setProgramDir("src/test/resources/"); | ||
inputProgram.setRelativeSourceCodeDir("src"); | ||
inputProgram.setRelativeTestSourceCodeDir("test"); | ||
inputProgram.setTransformationPerRun(1); | ||
inputProgram.setJavaVersion(8); | ||
return inputProgram; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/java/fr/inria/diversify/dspot/amp/StatementAddTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package fr.inria.diversify.dspot.amp; | ||
|
||
import fr.inria.diversify.dspot.Utils; | ||
import fr.inria.diversify.dspot.value.ValueFactory; | ||
import fr.inria.diversify.runner.InputProgram; | ||
import org.junit.Test; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.factory.Factory; | ||
|
||
import java.util.*; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Created by Benjamin DANGLOT | ||
* benjamin.danglot@inria.fr | ||
* on 11/30/16 | ||
*/ | ||
public class StatementAddTest { | ||
|
||
@Test | ||
public void testStatementAdd() throws Exception { | ||
final String packageName = "statementadd"; | ||
InputProgram inputProgram = Utils.getInputProgram(); | ||
|
||
final Factory factory = Utils.getFactory(inputProgram); | ||
inputProgram.setFactory(factory); | ||
AmplifierHelper.setSeedRandom(23L); | ||
ValueFactory valueFactory = new ValueFactory(inputProgram); | ||
StatementAdd amplificator = new StatementAdd(inputProgram.getFactory(), valueFactory, packageName); | ||
amplificator.reset(null, factory.Class().get(packageName + ".ClassTargetAmplify")); | ||
|
||
CtMethod<?> ctMethod = Utils.getCtMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test"); | ||
// CtMethod<?> ctMethod = factory.Class().get(packageName + ".TestClassTargetAmplify").getMethods().stream().findAny().get(); | ||
List<CtMethod> amplifiedMethods = amplificator.apply(ctMethod); | ||
|
||
assertEquals(4, amplifiedMethods.size()); | ||
|
||
amplifiedMethods.forEach(System.out::println); | ||
} | ||
|
||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/test/resources/src/statementadd/ClassParameterAmplify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package statementadd; | ||
|
||
/** | ||
* Created by bdanglot on 11/30/16. | ||
*/ | ||
public class ClassParameterAmplify { | ||
|
||
public void method1() { | ||
System.out.println(""); | ||
} | ||
|
||
private void method2() { | ||
System.out.println(""); | ||
} | ||
|
||
protected void method3() { | ||
System.out.println(""); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/test/resources/src/statementadd/ClassTargetAmplify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package statementadd; | ||
|
||
/** | ||
* Created by bdanglot on 11/30/16. | ||
*/ | ||
public class ClassTargetAmplify { | ||
|
||
public ClassParameterAmplify methodWithReturn() { | ||
return new ClassParameterAmplify(); | ||
} | ||
|
||
public void methodPrimitif(Integer i) { | ||
System.out.println(i); | ||
} | ||
|
||
public void method() { | ||
System.out.println(""); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/test/resources/test/statementadd/TestClassTargetAmplify.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package statementadd; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Created by bdanglot on 11/30/16. | ||
*/ | ||
public class TestClassTargetAmplify { | ||
|
||
@Test | ||
public void test() throws Exception { | ||
ClassTargetAmplify clazz = new ClassTargetAmplify(); | ||
clazz.methodWithReturn(); | ||
} | ||
|
||
} |