Skip to content

Commit

Permalink
Fix alternate track bug. Code cleanup, more testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielboudreau authored and danielboudreau committed Feb 21, 2021
1 parent 6a80e25 commit f8a4aa6
Show file tree
Hide file tree
Showing 12 changed files with 809 additions and 494 deletions.
Expand Up @@ -860,7 +860,6 @@ buildReturnCarToStaging = Returning car ({0}) to staging ({1}), no other tra

buildCanNotDropLocation = Car ({0}) type ({1}) isn''t serviced by destination ({2})
buildSearchTrackNewLoad = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4})
buildGenerateLoad = Generate load for ({0}) type ({1}) destination ({2}, {3})
buildSearchTrackLoadStaging = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4}) to staging ({5}, {6})
buildTrainNotNewLoad = Train ({0}) doesn''t service load ({1}) destination ({2}, {3})
buildTrackNotNewLoad = Departure track ({0}) can''t ship load ({1}) to destination ({2}, {3})
Expand Down
Expand Up @@ -790,7 +790,6 @@ buildReturnCarToStaging = Returning car ({0}) to staging ({1}), no other tra

buildCanNotDropLocation = Can''t send ({0}) type ({1}) to destination ({2})
buildSearchTrackNewLoad = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4})
buildGenerateLoad = Generate load for ({0}) type ({1}) destination ({2}, {3})
buildSearchTrackLoadStaging = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4}) to staging ({5}, {6})
buildTrainNotNewLoad = Train ({0}) doesn''t service load ({1}) destination ({2}, {3})
buildTrackNotNewLoad = Departure track ({0}) can''t ship load ({1}) to destination ({2}, {3})
Expand Down
Expand Up @@ -807,7 +807,6 @@ buildReturnCarToStaging = Returning car ({0}) to staging ({1}), no other tra

buildCanNotDropLocation = Can''t send ({0}) type ({1}) to destination ({2})
buildSearchTrackNewLoad = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4})
buildGenerateLoad = Generate load for ({0}) type ({1}) destination ({2}, {3})
buildSearchTrackLoadStaging = Generate load for ({0}) type ({1}) load ({2}) at ({3}, {4}) to staging ({5}, {6})
buildTrainNotNewLoad = Train ({0}) doesn''t service load ({1}) destination ({2}, {3})
buildTrackNotNewLoad = Departure track ({0}) can''t ship load ({1}) to destination ({2}, {3})
Expand Down
Expand Up @@ -830,7 +830,6 @@ buildReturnCarToStaging = Le wagon ({0}) retourne \u00e0 la coulisse ({1}),

buildCanNotDropLocation = Impossible de d\u00e9pos\u00e9 wagon ({0}) type ({1}) \u00e0 destination ({2})
buildSearchTrackNewLoad = G\u00e9n\u00e9rer une charge pour ({0}) type ({1}) charge ({2}) voie ({3})
buildGenerateLoad = G\u00e9n\u00e9rer une charge pour ({0}) type ({1}) destination ({2}, {3})
buildSearchTrackLoadStaging = G\u00e9n\u00e9rer une charge pour ({0}) type ({1}) charge ({2}) voie ({3}) pour la coulisse ({4}, {5})
buildTrainNotNewLoad = Train ({0}) ne peut pas acheminer la charge ({1}) destination ({2}, {3})
buildTrackNotNewLoad = Voie de d\u00e9part ({0}) Impossible d'exp\u00e9dier la charge ({1}) \u00e0 destination ({2}, {3})
Expand Down
Expand Up @@ -715,7 +715,6 @@ buildReturnCarToStaging = Riporto carro ({0}) al deposito nascosto ({1}), ne

buildCanNotDropLocation = Non posso consegnare carro ({0}) tipo ({1}) alla destinazione ({2})
buildSearchTrackNewLoad = Genero carico per ({0}) tipo ({1}) carico ({2}) binario ({3}, {4})
buildGenerateLoad = Genera carico per ({0}) tipo ({1}) destinazione ({2}, {3})
buildSearchTrackLoadStaging = Genera carico per ({0}) tipo ({1}) carico ({2}) binario ({3}, {4}) in deposito ({5}, {6})
buildTrainNotNewLoad = Treno ({0}) non serve carico ({1}) con destinazione ({2}, {3})
buildTrackNotNewLoad = Binario di partenza ({0}) non pu\u00f2 inviare carico ({1}) alla destinazione ({2}, {3})
Expand Down
185 changes: 82 additions & 103 deletions java/src/jmri/jmrit/operations/trains/TrainBuilder.java

