Package com.willwinder.universalgcodesender.mockobjects

Examples of com.willwinder.universalgcodesender.mockobjects.MockConnection


    @Test
    public void testQueueStringForComm() throws Exception {
       
        System.out.println("queueStringForComm");
        String input = "someCommand";
        MockConnection mc = new MockConnection(mg.in, mg.out);
        GrblCommunicator instance = new GrblCommunicator(cb, asl, mc);
       
        try {
            instance.queueStringForComm(input);
            // The cb preloads commands so the size represents queued commands.
            assertEquals(1, cb.size());
           
            // Test that instance adds newline to improperly formed command.
            assertEquals(input + "\n", cb.peek());
           
            instance.queueStringForComm(input);
            instance.queueStringForComm(input);
           
            // Test that instance continues to queue inputs.
            assertEquals(3, cb.size());
           
            input = "someCommand\n";
            cb = new LinkedList<String>();
            mc = new MockConnection(mg.in, mg.out);
            instance = new GrblCommunicator(cb, asl, mc);

           
            instance.queueStringForComm(input);
            // Test that instance doesn't add superfluous newlines.
View Full Code Here


     * Test of sendByteImmediately method, of class GrblCommunicator.
     */
    @Test
    public void testSendByteImmediately() {
        System.out.println("sendByteImmediately");
        MockConnection mc = new MockConnection(mg.in, mg.out);
        GrblCommunicator instance = new GrblCommunicator(cb, asl, mc);

        // Ctrl-C is a common byte to send immediately.
        byte b = 0x18;
       
View Full Code Here

     * Test of areActiveCommands method, of class GrblCommunicator.
     */
    @Test
    public void testAreActiveCommands() {
        System.out.println("areActiveCommands");
        MockConnection mc = new MockConnection(mg.in, mg.out);
        GrblCommunicator instance = new GrblCommunicator(cb, asl, mc);
       
        boolean expResult = false;
        boolean result = instance.areActiveCommands();
       
View Full Code Here

     * Test of sendStringToComm method, of class GrblCommunicator.
     */
    @Test
    public void testStreamCommands() {
        System.out.println("streamCommands");
        MockConnection mc = new MockConnection(mg.in, mg.out);
        GrblCommunicator instance = new GrblCommunicator(cb, asl, mc);
        String thirtyNineCharString = "thirty-nine character command here.....";

        boolean result;
        boolean expResult;
       
        // Make sure CommUtil is still an overly cautious jerk.
        LinkedList<GcodeCommand> l = new LinkedList<GcodeCommand>();
        l.add(new GcodeCommand("12characters"));
        assertEquals(13, CommUtils.getSizeOfBuffer(l));

        // Make sure GrblUtils hasn't updated RX buffer size.
        assertEquals(123, GrblUtils.GRBL_RX_BUFFER_SIZE);

        // Add a bunch of commands so that the buffer is full.
        // 39*3 + 3 newlines + 3 CommUtils caution  = 123 == buffer size.
        instance.queueStringForComm(thirtyNineCharString);
        instance.queueStringForComm(thirtyNineCharString);
        instance.queueStringForComm(thirtyNineCharString);
       
        // Stream them so that there are active commands.
        instance.streamCommands();
        expResult = true;
        result = instance.areActiveCommands();
        assertEquals(expResult, result);

        // Add another command and stream it so that something is queued.
        instance.queueStringForComm(thirtyNineCharString);
        instance.streamCommands();
        expResult = true;
        result = instance.areActiveCommands();
        assertEquals(expResult, result);

        // Check with MockGrbl to verify the fourth command wasn't sent.
        String output = mg.readStringFromGrblBuffer();
        assertEquals(thirtyNineCharString+"\n"+thirtyNineCharString+"\n"+thirtyNineCharString+"\n",
                        output);
       
        // Make room for the next command.
        mc.sendResponse("ok");
       
        // Send it.
        instance.streamCommands();
       
        // Make sure the queued command was sent.
        output = mg.readStringFromGrblBuffer();
        assertEquals(thirtyNineCharString+"\n", output);
 
        // Wrap up.
        mc.sendResponse("ok");
        mc.sendResponse("ok");
        mc.sendResponse("ok");

        expResult = false;
        result = instance.areActiveCommands();
        assertEquals(expResult, result);
    }
View Full Code Here

     * Test of pauseSend method, of class GrblCommunicator.
     */
    @Test
    public void testPauseSendAndResumeSend() {
        System.out.println("pauseSend");
        MockConnection mc = new MockConnection(mg.in, mg.out);
        GrblCommunicator instance = new GrblCommunicator(cb, asl, mc);
        String twentyCharString = "twenty characters...";
        String grblReceiveString;
        String arr[];
        int expectedInt;
       
        // Queue a bunch of commands
        for (int i=0; i < 30; i++) {
            instance.queueStringForComm(twentyCharString);
        }
       
        // Fill initial buffer, then pause.
        instance.streamCommands();
        instance.pauseSend();

        // Check that the correct number of commands were buffered (even though
        // that isn't pause/resume).
        grblReceiveString = mg.readStringFromGrblBuffer();
        arr = grblReceiveString.split("\n");
        expectedInt = GrblUtils.GRBL_RX_BUFFER_SIZE / (twentyCharString.length()+1);
        assertEquals(expectedInt, arr.length);

        // Process 'ok' messages.
        for (int i=0; i <arr.length; i++) {
            mc.sendResponse("ok");
        }

        // Make sure we don't stream anymore.
        instance.streamCommands();
        grblReceiveString = mg.readStringFromGrblBuffer();
View Full Code Here

     * Test of cancelSend method, of class GrblCommunicator.
     */
    @Test
    public void testCancelSend() {
        System.out.println("cancelSend");
        MockConnection mc = new MockConnection(mg.in, mg.out);
        GrblCommunicator instance = new GrblCommunicator(cb, asl, mc);
        String twentyCharString = "twenty characters...";
        String grblReceiveString;
        String arr[];
        int expectedInt;
        Boolean expectedBool;
       
        // 1.
        // Queue some commands, but cancel before sending them.
        for (int i=0; i < 30; i++) {
            instance.queueStringForComm(twentyCharString);
        }
        instance.cancelSend();

        // try streaming them and make sure nothing is received.
        instance.streamCommands();
        grblReceiveString = mg.readStringFromGrblBuffer();
        expectedInt = 0;
        assertEquals(expectedInt, grblReceiveString.length());
       
        // 2.
        // We can't un-send things to GRBL, so make sure we still acknowledge
        // that there are active commands.
        for (int i=0; i < 30; i++) {
            instance.queueStringForComm(twentyCharString);
        }
        instance.streamCommands();
        instance.cancelSend();
        // Verify that there are several active commands.
        expectedBool = true;
        assertEquals(expectedBool, instance.areActiveCommands());
       
        grblReceiveString = mg.readStringFromGrblBuffer();
        arr = grblReceiveString.split("\n");
        expectedInt = GrblUtils.GRBL_RX_BUFFER_SIZE / (twentyCharString.length()+1);
        assertEquals(expectedInt, arr.length);

        // Wrap up the active commands.
        for (int i=0; i <arr.length; i++) {
            mc.sendResponse("ok");
        }
           
        // Make sure canceled commands are not sent.
        instance.streamCommands();
        grblReceiveString = mg.readStringFromGrblBuffer();
View Full Code Here

     * Test of softReset method, of class GrblCommunicator.
     */
    @Test
    public void testSoftReset() {
        System.out.println("softReset");
        MockConnection mc = new MockConnection(mg.in, mg.out);
        GrblCommunicator instance = new GrblCommunicator(cb, asl, mc);
        String twentyCharString = "twenty characters...";
        String grblReceiveString;
        String arr[];
        int expectedInt;
View Full Code Here

TOP

Related Classes of com.willwinder.universalgcodesender.mockobjects.MockConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.