18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 08:17:09 +01:00
Files
maszyna/tests/unit/test_radio.cpp
T
Hirek 84f1aa2515 refactor(physics): the controllers and the switches of the cab are private to the vehicle
The positions of the master and the secondary controller, of the analog
controller and of the lights selector, the occupied cab, the horns, the radio
and its fuse, the radio-stop, the wipers' switch, the dimmer, the mirrors'
button, the end-of-train signalling and the forced resistor fans: fourteen
fields the cab, the AI, the scenery and the tests wrote straight into
physics::Vehicle are private now. The rest of the simulator reads them through
queries named as the fields were (MainCtrlPos(), Radio(), ...) and changes them
through operations (SetMainCtrlPos(), SetRadio(), ...), so every place that
moves a controller past its own stepping (IncMainCtrl()) is named and can be
found; the compiler keeps anything else out. Inside the vehicle they keep
their meaning under camelCase names. The queries return const references, as
the gauges of the cab bind to them.

The .fiz keys are untouched.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
2026-11-29 12:26:21 +01:00

59 lines
2.1 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
// the radio works only switched on and with the low voltage (eu07/maszyna#429): its channel and volume buttons,
// the calls and the radio-stop all ask RadioPowered()
TEST_CASE("radio: a radio switched on with the low voltage works") {
test::vehicle vehicle{test::definition::load("wagon")};
vehicle->SetRadio(true);
SUBCASE("24 V") { vehicle->lowVoltage.Set24vAvailableForTest(true); }
SUBCASE("110 V") { vehicle->lowVoltage.Set110vAvailableForTest(true); }
CHECK(vehicle->RadioPowered());
}
TEST_CASE("radio: a radio switched off or without the low voltage doesn't") {
test::vehicle vehicle{test::definition::load("wagon")};
SUBCASE("switched off") {
vehicle->SetRadio(false);
vehicle->lowVoltage.Set24vAvailableForTest(true);
}
SUBCASE("batteries off") {
vehicle->SetRadio(true);
vehicle->lowVoltage.Set24vAvailableForTest(false);
vehicle->lowVoltage.Set110vAvailableForTest(false);
}
CHECK_FALSE(vehicle->RadioPowered());
}
// the cut-off in the radio's power supply (eu07/maszyna#438): a fuse, a desk lever or the switch on the radio's
// power supply, closed unless the driver opens it
TEST_CASE("radio: the radio fuse is closed by default") {
test::vehicle vehicle{test::definition::load("wagon")};
CHECK(vehicle->RadioFuse());
}
TEST_CASE("radio: an opened radio fuse cuts the radio off") {
test::vehicle vehicle{test::definition::load("wagon")};
vehicle->SetRadio(true);
vehicle->lowVoltage.Set24vAvailableForTest(true);
vehicle->SetRadioFuse(false);
CHECK_FALSE(vehicle->RadioPowered());
vehicle->SetRadioFuse(true);
CHECK(vehicle->RadioPowered());
}
TEST_CASE("radio: opening the radio fuse at a standstill resets the radio-stop, as switching the radio off does") {
test::vehicle loco{test::definition::fiz("4e_v1/4e")};
loco->lowVoltage.SetBatteryOnForTest(true);
loco->SetRadio(true);
REQUIRE(loco->RadiostopSwitch(true));
loco->SecuritySystemCheck(0.1);
CHECK(loco->RadioStopFlag());
loco->SetRadioFuse(false);
loco->SecuritySystemCheck(0.1);
CHECK_FALSE(loco->RadioStopFlag());
}