Search in sources :

Example 21 with XNetMessage

use of jmri.jmrix.lenz.XNetMessage in project JMRI by JMRI.

the class XNetSimulatorAdapterTest method testGenerateEmergencyStopReply.

@Test
public void testGenerateEmergencyStopReply() {
    XNetSimulatorAdapter a = new XNetSimulatorAdapter();
    // NOTE: this test uses reflection to test a private method.
    java.lang.reflect.Method generateReplyMethod = null;
    try {
        generateReplyMethod = a.getClass().getDeclaredMethod("generateReply", XNetMessage.class);
    } catch (java.lang.NoSuchMethodException nsm) {
        Assert.fail("Could not find method generateReply in XNetSimulatorAdapter class: ");
    }
    // override the default permissions.
    Assert.assertNotNull(generateReplyMethod);
    generateReplyMethod.setAccessible(true);
    try {
        XNetReply r = (XNetReply) generateReplyMethod.invoke(a, new XNetMessage("21 80 A1"));
        Assert.assertEquals("CS Emergency Stop Reply", new XNetReply("61 82 E3"), r);
    } catch (java.lang.IllegalAccessException ite) {
        Assert.fail("could not access method generateReply in XNetSimulatoradapter class");
    } catch (java.lang.reflect.InvocationTargetException ite) {
        Throwable cause = ite.getCause();
        Assert.fail("generateReply execution failed reason: " + cause.getMessage());
    }
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Example 22 with XNetMessage

use of jmri.jmrix.lenz.XNetMessage in project JMRI by JMRI.

the class XNetSimulatorAdapterTest method testEmergencyStopLocoReply.

@Test
public void testEmergencyStopLocoReply() {
    XNetSimulatorAdapter a = new XNetSimulatorAdapter();
    // NOTE: this test uses reflection to test a private method.
    java.lang.reflect.Method generateReplyMethod = null;
    try {
        generateReplyMethod = a.getClass().getDeclaredMethod("generateReply", XNetMessage.class);
    } catch (java.lang.NoSuchMethodException nsm) {
        Assert.fail("Could not find method generateReply in XNetSimulatorAdapter class: ");
    }
    // override the default permissions.
    Assert.assertNotNull(generateReplyMethod);
    generateReplyMethod.setAccessible(true);
    try {
        XNetReply r = (XNetReply) generateReplyMethod.invoke(a, new XNetMessage("92 00 02 90"));
        Assert.assertEquals("CS Emergency Specific Loco (XNetV4) Reply ", new XNetReply("01 04 05"), r);
    } catch (java.lang.IllegalAccessException ite) {
        Assert.fail("could not access method generateReply in XNetSimulatoradapter class");
    } catch (java.lang.reflect.InvocationTargetException ite) {
        Throwable cause = ite.getCause();
        Assert.fail("generateReply execution failed reason: " + cause.getMessage());
    }
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Example 23 with XNetMessage

use of jmri.jmrix.lenz.XNetMessage in project JMRI by JMRI.

the class XNetSimulatorAdapterTest method testGenerateResumeOperationsReply.

@Test
public void testGenerateResumeOperationsReply() {
    XNetSimulatorAdapter a = new XNetSimulatorAdapter();
    // NOTE: this test uses reflection to test a private method.
    java.lang.reflect.Method generateReplyMethod = null;
    try {
        generateReplyMethod = a.getClass().getDeclaredMethod("generateReply", XNetMessage.class);
    } catch (java.lang.NoSuchMethodException nsm) {
        Assert.fail("Could not find method generateReply in XNetSimulatorAdapter class: ");
    }
    // override the default permissions.
    Assert.assertNotNull(generateReplyMethod);
    generateReplyMethod.setAccessible(true);
    try {
        XNetReply r = (XNetReply) generateReplyMethod.invoke(a, new XNetMessage("21 81 A0"));
        Assert.assertEquals("CS Resume Operations Reply", new XNetReply("61 82 E3"), r);
    } catch (java.lang.IllegalAccessException ite) {
        Assert.fail("could not access method generateReply in XNetSimulatoradapter class");
    } catch (java.lang.reflect.InvocationTargetException ite) {
        Throwable cause = ite.getCause();
        Assert.fail("generateReply execution failed reason: " + cause.getMessage());
    }
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply) XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Example 24 with XNetMessage

use of jmri.jmrix.lenz.XNetMessage in project JMRI by JMRI.

the class XnTcpXNetPacketizerTest method testInterference.

@Override
@Test
public void testInterference() throws Exception {
    // This test checks to make sure that when two listeners register for events
    // at the same time, the first listener is still the active listener until
    // it receives a message.
    XnTcpXNetPacketizer c = (XnTcpXNetPacketizer) tc;
    // connect to iostream via port controller
    XnTcpPortControllerScaffold p = new XnTcpPortControllerScaffold();
    c.connectPort(p);
    // We need three objects to receive messages.
    // The first one recieves broadcast messages.
    // The others only receive directed messages.
    XNetListenerScaffold l = new XNetListenerScaffold();
    XNetListenerScaffold l1 = new XNetListenerScaffold();
    XNetListenerScaffold l2 = new XNetListenerScaffold();
    c.addXNetListener(~0, l);
    // a threading/synchronization issue in AbstractMRTrafficController.
    for (int i = 0; i < 5; i++) {
        l.setRcvdRply(null);
        l1.setRcvdRply(null);
        l2.setRcvdRply(null);
        // first, we send an unsolicited message
        p.tistream.write(0x42);
        p.tistream.write(0x12);
        p.tistream.write(0x12);
        p.tistream.write(0x42);
        p.flush();
        jmri.util.JUnitUtil.waitFor(() -> {
            return l.getRcvdRply() != null;
        }, "reply received");
        // check that the message was picked up by the read thread.
        Assert.assertTrue("iteration " + i + " reply received ", l.getRcvdRply() != null);
        Assert.assertEquals("iteration " + i + " first char of broadcast reply to l", 0x42, l.getRcvdRply().getElement(0));
        // now we need to send a message with both the second and third listeners
        // as reply receiver.
        XNetMessage m = XNetMessage.getTurnoutCommandMsg(22, true, false, true);
        c.sendXNetMessage(m, l1);
        XNetMessage m1 = XNetMessage.getTurnoutCommandMsg(23, true, false, true);
        c.sendXNetMessage(m1, l2);
        p.flush();
        // and now we verify l1 is the last sender.
        jmri.util.JUnitUtil.waitFor(() -> {
            return l1 == c.getLastSender();
        }, "iteration " + i + " Last Sender l1, before l1 reply");
        l.setRcvdRply(null);
        l1.setRcvdRply(null);
        l2.setRcvdRply(null);
        // Now we reply to the messages above
        p.tistream.write(0x01);
        p.tistream.write(0x04);
        p.tistream.write(0x05);
        p.flush();
        jmri.util.JUnitUtil.waitFor(() -> {
            return l1.getRcvdRply() != null;
        }, "iteration " + i + " reply received ");
        // check that the message was picked up by the read thread.
        Assert.assertTrue("iteration " + i + " reply received ", l1.getRcvdRply() != null);
        Assert.assertEquals("iteration " + i + " first char of reply to l1", 0x01, l1.getRcvdRply().getElement(0));
        Assert.assertNotNull("iteration " + i + " broadcast reply after l1 message", l.getRcvdRply());
        Assert.assertNotNull("iteration " + i + " l1 reply after l1 message", l1.getRcvdRply());
        Assert.assertNull("iteration " + i + " l2 reply after l1 message", l2.getRcvdRply());
        // and now we verify l2 is the last sender.
        jmri.util.JUnitUtil.waitFor(() -> {
            return l2 == c.getLastSender();
        }, "Last Sender l2");
        l.setRcvdRply(null);
        l1.setRcvdRply(null);
        l2.setRcvdRply(null);
        p.tistream.write(0x01);
        p.tistream.write(0x04);
        p.tistream.write(0x05);
        p.flush();
        jmri.util.JUnitUtil.waitFor(() -> {
            return l2.getRcvdRply() != null;
        }, "iteration " + i + " reply received ");
        // check that the message was picked up by the read thread.
        Assert.assertTrue("iteration " + i + " reply received ", l2.getRcvdRply() != null);
        Assert.assertEquals("iteration " + i + " first char of reply to l2", 0x01, l2.getRcvdRply().getElement(0));
        Assert.assertNotNull("iteration " + i + " broadcast reply after l2 message", l.getRcvdRply());
        Assert.assertNull("iteration " + i + " l1 reply after l2 message", l1.getRcvdRply());
        Assert.assertNotNull("iteration " + i + " l2 reply after l2 message", l2.getRcvdRply());
        l.setRcvdRply(null);
        l1.setRcvdRply(null);
        l2.setRcvdRply(null);
        Assert.assertEquals("iteration " + i + " l received count ", 3 * (i + 1), l.getRcvCount());
    }
}
Also used : XNetListenerScaffold(jmri.jmrix.lenz.XNetListenerScaffold) XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Example 25 with XNetMessage

use of jmri.jmrix.lenz.XNetMessage in project JMRI by JMRI.

the class PacketGenFrameTest method testPacketNull.

@Test
public void testPacketNull() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    PacketGenFrame t = new PacketGenFrame();
    XNetMessage m = t.createPacket("");
    Assert.assertEquals("null pointer", null, m);
}
Also used : XNetMessage(jmri.jmrix.lenz.XNetMessage) Test(org.junit.Test)

Aggregations

XNetMessage (jmri.jmrix.lenz.XNetMessage)55 XNetReply (jmri.jmrix.lenz.XNetReply)14 Test (org.junit.Test)14 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 IOException (java.io.IOException)1 XNetListenerScaffold (jmri.jmrix.lenz.XNetListenerScaffold)1 Z21Reply (jmri.jmrix.roco.z21.Z21Reply)1