Skip to content

Commit

Permalink
fixed top-level coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmkeeble committed Dec 4, 2016
1 parent d3e2944 commit a11cd64
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,12 @@ public VectorCASTBuildAction getPreviousResult() {
*/
public static VectorCASTBuildAction load(AbstractBuild<?,?> owner, Rule rule, VectorCASTHealthReportThresholds thresholds, FilePath... files) throws IOException {
Ratio ratios[] = null;
boolean[] flag = {false};
for (FilePath f: files ) {
InputStream in = null;
try {
in = f.read();
ratios = loadRatios(in, ratios);
ratios = loadRatios(in, ratios, flag);
} catch (XmlPullParserException e) {
throw new IOException2("Failed to parse " + f, e);
} catch (InterruptedException e) {
Expand All @@ -264,23 +265,25 @@ public static VectorCASTBuildAction load(AbstractBuild<?,?> owner, Rule rule, Ve
}
}
}

return new VectorCASTBuildAction(owner,rule,ratios[0],ratios[1],ratios[2],ratios[3],ratios[4],ratios[5],ratios[6],thresholds);
}

public static VectorCASTBuildAction load(AbstractBuild<?,?> owner, Rule rule, VectorCASTHealthReportThresholds thresholds, InputStream... streams) throws IOException, XmlPullParserException {
Ratio ratios[] = null;
boolean[] flag = {false};
for (InputStream in: streams) {
ratios = loadRatios(in, ratios);
ratios = loadRatios(in, ratios, flag);
}
return new VectorCASTBuildAction(owner,rule,ratios[0],ratios[1],ratios[2],ratios[3],ratios[4],ratios[5],ratios[6],thresholds);
}

private static Ratio[] loadRatios(InputStream in, Ratio[] r) throws IOException, XmlPullParserException {

private static Ratio[] loadRatios(InputStream in, Ratio[] r, boolean[] topLevel) throws IOException, XmlPullParserException {

System.out.println("RMK: topLevel = " + topLevel[0]);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);

XmlPullParser parser = factory.newPullParser();

parser.setInput(in,null);
Expand All @@ -291,7 +294,7 @@ private static Ratio[] loadRatios(InputStream in, Ratio[] r) throws IOException,
if (parser.getName().equals("version")) {
versionRead = parser.getAttributeValue("", "value");
}
if(!parser.getName().equals("coverage"))
if(!parser.getName().equals("coverage") && !parser.getName().equals("combined-coverage"))
continue;
break;
}
Expand All @@ -302,16 +305,24 @@ private static Ratio[] loadRatios(InputStream in, Ratio[] r) throws IOException,

if (r == null || r.length < 7)
r = new Ratio[7];

// head for the first <coverage> tag.
for( int i=0; i<r.length; i++ ) {
if(!parser.getName().equals("coverage"))
boolean combined = false;
if(!parser.getName().equals("coverage") && !parser.getName().equals("combined-coverage"))
break;

parser.require(XmlPullParser.START_TAG,"","coverage");
if (parser.getName().equals("coverage")) {
parser.require(XmlPullParser.START_TAG,"","coverage");
combined = false;
} else if (parser.getName().equals("combined-coverage")) {
parser.require(XmlPullParser.START_TAG,"","combined-coverage");
combined = true;
topLevel[0] = true;
}
String v = parser.getAttributeValue("", "value");
String t = parser.getAttributeValue("", "type");

int index ;
if ( t.equals("statement, %") )
index = 0;
Expand All @@ -329,19 +340,24 @@ else if ( t.equals("complexity, %") )
index = 6;
else
continue;



if (r[index] == null) {
r[index] = Ratio.parseValue(v);
} else {
r[index].addValue(v);
if (combined) {
r[index].setValue(v);
} else {
if (!topLevel[0]) {
r[index].addValue(v);
}
}
}

// move to the next coverage tag.
parser.nextTag();
parser.nextTag();
}

return r;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,33 @@
*/
public class VectorCASTBuildActionTest extends AbstractVectorCASTTestBase {

public void testLoadReport1() throws Exception {
public void testLoadReport1a() throws Exception {
VectorCASTBuildAction r = VectorCASTBuildAction.load(null,null,
new VectorCASTHealthReportThresholds(30, 90, 25, 80, 20, 70, 15, 60, 20, 70, 80, 90),
getClass().getResourceAsStream("top-level.xml"),
getClass().getResourceAsStream("coverage.xml"));
assertEquals(42, r.Statement.getPercentage());
assertEquals(26, r.Branch.getPercentage());
assertRatio(r.Statement, 23, 55);
assertRatio(r.Branch, 13, 50);
assertRatio(r.MCDC, 1, 12);
assertEquals(75, r.Statement.getPercentage());
assertEquals(33, r.Branch.getPercentage());
assertRatio(r.Statement, 45, 60);
assertRatio(r.Branch, 18, 54);
assertRatio(r.MCDC, 7, 14);
assert(r.Function == null);
assertEquals("Coverage: Statement 23/55 (42%). Branch 13/50 (26%). MC/DC 1/12 (8%). ",
assertEquals("Coverage: Statement 45/60 (75%). Branch 18/54 (33%). MC/DC 7/14 (50%). ",
r.getBuildHealth().getDescription());
}

public void testLoadReport1b() throws Exception {
VectorCASTBuildAction r = VectorCASTBuildAction.load(null,null,
new VectorCASTHealthReportThresholds(30, 90, 25, 80, 20, 70, 15, 60, 20, 70, 80, 90),
getClass().getResourceAsStream("coverage.xml"),
getClass().getResourceAsStream("top-level.xml"));
assertEquals(75, r.Statement.getPercentage());
assertEquals(33, r.Branch.getPercentage());
assertRatio(r.Statement, 45, 60);
assertRatio(r.Branch, 18, 54);
assertRatio(r.MCDC, 7, 14);
assert(r.Function == null);
assertEquals("Coverage: Statement 45/60 (75%). Branch 18/54 (33%). MC/DC 7/14 (50%). ",
r.getBuildHealth().getDescription());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
<combined-coverage type="mcdc, %" value="50% (7 / 14)"/>
<combined-coverage type="complexity, %" value="0% (74 / 0)"/>
</report>

0 comments on commit a11cd64

Please sign in to comment.