X-Git-Url: http://jaekl.net/gitweb/?p=cfb.git;a=blobdiff_plain;f=test%2Fnet%2Fjaekl%2Fcfb%2Fanalyze%2FDeltaTest.java;fp=test%2Fnet%2Fjaekl%2Fcfb%2Fanalyze%2FDeltaTest.java;h=04f1dcd4338d9dab398f884e706460967a3555af;hp=0000000000000000000000000000000000000000;hb=e39cfda923b6edce0fb80211cc927a7534abba10;hpb=327080b11e9161f059432b680a97c9341deb4a5c
diff --git a/test/net/jaekl/cfb/analyze/DeltaTest.java b/test/net/jaekl/cfb/analyze/DeltaTest.java
new file mode 100644
index 0000000..04f1dcd
--- /dev/null
+++ b/test/net/jaekl/cfb/analyze/DeltaTest.java
@@ -0,0 +1,211 @@
+package net.jaekl.cfb.analyze;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.HashSet;
+
+import net.jaekl.cfb.util.Command;
+import net.jaekl.cfb.xml.BugInstance;
+
+import org.junit.Test;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class DeltaTest {
+ private static final String DM_DEFAULT_ENCODING = ""
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n";
+
+ private static final String RCN_REDUNDANT_NULL_CHECK = ""
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n"
+ + "\n";
+
+ /*
+ private static String VO_VOLATILE_INCREMENT = ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "";
+ */
+
+ private static final String DM_NUMBER_CTOR_156 = ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "";
+
+ private static final String DM_NUMBER_CTOR_169 = ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + ""
+ + "";
+
+ private static final String PROLOGUE = ""
+ + "\n"
+ + "\n"
+ + "\n"
+ + "/home/chris/prog/././cfb/bin\n"
+ + "/home/chris/prog/././cfb/src\n"
+ + "\n";
+
+ private static final String EPILOGUE = ""
+ + "\n";
+
+ private Analysis analysisFromXml(String xml, String projectName, String version)
+ throws FileNotFoundException, IOException, SAXException
+ {
+ Analysis analysis = new Analysis(projectName, version);
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes(Command.UTF_8));
+ InputSource inputSource = new InputSource(bais);
+ analysis.parse(inputSource);
+
+ return analysis;
+ }
+
+ private HashSet buildSet(String[][] bugSpecs, int from, int to)
+ {
+ HashSet set = new HashSet();
+ for (int i = from; i <= to; ++i) {
+ set.add(bugSpecs[i][1]);
+ }
+
+ return set;
+ }
+
+ private String buildXml(String[][] bugSpecs, int from, int to)
+ {
+ StringBuilder sb = new StringBuilder(PROLOGUE);
+ for (int i = from; i <= to; ++i) {
+ sb.append(bugSpecs[i][0]);
+ }
+ sb.append(EPILOGUE);
+
+ return sb.toString();
+ }
+
+ private boolean contains(BugInstance[] bugs, String bugName)
+ {
+ for (BugInstance bug : bugs) {
+ if (bugName.equals(bug.getType())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void execDeltaForRanges (String[][] bugSpecs, int w, int x, int y, int z) throws FileNotFoundException, IOException, SAXException
+ {
+ final String PROJECT_NAME = "ProjectName";
+ String firstXml = buildXml(bugSpecs, w, x);
+ String secondXml = buildXml(bugSpecs, y, z);
+ HashSet firstSet = buildSet(bugSpecs, w, x);
+ HashSet secondSet = buildSet(bugSpecs, y, z);
+
+ Analysis first = analysisFromXml(firstXml, PROJECT_NAME, "1.0.1");
+ Analysis second = analysisFromXml(secondXml, PROJECT_NAME, "1.0.2");
+
+ assertNotNull(first);
+ assertNotNull(second);
+
+ Delta delta = new Delta(first, second);
+
+ for (int i = 0; i < bugSpecs.length; ++i) {
+ String bugName = bugSpecs[i][1];
+ if (firstSet.contains(bugName) && secondSet.contains(bugName)) {
+ assertTrue(contains(delta.getCommon(), bugName));
+ assertFalse(contains(delta.getFixed(), bugName));
+ assertFalse(contains(delta.getNew(), bugName));
+ }
+ else if (firstSet.contains(bugName) && !secondSet.contains(bugName)) {
+ assertFalse(contains(delta.getCommon(), bugName));
+ assertTrue(contains(delta.getFixed(), bugName));
+ assertFalse(contains(delta.getNew(), bugName));
+ }
+ else if (!firstSet.contains(bugName) && secondSet.contains(bugName)) {
+ assertFalse(contains(delta.getCommon(), bugName));
+ assertFalse(contains(delta.getFixed(), bugName));
+ assertTrue(contains(delta.getNew(), bugName));
+ }
+ else if (!firstSet.contains(bugName) && !secondSet.contains(bugName)) {
+ assertFalse(contains(delta.getCommon(), bugName));
+ assertFalse(contains(delta.getFixed(), bugName));
+ assertFalse(contains(delta.getNew(), bugName));
+ }
+ }
+ }
+
+ @Test
+ public void test_computeDeltas() throws FileNotFoundException, IOException, SAXException {
+ String[][] bugSpecs = {
+ { DM_DEFAULT_ENCODING, "DM_DEFAULT_ENCODING" },
+ { RCN_REDUNDANT_NULL_CHECK, "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" },
+ { DM_NUMBER_CTOR_156, "DM_NUMBER_CTOR" },
+ { DM_NUMBER_CTOR_169, "DM_NUMBER_CTOR" }
+ };
+
+ for (int w = 0; w < bugSpecs.length; ++w) {
+ for (int x = w + 1; x < bugSpecs.length; ++x) {
+ for (int y = 0; y < bugSpecs.length; ++y) {
+ for (int z = y + 1; z < bugSpecs.length; ++z) {
+ execDeltaForRanges(bugSpecs, w, x, y, z);
+ }
+ }
+ }
+ }
+ }
+
+}