Add unit-test coverage for the transponder
This commit is contained in:
parent
fe99747d37
commit
4542691772
4 changed files with 166 additions and 0 deletions
|
@ -7,6 +7,7 @@ set(TESTSUITE_SOURCES
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/test_rnav_procedures.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_dme.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_commRadio.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_transponder.cxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
|
@ -18,5 +19,6 @@ set(TESTSUITE_HEADERS
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/test_rnav_procedures.hxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_dme.hxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_commRadio.hxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_transponder.hxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "test_hold_controller.hxx"
|
||||
#include "test_navRadio.hxx"
|
||||
#include "test_rnav_procedures.hxx"
|
||||
#include "test_transponder.hxx"
|
||||
|
||||
// Set up the unit tests.
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NavRadioTests, "Unit tests");
|
||||
|
@ -31,3 +32,4 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(HoldControllerTests, "Unit tests");
|
|||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(RNAVProcedureTests, "Unit tests");
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(DMEReceiverTests, "Unit tests");
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(CommRadioTests, "Unit tests");
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TransponderTests, "Unit tests");
|
||||
|
|
107
test_suite/unit_tests/Instrumentation/test_transponder.cxx
Normal file
107
test_suite/unit_tests/Instrumentation/test_transponder.cxx
Normal file
|
@ -0,0 +1,107 @@
|
|||
#include "test_transponder.hxx"
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
#include "test_suite/FGTestApi/NavDataCache.hxx"
|
||||
#include "test_suite/FGTestApi/testGlobals.hxx"
|
||||
|
||||
#include <Airports/airport.hxx>
|
||||
#include <Navaids/NavDataCache.hxx>
|
||||
|
||||
#include <Instrumentation/transponder.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Main/locale.hxx>
|
||||
|
||||
// Set up function for each test.
|
||||
void TransponderTests::setUp()
|
||||
{
|
||||
FGTestApi::setUp::initTestGlobals("transponder");
|
||||
FGTestApi::setUp::initNavDataCache();
|
||||
}
|
||||
|
||||
|
||||
// Clean up after each test.
|
||||
void TransponderTests::tearDown()
|
||||
{
|
||||
FGTestApi::tearDown::shutdownTestGlobals();
|
||||
}
|
||||
|
||||
SGSubsystemRef TransponderTests::setupStandardTransponder(const std::string& name, int index)
|
||||
{
|
||||
SGPropertyNode_ptr configNode(new SGPropertyNode);
|
||||
|
||||
globals->get_props()->setDoubleValue("systems/electrical/outputs/transponder", 10.0);
|
||||
|
||||
configNode->setStringValue("name", name);
|
||||
configNode->setIntValue("number", index);
|
||||
auto r = new Transponder(configNode);
|
||||
|
||||
r->bind();
|
||||
r->init();
|
||||
|
||||
globals->add_subsystem("transponder", r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void TransponderTests::testBasic()
|
||||
{
|
||||
SGPropertyNode* altitudeSource = fgGetNode("/instrumentation/altimeter", true);
|
||||
|
||||
auto t = setupStandardTransponder("transponder", 0);
|
||||
altitudeSource->setDoubleValue("mode-s-alt-ft", 1234.0);
|
||||
|
||||
|
||||
SGPropertyNode* xpdrNode = fgGetNode("/instrumentation/transponder[0]");
|
||||
xpdrNode->setIntValue("inputs/knob-mode", 5); // KNOB_ALT
|
||||
xpdrNode->setIntValue("inputs/mode", 2); // MODE S
|
||||
|
||||
xpdrNode->setIntValue("id-code", 4621);
|
||||
|
||||
t->update(1.0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(4, xpdrNode->getIntValue("inputs/digit[3]"));
|
||||
CPPUNIT_ASSERT_EQUAL(6, xpdrNode->getIntValue("inputs/digit[2]"));
|
||||
CPPUNIT_ASSERT_EQUAL(2, xpdrNode->getIntValue("inputs/digit[1]"));
|
||||
CPPUNIT_ASSERT_EQUAL(1, xpdrNode->getIntValue("inputs/digit[0]"));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(true, xpdrNode->getBoolValue("altitude-valid"));
|
||||
CPPUNIT_ASSERT_EQUAL(1234, xpdrNode->getIntValue("altitude"));
|
||||
|
||||
xpdrNode->setIntValue("inputs/digit[2]", 2);
|
||||
CPPUNIT_ASSERT_EQUAL(4221, xpdrNode->getIntValue("id-code"));
|
||||
|
||||
t->update(1.0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(4221, xpdrNode->getIntValue("transmitted-id"));
|
||||
|
||||
xpdrNode->setBoolValue("inputs/ident-btn", true);
|
||||
CPPUNIT_ASSERT_EQUAL(true, xpdrNode->getBoolValue("ident"));
|
||||
xpdrNode->setBoolValue("inputs/ident-btn", false);
|
||||
|
||||
// remain on for now
|
||||
CPPUNIT_ASSERT_EQUAL(true, xpdrNode->getBoolValue("ident"));
|
||||
|
||||
FGTestApi::runForTime(20.0);
|
||||
CPPUNIT_ASSERT_EQUAL(false, xpdrNode->getBoolValue("ident"));
|
||||
|
||||
xpdrNode->setIntValue("inputs/knob-mode", 1); // KNOB_STANDBY
|
||||
}
|
||||
|
||||
void TransponderTests::testStandby()
|
||||
{
|
||||
SGPropertyNode* altitudeSource = fgGetNode("/instrumentation/altimeter", true);
|
||||
auto t = setupStandardTransponder("transponder", 0);
|
||||
altitudeSource->setDoubleValue("mode-s-alt-ft", 1234.0);
|
||||
|
||||
|
||||
SGPropertyNode* xpdrNode = fgGetNode("/instrumentation/transponder[0]");
|
||||
xpdrNode->setIntValue("inputs/knob-mode", 1); // KNOB_STANDBY
|
||||
xpdrNode->setIntValue("id-code", 4621);
|
||||
|
||||
t->update(1.0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(4621, xpdrNode->getIntValue("id-code"));
|
||||
CPPUNIT_ASSERT_EQUAL(-9999, xpdrNode->getIntValue("transmitted-id"));
|
||||
}
|
55
test_suite/unit_tests/Instrumentation/test_transponder.hxx
Normal file
55
test_suite/unit_tests/Instrumentation/test_transponder.hxx
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Edward d'Auvergne
|
||||
*
|
||||
* This file is part of the program FlightGear.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
|
||||
class Transponder;
|
||||
class SGGeod;
|
||||
|
||||
// The flight plan unit tests.
|
||||
class TransponderTests : public CppUnit::TestFixture
|
||||
{
|
||||
// Set up the test suite.
|
||||
CPPUNIT_TEST_SUITE(TransponderTests);
|
||||
|
||||
CPPUNIT_TEST(testBasic);
|
||||
CPPUNIT_TEST(testStandby);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
SGSubsystemRef setupStandardTransponder(const std::string& name, int index);
|
||||
|
||||
public:
|
||||
// Set up function for each test.
|
||||
void setUp();
|
||||
|
||||
// Clean up after each test.
|
||||
void tearDown();
|
||||
|
||||
// The tests.
|
||||
void testBasic();
|
||||
void testStandby();
|
||||
};
|
Loading…
Reference in a new issue