| 1 | /* |
| 2 | * SPDX-FileCopyrightText: (C) 2022 Lars Toenning <[email protected]> |
| 3 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | #include "test_swiftService.hxx" |
| 7 | |
| 8 | #include "test_suite/FGTestApi/testGlobals.hxx" |
| 9 | |
| 10 | #include "Network/Swift/service.h" |
| 11 | #include <Main/fg_props.hxx> |
| 12 | |
| 13 | void SwiftServiceTest::setUp() |
| 14 | { |
| 15 | FGTestApi::setUp::initTestGlobals("SwiftService"); |
| 16 | |
| 17 | // Setup properties |
| 18 | fgSetBool("/sim/freeze/master", true); |
| 19 | fgSetDouble("/position/latitude-deg", 50.12); |
| 20 | fgSetDouble("/position/longitude-deg", 6.3); |
| 21 | fgSetDouble("/position/altitude-ft", 12000.0); |
| 22 | fgSetDouble("/position/altitude-agl-ft", 1020.0); |
| 23 | fgSetDouble("/velocities/groundspeed-kt", 242.0); |
| 24 | fgSetDouble("/orientation/pitch-deg", 3.0); |
| 25 | fgSetDouble("/orientation/roll-deg", 1.0); |
| 26 | fgSetDouble("/orientation/heading-deg", 230.0); |
| 27 | fgSetBool("/gear/gear/wow", false); |
| 28 | fgSetDouble("/instrumentation/comm/frequencies/selected-mhz", 122.8); |
| 29 | fgSetDouble("/instrumentation/comm/frequencies/standby-mhz", 135.65); |
| 30 | fgSetDouble("/instrumentation/comm[1]/frequencies/selected-mhz", 121.5); |
| 31 | fgSetDouble("/instrumentation/comm[1]/frequencies/standby-mhz", 118.3); |
| 32 | fgSetInt("/instrumentation/transponder/id-code", 1234); |
| 33 | fgSetInt("/instrumentation/transponder/inputs/knob-mode", 1); |
| 34 | fgSetBool("/instrumentation/transponder/ident", true); |
| 35 | fgSetBool("/controls/lighting/beacon", true); |
| 36 | fgSetBool("/controls/lighting/landing-lights", false); |
| 37 | fgSetBool("/controls/lighting/nav-lights", true); |
| 38 | fgSetBool("/controls/lighting/strobe", true); |
| 39 | fgSetBool("/controls/lighting/taxi-light", false); |
| 40 | fgSetBool("/instrumentation/altimeter/serviceable", true); |
| 41 | fgSetDouble("/instrumentation/altimeter/pressure-alt-ft", 24000.0); |
| 42 | fgSetDouble("/surface-positions/flap-pos-norm", 0.0); |
| 43 | fgSetDouble("/gear/gear/position-norm", 0.7); |
| 44 | fgSetDouble("/surface-positions/speedbrake-pos-norm", 0.4); |
| 45 | fgSetString("/sim/aircraft", "glider"); |
| 46 | fgSetDouble("/position/ground-elev-m", 778.0); |
| 47 | fgSetDouble("/velocities/speed-east-fps", 20.0); |
| 48 | fgSetDouble("/velocities/speed-down-fps", -30.0); |
| 49 | fgSetDouble("/velocities/speed-north-fps", -10.2); |
| 50 | fgSetDouble("/orientation/roll-rate-degps", 1.0); |
| 51 | fgSetDouble("/orientation/pitch-rate-degps", 0.0); |
| 52 | fgSetDouble("/orientation/yaw-rate-degps", -2.0); |
| 53 | fgSetDouble("/instrumentation/comm/volume", 42.0); |
| 54 | fgSetDouble("/instrumentation/comm[1]/volume", 100.0); |
| 55 | } |
| 56 | |
| 57 | void SwiftServiceTest::tearDown() |
| 58 | { |
| 59 | FGTestApi::tearDown::shutdownTestGlobals(); |
| 60 | } |
| 61 | |
| 62 | void SwiftServiceTest::testService() |
| 63 | { |
| 64 | flightgear::swift::CService service; |
| 65 | CPPUNIT_ASSERT(service.isPaused()); |
| 66 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getLatitude(), 50.12, 0.1); |
| 67 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getLongitude(), 6.3, 0.1); |
| 68 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getAltitudeMSL(), 12000.0, 0.1); |
| 69 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getHeightAGL(), 1020.0, 0.1); |
| 70 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getGroundSpeed(), 242.0, 0.1); |
| 71 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getPitch(), 3.0, 0.1); |
| 72 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getRoll(), 1.0, 0.1); |
| 73 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getTrueHeading(), 230.0, 0.1); |
| 74 | CPPUNIT_ASSERT(!service.getAllWheelsOnGround()); |
| 75 | CPPUNIT_ASSERT_EQUAL(service.getCom1Active(), 122800); |
| 76 | CPPUNIT_ASSERT_EQUAL(service.getCom1Standby(), 135650); |
| 77 | CPPUNIT_ASSERT_EQUAL(service.getCom2Active(), 121500); |
| 78 | CPPUNIT_ASSERT_EQUAL(service.getCom2Standby(), 118300); |
| 79 | |
| 80 | CPPUNIT_ASSERT_EQUAL(service.getTransponderCode(), 1234); |
| 81 | CPPUNIT_ASSERT_EQUAL(service.getTransponderMode(), 1); |
| 82 | CPPUNIT_ASSERT(service.getTransponderIdent()); |
| 83 | CPPUNIT_ASSERT(service.getBeaconLightsOn()); |
| 84 | CPPUNIT_ASSERT(!service.getLandingLightsOn()); |
| 85 | CPPUNIT_ASSERT(service.getNavLightsOn()); |
| 86 | CPPUNIT_ASSERT(service.getStrobeLightsOn()); |
| 87 | CPPUNIT_ASSERT(!service.getTaxiLightsOn()); |
| 88 | |
| 89 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getFlapsDeployRatio(), 0.0, 0.1); |
| 90 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getGearDeployRatio(), 0.7, 0.1); |
| 91 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getSpeedBrakeRatio(), 0.4, 0.1); |
| 92 | |
| 93 | CPPUNIT_ASSERT_EQUAL(service.getAircraftName(), std::string("glider")); |
| 94 | |
| 95 | |
| 96 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getGroundElevation(), 778.0, 0.1); |
| 97 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getVelocityX(), 20.0 * SG_FEET_TO_METER, 0.1); |
| 98 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getVelocityY(), -30.0 * SG_FEET_TO_METER * -1, 0.1); |
| 99 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getVelocityZ(), -10.2 * SG_FEET_TO_METER, 0.1); |
| 100 | |
| 101 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getRollRate(), 1.0 * SG_DEGREES_TO_RADIANS, 0.1); |
| 102 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getPitchRate(), 0.0 * SG_DEGREES_TO_RADIANS, 0.1); |
| 103 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getYawRate(), -2.0 * SG_DEGREES_TO_RADIANS, 0.1); |
| 104 | |
| 105 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getCom1Volume(), 42.0, 0.1); |
| 106 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getCom2Volume(), 100.0, 0.1); |
| 107 | |
| 108 | |
| 109 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getPressAlt(), 24000.0, 0.1); |
| 110 | fgSetBool("/instrumentation/altimeter/serviceable", false); |
| 111 | // Fallback if altimeter is not serviceable |
| 112 | CPPUNIT_ASSERT_DOUBLES_EQUAL(service.getPressAlt(), service.getAltitudeMSL(), 0.1); |
| 113 | |
| 114 | // Test setter |
| 115 | service.setCom1Active(128550); |
| 116 | CPPUNIT_ASSERT_EQUAL(service.getCom1Active(), 128550); |
| 117 | CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/instrumentation/comm/frequencies/selected-mhz"), 128.550, 0.1); |
| 118 | |
| 119 | service.setCom1Standby(128650); |
| 120 | CPPUNIT_ASSERT_EQUAL(service.getCom1Standby(), 128650); |
| 121 | CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/instrumentation/comm/frequencies/standby-mhz"), 128.650, 0.1); |
| 122 | |
| 123 | |
| 124 | service.setCom2Active(121900); |
| 125 | CPPUNIT_ASSERT_EQUAL(service.getCom2Active(), 121900); |
| 126 | CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/instrumentation/comm[1]/frequencies/selected-mhz"), 121.900, 0.1); |
| 127 | |
| 128 | service.setCom2Standby(121600); |
| 129 | CPPUNIT_ASSERT_EQUAL(service.getCom2Standby(), 121600); |
| 130 | CPPUNIT_ASSERT_DOUBLES_EQUAL(fgGetDouble("/instrumentation/comm[1]/frequencies/standby-mhz"), 121.600, 0.1); |
| 131 | |
| 132 | service.setTransponderCode(2000); |
| 133 | CPPUNIT_ASSERT_EQUAL(service.getTransponderCode(), 2000); |
| 134 | CPPUNIT_ASSERT_EQUAL(fgGetInt("/instrumentation/transponder/id-code"), 2000); |
| 135 | |
| 136 | |
| 137 | service.setTransponderMode(0); |
| 138 | CPPUNIT_ASSERT_EQUAL(service.getTransponderMode(), 0); |
| 139 | CPPUNIT_ASSERT_EQUAL(fgGetInt("/instrumentation/transponder/inputs/knob-mode"), 0); |
| 140 | } |