Skip to content

Commit

Permalink
fix: quote and dquote are discarded for the random char
Browse files Browse the repository at this point in the history
  • Loading branch information
danglotb committed Dec 20, 2016
1 parent eb9a750 commit f6cd206
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
17 changes: 7 additions & 10 deletions src/main/java/fr/inria/diversify/dspot/amp/TestDataMutator.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,11 @@ protected List<CtMethod> createAllStringMutant(CtMethod method, CtLiteral litera
}


protected CtMethod createStringMutant(CtMethod method, int original_lit_index, String newValue) {
private CtMethod createStringMutant(CtMethod method, int original_lit_index, String newValue) {
dataCount++;
//clone the method
CtMethod cloned_method = AmplificationHelper.cloneMethod(method, "_literalMutation");
//get the lit_indexth literal of the cloned method
CtLiteral newLiteral = Query.getElements(cloned_method, new TypeFilter<CtLiteral>(CtLiteral.class))
.get(original_lit_index);

newLiteral.setValue(newValue);

Query.getElements(cloned_method, new TypeFilter<>(CtLiteral.class))
.get(original_lit_index).replace(cloned_method.getFactory().Code().createLiteral(newValue));
return cloned_method;
}

Expand Down Expand Up @@ -170,8 +165,10 @@ protected Set<String> stringMutated(CtLiteral literal) {
return values;
}

protected char getRandomChar() {
return (char) (AmplificationHelper.getRandom().nextInt(94) + 32);
private char getRandomChar() {
int value = AmplificationHelper.getRandom().nextInt(94) + 32;
char c = (char) ((value == 34 || value == 39) ? value + (AmplificationHelper.getRandom().nextBoolean() ? 1 : -1) : value);
return c;//excluding " and '
}

protected Set<? extends Number> numberMutated(CtLiteral literal) {
Expand Down
33 changes: 19 additions & 14 deletions src/test/java/fr/inria/diversify/dspot/DSpotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ public void test() throws Exception, InvalidSdkException {
DSpot dspot = new DSpot(configuration);

CtType amplifiedTest = dspot.amplifyTest("example.TestSuiteExample");
assertEquals(19, amplifiedTest.getMethods().size());
assertEquals(18, amplifiedTest.getMethods().size());
assertEquals(originalTestBody, amplifiedTest.getMethod("test1").getBody().toString());
assertEquals(expectedAmplifiedBody, amplifiedTest.getMethod("test1_cf5_cf236").getBody().toString());

amplifiedTest.getMethods();

assertEquals(expectedAmplifiedBody, amplifiedTest.getMethod("test1_cf6_cf34_cf167").getBody().toString());
}

private final String pathToPropertiesFile = "src/test/resources/test-projects/test-projects.properties";
Expand All @@ -53,18 +56,20 @@ public void test() throws Exception, InvalidSdkException {

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 +
" int vc_5 = -619987209;" + nl +
" junit.framework.Assert.assertEquals(vc_5, -619987209);" + nl +
" java.lang.String vc_0 = \"abcd\";" + nl +
" junit.framework.Assert.assertEquals(vc_0, \"abcd\");" + nl +
" char o_test1_cf6_cf34_cf167__5 = ex.charAt(vc_0, vc_5);" + nl +
" junit.framework.Assert.assertEquals(o_test1_cf6_cf34_cf167__5, 'a');" + nl +
" char o_test1_cf6_cf34_cf167__6 = ex.charAt(vc_0, vc_5);" + nl +
" junit.framework.Assert.assertEquals(o_test1_cf6_cf34_cf167__6, 'a');" + nl +
" int vc_29 = 995075168;" + nl +
" junit.framework.Assert.assertEquals(vc_29, 995075168);" + nl +
" java.lang.String vc_8 = \"abcd\";" + nl +
" junit.framework.Assert.assertEquals(vc_8, \"abcd\");" + nl +
" char o_test1_cf6_cf34_cf167__9 = ex.charAt(vc_8, vc_29);" + nl +
" junit.framework.Assert.assertEquals(o_test1_cf6_cf34_cf167__9, 'd');" + nl +
" org.junit.Assert.assertEquals('a', ex.charAt(\"abcd\", 0));" + nl +
"}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ private void assertDistanceBetweenOriginalAndMuted(String original, String mutan
}
}

assertTrue(addCharAssertion || removeCharAssertion || (diffFound && replaceCharAssertion) || "MySecondStringLiteral".equals(mutant));
System.out.println(mutant);

assertTrue(addCharAssertion || removeCharAssertion || (diffFound && replaceCharAssertion) || "".equals(mutant));
}

@Test
Expand Down

0 comments on commit f6cd206

Please sign in to comment.