Skip to content
Permalink
Browse files

increase tests

  • Loading branch information...
icklesteve committed May 19, 2019
1 parent 37b0e96 commit 7118d3e71988062a8c036bae9c4e1aa5d4c98b56
@@ -522,7 +522,7 @@ CMDERR12 = Invalid Node Variable Value

# Command Station Error Codes
ERR_LOCO_STACK_FULL = Loco stack full for address
ERR_LOCO_ADDRESS_TAKEN = Loco address taken for address
ERR_LOCO_ADDRESS_TAKEN = Loco address {0} taken
ERR_SESSION_NOT_PRESENT = Session {0} not present on Command Station
ERR_CONSIST_EMPTY = Consist empty for consist
ERR_LOCO_NOT_FOUND = Loco not found for session
@@ -171,7 +171,7 @@ protected CbusNode getMasterCommandStation(){
*/
protected boolean isStealAvailable() {
if ( getMasterCommandStation() != null ) {
log.debug("found master command sttaion");
log.debug("found master command station");
if ( getMasterCommandStation().getNV(2) > -1 ){
log.debug("nv 2 has a value");
return (( getMasterCommandStation().getNV(2) >> 1 ) & 1) != 0; // NV2 bit 1 set
@@ -77,8 +77,8 @@ else if (fields[i].startsWith("$2")) { // replace the 2 bytes with node name ( i
buf.append(locoFromBytes(msg.getElement(1),msg.getElement(2)));
break;
case 2:
buf.append(Bundle.getMessage("ERR_LOCO_ADDRESS_TAKEN"));
buf.append(locoFromBytes(msg.getElement(1),msg.getElement(2)));
buf.append(Bundle.getMessage("ERR_LOCO_ADDRESS_TAKEN",
locoFromBytes(msg.getElement(1),msg.getElement(2))));
break;
case 3:
buf.append(Bundle.getMessage("ERR_SESSION_NOT_PRESENT",msg.getElement(1)));
@@ -248,7 +248,7 @@ public void reply(CanReply m) {
errStr = Bundle.getMessage("ERR_LOCO_STACK_FULL") + " " + rcvdIntAddr;
}
else if ( errCode == CbusConstants.ERR_LOCO_ADDRESS_TAKEN ){
errStr = Bundle.getMessage("ERR_LOCO_ADDRESS_TAKEN") + " " + rcvdIntAddr;
errStr = Bundle.getMessage("ERR_LOCO_ADDRESS_TAKEN",rcvdIntAddr);
}

log.debug("handlexpected {} _dccAddr {} got {} ",_handleExpected,_dccAddr,rcvdDccAddr);
@@ -263,7 +263,7 @@ else if ( errCode == CbusConstants.ERR_LOCO_ADDRESS_TAKEN ){
// if this is the result of a share or steal request,
// we need to stop here and inform the ThrottleListener
if ( _handleExpectedSecondLevelRequest ){
failedThrottleRequest(_dccAddr, Bundle.getMessage("CBUS_ERROR") + errStr);
failedThrottleRequest(_dccAddr, errStr);
return;
}

@@ -274,15 +274,16 @@ else if ( errCode == CbusConstants.ERR_LOCO_ADDRESS_TAKEN ){
boolean steal = false;
boolean share = false;

if ( jmri.InstanceManager.getNullableDefault(jmri.CommandStation.class) != null ) {
CbusCommandStation cs = (CbusCommandStation) _memo.get(jmri.CommandStation.class);
CbusCommandStation cs = (CbusCommandStation) jmri.InstanceManager.getNullableDefault(jmri.CommandStation.class);

if ( cs != null ) {
log.debug("cs says can steal {}, can share {}", cs.isStealAvailable(),cs.isShareAvailable() );
steal = cs.isStealAvailable();
share = cs.isShareAvailable();
}

if ( !steal && !share ){
failedThrottleRequest(_dccAddr, Bundle.getMessage("CBUS_ERROR") + errStr);
failedThrottleRequest(_dccAddr, errStr);
return;
}
else if ( steal && share ){
@@ -297,7 +298,6 @@ else if ( share ){
notifyDecisionRequest(_dccAddr,DecisionType.SHARE);
return;
}

} else {
log.debug("ERR address not matched");
}
@@ -576,7 +576,7 @@ else if ( question == DecisionType.SHARE ){ // steal has been disabled in comman
}
else if ( question == DecisionType.STEAL_OR_SHARE ){
if (jmri.InstanceManager.getNullableDefault(ThrottlesPreferences.class) == null) {
log.info("Creating new ThrottlesPreference Instance");
log.debug("Creating new ThrottlesPreference Instance");
jmri.InstanceManager.store(new ThrottlesPreferences(), ThrottlesPreferences.class);
}
ThrottlesPreferences tp = jmri.InstanceManager.getDefault(ThrottlesPreferences.class);
@@ -742,8 +742,7 @@ private void processerr(boolean messagein, int one, int two, int errnum) {
buf.append(rcvdIntAddr);
break;
case 2:
buf.append(Bundle.getMessage("ERR_LOCO_ADDRESS_TAKEN"));
buf.append(rcvdIntAddr);
buf.append(Bundle.getMessage("ERR_LOCO_ADDRESS_TAKEN",rcvdIntAddr));
break;
case 3:
buf.append(Bundle.getMessage("ERR_SESSION_NOT_PRESENT",one));
@@ -1,14 +1,12 @@
package jmri.jmrit.throttle;

import java.awt.GraphicsEnvironment;
import java.io.File;
import jmri.InstanceManager;
import jmri.DccLocoAddress;
import jmri.util.JUnitUtil;
import jmri.util.junit.rules.RetryRule;
import jmri.util.swing.JemmyUtil;
import org.junit.*;
import org.junit.rules.TemporaryFolder;

/**
* Test steal or sharing functionality of ThrottleFrame
@@ -36,8 +34,8 @@ public void testSetAndReleaseWithSteal() {
// request is expected next, and we want to steal.
to.answerStealShareQuestionSteal();

Assert.assertEquals("address set",new DccLocoAddress(42,false),
to.getAddressValue());
Assert.assertEquals("address set",new DccLocoAddress(42,false),to.getAddressValue());
jmri.util.JUnitAppender.assertErrorMessage("1: Got a steal decision");

to.pushReleaseButton();
}
@@ -50,11 +48,11 @@ public void testSetAndReleaseWithShare() {
to.pushSetButton();

// because of the throttle manager we are using, a steal or share
// request is expected next, and we want to steal.
// request is expected next, and we want to share.
to.answerStealShareQuestionShare();

Assert.assertEquals("address set",new DccLocoAddress(42,false),
to.getAddressValue());
Assert.assertEquals("address set",new DccLocoAddress(42,false),to.getAddressValue());
jmri.util.JUnitAppender.assertErrorMessage("1: Got a share decision");

to.pushReleaseButton();
}
@@ -68,7 +66,7 @@ public void testSetAndRefuseShare() {

// because of the throttle manager we are using, a steal or share
// request is expected next, and we want to cancel.
to.answerStealShareQuestionCancel();
to.answerStealShareQuestionCancel();

Assert.assertFalse("release button disabled",to.releaseButtonEnabled());
Assert.assertTrue("set button enabled",to.setButtonEnabled());
@@ -93,20 +91,48 @@ public void testRefuseOneShareOne() {

// because of the throttle manager we are using, a steal or share
// request is expected next, and we want to share.
to.answerStealShareQuestionShare();
to.answerStealShareQuestionShare();

Assert.assertEquals("address set",new DccLocoAddress(4245,true),
to.getAddressValue());
Assert.assertEquals("address set",new DccLocoAddress(4245,true),to.getAddressValue());
jmri.util.JUnitAppender.assertErrorMessage("1: Got a share decision");

to.pushReleaseButton();
}

@Test
public void testPreferenceSteal() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());

// set preference to silent steal
ThrottlesPreferences tp = jmri.InstanceManager.getDefault(ThrottlesPreferences.class);
tp.setSilentSteal(true);

to.typeAddressValue(42);
to.pushSetButton();
jmri.util.JUnitAppender.assertErrorMessage("1: Got a steal decision");

}

@Test
public void testPreferenceShare() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());

// set preference to silent share
ThrottlesPreferences tp = jmri.InstanceManager.getDefault(ThrottlesPreferences.class);
tp.setSilentShare(true);

to.typeAddressValue(42);
to.pushSetButton();
jmri.util.JUnitAppender.assertErrorMessage("1: Got a share decision");

}


@Before
public void setUp() {
JUnitUtil.setUp();
JUnitUtil.resetProfileManager();
// these tests use the SharingThrottleManager.
// these tests use the StealingOrSharingThrottleManager.
jmri.ThrottleManager m = new jmri.managers.StealingOrSharingThrottleManager();
jmri.InstanceManager.setThrottleManager(m);

@@ -48,7 +48,7 @@ public void testDecode() {
m.setElement(3, 0x01);
Assert.assertEquals("CBUS_ERR 1","Command Station Error Loco stack full for address 3215 L",CbusOpCodes.decode(m));
m.setElement(3, 0x02);
Assert.assertEquals("CBUS_ERR 2","Command Station Error Loco address taken for address 3215 L",CbusOpCodes.decode(m));
Assert.assertEquals("CBUS_ERR 2","Command Station Error Loco address 3215 L taken",CbusOpCodes.decode(m));
m.setElement(3, 0x03);
Assert.assertEquals("CBUS_ERR 3","Command Station Error Session 204 not present on Command Station",CbusOpCodes.decode(m));
m.setElement(3, 0x04);

0 comments on commit 7118d3e

Please sign in to comment.
You can’t perform that action at this time.