How to get method level coverage with gcovr? - code-coverage

I've been working with gcovr to generate coverage data for my whole project.
I am able to generate summary reports like this:
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: ...../src/
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
src/A/A1/xyz.cpp 1609 2 0% 97,99,101....
src/A/A2/abcg.cpp 271 4 1% .......
src/B/B1/mnop.cpp 74 2 2% 34,42,56-.....
src/B/B2/wrds.cpp 1533 6 0% 76,83,85-.....
src/C/C1/abcdefg.cpp 1079 8 0% 143,150,152.....
with total and everything else too, but this data is at source level. So I tried generating xml files which had the same kind of data in xml format. When I finally generated denser xml file with line level coverage like this one:
<class branch-rate="0.285714285714" complexity="0.0" filename="src/absc/mno/xyz/ahgs.cpp" line-rate="0.231481481481" name="os_clib_hxx">
<methods/>
<lines>
<line branch="false" hits="0" number="200"/>
<line branch="false" hits="0" number="202"/>
<line branch="false" hits="3" number="208"/>
<line branch="false" hits="3" number="210"/>
<line branch="false" hits="63" number="213"/>
<line branch="true" condition-coverage="50% (1/2)" hits="63" number="215">
<conditions>
<condition coverage="50%" number="0" type="jump"/>
</conditions>
</line>
<line branch="false" hits="0" number="218"/>
.........
..........
I still couldn't find anything method level.
I know it is possible with gcov to generate method level coverage for one file at a time, but that is not possible in my case as I am working with thousands of files, for which if I try to generate data for each of them by any method it would be problematic.

Unfortunately, gcovr is not currently able to report coverage on a per-function basis.
The XML report contains an empty <methods/> section because this section is required by the DTD schema for the Cobertura XML format, but it does not contain useful data. Similarly, other XML fields like complexity just contain dummy data.

Related

How to concatenate paths returned from `fileset` into the XML file?

I'm trying to concatenate an unknown number of HTML files into one XML file.
That's no problem with:
<concat destfile="${temp.dir}/file.xml" encoding="UTF-8" outputencoding="UTF-8">
<fileset dir="${html.dir}" includes="**/*.html" />
</concat>
Now what I would like to do is, for each file of the fileset, insert its path into the concatenated file.
Example
I have the following HTML files in C:\whatever\sources:
A.html
B.html
In the result XML file, I'd like to get:
<allfiles>
<html url="C:\whatever\sources\A.html>...content of A.html...</html>
<html url="C:\whatever\sources\B.html>...content of B.html...</html>
</allfiles>
Is there a way to do that simply without reinventing the wheel and if possible without using ant-contrib?
As mentioned, you can use a scriptfilter inside filterchain task to run Javascript inside your Ant build.
For example:
<concat destfile="${temp.dir}/file.xml" encoding="UTF-8" outputencoding="UTF-8">
<fileset dir="${html.dir}" includes="**/*.html" id="my-files"/>
<filterchain>
<tokenfilter>
<filetokenizer />
<scriptfilter language="javascript" byline="false"><![CDATA[
content = self.getToken();
// Modify content of token.
//content=content.replaceAll("(?s)/\\*.*?\\*/","");
self.setToken(content);
]]></scriptfilter>
</tokenfilter>
<striplinecomments>
<comment value="//"/>
</striplinecomments>
<striplinebreaks/>
</filterchain>
</concat>
Find more examples at:
JavaExplorer/blob/master/static/build.xml
Getting file name inside Ant copy task filter
Using Ant scriptfilter to count lines

ant Task for or foreach loop in xml files

I need some help on looping through an xml file which I manged to get the nodes using xmlproperty but I am struggling on how to loop through them where there are more than one params.
So here is the format:
<Problems>
<Problem>
<Rule>1</Rule>
<ProblemDescription>1</ProblemDescription>
<SourceFile>1</SourceFile>
<Line>1</Line>
<Column>1</Column>
<Severity>Warning</Severity>
</Problem>
<Problem>
<Rule>2</Rule>
<ProblemDescription>2</ProblemDescription>
<SourceFile>2</SourceFile>
<Line>2</Line>
<Column>2</Column>
<Severity>Warning</Severity>
</Problem>
</problems>
I want to loop through this so I can get the following output:
1
1
1
1
1
1
2
2
2
2
2
Solution:
<target>
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
<xmltask source="problem.xml">
<call path="/Problems/Problem">
<param name="rule" path="Rule/text()" />
<param name="probdesc" path="ProblemDescription/text()" />
<actions>
<echo>Rule: #{rule}</echo>
<echo>Problem Description: #{probdesc}</echo>
</actions>
</call>
</target>
You can use an XPATH expression to return everything that matches a given pattern. In your case, the value of certain tags.
Here is an XPATH Ant task.
Haven't used ANT in years, not since I switched to maven.
When I was using ant I would create a custom ant task for this sort of functionality. Then you have the full power of java and far more readable code, at the cost of having to compile the task if you need to make changes.
It really depends on what you are going to do with the output. The other answer with xpath is more appropriate if your doing something really simple.
See:
http://ant.apache.org/manual/develop.html
http://docs.oracle.com/javase/tutorial/jaxp/sax/parsing.html

JaCoCo report looks correct but can not view source

