Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package jmri.jmris; | ||
|
||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import jmri.LocoAddress; | ||
import jmri.DccLocoAddress; | ||
import jmri.DccThrottle; | ||
import jmri.Throttle; | ||
import jmri.ThrottleListener; | ||
|
||
/** | ||
* Common tests for classes derived from jmri.jmris.AbstractThrottleServer class | ||
* | ||
* @author Paul Bender Copyright (C) 2017 | ||
*/ | ||
abstract public class AbstractThrottleServerTestBase { | ||
|
||
protected AbstractThrottleServer ats = null; | ||
|
||
@Test | ||
public void testCtor() { | ||
Assert.assertNotNull(ats); | ||
} | ||
|
||
@Test | ||
public void requestThrottleTest(){ | ||
ats.requestThrottle(new DccLocoAddress(42,false)); | ||
confirmThrottleRequestSucceeded(); | ||
} | ||
|
||
/** | ||
* confirm the throttle request succeeded and an appropirate response | ||
* was forwarded to the client. | ||
*/ | ||
abstract public void confirmThrottleRequestSucceeded(); | ||
|
||
@Before | ||
// derived classes must configure the ThrottleServer variable (ats) | ||
// and should also install a throttle manager. | ||
abstract public void setUp(); | ||
|
||
@After | ||
public void postTestReset(){ | ||
ats = null; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,77 @@ | ||
package jmri.jmris.srcp; | ||
|
||
import org.junit.Assert; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import jmri.util.JUnitUtil; | ||
|
||
/** | ||
* Tests for the jmri.jmris.srcp.JmriSRCPThrottleServer class | ||
* | ||
* @author Paul Bender copyright (C) 2016 | ||
*/ | ||
public class JmriSRCPThrottleServerTest { | ||
public class JmriSRCPThrottleServerTest extends jmri.jmris.AbstractThrottleServerTestBase { | ||
|
||
private StringBuilder sb = null; | ||
|
||
@Test | ||
@Override | ||
public void requestThrottleTest(){ | ||
try { | ||
((JmriSRCPThrottleServer)ats).initThrottle(1,42,false,128,28); | ||
confirmThrottleRequestSucceeded(); | ||
} catch (java.io.IOException ioe) { | ||
Assert.fail("failed requesting throttle"); | ||
} | ||
} | ||
|
||
/** | ||
* confirm the throttle request succeeded and an appropirate response | ||
* was forwarded to the client. | ||
*/ | ||
public void confirmThrottleRequestSucceeded(){ | ||
Assert.assertTrue("Throttle notification sent", sb.toString().endsWith("101 INFO 1 GL 42 N 1 28\n\r")); | ||
} | ||
|
||
@Test | ||
public void testCtor() { | ||
public void requestThrottleBadBusTest(){ | ||
try { | ||
((JmriSRCPThrottleServer)ats).initThrottle(44,42,false,128,28); | ||
} catch (java.io.IOException ioe) { | ||
Assert.fail("failed requesting throttle"); | ||
} | ||
Assert.assertTrue("wrong value",sb.toString().endsWith("412 ERROR wrong value\n\r")); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
JUnitUtil.setUp(); | ||
JUnitUtil.resetProfileManager(); | ||
// verify the Internal System Connection memo is available. | ||
jmri.InstanceManager.getDefault(jmri.jmrix.internal.InternalSystemConnectionMemo.class); | ||
|
||
JUnitUtil.initInternalTurnoutManager(); | ||
JUnitUtil.initInternalLightManager(); | ||
JUnitUtil.initInternalSensorManager(); | ||
JUnitUtil.initDebugThrottleManager(); | ||
sb = new StringBuilder(); | ||
java.io.DataOutputStream output = new java.io.DataOutputStream( | ||
new java.io.OutputStream() { | ||
// null output string drops characters | ||
// could be replaced by one that checks for specific outputs | ||
@Override | ||
public void write(int b) throws java.io.IOException { | ||
sb.append((char)b); | ||
} | ||
}); | ||
java.io.DataInputStream input = new java.io.DataInputStream(System.in); | ||
JmriSRCPThrottleServer a = new JmriSRCPThrottleServer(input,output); | ||
Assert.assertNotNull(a); | ||
ats = new JmriSRCPThrottleServer(input,output); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
sb = null; | ||
ats = null; | ||
JUnitUtil.tearDown(); | ||
} | ||
} |