Search in sources :

Example 11 with ExecutionData

use of org.jacoco.core.data.ExecutionData in project jacoco by jacoco.

the class ExecInfoTest method createExecFile.

private File createExecFile() throws IOException {
    File f = new File(tmp.getRoot(), "test.exec");
    final FileOutputStream out = new FileOutputStream(f);
    final ExecutionDataWriter writer = new ExecutionDataWriter(out);
    writer.visitSessionInfo(new SessionInfo("testid", 1, 2));
    writer.visitClassExecution(new ExecutionData(0x1234, "foo/MyClass", new boolean[] { false, true, true }));
    out.close();
    return f;
}
Also used : FileOutputStream(java.io.FileOutputStream) SessionInfo(org.jacoco.core.data.SessionInfo) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter) File(java.io.File) ExecutionData(org.jacoco.core.data.ExecutionData)

Example 12 with ExecutionData

use of org.jacoco.core.data.ExecutionData in project jacoco by jacoco.

the class ReportTest method should_print_warning_when_exec_data_does_not_match.

@Test
public void should_print_warning_when_exec_data_does_not_match() throws Exception {
    File exec = new File(tmp.getRoot(), "jacoco.exec");
    final FileOutputStream execout = new FileOutputStream(exec);
    ExecutionDataWriter writer = new ExecutionDataWriter(execout);
    // Add probably invalid id for this test class:
    writer.visitClassExecution(new ExecutionData(0x123, getClass().getName().replace('.', '/'), new boolean[] { true }));
    execout.close();
    execute("report", exec.getAbsolutePath(), "--classfiles", getClassPath());
    assertOk();
    assertContains("[WARN] Some classes do not match with execution data.", out);
    assertContains("[WARN] For report generation the same class files must be used as at runtime.", out);
    assertContains("[WARN] Execution data for class org/jacoco/cli/internal/commands/ReportTest does not match.", out);
}
Also used : FileOutputStream(java.io.FileOutputStream) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter) File(java.io.File) ExecutionData(org.jacoco.core.data.ExecutionData) Test(org.junit.Test)

Example 13 with ExecutionData

use of org.jacoco.core.data.ExecutionData in project jacoco by jacoco.

the class ExecDumpTest method createExecFile.

private String createExecFile() throws IOException {
    File f = File.createTempFile("jacoco", ".exec");
    final FileOutputStream out = new FileOutputStream(f);
    final ExecutionDataWriter writer = new ExecutionDataWriter(out);
    writer.visitSessionInfo(new SessionInfo("testid", 1, 2));
    writer.visitClassExecution(new ExecutionData(0x1234, "foo/MyClass", new boolean[] { false, true, true }));
    writer.flush();
    out.close();
    return f.getPath();
}
Also used : FileOutputStream(java.io.FileOutputStream) SessionInfo(org.jacoco.core.data.SessionInfo) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter) File(java.io.File) ExecutionData(org.jacoco.core.data.ExecutionData)

Example 14 with ExecutionData

use of org.jacoco.core.data.ExecutionData in project jacoco by jacoco.

the class ExecDump method dump.

private void dump(final String file) throws IOException {
    out.printf("exec file: %s%n", file);
    out.println("CLASS ID         HITS/PROBES   CLASS NAME");
    final FileInputStream in = new FileInputStream(file);
    final ExecutionDataReader reader = new ExecutionDataReader(in);
    reader.setSessionInfoVisitor(new ISessionInfoVisitor() {

        public void visitSessionInfo(final SessionInfo info) {
            out.printf("Session \"%s\": %s - %s%n", info.getId(), new Date(info.getStartTimeStamp()), new Date(info.getDumpTimeStamp()));
        }
    });
    reader.setExecutionDataVisitor(new IExecutionDataVisitor() {

        public void visitClassExecution(final ExecutionData data) {
            out.printf("%016x  %3d of %3d   %s%n", Long.valueOf(data.getId()), Integer.valueOf(getHitCount(data.getProbes())), Integer.valueOf(data.getProbes().length), data.getName());
        }
    });
    reader.read();
    in.close();
    out.println();
}
Also used : ISessionInfoVisitor(org.jacoco.core.data.ISessionInfoVisitor) SessionInfo(org.jacoco.core.data.SessionInfo) IExecutionDataVisitor(org.jacoco.core.data.IExecutionDataVisitor) FileInputStream(java.io.FileInputStream) Date(java.util.Date) ExecutionDataReader(org.jacoco.core.data.ExecutionDataReader) ExecutionData(org.jacoco.core.data.ExecutionData)

Example 15 with ExecutionData

use of org.jacoco.core.data.ExecutionData in project jacoco by jacoco.

the class SessionsPageTest method testExecutionDataContent.

@Test
public void testExecutionDataContent() throws Exception {
    final Collection<ExecutionData> data = new ArrayList<ExecutionData>();
    data.add(new ExecutionData(0x1000, "ClassB", new boolean[0]));
    data.add(new ExecutionData(0x1001, "ClassC", new boolean[0]));
    data.add(new ExecutionData(0x1002, "ClassA", new boolean[0]));
    index.addClass(new ReportPage(null, rootFolder, context) {

        public String getLinkLabel() {
            return "Foo";
        }

        @Override
        protected String getFileName() {
            return "Foo.html";
        }

        public String getLinkStyle() {
            return "sample";
        }

        @Override
        protected void content(HTMLElement body) throws IOException {
        }
    }, 0x1002);
    final SessionsPage page = new SessionsPage(noSessions, data, index, null, rootFolder, context);
    page.render();
    final Document doc = support.parse(output.getFile("jacoco-sessions.html"));
    assertEquals("el_class", support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[1]/a/@class"));
    assertEquals("Foo.html", support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[1]/a/@href"));
    assertEquals("ClassA", support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[1]/a"));
    assertEquals("0000000000001002", support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[2]/code"));
    assertEquals("ClassB", support.findStr(doc, "/html/body/table[1]/tbody/tr[2]/td[1]"));
    assertEquals("ClassC", support.findStr(doc, "/html/body/table[1]/tbody/tr[3]/td[1]"));
}
Also used : HTMLElement(org.jacoco.report.internal.html.HTMLElement) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) ExecutionData(org.jacoco.core.data.ExecutionData) Test(org.junit.Test)

Aggregations

ExecutionData (org.jacoco.core.data.ExecutionData)17 SessionInfo (org.jacoco.core.data.SessionInfo)7 File (java.io.File)6 FileOutputStream (java.io.FileOutputStream)6 ExecutionDataWriter (org.jacoco.core.data.ExecutionDataWriter)6 Test (org.junit.Test)3 FileInputStream (java.io.FileInputStream)2 Date (java.util.Date)2 ExecutionDataReader (org.jacoco.core.data.ExecutionDataReader)2 IExecutionDataVisitor (org.jacoco.core.data.IExecutionDataVisitor)2 ISessionInfoVisitor (org.jacoco.core.data.ISessionInfoVisitor)2 HTMLElement (org.jacoco.report.internal.html.HTMLElement)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Analyzer (org.jacoco.core.analysis.Analyzer)1 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)1