From: Bob J. <jac...@us...> - 2002-04-29 16:14:49
|
Update of /cvsroot/jmri/test/jmri/jmrix/lenz In directory usw-pr-cvs1:/tmp/cvs-serv31113/jmri/jmrix/lenz Added Files: COPYING XNetInterfaceScaffold.java XNetMessageTest.java XNetPacketizerTest.java XNetProgrammerTest.java XNetTest.java XNetTrafficControllerTest.java XNetTrafficRouterTest.java XNetTurnoutManagerTest.java XNetTurnoutTest.java Log Message: Initial add of Lenz XpressNet support. THIS IS NOT YET COMPLETELY FUNCTIONAL. It does compile, build, run, etc, but there are various details still to be sorted. Note that this has a new structure, different from the other protocol packages. Its the first protocol implementation to (start to) use the new common NetMessage class, and push more functionality higher up in the class tree. --- NEW FILE: COPYING --- The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: * "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. * "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. * "Copyright Holder" is whoever is named in the copyright or copyrights for the package. * "You" is you, if you're thinking about copying or distributing this Package. * "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) * "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. --- NEW FILE: XNetInterfaceScaffold.java --- /** * XNetInterfaceScaffold.java * * Description: Test scaffold implementation of XNetInterface * @author Bob Jacobsen Copyright (C) 2002 * @version $Revision: 1.1 $ * * Use an object of this type as a XNetTrafficController in tests */ package jmri.jmrix.lenz; import java.util.Vector; public class XNetInterfaceScaffold extends XNetTrafficController { public XNetInterfaceScaffold(LenzCommandStation pCommandStation) { super(pCommandStation); self = this; } // override some XNetTrafficController methods for test purposes public boolean status() { return true; } /** * record XNet messages sent, provide access for making sure they are OK */ public Vector outbound = new Vector(); // public OK here, so long as this is a test class public void sendXNetMessage(XNetMessage m) { if (log.isDebugEnabled()) log.debug("sendXNetMessage ["+m+"]"); // save a copy outbound.addElement(m); // we don't return an echo so that the processing before the echo can be // separately tested } // test control member functions /** * forward a message to the listeners, e.g. test receipt */ public void sendTestMessage (XNetMessage m) { // forward a test message to XNetListeners if (log.isDebugEnabled()) log.debug("sendTestMessage ["+m+"]"); notify(m); return; } /* * Check number of listeners, used for testing dispose() */ public int numListeners() { return listeners.size(); } static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(XNetInterfaceScaffold.class.getName()); } /* @(#)LocoNetInterfaceScaffold.java */ --- NEW FILE: XNetMessageTest.java --- package jmri.jmrix.lenz; import java.io.*; import junit.framework.Assert; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * XNetMessageTest.java * * Description: tests for the jmri.jmrix.lenz.XNetMessage class * @author Bob Jacobsen * @version $Revision: 1.1 $ */ public class XNetMessageTest extends TestCase { public void testCtor() { XNetMessage m = new XNetMessage(3); Assert.assertEquals("length", 3, m.getNumDataElements()); } // check opcode inclusion in message public void testOpCode() { XNetMessage m = new XNetMessage(5); m.setOpCode(4); Assert.assertEquals("read=back op code", 4, m.getOpCode()); Assert.assertEquals("stored op code", 0x43, m.getElement(0)); } // check parity operations public void testParity() { XNetMessage m; m = new XNetMessage(3); m.setElement(0,0x21); m.setElement(1,0x21); m.setParity(); Assert.assertEquals("parity set test 1", 0, m.getElement(2)); Assert.assertEquals("parity check test 1", true, m.checkParity()); m = new XNetMessage(3); m.setElement(0,0x21); m.setElement(1,~0x21); m.setParity(); Assert.assertEquals("parity set test 2", 0xFF, m.getElement(2)); Assert.assertEquals("parity check test 2", true, m.checkParity()); m = new XNetMessage(3); m.setElement(0,0x18); m.setElement(1,0x36); m.setParity(); Assert.assertEquals("parity set test 3", 0x2E, m.getElement(2)); Assert.assertEquals("parity check test 3", true, m.checkParity()); m = new XNetMessage(3); m.setElement(0,0x87); m.setElement(1,0x31); m.setParity(); Assert.assertEquals("parity set test 4", 0xB6, m.getElement(2)); Assert.assertEquals("parity check test 4", true, m.checkParity()); m = new XNetMessage(3); m.setElement(0,0x18); m.setElement(1,0x36); m.setElement(2,0x0e); Assert.assertEquals("parity check test 5", false, m.checkParity()); m = new XNetMessage(3); m.setElement(0,0x18); m.setElement(1,0x36); m.setElement(2,0x8e); Assert.assertEquals("parity check test 6", false, m.checkParity()); } // from here down is testing infrastructure public XNetMessageTest(String s) { super(s); } // Main entry point static public void main(String[] args) { String[] testCaseName = {XNetMessageTest.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } // test suite from all defined tests public static Test suite() { TestSuite suite = new TestSuite(XNetMessageTest.class); return suite; } static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(XNetMessageTest.class.getName()); } --- NEW FILE: XNetPacketizerTest.java --- package jmri.jmrix.lenz; import junit.framework.*; import apps.tests.*; /** * <p>Title: XNetPacketizerTest </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * @author Bob Jacobsen * @version $Revision: 1.1 $ */ public class XNetPacketizerTest extends TestCase { Log4JFixture log4jfixtureInst = new Log4JFixture(this); public XNetPacketizerTest(String s) { super(s); } protected void setUp() { log4jfixtureInst.setUp(); } protected void tearDown() { log4jfixtureInst.tearDown(); } public void testDummy() {} } --- NEW FILE: XNetProgrammerTest.java --- /** * XNetProgrammerTest.java * * Description: JUnit tests for the XNetProgrammer class * @author Bob Jacobsen * @version $Revision: 1.1 $ */ package jmri.jmrix.lenz; import jmri.*; import java.util.*; import junit.framework.Test; import junit.framework.Assert; import junit.framework.TestCase; import junit.framework.TestSuite; public class XNetProgrammerTest extends TestCase { public void testWriteCvSequence() throws JmriException { XNetProgrammer.self = null; // avoid spurious warning message // infrastructure objects XNetInterfaceScaffold t = new XNetInterfaceScaffold(new LenzCommandStation()); XNetListenerScaffold l = new XNetListenerScaffold(); XNetProgrammer p = new XNetProgrammer(); // and do the write p.writeCV(10, 20, l); // check "prog mode" message sent Assert.assertEquals("mode message sent", 1, t.outbound.size()); } public void testWriteRegisterSequence() throws JmriException { XNetProgrammer.self = null; // avoid spurious warning message // infrastructure objects XNetInterfaceScaffold t = new XNetInterfaceScaffold(new LenzCommandStation()); XNetListenerScaffold l = new XNetListenerScaffold(); XNetProgrammer p = new XNetProgrammer(); // set register mode p.setMode(Programmer.REGISTERMODE); // and do the write p.writeCV(3, 12, l); // check "prog mode" message sent Assert.assertEquals("mode message sent", 1, t.outbound.size()); } public void testReadCvSequence() throws JmriException { XNetProgrammer.self = null; // avoid spurious warning message // infrastructure objects XNetInterfaceScaffold t = new XNetInterfaceScaffold(new LenzCommandStation()); XNetListenerScaffold l = new XNetListenerScaffold(); XNetProgrammer p = new XNetProgrammer(); // and do the read p.readCV(10, l); // check "prog mode" message sent Assert.assertEquals("mode message sent", 1, t.outbound.size()); } // internal class to simulate a XNetListener class XNetListenerScaffold implements jmri.ProgListener { public XNetListenerScaffold() { rcvdInvoked = 0;; rcvdValue = 0; rcvdStatus = 0; } public void programmingOpReply(int value, int status) { rcvdValue = value; rcvdStatus = status; rcvdInvoked++; } } int rcvdValue; int rcvdStatus; int rcvdInvoked; // from here down is testing infrastructure public XNetProgrammerTest(String s) { super(s); } // Main entry point static public void main(String[] args) { String[] testCaseName = {XNetProgrammerTest.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } // test suite from all defined tests public static Test suite() { TestSuite suite = new TestSuite(XNetProgrammerTest.class); return suite; } // The minimal setup is for log4J apps.tests.Log4JFixture log4jfixtureInst = new apps.tests.Log4JFixture(this); protected void setUp() { log4jfixtureInst.setUp(); } protected void tearDown() { log4jfixtureInst.tearDown(); } static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(XNetProgrammerTest.class.getName()); } --- NEW FILE: XNetTest.java --- /** * XNetTest.java * * Description: tests for the jmri.jmrix.lenz package * @author Bob Jacobsen * @version $Revision: 1.1 $ */ package jmri.jmrix.lenz; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; public class XNetTest extends TestCase { // from here down is testing infrastructure public XNetTest(String s) { super(s); } // Main entry point static public void main(String[] args) { String[] testCaseName = {XNetTest.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } // test suite from all defined tests public static Test suite() { TestSuite suite = new TestSuite("jmri.jmrix.lenz.XNetTest"); // no tests in this class itself suite.addTest(new TestSuite(XNetMessageTest.class)); suite.addTest(new TestSuite(XNetTurnoutTest.class)); suite.addTest(new TestSuite(XNetPacketizerTest.class)); suite.addTest(new TestSuite(jmri.jmrix.lenz.packetgen.PacketGenFrameTest.class)); suite.addTest(new TestSuite(XNetTurnoutManagerTest.class)); suite.addTest(new TestSuite(XNetTrafficControllerTest.class)); suite.addTest(new TestSuite(XNetTrafficRouterTest.class)); return suite; } static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(XNetTest.class.getName()); } --- NEW FILE: XNetTrafficControllerTest.java --- package jmri.jmrix.lenz; import junit.framework.*; import apps.tests.*; /** * Generated by JBuilder * <p>Title: XNetTrafficControllerTest </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * @author Bob Jacobsen * @version $Revision: 1.1 $ */ public class XNetTrafficControllerTest extends TestCase { Log4JFixture log4jfixtureInst = new Log4JFixture(this); public XNetTrafficControllerTest(String s) { super(s); } protected void setUp() { log4jfixtureInst.setUp(); } protected void tearDown() { log4jfixtureInst.tearDown(); } public void testDummy() {} } --- NEW FILE: XNetTrafficRouterTest.java --- package jmri.jmrix.lenz; import junit.framework.*; import apps.tests.*; /** * <p>Title: XNetTrafficRouterTest </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * @author Bob Jacobsen * @version $Revision: 1.1 $ */ public class XNetTrafficRouterTest extends TestCase { Log4JFixture log4jfixtureInst = new Log4JFixture(this); public XNetTrafficRouterTest(String s) { super(s); } protected void setUp() { log4jfixtureInst.setUp(); } protected void tearDown() { log4jfixtureInst.tearDown(); } public void testConnectAndSend() { // scaffold for upstream XNetInterfaceScaffold upstream = new XNetInterfaceScaffold(new LenzCommandStation()); // create object XNetTrafficRouter router = new XNetTrafficRouter(new LenzCommandStation()); Assert.assertEquals("router is instance", XNetTrafficController.instance(), router); // connect router.connect(upstream); Assert.assertTrue("connected", router.status()); // send a message XNetMessage m = new XNetMessage(3); router.sendXNetMessage(m); // check receipt Assert.assertEquals("one message sent", 1, upstream.outbound.size()); Assert.assertTrue(upstream.outbound.elementAt(0)==m); } static int count = 0; public void testReceiveAndForward() { // create object XNetTrafficRouter router = new XNetTrafficRouter(new LenzCommandStation()); Assert.assertEquals("router is instance", XNetTrafficController.instance(), router); count = 0; // register a listener XNetListener l = new XNetListener(){ public void message(XNetMessage m) { count++; } }; router.addXNetListener(~0, l); // send a message XNetMessage m = new XNetMessage(3); router.message(m); // check receipt Assert.assertEquals("one message sent", 1, count); } public void testConnectAndDisconnect() { // scaffold for upstream XNetInterfaceScaffold upstream = new XNetInterfaceScaffold(new LenzCommandStation()); // create object XNetTrafficRouter router = new XNetTrafficRouter(new LenzCommandStation()); Assert.assertEquals("router is instance", XNetTrafficController.instance(), router); // connect router.connect(upstream); Assert.assertTrue("connected", router.status()); // disconnect router.disconnectPort(upstream); Assert.assertTrue("not connected", !router.status()); } } --- NEW FILE: XNetTurnoutManagerTest.java --- /** * XNetTurnoutManagerTest.java * * Description: tests for the jmri.jmrix.loconet.LnTurnoutManager class * @author Bob Jacobsen * @version $Revision: 1.1 $ */ package jmri.jmrix.lenz; import java.io.*; import junit.framework.Assert; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import com.sun.java.util.collections.List; import com.sun.java.util.collections.ArrayList; import jmri.*; public class XNetTurnoutManagerTest extends jmri.AbstractTurnoutMgrTest { public String getSystemName(int i) { return "XT"+i; } XNetInterfaceScaffold lnis; public void setUp() { // prepare an interface, register lnis = new XNetInterfaceScaffold(new LenzCommandStation()); // create and register the manager object l = new XNetTurnoutManager(); jmri.InstanceManager.setTurnoutManager(l); } public void testArraySort() { String[] str = new String[]{"8567", "8456"}; java.util.Arrays.sort(str); Assert.assertEquals("first ","8456",str[0]); } public void testMisses() { // sample address object TurnoutAddress a = new TurnoutAddress("XT22", "user"); // try to get nonexistant turnouts Assert.assertTrue(null == l.getByAddress(a)); Assert.assertTrue(null == l.getByUserName("foo")); Assert.assertTrue(null == l.getBySystemName("bar")); } public void testXNetMessages() { // send messages for 21, 22 // notify that somebody else changed it... XNetMessage m1 = new XNetMessage(4); m1.setOpCode(0xb1); m1.setElement(1, 0x14); // set CLOSED m1.setElement(2, 0x20); m1.setElement(3, 0x7b); lnis.sendTestMessage(m1); // notify the Ln that somebody else changed it... XNetMessage m2 = new XNetMessage(4); m2.setOpCode(0xb0); m2.setElement(1, 0x15); // set CLOSED m2.setElement(2, 0x20); m2.setElement(3, 0x7a); lnis.sendTestMessage(m2); // try to get turnouts to see if they exist Assert.assertTrue(null != l.getBySystemName("XT21")); Assert.assertTrue(null != l.getBySystemName("XT22")); // check the list List testList = new ArrayList(2); testList.add("XT21"); testList.add("XT22"); Assert.assertEquals("system name list", testList, l.getSystemNameList()); } public void testAsAbstractFactory () { // create and register the manager object XNetTurnoutManager l = new XNetTurnoutManager(); jmri.InstanceManager.setTurnoutManager(l); // ask for a Turnout, and check type TurnoutManager t = jmri.InstanceManager.turnoutManagerInstance(); Turnout o = t.newTurnout("XT21", "my name"); if (log.isDebugEnabled()) log.debug("received turnout value "+o); Assert.assertTrue( null != (XNetTurnout)o); // make sure loaded into tables if (log.isDebugEnabled()) log.debug("by system name: "+t.getBySystemName("XT21")); if (log.isDebugEnabled()) log.debug("by user name: "+t.getByUserName("my name")); Assert.assertTrue(null != t.getBySystemName("XT21")); Assert.assertTrue(null != t.getByUserName("my name")); } // from here down is testing infrastructure public XNetTurnoutManagerTest(String s) { super(s); } // Main entry point static public void main(String[] args) { String[] testCaseName = {XNetTurnoutManager.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } // test suite from all defined tests public static Test suite() { TestSuite suite = new TestSuite(XNetTurnoutManagerTest.class); return suite; } static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(XNetTurnoutManagerTest.class.getName()); } --- NEW FILE: XNetTurnoutTest.java --- /** * XNetTurnoutTest.java * * Description: tests for the jmri.jmrix.loconet.LnTurnout class * @author Bob Jacobsen * @version $Revision: 1.1 $ */ package jmri.jmrix.lenz; import java.io.*; import junit.framework.*; public class XNetTurnoutTest extends jmri.AbstractTurnoutTest { public void setUp() { // prepare an interface lnis = new XNetInterfaceScaffold(new LenzCommandStation()); t = new XNetTurnout(21); } public int numListeners() { return lnis.numListeners(); } XNetInterfaceScaffold lnis; public void checkClosedMsgSent() { Assert.assertEquals("closed message","52 5 0 0 ", lnis.outbound.elementAt(lnis.outbound.size()-1).toString()); Assert.assertEquals("CLOSED state",jmri.Turnout.CLOSED,t.getCommandedState()); } public void checkThrownMsgSent() { Assert.assertEquals("thrown message","52 5 1 0 ", lnis.outbound.elementAt(lnis.outbound.size()-1).toString()); Assert.assertEquals("THROWN state",jmri.Turnout.THROWN,t.getCommandedState()); } public void checkIncoming() { // notify the object that somebody else changed it... XNetMessage m = new XNetMessage(4); m.setOpCode(0xb0); m.setElement(1, 0x14); // set CLOSED m.setElement(2, 0x30); m.setElement(3, 0x00); lnis.sendTestMessage(m); Assert.assertTrue(t.getCommandedState() == jmri.Turnout.CLOSED); m = new XNetMessage(4); m.setOpCode(0xb0); m.setElement(1, 0x14); // set THROWN m.setElement(2, 0x10); m.setElement(3, 0x00); lnis.sendTestMessage(m); Assert.assertTrue(t.getCommandedState() == jmri.Turnout.THROWN); } // XNetTurnout test for incoming status message public void testXNetTurnoutStatusMsg() { // prepare an interface // set closed try { t.setCommandedState(jmri.Turnout.CLOSED); } catch (Exception e) { log.error("TO exception: "+e); } Assert.assertTrue(t.getCommandedState() == jmri.Turnout.CLOSED); // notify the Ln that somebody else changed it... XNetMessage m = new XNetMessage(4); m.setOpCode(0xb1); m.setElement(1, 0x14); // set CLOSED m.setElement(2, 0x20); m.setElement(3, 0x7b); lnis.sendTestMessage(m); Assert.assertTrue(t.getCommandedState() == jmri.Turnout.CLOSED); } // from here down is testing infrastructure public XNetTurnoutTest(String s) { super(s); } // Main entry point static public void main(String[] args) { String[] testCaseName = {XNetTurnoutTest.class.getName()}; junit.swingui.TestRunner.main(testCaseName); } // test suite from all defined tests public static Test suite() { TestSuite suite = new TestSuite(XNetTurnoutTest.class); return suite; } static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(XNetTurnoutTest.class.getName()); } |