Search in sources :

Example 6 with ExecutionDataWriter

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

the class TcpConnectionTest method testRemoteClose.

/**
 * Remote endpoint is closed after a valid header has been send.
 */
@Test
public void testRemoteClose() throws Exception {
    final OutputStream remoteOut = mockConnection.getSocketB().getOutputStream();
    new ExecutionDataWriter(remoteOut);
    final TcpConnection con = new TcpConnection(mockConnection.getSocketA(), data);
    con.init();
    final Future<Void> f = executor.submit(new Callable<Void>() {

        public Void call() throws Exception {
            con.run();
            return null;
        }
    });
    assertBlocks(f);
    mockConnection.getSocketA().waitUntilInputBufferIsEmpty();
    mockConnection.getSocketB().close();
    f.get();
}
Also used : OutputStream(java.io.OutputStream) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with ExecutionDataWriter

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

the class FileOutput method writeExecutionData.

public void writeExecutionData(final boolean reset) throws IOException {
    final OutputStream output = openFile();
    try {
        final ExecutionDataWriter writer = new ExecutionDataWriter(output);
        data.collect(writer, writer, reset);
    } finally {
        output.close();
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter)

Example 8 with ExecutionDataWriter

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

the class CreateExecFiles method main.

public static void main(String[] args) throws IOException {
    OutputStream out;
    out = new FileOutputStream(BASE_LOCATION + "sample1.exec");
    new ExecutionDataWriter(out);
    out.close();
    out = new FileOutputStream(BASE_LOCATION + "sample2.exec");
    new ExecutionDataWriter(out);
    out.close();
    out = new FileOutputStream(BASE_LOCATION + "nomatch.exec");
    ExecutionDataWriter writer = new ExecutionDataWriter(out);
    writer.visitClassExecution(new ExecutionData(0, "org/jacoco/ant/TestTarget", new boolean[0]));
    out.close();
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter) ExecutionData(org.jacoco.core.data.ExecutionData)

Example 9 with ExecutionDataWriter

use of org.jacoco.core.data.ExecutionDataWriter 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 10 with ExecutionDataWriter

use of org.jacoco.core.data.ExecutionDataWriter 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)

Aggregations

ExecutionDataWriter (org.jacoco.core.data.ExecutionDataWriter)15 FileOutputStream (java.io.FileOutputStream)10 ExecutionData (org.jacoco.core.data.ExecutionData)6 File (java.io.File)5 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)5 SessionInfo (org.jacoco.core.data.SessionInfo)4 Test (org.junit.Test)4 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 Map (java.util.Map)1 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)1 IExecutionDataVisitor (org.jacoco.core.data.IExecutionDataVisitor)1 ISessionInfoVisitor (org.jacoco.core.data.ISessionInfoVisitor)1 RemoteControlReader (org.jacoco.core.runtime.RemoteControlReader)1 RemoteControlWriter (org.jacoco.core.runtime.RemoteControlWriter)1 AnalysisException (org.sonar.java.AnalysisException)1