18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 14:07:06 +01:00
Files
maszyna/tests/editor
maj00r c7afa3ca10 fix(editor): a switch laid gets the speed of its diverging track, one breaking a hard rule of ST-T1-A6 isn't laid
- Every switch laid writes the speed of its diverging track (`velocity`): the switch tool on a
  straight, into a curve, from a free end and linked, a double switch, the switches of a slip, a
  switch given another template of the catalogue, and a switch moved along the curve it's bent
  into. A switch of the catalogue had no limit before, one copied from a switch of the scenery kept
  that one's, one laid without a track had the laying speed on both its tracks. The limit is for the
  diverging track alone (`velocity -V`); the own limit of the track it goes into stays for both
  where it's the lower. The switch tool says the speed and what gives it.
- The speed is formula 9.9 of PKP PLK ST-T1-A6 the other way round, V = sqrt((I + D) r / 11.8), with
  the normal cant deficiency of the frog of table 9.7 (110 mm a fixed frog, 130 mm a movable nose),
  rounded down to the steps of the speed limits and no more than table 11.2 gives the basic switch.
  For the fixed frogs the formula gives table 11.2 itself (190 40, 300 50, 500 60, 760 80, 1200
  100 km/h); the 2500-1:26.5 with a movable nose stays 130. A switch bent into a curve takes the
  radius of its diverging track from table 11.8 (one-sided r" = (Rr - t^2)/(R + r), two-sided
  (Rr + t^2)/(R - r)) and the cant of the line with its sign: leaning against the diverging track it
  takes speed away, where the speed check counted it as helping. Rz 60E1-190-1:9 bent out of the
  curve R 600 m with 60 mm: 30 km/h, not 40; the 60E1-500-1:12 of the review, out of R 1200 m with
  60 mm: 60 km/h at its fixed frog (54 at I = 100 mm, the 0.65 m/s2 the editor took), not 107.
- A switch breaking a hard rule isn't laid, the tracks left as they were, and the switch tool says
  why, with the value, the limit and the paragraph: the cant changing within it (11.4 pkt 7), a cant
  ramp ending within it or nearer than 6 m (9.6 pkt 16-17; one ending right at an end of the switch
  is let be, as the snapping of the start offers it), a double switch, a slip or a crossing bent
  (11.4 pkt 4), the curvature of its diverging or its main track turning from one side to the other
  (9.7 pkt 12, KZW II). They were warnings shown after the switch was laid, and on a straight the
  cant wasn't looked at at all. The line is looked at 10 m past the ends of the curve or the
  straight too, so the ramp on the straight before a curve counts. The previews show the refusals.
- A switch moved along its straight or the curve it's bent into, a double switch moved along its
  straight, and a switch given another template go through the same checks; one breaking a rule
  stays as it is.
- Warnings still: 1:9.403 and steeper than 1:9 bent (11.4 pkt 4c-d), a rule of the running and the
  main tracks, which the editor doesn't tell from the side ones, as the warning now says; the limits
  of table 11.9 and a cant over 100 mm in a bent switch (table 9.6), as before.

Tests: unit tests of tables 11.8 and 11.9 (the least main radius bends the diverging track to the
least radius the table gives), table 9.7, the speeds of table 11.2 by formula 9.9, the speed of a
bent switch with the cant with its sign (the example of the review), the cant over a switch on a
straight and a double switch bent. Editor cases `q2_1_switch_speed`, `q2_2_switch_refusals` and
`q2_3_switch_move`, with `expect status` (the status of the switch tool) and `expect steps` (the
undo steps), the fixture with a straight taking a cant on and a compound curve without cant. All
pass; with the changes of the editor reverted all three fail.
2026-11-23 09:09:01 +01:00
..

Self-tests of the track editor

Scripts that drive the track editor through the commands of its self-test (application/editormodeselftest*.cpp) and check what came out with expect commands. A failed expectation makes the run fail: the editor ends with a non-zero exit code.

The game data isn't in this repository, so these run against a local game install only, not in CI.

Running

The editor has to be built with the self-tests, which a normal build leaves out (a script takes over the input of the editor):

cmake -S . -B build -DWITH_EDITOR_SELFTESTS=ON
cmake --build build --config RelWithDebInfo

Then, with the game folder (one with scenery/, models/ and dynamic/ of the game data):

python tests/editor/run.py --game-dir C:/MaSzyna                       # all cases
python tests/editor/run.py --game-dir C:/MaSzyna 1_inspector_cant      # chosen cases
python tests/editor/run.py --game-dir C:/MaSzyna --ini low.ini         # with settings of your own over the runner's
  • --exe names the executable; by default it's the newest eu07*.exe under build/bin.
  • --ini is read over the runner's settings (a 640x480 window, no sound, convertmodels 0, log.txt in the game folder), which are read over the player's own eu07.ini. A file with low settings of the picture makes the runs quicker.
  • --timeout (240 s) and --memory-mb (8192 MB) limit each run of the editor. On Windows the editor runs in a job object which keeps its memory under the limit and ends it with the runner; the runner also stops it when it goes over the limit.
  • --show shows the window of the editor; without it the window is never shown nor focused (EU07_EDITOR_SELFTEST_HIDDEN), so the computer can be used meanwhile.
  • --keep keeps the copies of the scenery, to look at what a script saved.

