-
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.
- Loading branch information
Showing
9 changed files
with
204 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package fr.inria.diversify.dspot; | ||
|
||
import fr.inria.diversify.Utils; | ||
import fr.inria.diversify.buildSystem.android.InvalidSdkException; | ||
import fr.inria.diversify.runner.InputConfiguration; | ||
import fr.inria.diversify.runner.InputProgram; | ||
import org.junit.Test; | ||
import spoon.reflect.declaration.CtType; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Created by Benjamin DANGLOT | ||
* benjamin.danglot@inria.fr | ||
* on 12/13/16 | ||
*/ | ||
public class DSpotTest { | ||
|
||
|
||
@Test | ||
public void test() throws Exception, InvalidSdkException { | ||
|
||
/* | ||
Test the whole dspot procedure. | ||
It results with 20 methods: 7 manual + 13 amplified. | ||
The test consist of assert that the manual test remains, and there is an amplified version | ||
*/ | ||
|
||
addMavenHomeToPropertiesFile(); | ||
AmplificationHelper.setSeedRandom(23L); | ||
InputConfiguration configuration = new InputConfiguration(pathToPropertiesFile); | ||
InputProgram program = new InputProgram(); | ||
configuration.setInputProgram(program); | ||
DSpot dspot = new DSpot(configuration); | ||
|
||
CtType amplifiedTest = dspot.amplifyTest("example.TestSuiteExample"); | ||
assertEquals(19, amplifiedTest.getMethods().size()); | ||
assertEquals(originalTestBody, amplifiedTest.getMethod("test1").getBody().toString()); | ||
assertEquals(expectedAmplifiedBody, amplifiedTest.getMethod("test1_cf5_cf236").getBody().toString()); | ||
} | ||
|
||
private final String pathToPropertiesFile = "src/test/resources/test-projects/test-projects.properties"; | ||
|
||
private final String nl = System.getProperty("line.separator"); | ||
|
||
private final String originalTestBody = "{" + nl + | ||
" example.Example ex = new example.Example();" + nl + | ||
" org.junit.Assert.assertEquals('a', ex.charAt(\"abcd\", 0));" + nl + | ||
"}"; | ||
|
||
private final String expectedAmplifiedBody = "{" + nl + | ||
" example.Example ex = new example.Example();" + nl + | ||
" int vc_1 = 0;" + nl + | ||
" junit.framework.Assert.assertEquals(vc_1, 0);" + nl + | ||
" java.lang.String s = \"abcd\";" + nl + | ||
" junit.framework.Assert.assertEquals(s, \"abcd\");" + nl + | ||
" char o_test1_cf5_cf236__5 = ex.charAt(s, vc_1);" + nl + | ||
" junit.framework.Assert.assertEquals(o_test1_cf5_cf236__5, 'a');" + nl + | ||
" int vc_35 = 715956334;" + nl + | ||
" junit.framework.Assert.assertEquals(vc_35, 715956334);" + nl + | ||
" java.lang.String vc_10 = \"abcd\";" + nl + | ||
" junit.framework.Assert.assertEquals(vc_10, \"abcd\");" + nl + | ||
" char o_test1_cf5_cf236__8 = ex.charAt(vc_10, vc_35);" + nl + | ||
" junit.framework.Assert.assertEquals(o_test1_cf5_cf236__8, 'd');" + nl + | ||
" org.junit.Assert.assertEquals('a', ex.charAt(\"abcd\", 0));" + nl + | ||
"}"; | ||
|
||
// hack to add maven.home to the properties automatically for travis. | ||
private void addMavenHomeToPropertiesFile() { | ||
final String mavenHome = Utils.buildMavenHome(); | ||
if (mavenHome != null) { | ||
try { | ||
FileWriter writer = new FileWriter(pathToPropertiesFile, true); | ||
writer.write(nl + "maven.home=" + mavenHome + nl); | ||
writer.close(); | ||
} catch (IOException ignored) { | ||
//ignored | ||
} | ||
} | ||
} | ||
} |
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,21 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>fr.inria.lille.toolset</groupId> | ||
<artifactId>test-projects</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>test-projects</name> | ||
|
||
<properties> | ||
<default.encoding>UTF-8</default.encoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
29 changes: 29 additions & 0 deletions
29
src/test/resources/test-projects/src/main/java/example/Example.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,29 @@ | ||
package example; | ||
|
||
public class Example { | ||
|
||
/* | ||
* Return the index char of s | ||
* or the last if index > s.length | ||
* or the first if index < 0 | ||
*/ | ||
public char charAt(String s, int index){ | ||
|
||
if ( index <= 0 ) // Fix index <= 0 | ||
return s.charAt(0); | ||
|
||
if ( index < s.length() ) | ||
return s.charAt(index); | ||
|
||
return s.charAt(s.length()-1); | ||
} | ||
|
||
public Example() { | ||
int variableInsideConstructor; | ||
variableInsideConstructor = 15; | ||
index = 2 * variableInsideConstructor; | ||
} | ||
|
||
private int index = 419382; | ||
private static String s = "Overloading field name with parameter name"; | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/resources/test-projects/src/test/java/example/TestSuiteExample.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,52 @@ | ||
package example; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TestSuiteExample { | ||
|
||
@Test | ||
public void test1(){ | ||
Example ex = new Example(); | ||
assertEquals('a', ex.charAt("abcd", 0)); | ||
} | ||
|
||
@Test | ||
public void test2(){ | ||
Example ex = new Example(); | ||
assertEquals('d', ex.charAt("abcd", 3)); | ||
} | ||
|
||
@Test | ||
public void test3(){ | ||
Example ex = new Example(); | ||
String s = "abcd"; | ||
assertEquals('d', ex.charAt(s, s.length()-1)); | ||
} | ||
|
||
@Test | ||
public void test4(){ | ||
Example ex = new Example(); | ||
String s = "abcd"; | ||
assertEquals('d', ex.charAt(s, 12)); | ||
} | ||
|
||
@Test | ||
public void test7(){ | ||
Example ex = new Example(); | ||
assertEquals('c', ex.charAt("abcd", 2)); | ||
} | ||
|
||
@Test | ||
public void test8(){ | ||
Example ex = new Example(); | ||
assertEquals('b', ex.charAt("abcd", 1)); | ||
} | ||
|
||
@Test | ||
public void test9(){ | ||
Example ex = new Example(); | ||
assertEquals('f', ex.charAt("abcdefghijklm", 5)); | ||
} | ||
} |
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,5 @@ | ||
project=src/test/resources/test-projects | ||
src=src/main/java/ | ||
testSrc=src/test/java | ||
javaVersion=8 | ||
filter=example |