Search in sources :

Example 1 with Connection

use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method responseMessageOnErrorShouldDispatchPauseEvent.

@Test
public void responseMessageOnErrorShouldDispatchPauseEvent() {
    // Given
    Connection connection = mock(Connection.class);
    instance.setConnection(connection);
    SerialCommunicatorListener serialCommunicatorListener = mock(SerialCommunicatorListener.class);
    instance.addCommandEventListener(serialCommunicatorListener);
    asl.add(new GcodeCommand("G0"));
    asl.add(new GcodeCommand("G0"));
    instance.streamCommands();
    // When
    instance.responseMessage("error");
    // Then
    assertTrue(instance.isPaused());
    verify(serialCommunicatorListener, times(1)).communicatorPausedOnError();
}
Also used : SerialCommunicatorListener(com.willwinder.universalgcodesender.listeners.SerialCommunicatorListener) Connection(com.willwinder.universalgcodesender.connection.Connection) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 2 with Connection

use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method softResetShouldClearBuffersAndResumeOperation.

@Test
public void softResetShouldClearBuffersAndResumeOperation() {
    // Given
    Connection connection = mock(Connection.class);
    instance.setConnection(connection);
    asl.add(new GcodeCommand("G0"));
    cb.add("G0");
    instance.pauseSend();
    assertTrue(instance.isPaused());
    assertEquals(1, instance.numActiveCommands());
    assertEquals(1, instance.numBufferedCommands());
    // When
    instance.softReset();
    // Then
    assertFalse("The communicator should resume operation after a reset", instance.isPaused());
    assertEquals("There should be no active commands", 0, instance.numActiveCommands());
    assertEquals("There should be no buffered manual commands", 0, instance.numBufferedCommands());
}
Also used : Connection(com.willwinder.universalgcodesender.connection.Connection) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 3 with Connection

use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method responseMessageOnErrorOnLastCommandStreamShouldNotPauseTheCommunicator.

@Test
public void responseMessageOnErrorOnLastCommandStreamShouldNotPauseTheCommunicator() throws IOException, GcodeStreamReader.NotGcodeStreamFile {
    // Given
    Connection connection = mock(Connection.class);
    instance.setConnection(connection);
    // Create a gcode file stream
    File gcodeFile = new File(tempDir, "gcodeFile");
    GcodeStreamWriter gcodeStreamWriter = new GcodeStreamWriter(gcodeFile);
    gcodeStreamWriter.addLine("G0", "G0", null, 0);
    gcodeStreamWriter.close();
    // Stream
    instance.queueStreamForComm(new GcodeStreamReader(gcodeFile));
    instance.streamCommands();
    // When
    instance.responseMessage("error");
    // Then
    assertFalse(instance.isPaused());
}
Also used : GcodeStreamWriter(com.willwinder.universalgcodesender.utils.GcodeStreamWriter) Connection(com.willwinder.universalgcodesender.connection.Connection) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) File(java.io.File) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 4 with Connection

use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method responseMessageOnErrorOnLastManualCommandShouldNotPauseTheCommunicator.

@Test
public void responseMessageOnErrorOnLastManualCommandShouldNotPauseTheCommunicator() {
    // Given
    Connection connection = mock(Connection.class);
    instance.setConnection(connection);
    cb.add("G0");
    instance.streamCommands();
    // When
    instance.responseMessage("error");
    // Then
    assertFalse(instance.isPaused());
}
Also used : Connection(com.willwinder.universalgcodesender.connection.Connection) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Example 5 with Connection

use of com.willwinder.universalgcodesender.connection.Connection in project Universal-G-Code-Sender by winder.

the class BufferedCommunicatorTest method testStreamCommandsOrderStringCommandsFirst.

@Test
public void testStreamCommandsOrderStringCommandsFirst() throws Exception {
    // Given
    Connection connection = mock(Connection.class);
    instance.setConnection(connection);
    ArgumentCaptor<String> commandCaptor = ArgumentCaptor.forClass(String.class);
    doNothing().when(connection).sendStringToComm(commandCaptor.capture());
    // Create a gcode file stream
    File gcodeFile = new File(tempDir, "gcodeFile");
    GcodeStreamWriter gcodeStreamWriter = new GcodeStreamWriter(gcodeFile);
    gcodeStreamWriter.addLine("G0", "G0", null, 0);
    gcodeStreamWriter.close();
    instance.queueStreamForComm(new GcodeStreamReader(gcodeFile));
    instance.queueStringForComm("G1");
    // When
    instance.streamCommands();
    // Then
    assertEquals(2, commandCaptor.getAllValues().size());
    assertEquals("The first command processed should be the string command", "G1\n", commandCaptor.getAllValues().get(0));
    assertEquals("The second command should be from the stream", "G0\n", commandCaptor.getAllValues().get(1));
}
Also used : GcodeStreamWriter(com.willwinder.universalgcodesender.utils.GcodeStreamWriter) Connection(com.willwinder.universalgcodesender.connection.Connection) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) File(java.io.File) Test(org.junit.Test) GcodeStreamTest(com.willwinder.universalgcodesender.utils.GcodeStreamTest)

Aggregations

Connection (com.willwinder.universalgcodesender.connection.Connection)9 GcodeStreamTest (com.willwinder.universalgcodesender.utils.GcodeStreamTest)9 Test (org.junit.Test)9 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)4 GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)3 GcodeStreamWriter (com.willwinder.universalgcodesender.utils.GcodeStreamWriter)3 File (java.io.File)3 SerialCommunicatorListener (com.willwinder.universalgcodesender.listeners.SerialCommunicatorListener)1