diff --git a/tests/unit/test_compartment_lights.cpp b/tests/unit/test_compartment_lights.cpp new file mode 100644 index 000000000..bff60e440 --- /dev/null +++ b/tests/unit/test_compartment_lights.cpp @@ -0,0 +1,80 @@ +#include "stdafx.h" +#include "doctest.h" +#include "vehicle.h" + +using test::definition; +using test::vehicle; + +// the compartment lights lamp of the cab (i-compartmentlights:) shows CompartmentLights.is_active of the cab's own +// vehicle, which LightsCheck() works out from the low voltage power and the compartment lights switch (eu07/maszyna#456) +// NOTE: the checks call LightsCheck() the way the vehicle update does, after setting the power by hand + +namespace { + +void lights_check(vehicle &Car) { + Car->LightsCheck(0.01); +} + +} // namespace + +TEST_CASE("compartment lights: the lights need low voltage power and the switch") { + vehicle car{definition::fiz("elf_v1/21we-a")}; + REQUIRE(car->CompartmentLights.start_type == start_t::manual); + car->Power24vIsAvailable = false; + car->Power110vIsAvailable = false; + + car->CompartmentLightsSwitch(true, range_t::local); // switch on, no power + lights_check(car); + CHECK_FALSE(car->CompartmentLights.is_active); + + car->Power110vIsAvailable = true; // converter on + lights_check(car); + CHECK(car->CompartmentLights.is_active); + CHECK(car->CompartmentLights.intensity == doctest::Approx(1.0)); + + car->Power110vIsAvailable = false; // battery only: the lights stay on, dimmed + car->Power24vIsAvailable = true; + lights_check(car); + CHECK(car->CompartmentLights.is_active); + CHECK(car->CompartmentLights.intensity == doctest::Approx(0.5)); + + car->Power24vIsAvailable = false; // no power at all + lights_check(car); + CHECK_FALSE(car->CompartmentLights.is_active); +} + +TEST_CASE("compartment lights: the off switch turns the lights off, the on switch back on") { + vehicle car{definition::fiz("elf_v1/21we-a")}; + car->Power110vIsAvailable = true; + + lights_check(car); + CHECK_FALSE(car->CompartmentLights.is_active); // manual start: off until switched on + + // push buttons: the on button latches the lights, they stay on once it is released + car->CompartmentLightsSwitch(true, range_t::local); + lights_check(car); + car->CompartmentLightsSwitch(false, range_t::local); + lights_check(car); + CHECK(car->CompartmentLights.is_active); + + car->CompartmentLightsSwitchOff(true, range_t::local); + lights_check(car); + CHECK_FALSE(car->CompartmentLights.is_active); + car->CompartmentLightsSwitchOff(false, range_t::local); + lights_check(car); + CHECK_FALSE(car->CompartmentLights.is_active); // still off once the off button is released +} + +TEST_CASE("compartment lights: lights started automatically come on with the power alone") { + vehicle car{definition::fiz("elf_v1/21we-a").set("Cntrl", "CompartmentLightsStart", "Automatic")}; + REQUIRE(car->CompartmentLights.start_type == start_t::automatic); + car->Power24vIsAvailable = false; + car->Power110vIsAvailable = false; + + lights_check(car); + CHECK_FALSE(car->CompartmentLights.is_active); + + car->Power110vIsAvailable = true; + lights_check(car); + CHECK(car->CompartmentLights.is_active); +} diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 9c5c9d500..4ed2a6b67 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -12237,6 +12237,7 @@ bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int co {"i-mainpipelock:", &mvOccupied->LockPipe}, {"i-battery:", &mvOccupied->Power24vIsAvailable}, {"i-cablight:", &Cabine[iCabn].bLight}, + {"i-compartmentlights:", &mvOccupied->CompartmentLights.is_active}, }; { auto lookup = autolights.find(Label);