Large diffs are not rendered by default.

523 changes: 239 additions & 284 deletions java/src/jmri/jmrit/operations/trains/TrainCommon.java

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions java/src/jmri/jmrit/operations/trains/TrainPrintUtilities.java
Expand Up @@ -44,8 +44,8 @@ public class TrainPrintUtilities {
* @param orientation Setup.LANDSCAPE, Setup.PORTRAIT, or Setup.HANDHELD
* @param fontSize font size
*/
public static void printReport(File file, String name, boolean isPreview, String fontName,
boolean isBuildReport, String logoURL, String printerName, String orientation, int fontSize) {
public static void printReport(File file, String name, boolean isPreview, String fontName, boolean isBuildReport,
String logoURL, String printerName, String orientation, int fontSize) {
// obtain a HardcopyWriter to do this
HardcopyWriter writer = null;
boolean isLandScape = false;
Expand All @@ -64,8 +64,8 @@ public static void printReport(File file, String name, boolean isPreview, String
TrainCommon.getPageSize(orientation).height + TrainCommon.PAPER_MARGINS.height);
}
try {
writer = new HardcopyWriter(new Frame(), name, fontSize, margin, margin, .5, .5,
isPreview, printerName, isLandScape, printHeader, pagesize);
writer = new HardcopyWriter(new Frame(), name, fontSize, margin, margin, .5, .5, isPreview, printerName,
isLandScape, printHeader, pagesize);
} catch (HardcopyWriter.PrintCanceledException ex) {
log.debug("Print cancelled");
return;
Expand Down Expand Up @@ -142,23 +142,23 @@ public static void printReport(File file, String name, boolean isPreview, String

// determine if line is a pickup or drop
if ((!Setup.getPickupEnginePrefix().trim().isEmpty() &&
line.startsWith(Setup.getPickupEnginePrefix())) ||
line.startsWith(Setup.getPickupEnginePrefix() + TrainCommon.SPACE)) ||
(!Setup.getPickupCarPrefix().trim().isEmpty() &&
line.startsWith(Setup.getPickupCarPrefix())) ||
line.startsWith(Setup.getPickupCarPrefix() + TrainCommon.SPACE)) ||
(!Setup.getSwitchListPickupCarPrefix().trim().isEmpty() &&
line.startsWith(Setup.getSwitchListPickupCarPrefix()))) {
line.startsWith(Setup.getSwitchListPickupCarPrefix() + TrainCommon.SPACE))) {
c = Setup.getPickupColor();
} else if ((!Setup.getDropEnginePrefix().trim().isEmpty() &&
line.startsWith(Setup.getDropEnginePrefix())) ||
line.startsWith(Setup.getDropEnginePrefix() + TrainCommon.SPACE)) ||
(!Setup.getDropCarPrefix().trim().isEmpty() &&
line.startsWith(Setup.getDropCarPrefix())) ||
line.startsWith(Setup.getDropCarPrefix() + TrainCommon.SPACE)) ||
(!Setup.getSwitchListDropCarPrefix().trim().isEmpty() &&
line.startsWith(Setup.getSwitchListDropCarPrefix()))) {
line.startsWith(Setup.getSwitchListDropCarPrefix() + TrainCommon.SPACE))) {
c = Setup.getDropColor();
} else if ((!Setup.getLocalPrefix().trim().isEmpty() &&
line.startsWith(Setup.getLocalPrefix())) ||
line.startsWith(Setup.getLocalPrefix() + TrainCommon.SPACE)) ||
(!Setup.getSwitchListLocalPrefix().trim().isEmpty() &&
line.startsWith(Setup.getSwitchListLocalPrefix()))) {
line.startsWith(Setup.getSwitchListLocalPrefix() + TrainCommon.SPACE))) {
c = Setup.getLocalColor();
} else if (line.contains(TrainCommon.TEXT_COLOR_START)) {
c = TrainCommon.getTextColor(line);
Expand Down Expand Up @@ -251,11 +251,11 @@ public static void editReport(File file, String name) {
return;
}
PrintWriter out;
File buildReport = InstanceManager.getDefault(TrainManagerXml.class).createTrainBuildReportFile(
Bundle.getMessage("Report") + " " + name);
File buildReport = InstanceManager.getDefault(TrainManagerXml.class)
.createTrainBuildReportFile(Bundle.getMessage("Report") + " " + name);
try {
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(buildReport), StandardCharsets.UTF_8)), true);
out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(buildReport), StandardCharsets.UTF_8)), true);
} catch (IOException e) {
log.error("Can not create build report file");
try {
Expand Down
Expand Up @@ -3,11 +3,12 @@
import java.awt.GraphicsEnvironment;

import org.junit.Assert;
import org.junit.jupiter.api.*;
import org.junit.Assume;
import org.junit.jupiter.api.Test;

import jmri.InstanceManager;
import jmri.jmrit.operations.OperationsTestCase;
import jmri.jmrit.operations.setup.Setup;
import jmri.jmrit.operations.trains.Train;
import jmri.jmrit.operations.trains.TrainManager;
import jmri.util.JUnitOperationsUtil;
Expand All @@ -34,6 +35,8 @@ public void testLocationWithWork() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());

JUnitOperationsUtil.initOperationsData();
// improve test coverage
Setup.setPrintHeadersEnabled(true);

// build a train to create data for the Yardmaster window
Train train = InstanceManager.getDefault(TrainManager.class).getTrainByName("STF");
Expand Down
99 changes: 97 additions & 2 deletions java/test/jmri/jmrit/operations/setup/SetupTest.java
@@ -1,8 +1,9 @@
package jmri.jmrit.operations.setup;

import jmri.jmrit.operations.OperationsTestCase;
import org.junit.Assert;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Test;

import jmri.jmrit.operations.OperationsTestCase;

/**
*
Expand All @@ -15,6 +16,100 @@ public void testCTor() {
Setup t = new Setup();
Assert.assertNotNull("exists",t);
}

@Test
public void testPrefixLength() {
Setup.setSwitchListFormatSameAsManifest(false);

Assert.assertEquals("Default length", 12, Setup.getManifestPrefixLength());
Assert.assertEquals("Default length", 12, Setup.getSwitchListPrefixLength());

Setup.setDropEnginePrefix("ABCDEFGHIJKLM"); // now 13 characters
Assert.assertEquals("new length 1", 13, Setup.getManifestPrefixLength());
Assert.assertEquals("new length 1", 13, Setup.getSwitchListPrefixLength());

Setup.setDropCarPrefix("ABCDEFGHIJKLMN"); // now 14 characters
Assert.assertEquals("new length 2", 14, Setup.getManifestPrefixLength());
Assert.assertEquals("new length 2", 13, Setup.getSwitchListPrefixLength());

Setup.setPickupCarPrefix("ABCDEFGHIJKLMNO"); // now 15 characters
Assert.assertEquals("new length 3", 15, Setup.getManifestPrefixLength());
Assert.assertEquals("new length 3", 13, Setup.getSwitchListPrefixLength());

Setup.setLocalPrefix("ABCDEFGHIJKLMNOP"); // now 16 characters
Assert.assertEquals("new length 4", 16, Setup.getManifestPrefixLength());
Assert.assertEquals("new length 4", 13, Setup.getSwitchListPrefixLength());

Setup.setSwitchListDropCarPrefix("ABCDEFGHIJKLMNOPQ"); // now 17 characters
Assert.assertEquals("new length 5", 16, Setup.getManifestPrefixLength());
Assert.assertEquals("new length 5", 17, Setup.getSwitchListPrefixLength());

Setup.setSwitchListPickupCarPrefix("ABCDEFGHIJKLMNOPQR"); // now 18 characters
Assert.assertEquals("new length 6", 16, Setup.getManifestPrefixLength());
Assert.assertEquals("new length 6", 18, Setup.getSwitchListPrefixLength());

Setup.setSwitchListLocalPrefix("ABCDEFGHIJKLMNOPQRS"); // now 19 characters
Assert.assertEquals("new length 7", 16, Setup.getManifestPrefixLength());
Assert.assertEquals("new length 7", 19, Setup.getSwitchListPrefixLength());

Setup.setSwitchListFormatSameAsManifest(true);
Assert.assertEquals("confirm length", 16, Setup.getSwitchListPrefixLength());
}

@Test
public void testDropTruncatedMessageFormat() {
Assert.assertEquals("default message", 10, Setup.getDropTruncatedManifestMessageFormat().length);
// confirm
Assert.assertEquals("attribute 1", Setup.ROAD, Setup.getDropTruncatedManifestMessageFormat()[0]);
Assert.assertEquals("attribute 2", Setup.NUMBER, Setup.getDropTruncatedManifestMessageFormat()[1]);
Assert.assertEquals("attribute 3", Setup.TYPE, Setup.getDropTruncatedManifestMessageFormat()[2]);
Assert.assertEquals("attribute 4", Setup.LENGTH, Setup.getDropTruncatedManifestMessageFormat()[3]);
Assert.assertEquals("attribute 5", Setup.COLOR, Setup.getDropTruncatedManifestMessageFormat()[4]);
Assert.assertEquals("attribute 7", Setup.LOAD, Setup.getDropTruncatedManifestMessageFormat()[5]);
Assert.assertEquals("attribute 6", Setup.HAZARDOUS, Setup.getDropTruncatedManifestMessageFormat()[6]);
Assert.assertEquals("attribute 7", Setup.NO_DESTINATION, Setup.getDropTruncatedManifestMessageFormat()[7]);
Assert.assertEquals("attribute 8", Setup.COMMENT, Setup.getDropTruncatedManifestMessageFormat()[8]);
Assert.assertEquals("attribute 9", Setup.DROP_COMMENT, Setup.getDropTruncatedManifestMessageFormat()[9]);
}

@Test
public void testPickupTruncatedMessageFormat() {
Assert.assertEquals("default message", 10, Setup.getPickupTruncatedManifestMessageFormat().length);
// confirm
Assert.assertEquals("attribute 1", Setup.ROAD, Setup.getPickupTruncatedManifestMessageFormat()[0]);
Assert.assertEquals("attribute 2", Setup.NUMBER, Setup.getPickupTruncatedManifestMessageFormat()[1]);
Assert.assertEquals("attribute 3", Setup.TYPE, Setup.getPickupTruncatedManifestMessageFormat()[2]);
Assert.assertEquals("attribute 4", Setup.LENGTH, Setup.getPickupTruncatedManifestMessageFormat()[3]);
Assert.assertEquals("attribute 5", Setup.COLOR, Setup.getPickupTruncatedManifestMessageFormat()[4]);
Assert.assertEquals("attribute 7", Setup.LOAD, Setup.getPickupTruncatedManifestMessageFormat()[5]);
Assert.assertEquals("attribute 6", Setup.HAZARDOUS, Setup.getPickupTruncatedManifestMessageFormat()[6]);
Assert.assertEquals("attribute 7", Setup.NO_LOCATION, Setup.getPickupTruncatedManifestMessageFormat()[7]);
Assert.assertEquals("attribute 8", Setup.COMMENT, Setup.getPickupTruncatedManifestMessageFormat()[8]);
Assert.assertEquals("attribute 9", Setup.PICKUP_COMMENT, Setup.getPickupTruncatedManifestMessageFormat()[9]);
}

@Test
public void testEngineMessageComboBox() {
Assert.assertEquals("default size", 13, Setup.getEngineMessageComboBox().getItemCount());
Setup.setTabEnabled(true);
Assert.assertEquals("with tabs", 16, Setup.getEngineMessageComboBox().getItemCount());
}

@Test
public void testCarMessageComboBox() {
Assert.assertEquals("default size", 23, Setup.getCarMessageComboBox().getItemCount());
Setup.setTabEnabled(true);
Assert.assertEquals("with tabs", 26, Setup.getCarMessageComboBox().getItemCount());
}

@Test
public void testDirectionInt() {
Assert.assertEquals("east", 1, Setup.getDirectionInt(Setup.EAST_DIR));
Assert.assertEquals("west", 2, Setup.getDirectionInt(Setup.WEST_DIR));
Assert.assertEquals("south", 8, Setup.getDirectionInt(Setup.SOUTH_DIR));
Assert.assertEquals("north", 4, Setup.getDirectionInt(Setup.NORTH_DIR));
Assert.assertEquals("error", 0, Setup.getDirectionInt("X"));
}

// private final static Logger log = LoggerFactory.getLogger(SetupTest.class);

Expand Down

0 comments on commit f8a4aa6

Please sign in to comment.