Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new tests; more internationalization work. #3014

Merged
merged 5 commits into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions java/src/jmri/jmrix/lenz/XNetBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ TurnoutStateThrown = Thrown (+)
# Command Station Version String {0} - hardware type, {1} - software version.
CSVersionString = hardware type: {0} software version: {1}

# Strings for command station types
CSTypeLZ100 = LZ100/LZV100
CSTypeLH200 = LH200
CSTypeCompact = Compact or Other
CSTypeMultiMaus = multiMaus
CSTypeZ21 = Z21
CSTypeUNKNOWN = <unknown>

#Strings for port speeds, used by the XPressNet Monitor.
LIBaud19200 = 19200bps (default)
LIBaud38400 = 38400bps
Expand Down Expand Up @@ -91,13 +99,18 @@ XNetReplyRetransmitRequest = Retransmission Requested
XNetReplyCSTransferError = Command Station Reported Transfer Error
XNetReplyCSBusy = Command Station Busy
XNetReplyCSNotSupported = XPressNet Instruction not supported by Command Station
XNetReplyCSVersionV1 = Command Station Software Version: {0} Type: Unknown (X-Bus V1 or V2)
XNetReplyCSVersion = Command Station Software Version: {0} Type: {1}
XNetReplyBCNormalOpsResumed = Broadcast: Normal Operations Resumed
XNetReplyBCEverythingOff = Broadcast: Emergency Off (short circuit)
XNetReplyBCEverythingStop = Broadcast: Emergency Stop (track power on)
XNetReplyBCServiceEntry = Broadcast: Service Mode Entry
XNetReplyServiceModeShort = Service Mode: Short Circuit
XNetReplyServiceModeDataByteNotFound = Service Mode: Data Byte Not Found
XNetReplyServiceModeCSBusy = Service Mode: Command Station Busy
XNetReplyServiceModeCSReady = Service Mode: Command Station Ready
XNetReplyServiceModeDirectResponse = Service Mode: Direct Programming Mode Response: CV:{0,number,####} Value: {1}
XNetReplyServiceModePagedResponse = Service Mode: Register or Paged Mode Response: CV:{0,number,####} Value: {1}
XNetReplyV1DHErrorNotOperated = XBus V1 and V2 MU+DH error: Selected Locomotive has not been operated by this XPressNet device or address 0 selected
XNetReplyV1DHErrorInUse = XBus V1 and V2 MU+DH error: Selected Locomotive is being operated by another XPressNet device
XNetReplyV1DHErrorAlreadyDH = XBus V1 and V2 MU+DH error: Selected Locomotive already in MU or DH
Expand Down
37 changes: 18 additions & 19 deletions java/src/jmri/jmrix/lenz/XNetReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -810,38 +810,39 @@ public String toMonitorString(){
}
} else if (getElement(0) == XNetConstants.BC_EMERGENCY_STOP
&& getElement(1) == XNetConstants.BC_EVERYTHING_STOP) {
text = "Broadcast: Emergency Stop (track power on)";
text = Bundle.getMessage("XNetReplyBCEverythingStop");
/* Followed by Service Mode responses */
} else if (getElement(0) == XNetConstants.CS_SERVICE_MODE_RESPONSE) {
if (isDirectModeResponse()) {
text = "Service Mode: Direct Programming Response: CV:"
+ getServiceModeCVNumber()
+ " Value: " + getServiceModeCVValue();
text = Bundle.getMessage("XNetReplyServiceModeDirectResponse",
getServiceModeCVNumber(),
getServiceModeCVValue());
} else if (isPagedModeResponse()) {
text = "Service Mode: Register or Paged Mode Response: CV:"
+ getServiceModeCVNumber()
+ " Value: " + getServiceModeCVValue();
text = Bundle.getMessage("XNetReplyServiceModePagedResponse",
getServiceModeCVNumber(),
getServiceModeCVValue());
} else if (getElement(1) == XNetConstants.CS_SOFTWARE_VERSION) {
text
= "Command Station Software Version: "
+ (getElementBCD(2).floatValue()) / 10 + " Type: ";
String typeString;
switch (getElement(3)) {
case 0x00:
text = text + "LZ100/LZV100";
typeString = Bundle.getMessage("CSTypeLZ100");
break;
case 0x01:
text = text + "LH200";
typeString = Bundle.getMessage("CSTypeLH200");
break;
case 0x02:
text = text + "Compact or Other";
typeString = Bundle.getMessage("CSTypeCompact");
break;
// GT 2007/11/6 - Added multiMaus
case 0x10:
text = text + "multiMaus";
typeString = Bundle.getMessage("CSTypeMultiMaus");
break;
default:
text = text + getElement(3);
typeString = "" + getElement(3);
}
text = Bundle.getMessage("XNetReplyCSVersion",
(getElementBCD(2).floatValue()) / 10,
typeString);
} else {
text = toString();
}
Expand Down Expand Up @@ -879,10 +880,8 @@ && getElement(1) == XNetConstants.BC_EVERYTHING_STOP) {
} else if (getElement(1) == XNetConstants.CS_SOFTWARE_VERSION) {
/* This is a Software version response for XPressNet
Version 1 or 2 */
text
= "Command Station Software Version: "
+ (getElementBCD(2).floatValue()) / 10
+ "Type: Unknown (X-Bus V1 or V2)";
text = Bundle.getMessage("XNetReplyCSVersionV1",
(getElementBCD(2).floatValue()) / 10);
} else {
text = toString();
}
Expand Down
1 change: 1 addition & 0 deletions java/src/jmri/jmrix/lenz/swing/XNetSwingBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

PacketGenFrameTitle = Send XPressNet Packet
XNetMonFrameTitle = XpressNet Traffic
SystemInfoFrameTitle = XpressNet System Information
98 changes: 98 additions & 0 deletions java/src/jmri/jmrix/lenz/swing/systeminfo/Bundle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package jmri.jmrix.lenz.swing.systeminfo;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Locale;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
@CheckReturnValue
@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", justification = "Desired pattern is repeated class names with package-level access to members")

@net.jcip.annotations.Immutable

/**
* Provides standard access for resource bundles in a package.
*
* Convention is to provide a subclass of this name in each package, working off
* the local resource bundle name.
*
* @author Bob Jacobsen Copyright (C) 2012
* @since 4.3.6
*/
public class Bundle extends jmri.jmrix.lenz.swing.Bundle {

private final static String name = "jmri.jmrix.lenz.swing.systeminfo.SystemInfoBundle"; // NOI18N

//
// below here is boilerplate to be copied exactly
//
/**
* Provides a translated string for a given key from the package resource
* bundle or parent.
* <p>
* Note that this is intentionally package-local access.
*
* @param key Bundle key to be translated
* @return Internationalized text
*/
static String getMessage(String key) {
return b.handleGetMessage(key);
}

/**
* Merges user data with a translated string for a given key from the
* package resource bundle or parent.
* <p>
* Uses the transformation conventions of the Java MessageFormat utility.
* <p>
* Note that this is intentionally package-local access.
*
* @see java.text.MessageFormat
* @param key Bundle key to be translated
* @param subs One or more objects to be inserted into the message
* @return Internationalized text
*/
static String getMessage(String key, Object... subs) {
return b.handleGetMessage(key, subs);
}

/**
* Merges user data with a translated string for a given key in a given
* locale from the package resource bundle or parent.
* <p>
* Uses the transformation conventions of the Java MessageFormat utility.
* <p>
* Note that this is intentionally package-local access.
*
* @see java.text.MessageFormat
* @param locale The locale to be used
* @param key Bundle key to be translated
* @param subs One or more objects to be inserted into the message
* @return Internationalized text
*/
static String getMessage(Locale locale, String key, Object... subs) {
return b.handleGetMessage(locale, key, subs);
}


private final static Bundle b = new Bundle();

@Override
@Nullable
protected String bundleName() {
return name;
}

@Override
protected jmri.Bundle getBundle() {
return b;
}

@Override
protected String retry(Locale locale, String key) {
return super.getBundle().handleGetMessage(locale,key);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public SystemInfoAction(String s, jmri.jmrix.lenz.XNetSystemConnectionMemo memo)
}

public SystemInfoAction(jmri.jmrix.lenz.XNetSystemConnectionMemo memo) {
this("Xpressnet System Information", memo);
this(Bundle.getMessage("SystemInfoFrameTitle"), memo);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SystemInfoBundle.properties
#
#
#
# Default properties for the jmri.jmrix.lenz.swing.systeminfo package

CommandStationLabel = Command Station:
SoftwareVersionLabel = Software Version:
StatusLabel = Status:
InterfaceLabel = Interface:
LIHardwareVersionLabel = Hardware Version:
LISoftwareVersionLabel = Software Version:
GetSystemInfoButtonLabel = Get System Information
CloseButtonLabel = Close
28 changes: 14 additions & 14 deletions java/src/jmri/jmrix/lenz/swing/systeminfo/SystemInfoFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ public SystemInfoFrame(jmri.jmrix.lenz.XNetSystemConnectionMemo memo) {
tc = memo.getXNetTrafficController();
getContentPane().setLayout(new GridLayout(0, 2));

getContentPane().add(new JLabel("Command Station: "));
getContentPane().add(new JLabel(Bundle.getMessage("CommandStationLabel")));
getContentPane().add(CSType);

getContentPane().add(new JLabel("Software Version:"));
getContentPane().add(new JLabel(Bundle.getMessage("SoftwareVersionLabel")));
getContentPane().add(CSSoftwareVersion);

getContentPane().add(new JLabel("Status:"));
getContentPane().add(new JLabel(Bundle.getMessage("StatusLabel")));
getContentPane().add(CSStatus);

getContentPane().add(new JLabel("Interface: "));
getContentPane().add(new JLabel(Bundle.getMessage("InterfaceLabel")));
getContentPane().add(LIType);

getContentPane().add(new JLabel("Hardware Version:"));
getContentPane().add(new JLabel(Bundle.getMessage("LIHardwareVersionLabel")));
getContentPane().add(LIHardwareVersion);

getContentPane().add(new JLabel("Software Version:"));
getContentPane().add(new JLabel(Bundle.getMessage("LISoftwareVersionLabel")));
getContentPane().add(LISoftwareVersion);

getContentPane().add(getSystemInfoButton);
Expand Down Expand Up @@ -102,8 +102,8 @@ public void actionPerformed(ActionEvent a) {
JLabel LIHardwareVersion = new JLabel("");
JLabel LISoftwareVersion = new JLabel("");

JToggleButton getSystemInfoButton = new JToggleButton("Get System Info");
JToggleButton closeButton = new JToggleButton("Close");
JToggleButton getSystemInfoButton = new JToggleButton(Bundle.getMessage("GetSystemInfoButtonLabel"));
JToggleButton closeButton = new JToggleButton(Bundle.getMessage("CloseButtonLabel"));

//Send Information request to LI100/LI101
void getSystemInfo() {
Expand Down Expand Up @@ -192,17 +192,17 @@ private void setCSVersionDisplay() {
.getCommandStationSoftwareVersion());
int cs_type = tc.getCommandStation().getCommandStationType();
if (cs_type == jmri.jmrix.lenz.XNetConstants.CS_TYPE_LZ100) {
CSType.setText("LZ100/LZV100");
CSType.setText(Bundle.getMessage("CSTypeLZ100"));
} else if (cs_type == jmri.jmrix.lenz.XNetConstants.CS_TYPE_LH200) {
CSType.setText("LH200");
CSType.setText(Bundle.getMessage("CSTypeLH200"));
} else if (cs_type == jmri.jmrix.lenz.XNetConstants.CS_TYPE_COMPACT) {
CSType.setText("Compact or Other");
CSType.setText(Bundle.getMessage("CSTypeCompact"));
} else if (cs_type == jmri.jmrix.lenz.XNetConstants.CS_TYPE_MULTIMAUS) {
CSType.setText("multiMAUS");
CSType.setText(Bundle.getMessage("CSTypeMultiMaus"));
} else if (cs_type == jmri.jmrix.lenz.XNetConstants.CS_TYPE_Z21) {
CSType.setText("Z21");
CSType.setText(Bundle.getMessage("CSTypeZ21"));
} else {
CSType.setText("<unknown>");
CSType.setText(Bundle.getMessage("CSTypeUNKNOWN"));
}
}

Expand Down
46 changes: 46 additions & 0 deletions java/test/jmri/jmrix/lenz/XNetReplyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ public void testIsServiceModeResponse() {
r = new XNetReply("01 04 05");
Assert.assertFalse(r.isServiceModeResponse());
}

@Test
public void testToMonitorStringServiceModeDirectResponse(){
XNetReply r = new XNetReply("63 14 01 04 72");
Assert.assertEquals("Monitor String","Service Mode: Direct Programming Mode Response: CV:1 Value: 4",r.toMonitorString());
}

@Test
public void testToMonitorStringServiceModePagedResponse(){
XNetReply r = new XNetReply("63 10 01 04 76");
Assert.assertEquals("Monitor String","Service Mode: Register or Paged Mode Response: CV:1 Value: 4",r.toMonitorString());
}

// check is paged mode response
@Test
Expand Down Expand Up @@ -1052,6 +1064,40 @@ public void testToMonitorStringLIBaud5Reply(){
Assert.assertEquals("Monitor String","RESPONSE LI101 Baud Rate: <undefined>",r.toMonitorString());
}

@Test
public void testToMonitorStringCSStatusReply(){
XNetReply r = new XNetReply("62 22 00 40");
Assert.assertEquals("Monitor String","Command Station Status: Manual power-up Mode",r.toMonitorString());
r = new XNetReply("62 22 FF BF");
Assert.assertEquals("Monitor String","Command Station Status: Emergency Off Emergency Stop Service Mode Powering up Auto power-up Mode RAM check error!",r.toMonitorString());
}

@Test
public void testToMonitorStringCSVersionReply(){
XNetReply r = new XNetReply("63 21 36 00 55");
Assert.assertEquals("Monitor String","Command Station Software Version: 3.6 Type: LZ100/LZV100",r.toMonitorString());
r = new XNetReply("63 21 36 01 55");
Assert.assertEquals("Monitor String","Command Station Software Version: 3.6 Type: LH200",r.toMonitorString());
r = new XNetReply("63 21 36 02 55");
Assert.assertEquals("Monitor String","Command Station Software Version: 3.6 Type: Compact or Other",r.toMonitorString());
r = new XNetReply("63 21 36 10 55");
Assert.assertEquals("Monitor String","Command Station Software Version: 3.6 Type: multiMaus",r.toMonitorString());
r = new XNetReply("63 21 36 20 55");
Assert.assertEquals("Monitor String","Command Station Software Version: 3.6 Type: 32",r.toMonitorString());
}

@Test
public void testToMonitorStringCSV1VersionReply(){
XNetReply r = new XNetReply("62 21 21 62");
Assert.assertEquals("Monitor String","Command Station Software Version: 2.1 Type: Unknown (X-Bus V1 or V2)",r.toMonitorString());
}

@Test
public void testToMonitorStringBCEmeregncyStop(){
XNetReply r = new XNetReply("81 00 81");
Assert.assertEquals("Monitor String","Broadcast: Emergency Stop (track power on)",r.toMonitorString());
}

// The minimal setup for log4J
@Before
public void setUp() {
Expand Down