1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*******************************************************************************
* Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Marc R. Hoffmann - initial API and implementation
*
*******************************************************************************/
package org.jacoco.core.runtime;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.jacoco.core.data.ExecutionDataReader;
import org.jacoco.core.data.ExecutionDataReaderWriterTest;
import org.jacoco.core.data.ExecutionDataWriter;
import org.junit.Before;
import org.junit.Test;
/**
* Unit tests for {@link ExecutionDataReader} and {@link ExecutionDataWriter}.
* The tests don't care about the written binary format, they just verify
* symmetry.
*/
public class RemoteControlReaderWriterTest
extends ExecutionDataReaderWriterTest {
private RemoteControlWriter writer;
@Before
@Override
public void setup() throws IOException {
super.setup();
writer = createWriter(buffer);
}
@Test(expected = IOException.class)
public void testNoRemoteCommandVisitor() throws IOException {
writer.visitDumpCommand(false, false);
final RemoteControlReader reader = createReader();
reader.read();
}
@Test
public void testVisitDump1() throws IOException {
testVisitDump(false, false);
}
@Test
public void testVisitDump2() throws IOException {
testVisitDump(false, true);
}
@Test
public void testVisitDump3() throws IOException {
testVisitDump(true, false);
}
@Test
public void testVisitDump4() throws IOException {
testVisitDump(true, true);
}
private void testVisitDump(boolean doDump, boolean doReset)
throws IOException {
writer.visitDumpCommand(doDump, doReset);
final RemoteControlReader reader = createReader();
final StringBuilder calls = new StringBuilder();
reader.setRemoteCommandVisitor(new IRemoteCommandVisitor() {
public void visitDumpCommand(boolean dump, boolean reset) {
calls.append("cmd(" + dump + "," + reset + ")");
}
});
assertFalse(reader.read());
assertEquals("cmd(" + doDump + "," + doReset + ")", calls.toString());
}
@Test
public void testSendCmdOk() throws IOException {
writer.sendCmdOk();
final RemoteControlReader reader = createReader();
assertTrue(reader.read());
}
@Override
protected RemoteControlReader createReader() throws IOException {
return new RemoteControlReader(
new ByteArrayInputStream(buffer.toByteArray()));
}
@Override
protected RemoteControlWriter createWriter(OutputStream out)
throws IOException {
return new RemoteControlWriter(out);
}
}
|