18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 11:47:06 +01:00
Files
maszyna/tests/unit/test_editor_records.cpp
T
maj00r c3b987abb2 test(editor): golden round trips of the tracks and of the //$ lines, the cant at the joints (#455)
* fix(editor): track edits keep the joints, the norms, the records and the saved speed together

- The cant typed in the inspector goes on into the track joined at that end, as the gizmo and the
  joints tool do it; the neighbours go into the same undo step. The joint stepped before.
- A track laid on from a canted joint takes the cant off along the ramp the norms ask for at the
  speed (`alignment::cant_ramp_length`), not at a fixed 1.5 mm a metre whatever the speed and the
  norms: 120 mm at 100 km/h over 120 m, not 80 m.
- Deleting a track of the line under the route tool keeps the laying norms. They went back to the
  defaults, and every later lay, extend and join used those.
- The gauge is a paste group of its own, off by default: pasting how a track rides or sounds no
  longer changes its gauge.
- The speed of a turntable set in the editor is the one saved. The editor changed the speed the
  turntable runs at, while the file keeps the limit it was loaded with.
- Deleting a set of tracks does what Del does with each: a double switch, a slip and a crossover go
  whole, the records of the switches go with them, and the model and events of a turntable too. The
  records stayed behind and on saving were given to another switch, which then showed a wrong type.
- Deleting a switch of a crossover takes the crossover out whole, as the connection tools do: the
  outer track of a crossover on a curve comes down by its lift and the record of the connection
  goes. Alone, the switch left the outer track up for good, and the connection to the next switch
  given its name. A switch bent out of the shape of its record is found by its name.

Tests: a unit test of the norm ramp. The other changes are in the editor's UI, which the unit tests
don't reach.

* test(editor): self-test scripts that fail, a runner, and a case for each fix of the track editing

The editor's self-test scripts only logged: nothing made a run fail. Now:

- `expect` commands check the state and log `SELFTEST PASS` or `SELFTEST FAIL ... got X, expected Y`:
  the cant at a track end, the joint at an end (gap, angle, cant step), the records of a switch and
  the connections naming it, speed, gauge, a track present or removed, the laying norms' gauge,
  heights and lifts against a mark, whether a track is in the line under the route tool, and the
  includes of a turntable. A command no group takes counts as a failure, so a mistyped one can't
  make the checks after it pass.
