18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-16 19:14:11 +01:00
Files
maszyna/tests/unit/test_door_closure.cpp
jerrrrycho 4b769d95c1 fix: SOD lamp shows the doors of the whole consist in three states (eu07/maszyna#288)
The door closure signalling lamp (i-door_blocked) showed only Doors.is_locked
of the occupied vehicle, so a door open in another car or a coupled unit
didn't show on it.

TMoverParameters::door_closure() gives the state of one vehicle (none, locked,
released, open), the driver gathers the most severe one of the train in
determine_consist_state(), next to IsAnyDoorOpen, and the lamp is lit for
locked doors, blinks for closed but released ones (a permit given, or no lock
engaged on doors that need no permit) and is dark with a door open.

doorclosuresignal in eu07.ini (default yes) switches it; with no the lamp
shows is_locked of the occupied vehicle as before. No data change needed.
2026-11-08 02:05:45 +01:00

111 lines
4.6 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "scenario.h"
// the door closure signalling (SOD, the i-door_blocked lamp of a cab): the state of each vehicle's doors and of the
// whole train, the most severe of its vehicles, as the driver gathers it for the lamp (eu07/maszyna#288)
using test::scenario;
using namespace test::channels;
namespace {
// the state of the whole train, the way TController::determine_consist_state() gathers it
door_closure_t consist_closure(scenario &Scenario) {
auto closure{door_closure_t::none};
for (std::size_t i = 0; i < Scenario.train().size(); ++i) {
closure = std::max(closure, Scenario.vehicle(i).door_closure());
}
return closure;
}
} // namespace
TEST_CASE("door closure: the lamp is lit for locked doors, blinks for released ones and is dark for open ones") {
for (auto const lit : {true, false}) {
CAPTURE(lit);
CHECK(door_closure_lamp(door_closure_t::locked, lit));
CHECK(door_closure_lamp(door_closure_t::released, lit) == lit);
CHECK_FALSE(door_closure_lamp(door_closure_t::open, lit));
CHECK_FALSE(door_closure_lamp(door_closure_t::none, lit));
}
// a consist takes the most severe state of its vehicles
CHECK(std::max(door_closure_t::none, door_closure_t::locked) == door_closure_t::locked);
CHECK(std::max(door_closure_t::locked, door_closure_t::released) == door_closure_t::released);
CHECK(std::max(door_closure_t::released, door_closure_t::open) == door_closure_t::open);
}
TEST_CASE("door closure: a unit with permits, locked, released by the permit and open, in any of its cars") {
scenario scenario{"door closure/elf", motion() + doors()};
scenario.add("elf_v1/21we-a", 1).add("elf_v1/21we-b").add("elf_v1/21we-c");
scenario.start_up();
auto &cab{scenario.cab()};
auto &last{scenario.vehicle(scenario.train().size() - 1)};
// closed with no permit: no door can be opened
CHECK(cab.door_closure() == door_closure_t::locked);
CHECK(last.door_closure() == door_closure_t::locked);
CHECK(consist_closure(scenario) == door_closure_t::locked);
scenario.act("permit left");
cab.PermitDoors(side::left, true);
scenario.wait(2.0);
CHECK(last.door_closure() == door_closure_t::released);
CHECK(consist_closure(scenario) == door_closure_t::released);
scenario.act("the last car opens its own door");
last.OperateDoors(side::left, true, range_t::local);
scenario.wait(5.0);
// the cab's own doors stay closed, the train is open all the same
CHECK(cab.door_closure() == door_closure_t::released);
CHECK(last.door_closure() == door_closure_t::open);
CHECK(consist_closure(scenario) == door_closure_t::open);
scenario.act("close, the steps stay out under the permit");
last.OperateDoors(side::left, false, range_t::local);
cab.OperateDoors(side::left, false);
scenario.wait(10.0);
CHECK(last.Doors.instances[side::left].position <= 0.f);
// a step out isn't a closed door
CHECK(consist_closure(scenario) == door_closure_t::open);
scenario.act("revoke the permit");
cab.PermitDoors(side::left, false);
scenario.wait(10.0);
CHECK(consist_closure(scenario) == door_closure_t::locked);
}
TEST_CASE("door closure: the doors of a unit without permits are released at a standstill") {
scenario scenario{"door closure/en57", motion() + doors()};
scenario.add("en57_v1/5bgaiii_led_spot", 1).add("en57_v1/6ba_840").add("en57_v1/5bgb");
scenario.start_up();
auto &cab{scenario.cab()};
auto &middle{scenario.vehicle(1)};
REQUIRE_FALSE(cab.Doors.permit_needed);
REQUIRE(middle.Doors.permit_needed);
// the door lock engages only once the train runs (DoorLockSpeed), till then the end cars' doors can be opened
CHECK(cab.door_closure() == door_closure_t::released);
CHECK(middle.door_closure() == door_closure_t::locked);
CHECK(consist_closure(scenario) == door_closure_t::released);
scenario.act("open right");
cab.OperateDoors(side::right, true);
scenario.wait(10.0);
CHECK(consist_closure(scenario) == door_closure_t::open);
scenario.act("close right");
cab.OperateDoors(side::right, false);
scenario.wait(10.0);
CHECK(consist_closure(scenario) == door_closure_t::released);
}
TEST_CASE("door closure: a locomotive has no doors to signal, its coach does") {
scenario scenario{"door closure/eu07 with a coach", motion() + doors()};
scenario.add("4e_v1/4e", 1).add("bdhpumn_v3/bdhpumn");
scenario.start_up();
CHECK(scenario.cab().door_closure() == door_closure_t::none);
scenario.act("open right");
scenario.cab().PermitDoors(side::right, true);
scenario.cab().OperateDoors(side::right, true);
scenario.wait(10.0);
CHECK(scenario.vehicle(1).door_closure() == door_closure_t::open);
CHECK(consist_closure(scenario) == door_closure_t::open);
}