| 1 | #include "test_transponder.hxx" |
| 2 | |
| 3 | #include <cstring> |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "test_suite/FGTestApi/NavDataCache.hxx" |
| 7 | #include "test_suite/FGTestApi/testGlobals.hxx" |
| 8 | |
| 9 | #include <Airports/airport.hxx> |
| 10 | #include <Navaids/NavDataCache.hxx> |
| 11 | |
| 12 | #include <Instrumentation/transponder.hxx> |
| 13 | #include <Main/fg_props.hxx> |
| 14 | #include <Main/locale.hxx> |
| 15 | |
| 16 | // Set up function for each test. |
| 17 | void TransponderTests::setUp() |
| 18 | { |
| 19 | FGTestApi::setUp::initTestGlobals("transponder"); |
| 20 | FGTestApi::setUp::initNavDataCache(); |
| 21 | } |
| 22 | |
| 23 | |
| 24 | // Clean up after each test. |
| 25 | void TransponderTests::tearDown() |
| 26 | { |
| 27 | FGTestApi::tearDown::shutdownTestGlobals(); |
| 28 | } |
| 29 | |
| 30 | SGSubsystemRef TransponderTests::setupStandardTransponder(const std::string& name, int index) |
| 31 | { |
| 32 | SGPropertyNode_ptr configNode(new SGPropertyNode); |
| 33 | |
| 34 | globals->get_props()->setDoubleValue("systems/electrical/outputs/transponder", 10.0); |
| 35 | |
| 36 | configNode->setStringValue("name", name); |
| 37 | configNode->setIntValue("number", index); |
| 38 | auto r = new Transponder(configNode); |
| 39 | |
| 40 | r->bind(); |
| 41 | r->init(); |
| 42 | |
| 43 | globals->get_subsystem_mgr()->add("transponder", r); |
| 44 | |
| 45 | return r; |
| 46 | } |
| 47 | |
| 48 | void TransponderTests::testBasic() |
| 49 | { |
| 50 | SGPropertyNode* altitudeSource = fgGetNode("/instrumentation/altimeter", true); |
| 51 | |
| 52 | auto t = setupStandardTransponder("transponder", 0); |
| 53 | altitudeSource->setDoubleValue("mode-s-alt-ft", 1234.0); |
| 54 | |
| 55 | |
| 56 | SGPropertyNode* xpdrNode = fgGetNode("/instrumentation/transponder[0]"); |
| 57 | xpdrNode->setIntValue("inputs/knob-mode", 5); // KNOB_ALT |
| 58 | xpdrNode->setIntValue("inputs/mode", 2); // MODE S |
| 59 | |
| 60 | xpdrNode->setIntValue("id-code", 4621); |
| 61 | |
| 62 | t->update(1.0); |
| 63 | |
| 64 | CPPUNIT_ASSERT_EQUAL(4, xpdrNode->getIntValue("inputs/digit[3]")); |
| 65 | CPPUNIT_ASSERT_EQUAL(6, xpdrNode->getIntValue("inputs/digit[2]")); |
| 66 | CPPUNIT_ASSERT_EQUAL(2, xpdrNode->getIntValue("inputs/digit[1]")); |
| 67 | CPPUNIT_ASSERT_EQUAL(1, xpdrNode->getIntValue("inputs/digit[0]")); |
| 68 | |
| 69 | CPPUNIT_ASSERT_EQUAL(true, xpdrNode->getBoolValue("altitude-valid")); |
| 70 | CPPUNIT_ASSERT_EQUAL(1234, xpdrNode->getIntValue("altitude")); |
| 71 | |
| 72 | xpdrNode->setIntValue("inputs/digit[2]", 2); |
| 73 | CPPUNIT_ASSERT_EQUAL(4221, xpdrNode->getIntValue("id-code")); |
| 74 | |
| 75 | t->update(1.0); |
| 76 | |
| 77 | CPPUNIT_ASSERT_EQUAL(4221, xpdrNode->getIntValue("transmitted-id")); |
| 78 | |
| 79 | xpdrNode->setBoolValue("inputs/ident-btn", true); |
| 80 | CPPUNIT_ASSERT_EQUAL(true, xpdrNode->getBoolValue("ident")); |
| 81 | xpdrNode->setBoolValue("inputs/ident-btn", false); |
| 82 | |
| 83 | // remain on for now |
| 84 | CPPUNIT_ASSERT_EQUAL(true, xpdrNode->getBoolValue("ident")); |
| 85 | |
| 86 | FGTestApi::runForTime(20.0); |
| 87 | CPPUNIT_ASSERT_EQUAL(false, xpdrNode->getBoolValue("ident")); |
| 88 | |
| 89 | xpdrNode->setIntValue("inputs/knob-mode", 1); // KNOB_STANDBY |
| 90 | } |
| 91 | |
| 92 | void TransponderTests::testStandby() |
| 93 | { |
| 94 | SGPropertyNode* altitudeSource = fgGetNode("/instrumentation/altimeter", true); |
| 95 | auto t = setupStandardTransponder("transponder", 0); |
| 96 | altitudeSource->setDoubleValue("mode-s-alt-ft", 1234.0); |
| 97 | |
| 98 | |
| 99 | SGPropertyNode* xpdrNode = fgGetNode("/instrumentation/transponder[0]"); |
| 100 | xpdrNode->setIntValue("inputs/knob-mode", 1); // KNOB_STANDBY |
| 101 | xpdrNode->setIntValue("id-code", 4621); |
| 102 | |
| 103 | t->update(1.0); |
| 104 | |
| 105 | CPPUNIT_ASSERT_EQUAL(4621, xpdrNode->getIntValue("id-code")); |
| 106 | CPPUNIT_ASSERT_EQUAL(-9999, xpdrNode->getIntValue("transmitted-id")); |
| 107 | } |