aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test/src/org/jacoco/core/runtime
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2010-05-18 06:27:25 +0000
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2010-05-18 06:27:25 +0000
commite4b0fede262e9df8546def83e68c687656f539ba (patch)
treeb3d590b4a413a9123d1175ca844a84d0cead7165 /org.jacoco.core.test/src/org/jacoco/core/runtime
parent20823ddbda94e8855c8528f3e0fc87eee1be2774 (diff)
downloadjacoco-e4b0fede262e9df8546def83e68c687656f539ba.tar.gz
Trac #82: Remote protocol implementation.
Diffstat (limited to 'org.jacoco.core.test/src/org/jacoco/core/runtime')
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/runtime/RemoteControlReaderWriterTest.java117
1 files changed, 117 insertions, 0 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/runtime/RemoteControlReaderWriterTest.java b/org.jacoco.core.test/src/org/jacoco/core/runtime/RemoteControlReaderWriterTest.java
new file mode 100644
index 00000000..c756b95b
--- /dev/null
+++ b/org.jacoco.core.test/src/org/jacoco/core/runtime/RemoteControlReaderWriterTest.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marc R. Hoffmann - initial API and implementation
+ *
+ * $Id: $
+ *******************************************************************************/
+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.
+ *
+ * @author Marc R. Hoffmann
+ * @version $Revision: $
+ */
+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());
+ }
+
+ @Test
+ public void testSendCmdClose() throws IOException {
+ writer.sendCmdClose();
+ final RemoteControlReader reader = createReader();
+ assertFalse(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);
+ }
+
+}