- At `quit` the result is logged, and a script whose expectations failed ends the editor with exit
  code 2 (a failed start stays 1; the simulator's test mode is unchanged).
- The commit of the inspector's cant field is `track_cant_commit`, which the inspector and the
  `trackcant` command both call; `routegauge` sets the laying norms as the route tool does, and
  `tracksetdelete` deletes a set of tracks by name.
- `tests/editor/run.py` runs each script of `tests/editor/cases` on a copy of the fixture scenery
  in the game folder, with a wall-time limit and a memory cap, reads the exit code and the
  `SELFTEST` lines, and deletes the copy. A `#> reopen` line restarts the editor on the saved
  scenery. See `tests/editor/README.md`.
- One case per fix of the track editing quick fixes (inspector cant, norms after deleting, the
  gauge paste group, turntable speed saved, deleting a set, a set with a double switch, a slip
  and a crossover, deleting a switch of a crossover, a bent switch). All pass; with the fixes
  reverted all fail.

* feat(editor): the track tool panels keep their fields, results and buttons within the panel

- The card of the tool: after a long gesture the action goes under it, at its indent, when what is
  left of the row is narrower than 8 font sizes or the longest word of the action. It was squeezed
  into a sliver and broken in the middle of its words.
- A click on the title row of the card folds it to that row (icon, name, family, key, and a small
  triangle marker) and opens it again. One flag for all the tools, kept with the editor settings
  (`track_card_folded` in eu07_editor.ini), open by default: the card took 250-300 px at the top
  of every tool and repeats the hint bar of the view.
- The grade labels of the vertical profile, on the graph and in the view, write the per mille as
  the panel does (the translated "per mille", the per mille sign in Polish), not "o/oo".
- The track analysis window: the thresholds of the speed check and of the joints keep to their
  widest name and a field of 10 font sizes where the window is wider than that, as docked across
  the bottom (`begin_fields_fitted`). The results are tables with each column as wide as what is in
  it: the speed check with its column names kept at the top as the list scrolls, the joints with
  the kind, the value and the two tracks next to each other. A click on a row shows it as before.
- `same_line_if_fits` puts the next button beside the one before only when it fits in what is left
  of the line, at the start of the next line otherwise. Used where the route design puts buttons
  side by side, for "Forget the design" in the profile panel, which was cut off at the edge, and for
  the buttons of a switch in the inspector.
- The laying options: the speed, the curve radius and the longest path are fields with the name on
  the left in two columns (`begin_fields`/`field_row`), as in the inspector, the route and the
  profile, the chips of the quick values under them. The segmented choices give the short names
  less of the room when a long one doesn't fit in its even share, and go on in a second bar when
  they don't fit side by side: "Through the clicked points" overflowed its third of the bar.

* 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.

* test(editor): golden round trips of the tracks and of the //$ lines, the cant at the joints

The safety net of the track editor before its domain model changes (E0 of
editor-tracks-tests.md): what the editor reads from the scenery files and
writes back is read, written and read again in tests/unit, with no game data.

Tracks (test_track_text.cpp, data/tracks/). Entries written the way the game
writes them, read by TTrack::Load() and written by export_as_text(), come out
byte for byte the same, and read again give the same track field by field:
plain tracks with all their attributes (events, speed, isolated, overhead,
vradius, rail profile, friction cell), a curve with cant, radius, uneven,
buckle, cwr and sleeper models, a bridge, switches with trackbed, frogs,
movable nose, blades, uneven of both paths and timbers, a turntable, paths of
pieces, the speeds +40, -40, 0.5, 0 and none of tracks, switches and
turntables, a river, a tributary, a road and a crossing. What the game writes
otherwise than given is checked as it is (table as turn, mountain as
mountains, the length of the path, a switch heard from 10 m, the events in
order, names in lower case, model paths with forward slashes, the texture
length, rolls as floats, no overhead and no vradius left out).

The seam: TTrack built from text with no scene. The engine stubs of the tests
had none of it, so the tests link the few sources reading and writing a track
takes (world/Track.cpp, Segment.cpp, TrackUneven.cpp, MemCell.cpp,
scene/scenenode.cpp, utilities/Timer.cpp, rendering/geometrybank.cpp) and
track_stubs.cpp stands in for the rest: a renderer keeping the materials by
their names, and the scene, events, vehicles and the geometry of the rails,
which reading and writing never reach and which stop the test with their name
if one does. It tests the game's own Load() and export, where a parser of its
own would have meant rewriting Load(), and changes no code of the game. The
stub of basic_node::radius_() goes, scenenode.cpp brings the real one. The
rails don't buckle in the tests (TrackBuckle.cpp needs the environment), the
buckle declared is read and written either way; material names go through a
stand-in, the game's material manager isn't tested here.

The //$ lines (test_editor_records.cpp, data/records/). Their readers and
writers were members of editor_mode, srk_tool and the stores, with the scene
around them; they move as they were into editor/editorRecords.cpp, the one
place each kind is read and written, which the stores call (and which the
migration to the project file of E3 will need apart anyway). The methods of
scene::layer_context move into scene/scenelayercontext.cpp so it links alone.
Each kind, h r k p t w b s c o z, read from golden lines and written back comes
out the same, in the coordinates of the file and of a file placed at an
origin; //$e, the descriptions of the templates, read and saved by
editor_includes in a template in a scratch folder, leaves the file as it was.

Cant (test_cant.cpp). The paths an alignment lays roll by asin(cant/gauge),
signed with the turn, back to the cant of the line at every end; a curve the
other way rolls the other way. At a joint editor_track::match_rolls() gives
the joined track the roll for the travel across it, turned where the paths
face or stand back to back, and the track written keeps it. The inspector's
own conversion on 1500 mm stays in its lambdas here; named, as
editor_mode::cant_of_roll()/roll_of_cant(), it comes with the quick fixes.

Known bugs found, tests of the change each (doctest::should_fail, passing
until fixed, then reported to drop the decorator), data/tracks/known_lost.scn:
- angle1/angle2 are read and dropped: not written back.
- fouling1/fouling2 are read and dropped: not written back.
- name@circuit: the circuit is taken out of the name with the letter before
  the @ ("tor1@iso1" becomes track "tor"; substr(0, i - 1)).
- the attributes of the entry (gauge, friction, texture sizes, speed...) are
  written to 6 significant digits, a float has 9: more digits are lost on the
  first save.
None in the //$ lines.

Unit tests: 957 cases before, 974 after, all passing.

* test(editor): a mistyped track fails the self-test, indented comments are skipped, case 7b checks the switch got bent

- A blank line or an indented `#` comment in a script is no longer a command no group takes.
- `trackcant`, `routegauge` and `tracksetdelete` with a track that isn't there count as a failed expectation.
- `expect shaped <switch> <yes|no>`: 7b checks that the gizmo drag bent the switch out of its record before deleting it.
- The ramp-length loop of test_alignment counts in an integer (Sonar S2193).

* test(editor): the entries known to be lost are checked apart from should_fail, the cant test says where the inspector conversion is tested

- A normal test checks that known_lost.scn and each of its entries are there and read, so the should_fail tests can't pass for
  data gone missing.
- The comment of test_cant.cpp said the tests of cant_of_roll()/roll_of_cant() are here; they are the self-test case
  1_inspector_cant.txt, as the unit tests don't link the editor.
2026-11-27 03:57:53 +01:00

333 lines
14 KiB
C++

// the lines the track editor keeps in the scenery files after its //$ marks, read and written back by editor_records
// (editor/editorRecords.cpp), the one place the stores of the editor read and write them: the lines of data/records/ are written the
// way the editor writes them, so each kind read and written back comes out the same, which a second reading then reads the same as
// the first. The descriptions of the templates (//$e) are read and written by editor_includes, in the template files themselves
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorIncludeInfo.hpp"
#include "editor/editorRecords.hpp"
#include "scratch.h"
#include "utilities/Globals.h"
#include <fstream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
namespace {
std::string file_text(std::string const &Path) {
std::ifstream file{Path, std::ios::binary};
REQUIRE(file.is_open());
return {std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()};
}
// the lines of the file of data/records/ with the mark, the mark taken off as scene::node_layers::scan() takes it: with the blanks
// after it, the line ends left out
std::vector<std::string> marked(std::string const &File, std::string const &Mark) {
std::vector<std::string> result;
std::istringstream lines{file_text(std::string{EU07_UNIT_TESTS_DATA} + "/records/" + File)};
for (std::string line; std::getline(lines, line);) {
while (false == line.empty() && (line.back() == '\r' || line.back() == '\n')) {
line.pop_back();
}
if (line.starts_with(Mark + ' ')) {
line.erase(0, Mark.size());
line.erase(0, line.find_first_not_of(" \t"));
result.push_back(line);
}
}
REQUIRE_FALSE(result.empty());
return result;
}
// the lines one under another, for a failed check to show them
std::string text(std::vector<std::string> const &Lines) {
std::string result;
for (auto const &line : Lines) {
result += line + '\n';
}
return result;
}
// the lines without the comments, which the readers pass over
std::vector<std::string> uncommented(std::vector<std::string> Lines) {
std::erase_if(Lines, [](std::string const &Line) { return Line.starts_with("#"); });
return Lines;
}
// the placement of a file included at an origin: the lines say the same of other places in the world
scene::layer_context moved() {
scene::layer_context context;
context.offset = {1000.0, 5.0, -2000.0};
return context;
}
scene::layer_handle constexpr layer{3};
} // namespace
TEST_CASE("editor records: the horizontal alignments (//$h) read and written back come out the same") {
auto const lines{marked("alignment.scn", "//$h")};
for (auto const &context : {scene::layer_context{}, moved()}) {
auto records{editor_records::read_alignments(lines, context, layer)};
REQUIRE(records.size() == 2);
auto const &record{records.front()};
CHECK(record.layer == layer);
CHECK(record.design.start == context.to_world({0.0, 0.0, 0.0}));
CHECK(record.design.end == context.to_world({1000.0, 0.0, 1000.0}));
CHECK(record.source == "designed");
CHECK(record.origin == 1200.0);
CHECK(record.fit == 0.125);
CHECK(record.design.shape == alignment::transition_shape::clothoid);
CHECK(record.design.speed == 100.0);
CHECK(record.design.norms.gauge == 1500.0);
CHECK(record.design.transition_pieces == 3);
REQUIRE(record.design.vertices.size() == 1);
CHECK(record.design.vertices.front().radius == 400.0);
CHECK(record.design.vertices.front().cant == 80.0);
REQUIRE(record.clicks.size() == 1);
CHECK(record.clicks.front() == context.to_world({0.0, 0.0, 50.0}));
CHECK(record.elements.size() == 5);
CHECK(record.whole());
// a compound curve with the cants of its arcs and ramps of its own, from a curved track, kept for a part of its line
auto const &compound{records.back()};
CHECK(compound.source == "traced");
CHECK(compound.design.shape == alignment::transition_shape::cubic_parabola);
CHECK(compound.design.start_radius == 1200.0);
CHECK(compound.design.start_turn == 1);
CHECK(compound.design.start_curved);
CHECK(compound.design.start_cant == 60.0);
CHECK(compound.from == 10.0);
CHECK(compound.to == 1500.0);
REQUIRE(compound.design.vertices.size() == 1);
auto const &vertex{compound.design.vertices.front()};
CHECK(vertex.compound);
REQUIRE(vertex.arcs.size() == 1);
CHECK(vertex.arcs.front().radius == 900.0);
CHECK(vertex.first_cant == 70.0);
CHECK(vertex.arcs.front().cant == 50.0);
CHECK(vertex.ramp_out_length == 60.0);
// the lines of the elements are the ones the designs make, as alignment_store makes them before it writes the records
for (auto &entry : records) {
entry.result = alignment::compute(entry.design);
REQUIRE(entry.result.valid);
}
CHECK(text(editor_records::alignment_lines(records, context)) == text(lines));
}
}
TEST_CASE("editor records: the switches placed (//$r) read and written back come out the same") {
auto const lines{marked("switch.scn", "//$r")};
for (auto const &context : {scene::layer_context{}, moved()}) {
auto const records{editor_records::read_switches(lines, context, layer)};
REQUIRE(records.size() == 3);
auto const &plain{records[0]};
CHECK(plain.kind == "switch");
CHECK(plain.name == "z1");
CHECK(plain.type == "Rz");
CHECK(plain.rail == "60E1");
CHECK(plain.radius == 500.0);
CHECK(plain.ratio == 12.0);
CHECK(plain.hand == 'L');
CHECK(plain.parts == std::vector<std::string>{"z1"});
CHECK(plain.shaped);
CHECK(plain.start == context.to_world({100.0, 0.0, 200.0}));
REQUIRE(plain.km.has_value());
CHECK(*plain.km == doctest::Approx(12345.0));
auto const &connection{records[1]};
CHECK(connection.main_radius == -1200.0);
CHECK_FALSE(connection.km.has_value());
CHECK(connection.source == "measured");
CHECK(connection.lift == 0.06);
CHECK(connection.lift_end == 0.04);
CHECK(connection.lift_to == context.to_world({150.0, 0.0, 240.0}));
CHECK(connection.ramp == 60.0);
CHECK(records[2].parts.size() == 4);
CHECK(records[2].middle == 300.0);
CHECK(text(editor_records::switch_lines(records, context)) == text(lines));
}
}
TEST_CASE("editor records: the kilometrage (//$k) read and written back comes out the same") {
auto const lines{marked("kilometrage.scn", "//$k")};
for (auto const &context : {scene::layer_context{}, moved()}) {
std::vector<kilometrage::mark> marks;
std::vector<kilometrage::via> vias;
editor_records::read_kilometrage(lines, context, layer, marks, vias);
REQUIRE(marks.size() == 2);
REQUIRE(vias.size() == 1);
CHECK(marks[0].line == "91");
CHECK(marks[0].point == context.to_world({100.0, 0.0, 200.0}));
CHECK(marks[0].km == 12.345);
CHECK_FALSE(marks[0].beyond.has_value());
CHECK(marks[1].beyond == 14.0);
CHECK(vias[0].point == context.to_world({105.0, 0.0, 700.0}));
CHECK(text(editor_records::kilometrage_lines(marks, vias, context)) == text(lines));
}
}
TEST_CASE("editor records: the grade lines designed (//$p) read and written back come out the same") {
auto const lines{marked("profile.scn", "//$p")};
for (auto const &context : {scene::layer_context{}, moved()}) {
auto const profiles{editor_records::read_profiles(lines, context, layer)};
REQUIRE(profiles.size() == 1);
auto const &profile{profiles.front()};
CHECK(profile.length == 500.0);
CHECK(profile.start == context.to_world({0.0, 100.0, 0.0}));
CHECK(profile.line.speed == 120.0);
CHECK(profile.origin == 1000.0);
CHECK(profile.line.join_start);
CHECK_FALSE(profile.line.join_end);
CHECK(profile.line.norms.radius_min == 2000.0);
CHECK(profile.departure == 0.015);
REQUIRE(profile.line.points.size() == 3);
CHECK(profile.line.points[1].elevation == context.to_world({0.0, 101.0, 0.0}).y);
CHECK(profile.line.points[1].radius == 10000.0);
CHECK(profile.line.points[1].automatic);
CHECK(text(editor_records::profile_lines(profiles, context)) == text(lines));
}
}
TEST_CASE("editor records: the tracks fitted (//$t) and sharing a grade line (//$w) read and written back come out the same") {
auto const fitted{marked("fitted.scn", "//$t")};
auto const tracks{editor_records::read_fitted(fitted)};
REQUIRE(tracks.size() == 2);
CHECK(tracks[0].name == "tor_1");
CHECK(tracks[0].shape == 0x00ff00ff12345678ull);
CHECK_FALSE(tracks[0].hand);
CHECK(tracks[1].hand);
CHECK(text(editor_records::fitted_lines(tracks)) == text(fitted));
auto const shared{marked("gradeline.scn", "//$w")};
auto const lines{editor_records::read_grade_lines(shared)};
REQUIRE(lines.size() == 2);
CHECK(lines[0].key == "tor_1@100,200");
CHECK(lines[0].number == 3);
CHECK_FALSE(lines[0].hand);
CHECK(lines[1].hand);
CHECK(text(editor_records::grade_line_lines(lines)) == text(shared));
}
TEST_CASE("editor records: the objects bound to the paths (//$b) read and written back come out the same") {
auto const lines{marked("binding.scn", "//$b")};
for (auto const &context : {scene::layer_context{}, moved()}) {
std::vector<std::string> written{editor_records::binding_heading()};
std::vector<editor_records::binding> bindings;
for (auto const &line : uncommented(lines)) {
auto const binding{editor_records::read_binding(line, context)};
REQUIRE(binding.has_value());
bindings.push_back(*binding);
written.push_back(editor_records::binding_line(*binding, context));
}
REQUIRE(bindings.size() == 2);
CHECK(bindings[0].kind == "model");
CHECK(bindings[0].category == 2);
CHECK(bindings[0].location == context.to_world({10.0, 0.5, 20.0}));
CHECK(bindings[0].key == "models/slupy/slup.t3d");
CHECK(bindings[0].turns);
REQUIRE(bindings[1].anchors.size() == 2);
CHECK(bindings[1].anchors[1].path == 1);
CHECK(bindings[1].anchors[1].end == context.to_world({5.0, 0.0, 100.0}));
CHECK(text(written) == text(lines));
}
}
TEST_CASE("editor records: the stations described (//$s) read and written back come out the same, their names in windows-1250") {
auto const lines{marked("station.scn", "//$s")};
std::vector<editor_records::station> stations;
for (auto const &line : uncommented(lines)) {
auto const station{editor_records::read_station(line)};
REQUIRE(station.has_value());
stations.push_back(*station);
}
REQUIRE(stations.size() == 2);
auto const &first{stations[0]};
CHECK(first.code == "MMz");
CHECK(first.line == "91");
CHECK(first.km == "12.345");
CHECK_FALSE(first.reversed);
CHECK(first.anchor == "z1");
CHECK(first.braking == 700);
CHECK(first.blocks.at("bpd_a") == editor_records::block_kind::four);
CHECK(first.blocks.at("bpd_b") == editor_records::block_kind::semi);
CHECK(first.ways.at("bpd_a"));
REQUIRE(first.joints_added.size() == 1);
REQUIRE(first.joints_removed.size() == 1);
CHECK(first.joints_removed.front() == glm::dvec3{110.5, 0.0, 205.25});
CHECK(first.name == "\xC5\x81\xC3\xB3\x64\xC5\xBA Kaliska"); // Łódź Kaliska, in utf-8
// the words left empty are read as none
CHECK(stations[1].code.empty());
CHECK(stations[1].km.empty());
CHECK(stations[1].reversed);
CHECK(stations[1].blocks.at("x") == editor_records::block_kind::three);
CHECK(text(editor_records::station_lines(stations)) == text(lines));
}
TEST_CASE("editor records: the camera (//$c), the orthophoto (//$o) and its area (//$z) read and written back come out the same") {
auto const camera{marked("camera.scn", "//$c")};
auto const place{editor_records::read_camera(camera)};
REQUIRE(place.has_value());
CHECK(place->position == glm::dvec3{1234.5, 56.25, -789.125});
CHECK(place->angle == glm::vec3{0.125f, -1.5f, 0.f});
CHECK(editor_records::camera_line(*place) == camera.front());
for (auto const &line : marked("orthophoto.scn", "//$o")) {
CAPTURE(line);
bool enabled{false};
double north{0.0};
double east{0.0};
REQUIRE(editor_records::read_orthophoto(line, enabled, north, east));
// the editor writes where the scenery lies when it lies somewhere
CHECK(editor_records::orthophoto_line(enabled, north != 0.0 || east != 0.0, north, east) == line);
}
auto const area{marked("area.scn", "//$z")};
auto const polygon{editor_records::read_area(area)};
REQUIRE(polygon.size() == 3);
CHECK(polygon[2] == glm::dvec2{646000.5, 513000.25});
CHECK(text(editor_records::area_lines(polygon)) == text(area));
}
TEST_CASE("editor records: the description of a template (//$e) read and written back comes out the same, and the rest of the file with it") {
test::scratch_folder const folder{"editor_records_templates"};
auto const original{file_text(std::string{EU07_UNIT_TESTS_DATA} + "/records/semaphore.inc")};
folder.write("semaphore.inc", original);
// the templates are read from the folder of the scenery
struct scenery_folder {
explicit scenery_folder(std::string const &Path) : before{Global.asCurrentSceneryPath} { Global.asCurrentSceneryPath = Path; }
~scenery_folder() { Global.asCurrentSceneryPath = before; }
scenery_folder(scenery_folder const &) = delete;
scenery_folder &operator=(scenery_folder const &) = delete;
std::string before;
} const scenery{folder.path()};
include_info first;
std::string error;
REQUIRE(editor_includes::load("semaphore.inc", first, error));
CHECK(first.name == "Semaphore, 2 arms");
CHECK(first.category == "signals");
CHECK(first.signal_kind == "semaphore");
CHECK(first.signal_arms == 2);
CHECK(first.signal_height == 5.5);
REQUIRE(first.parameters.size() == 3);
CHECK(first.parameters[0].role == "name");
CHECK(first.parameters[2].value == "tor1");
REQUIRE(editor_includes::save("semaphore.inc", first, error));
CHECK(file_text(folder.path("semaphore.inc")) == original);
include_info second;
REQUIRE(editor_includes::load("semaphore.inc", second, error));
CHECK(second.name == first.name);
CHECK(second.description == first.description);
CHECK(second.signal_aspects == first.signal_aspects);
REQUIRE(second.parameters.size() == first.parameters.size());
for (std::size_t index = 0; index < first.parameters.size(); ++index) {
CHECK(second.parameters[index].id == first.parameters[index].id);
CHECK(second.parameters[index].role == first.parameters[index].role);
CHECK(second.parameters[index].label == first.parameters[index].label);
CHECK(second.parameters[index].value == first.parameters[index].value);
}
}