I am new to JaCoCo and trying to figure out why the html report that I am generating is not linked with my source.
The coverage numbers look correct and I can browse down to each class and then each method but I can not see the source. I have tried many different things inside the sourcefiles tag but nothing is working. Has anyone else had this issue? Here is a snippet of my ant script:
...
<test name="test.fw.UITestSuite" todir="${logdir}"/>
</junit>
</jacoco:coverage>
<fail if="TestFailed" status="1" message="UI junit test failure detected"/>
<echo message="${src}"/>
<jacoco:report>
<executiondata>
<file file="jacoco.exec"/>
</executiondata>
<structure name="UI">
<classfiles>
<fileset dir="${build}/fw"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="fw" includes="**./*.java"/>
</sourcefiles>
</structure>
<html destdir="report"/>
</jacoco:report>
</target>
...
Your fileset definition seems odd.
The include must be (the first . is misplaced):
includes="**/*.java
Try simply pointing it to the root of your src dir (there is no need for the includes)
<fileset dir="fw" />
But fw has to be the root of your sources, i.e. it contains the package folders like:
src
-org
-module
-MyClass1.java
-MyClass2.java
I’ve seen this break when using Scala-style package directory names, e.g.,
src/main/java/com.example.foo.bar/Foo.java
for fewer levels of nesting, faster autocompletion, &c., compared to the standard
src/main/java/com/example/foo/bar/Foo.java
Most tools support the first version just fine, but usually if you try it out and everything works fine, by the time you notice something like the jacoco reports not showing the source anymore, you’ve long forgotten the directory name change …

svg transform matrix parser

problem explain:
transform = "matrix(cos(a), sin(a), -sin(a), cos(a), -x1cos(a)+y1sin(a)+x2, -x1sin(a)-y1cos(a)+y2)"
can see 7.4 Coordinate system transformations
to be resolved:
in my work,i must resolve to parse matrix
example:
<?xml version="1.0" encoding="utf-8"?><svg width="800" height="500" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:PerfectSVG="http://www.perfectsvg.com/PerfectSVG" xml:space="preserve">
<defs>
<symbol overflow="visible" id="symbol1" connectPoints="15 70 50 0 87 68">
<g>
<line x1="300" y1="200" x2="309" y2="200" transform="matrix(1,0,0,1,0,0)" />
<line x1="311" y1="200" x2="320" y2="200" transform="matrix(1,0,0,1,0,0)" />
<line x1="300" y1="200" x2="304.75" y2="207.75" transform="matrix(1,0,0,1,0,0)" />
<line x1="315.75" y1="207" x2="320" y2="200" transform="matrix(1,0,0,1,0,0)" />
<line x1="309.25" y1="197.5" x2="309.25" y2="202.25" transform="matrix(1,0,0,1,0,0)"/>
<line x1="311" y1="197.25" x2="311" y2="202.5" transform="matrix(1,0,0,1,0,0)"/>
<line x1="313.75" y1="205.5" x2="318" y2="208.5" transform="matrix(1,0,0,1,0,0)"/>
<line x1="302.75" y1="209.5" x2="307.25" y2="206" transform="matrix(1,0,0,1,0,0)"/>
<line x1="303.75" y1="211" x2="308.25" y2="207.5" transform="matrix(1,0,0,1,0,0)"/>
<line x1="306" y1="209.25" x2="310.25" y2="215.5" transform="matrix(1,0,0,1,0,0)"/>
<line x1="312.75" y1="207.25" x2="317.25" y2="210.5" transform="matrix(1,0,0,1,0,0)"/>
<line x1="310.25" y1="215.25" x2="314.5" y2="208.75" transform="matrix(1,0,0,1,0,0)"/>
</g>
</symbol></defs><use xlink:href="#symbol1" transform="matrix(3.774,-2.246,2.246,3.774,-1562.468,-12.947)" stroke="#000000" fill="#FFFFFF" id="use3" stroke-width="0.2276867"/></svg>
Now:
i want to know In:transform="matrix(3.774,-2.246,2.246,3.774,-1562.468,-12.947)" out:(a:angle x1,y1:The original coordinates x2,y2:New coordinates) from the example
who can give suggestions or Some reference materials
tks.
It's impossible to get old x/y and new x/y only by transform data.
You must have two of the three data.
You can use getBBox method to get the outer box, and then you can get the box's dots.

Something to dynamically Generate a UI to edit XML file?

I have an XML file with a lot of nodes similar to the following format:
<Factsheet page="GenericOfflineFactsheet.aspx" pageTitle="MyTitle" >
<TopStrapline text="BlahBlahBlah" />
<Commentary page="Text.ascx" />
<ChartPanel page="Bar.ascx" appearanceFile="Bar.xml" />
<Strapline text="blah blah blah" />
<Funds>
<fund id="215" countryid="N0" />
<fund id="561" countryid="N0" />
</Funds>
<LegalText effectiveDate="08 June 2010">
<Line id="30321" />
<Line id="10301" />
</LegalText>
</Factsheet>
Is there any free plugins (or any other means) out there that I could use in an ASP.NET MVC application to generate a basic UI for editing this kind of file?
What about LinqToXML? Then you can use this as your model in your controllers and views just like LinqToSQL.
LinqToXML

Resources