The cases run one after another, one editor at a time. Each prints the exit code of the editor, its time and memory, the SELFTEST FAIL lines, and PASS or FAIL; a summary follows. The runner exits with 1 when any case failed. The scripts as they were run and the logs of the editor are in tests/editor/out/<case>/.

How it works

For each case the runner:

  1. copies the fixture, scenery/autotest_editor.scn, into the scenery folder of the game as autotest_editor_<case>.scn,
  2. starts eu07 -ini <runner's settings> [-ini <--ini>] -edit autotest_editor_<case>.scn in the game folder, with the script in EU07_EDITOR_SELFTEST (the settings first: a sceneryfile in them would take the place of the scenery otherwise),
  3. waits until the editor quits, or stops it at the limits of time and memory,
  4. reads the exit code and the SELFTEST lines of log.txt,
  5. deletes the copy of the scenery and whatever the editor wrote next to it under its name, and says what else the run added to the scenery folder or changed there.

A case passes when every run of the editor ended with the exit code 0, its log has SELFTEST result: 0 failed of N, and the case checked something (N above 0 over all its runs). The editor ends with 2 when an expectation failed or a command of the script wasn't taken by any group of the self-test (a typo would otherwise let the expectations after it pass for nothing), with 1 when it couldn't start or an error ended it, and with the system's code on a crash.

The fixture holds plain tracks only, no terrain: lines of straights (a, s, d, the pair p and q 4.5 m apart), a track of 1000 mm gauge (g1) beside one of the standard gauge (g2), a turntable of 16 m with velocity 10 (tt1, with the include of its model and events), two curves of 600 and 604.5 m side by side with a cant of 60 mm (i0..i9, o0..o9, the straights at their ends taking the cant on and off), a straight taking a cant of 60 mm on along its middle track (r1..r3), a curve without cant of 60 m of R 2000 m and 60 m of R 400 m turning the same way between straights (k0..k3), and a track apart with a vehicle (v1), without which the editor would put one of its own onto a track of the cases on saving. It uses only what every install of the game has.

Writing a case

A case is cases/<name>.txt: one command a line, # for comments, as for EU07_EDITOR_SELFTEST. The commands are listed at the top of application/editormodeselftest.cpp. Start with a wait of a few frames and end with quit, which logs SELFTEST result: <failed> failed of <expectations>.

The expectations (expect <what> ...), each logged as SELFTEST PASS <what> or SELFTEST FAIL <what>: got <value>, expected <value>:

expectation checks
expect cant <track> <start|end> <mm> <tolerance mm> the cant at the end of the first path, as the inspector shows it (1500 mm between the rail axes)
expect joint <track> <start|end> <gap m> <angle deg> <cant step mm> the end of the first path against the nearest end of another track (within 1 m): the gap, the kink and the step of the cant between them, each at most the value given
expect records <name> <count> [kind] the records of the switches (//$r) of the name, with the connections having the switch among theirs; only those of the kind (switch, slip, crossing, double, connection) when given
expect speed <track> <km/h> [tolerance] the speed of the track as the editor shows it (editor_track::velocity)
expect gauge <track> <m> [tolerance] the gauge of the track
expect track <name> <present|removed> a track of the name is in the scenery, or isn't
expect route <track> <in|out> the track is a part of the line open in the route tool, or isn't
expect norms gauge <mm> [tolerance] the rail axes distance of the norms the tracks are laid to
expect height <track> <start|end> <m> <tolerance> the height of the end of the first path
expect lift <track> <start|end> <label> <m> <tolerance> how far the end is above the height mark <label> <track> <start|end> kept
expect includes <track> <count> the includes whose parameters name the track: the model and the events of a turntable
expect status <text> the status of the switch tool, as its panel shows it, holds the text (the rest of the line)
expect steps <count> the steps of the history Ctrl+Z takes back, the ones made together counted once: none made by a change refused

A line #> reopen ends a run of the editor there (the part before it saves and ends with quit) and starts the editor again on the scenery as it was saved, for what has to be checked after a save and a load. The editor's own openscenery starts a new editor without the script, so it isn't for the cases.

The cases

The cases check the fixes of PR #450 (the numbers are those of its test plan):

case fix
1_inspector_cant the cant typed into the inspector goes on into the track joined at that end, in the same undo step
3_norms_after_delete deleting a track of the line open in the route tool keeps the laying norms
4_gauge_paste_group the gauge is a paste group of its own, off by default
5_turntable_speed the speed of a turntable set in the editor is the one saved
6_set_delete_records deleting a set of tracks takes the records of its switches, and the model and the events of a turntable
6b_set_delete_whole a double switch, a slip and a crossover in a set go whole, with their records
7_crossover_delete deleting a switch of a crossover on a curve takes the crossover out whole: the outer track comes down, the record goes
7b_bent_switch_delete a switch bent out of the shape of its record still takes the record along when deleted

and the quick fixes of the switches (Q2 of the plan of the track editing):

case fix
q2_1_switch_speed a switch laid, or given another template, gets the speed of its diverging track written: of its type, bent into a curve with the cant taken with its sign and the cant deficiency of its frog
q2_2_switch_refusals a switch with the cant changing within it or a ramp ending nearer than 6 m, a double switch or a slip bent, or the curvature of its diverging track turning from one side to the other isn't laid; 1:9.403 bent is only warned of
q2_3_switch_move a switch moved along its curve or its straight is judged as when it's laid: moved too near a cant ramp, or onto one, it stays