Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added some tests for the Remove Thread Calls operator
- Loading branch information
1 parent
b8d2ba5
commit 7178faf
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...he/mutation/bytecodeMutations/replaceThreadCalls/ReplaceThreadCallsPossibilitiesTest.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,60 @@ | ||
/* | ||
* Copyright (C) 2011 Saarland University | ||
* | ||
* This file is part of Javalanche. | ||
* | ||
* Javalanche is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Javalanche is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser Public License | ||
* along with Javalanche. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceThreadCalls; | ||
|
||
import static de.unisb.cs.st.javalanche.mutation.results.Mutation.MutationType.*; | ||
import static junit.framework.Assert.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import de.unisb.cs.st.javalanche.mutation.bytecodeMutations.ByteCodeTestUtils; | ||
import de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceThreadCalls.classes.WaitNotifyTEMPLATE; | ||
import de.unisb.cs.st.javalanche.mutation.properties.ConfigurationLocator; | ||
import de.unisb.cs.st.javalanche.mutation.properties.JavalancheConfiguration; | ||
import de.unisb.cs.st.javalanche.mutation.results.Mutation; | ||
import de.unisb.cs.st.javalanche.mutation.testutil.TestUtil; | ||
import de.unisb.cs.st.javalanche.mutation.util.JavalancheTestConfiguration; | ||
|
||
public class ReplaceThreadCallsPossibilitiesTest { | ||
|
||
@Test | ||
public void testForOneClass() throws Exception { | ||
JavalancheConfiguration back = ConfigurationLocator | ||
.getJavalancheConfiguration(); | ||
try { | ||
JavalancheTestConfiguration config = new JavalancheTestConfiguration(); | ||
config.setMutationType(REPLACE_THREAD_CALL, true); | ||
ConfigurationLocator.setJavalancheConfiguration(config); | ||
Class<?> clazz = WaitNotifyTEMPLATE.class; // TODO not all replace | ||
// types in class. | ||
ByteCodeTestUtils.deleteMutations(clazz.getCanonicalName()); | ||
List<Mutation> possibilities = TestUtil | ||
.getMutationsForClazzOnClasspath(clazz); | ||
int possibilityCount = TestUtil.filterMutations(possibilities, | ||
REPLACE_THREAD_CALL).size(); | ||
int expectedMutations = 8; | ||
assertEquals("Expected different number of mutations for class " | ||
+ clazz, expectedMutations, possibilityCount); | ||
} finally { | ||
ConfigurationLocator.setJavalancheConfiguration(back); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
.../unisb/cs/st/javalanche/mutation/bytecodeMutations/replaceThreadCalls/WaitNotifyTest.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,54 @@ | ||
/* | ||
* Copyright (C) 2011 Saarland University | ||
* | ||
* This file is part of Javalanche. | ||
* | ||
* Javalanche is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Javalanche is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser Public License | ||
* along with Javalanche. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceThreadCalls; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.Test; | ||
|
||
import de.unisb.cs.st.javalanche.mutation.bytecodeMutations.BaseBytecodeTest; | ||
import de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceThreadCalls.classes.WaitNotifyTEMPLATE; | ||
import de.unisb.cs.st.javalanche.mutation.results.Mutation.MutationType; | ||
|
||
public class WaitNotifyTest extends BaseBytecodeTest { | ||
|
||
private Class<?> clazz; | ||
|
||
public WaitNotifyTest() throws Exception { | ||
super(WaitNotifyTEMPLATE.class); | ||
config.setMutationType(MutationType.REPLACE_THREAD_CALL, true); | ||
// verbose = true; | ||
clazz = prepareTest(); | ||
} | ||
|
||
@Test | ||
public void testReplaceNotifyAll() throws Exception { | ||
Method m1 = clazz.getMethod("m1"); | ||
checkUnmutated(2, m1, clazz); | ||
checkMutation(42, MutationType.REPLACE_THREAD_CALL, 0, 1, m1, clazz); | ||
} | ||
|
||
@Test | ||
public void testReplaceNotify() throws Exception { | ||
Method m2 = clazz.getMethod("m2"); | ||
checkUnmutated(1, m2, clazz); | ||
checkMutation(65, MutationType.REPLACE_THREAD_CALL, 0, 2, m2, clazz); | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
.../javalanche/mutation/bytecodeMutations/replaceThreadCalls/classes/WaitNotifyTEMPLATE.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,76 @@ | ||
package de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceThreadCalls.classes; | ||
|
||
public class WaitNotifyTEMPLATE { | ||
|
||
private static class HelperRunnable implements Runnable { | ||
|
||
private final Object o; | ||
|
||
private boolean finished; | ||
|
||
public HelperRunnable(Object o) { | ||
this.o = o; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
synchronized (o) { | ||
try { | ||
o.wait(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
finished = true; | ||
} | ||
} | ||
|
||
public synchronized boolean isFinsished() { | ||
return finished; | ||
} | ||
} | ||
|
||
public static int m1() throws Exception { | ||
Object a = new Object(); | ||
HelperRunnable hr1 = new HelperRunnable(a); | ||
HelperRunnable hr2 = new HelperRunnable(a); | ||
Thread t1 = new Thread(hr1); | ||
Thread t2 = new Thread(hr2); | ||
t1.start(); | ||
t2.start(); | ||
Thread.sleep(40); | ||
synchronized (a) { | ||
a.notifyAll(); | ||
} | ||
Thread.sleep(40); | ||
int result = 0; | ||
result += hr1.isFinsished() ? 1 : 0; | ||
result += hr2.isFinsished() ? 1 : 0; | ||
synchronized (a) { | ||
a.notifyAll(); // Threads can finish executing when mutation is | ||
// applied | ||
} | ||
return result; | ||
} | ||
|
||
public static int m2() throws Exception { | ||
Object a = new Object(); | ||
HelperRunnable hr1 = new HelperRunnable(a); | ||
HelperRunnable hr2 = new HelperRunnable(a); | ||
Thread t1 = new Thread(hr1); | ||
Thread t2 = new Thread(hr2); | ||
t1.start(); | ||
t2.start(); | ||
Thread.sleep(40); | ||
synchronized (a) { | ||
a.notify(); | ||
} | ||
Thread.sleep(40); | ||
int result = 0; | ||
result += hr1.isFinsished() ? 1 : 0; | ||
result += hr2.isFinsished() ? 1 : 0; | ||
synchronized (a) { | ||
a.notifyAll(); // Threads can finish executing | ||
} | ||
return result; | ||
} | ||
} |