1
0
Fork 0

Unit-tests: add initial DME, new nav radio tests

Very basic so far, lots more to be done on both.
This commit is contained in:
James Turner 2021-01-17 16:21:07 +00:00
parent 85f3183232
commit ffda1a0cb8
6 changed files with 212 additions and 5 deletions

View file

@ -5,6 +5,7 @@ set(TESTSUITE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/test_gps.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_hold_controller.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_rnav_procedures.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_dme.cxx
PARENT_SCOPE
)
@ -14,5 +15,6 @@ set(TESTSUITE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/test_gps.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_hold_controller.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_rnav_procedures.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_dme.hxx
PARENT_SCOPE
)

View file

@ -17,9 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "test_navRadio.hxx"
#include "test_dme.hxx"
#include "test_gps.hxx"
#include "test_hold_controller.hxx"
#include "test_navRadio.hxx"
#include "test_rnav_procedures.hxx"
// Set up the unit tests.
@ -27,5 +28,4 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NavRadioTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(GPSTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(HoldControllerTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(RNAVProcedureTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(DMEReceiverTests, "Unit tests");

View file

@ -0,0 +1,120 @@
#include "test_dme.hxx"
#include <cstring>
#include <memory>
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestPilot.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include <Airports/airport.hxx>
#include <Navaids/NavDataCache.hxx>
#include <Navaids/navlist.hxx>
#include <Navaids/navrecord.hxx>
#include <Instrumentation/dme.hxx>
#include <Main/fg_props.hxx>
// Set up function for each test.
void DMEReceiverTests::setUp()
{
FGTestApi::setUp::initTestGlobals("navradio");
FGTestApi::setUp::initNavDataCache();
}
// Clean up after each test.
void DMEReceiverTests::tearDown()
{
FGTestApi::tearDown::shutdownTestGlobals();
}
void DMEReceiverTests::setPositionAndStabilise(DME* r, const SGGeod& g)
{
FGTestApi::setPosition(g);
for (int i = 0; i < 60; ++i) {
r->update(0.1);
}
}
SGSharedPtr<DME> DMEReceiverTests::setupStandardDME()
{
SGPropertyNode_ptr configNode(new SGPropertyNode);
configNode->setStringValue("name", "dmetest");
configNode->setIntValue("number", 2);
return new DME(configNode);
}
void DMEReceiverTests::testBasic()
{
SGSharedPtr<DME> r = setupStandardDME();
// set a source string pointing at a fictious nav-receiver
fgSetString("/instrumentation/dmetest[2]/frequencies/source",
"/instrumentation/nav[0]/frequencies/selected-mhz");
r->bind();
r->init();
globals->get_subsystem_mgr()->add("dme", r.get());
auto arlanda = fgFindAirportID("ESSA");
// set the nav frequency
fgSetDouble("/instrumentation/nav[0]/frequencies/selected-mhz", 113.30);
SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/dmetest[2]");
node->setBoolValue("serviceable", true);
fgSetDouble("systems/electrical/outputs/dme", 12.0);
setPositionAndStabilise(r.get(), arlanda->geod());
CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("in-range"));
CPPUNIT_ASSERT_DOUBLES_EQUAL(4.4, node->getDoubleValue("indicated-distance-nm"), 0.1);
// fly towards the station at constant speed
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot);
pilot->setSpeedKts(150);
FGPositioned::TypeFilter f{FGPositioned::DME};
FGNavRecordRef arlandaDME = fgpositioned_cast<FGNavRecord>(
FGPositioned::findClosestWithIdent("ANE", arlanda->geod(), &f));
const double trueCourseToANE = SGGeodesy::courseDeg(arlanda->geod(), arlandaDME->geod());
pilot->setCourseTrue(trueCourseToANE);
FGTestApi::runForTime(30.0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(150, node->getDoubleValue("indicated-ground-speed-kt"), 0.5);
// should have travelled (150 / 3600 * 30 ) = 1.25nm
CPPUNIT_ASSERT_DOUBLES_EQUAL(3.15, node->getDoubleValue("indicated-distance-nm"), 0.1);
}
void DMEReceiverTests::testRCFN_04DME()
{
// disabled pending discussion about the data for this one
return;
auto rcfn = fgFindAirportID("RCFN");
auto dmeReceiver = setupStandardDME();
FGRunwayRef rwy04 = rcfn->getRunwayByIdent("04");
FGPositioned::TypeFilter filter(FGPositioned::DME);
auto matches = FGPositioned::findAllWithIdent("IFNN", &filter);
FGPositioned::sortByRange(matches, rcfn->geod());
CPPUNIT_ASSERT(!matches.empty());
// should be size two, really
auto station = fgpositioned_cast<FGNavRecord>(matches.front());
CPPUNIT_ASSERT(station);
CPPUNIT_ASSERT_DOUBLES_EQUAL(110.9, station->get_freq(), 0.01);
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (C) 2021 James Turner <james@flightgear.org>
*
* 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/SGSharedPtr.hxx>
class DME;
class SGGeod;
// The DME unit tests.
class DMEReceiverTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(DMEReceiverTests);
CPPUNIT_TEST(testBasic);
CPPUNIT_TEST(testRCFN_04DME);
CPPUNIT_TEST_SUITE_END();
void setPositionAndStabilise(DME* r, const SGGeod& g);
SGSharedPtr<DME> setupStandardDME();
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
// The tests.
void testBasic();
void testRCFN_04DME();
};

View file

@ -6,11 +6,14 @@
#include "test_suite/FGTestApi/testGlobals.hxx"
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include <Main/globals.hxx>
#include <Navaids/NavDataCache.hxx>
#include <Navaids/navrecord.hxx>
#include <Navaids/navlist.hxx>
#include <Instrumentation/navradio.hxx>
#include <Instrumentation/newnavradio.hxx>
// Set up function for each test.
void NavRadioTests::setUp()
@ -26,7 +29,7 @@ void NavRadioTests::tearDown()
FGTestApi::tearDown::shutdownTestGlobals();
}
void NavRadioTests::setPositionAndStabilise(FGNavRadio* r, const SGGeod& g)
void NavRadioTests::setPositionAndStabilise(SGSubsystem* r, const SGGeod& g)
{
FGTestApi::setPosition(g);
for (int i=0; i<60; ++i) {
@ -476,3 +479,27 @@ void NavRadioTests::testGlideslopeLongDistance()
CPPUNIT_ASSERT_EQUAL(false, node->getBoolValue("gs-in-range"));
CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("in-range"));
}
void NavRadioTests::testNewRadioBasic()
{
SGPropertyNode_ptr configNode(new SGPropertyNode);
configNode->setStringValue("name", "navtest");
configNode->setIntValue("number", 2);
std::unique_ptr<SGSubsystem> r(Instrumentation::NavRadio::createInstance(configNode));
r->bind();
r->init();
SGPropertyNode_ptr node = globals->get_props()->getNode("instrumentation/navtest[2]");
node->setBoolValue("serviceable", true);
// needed for the radio to power up
globals->get_props()->setDoubleValue("systems/electrical/outputs/nav", 6.0);
node->setDoubleValue("frequencies/selected-mhz", 113.8);
SGGeod pos = SGGeod::fromDegFt(-3.352780, 55.499199, 20000);
setPositionAndStabilise(r.get(), pos);
CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("operable"));
CPPUNIT_ASSERT(!strcmp("TLA", node->getStringValue("nav-id")));
CPPUNIT_ASSERT_EQUAL(true, node->getBoolValue("in-range"));
}

View file

@ -27,6 +27,7 @@
class FGNavRadio;
class SGGeod;
class SGSubsystem;
// The flight plan unit tests.
class NavRadioTests : public CppUnit::TestFixture
@ -43,9 +44,11 @@ class NavRadioTests : public CppUnit::TestFixture
CPPUNIT_TEST(testILSAdjacentPaired);
CPPUNIT_TEST(testGlideslopeLongDistance);
CPPUNIT_TEST(testNewRadioBasic);
CPPUNIT_TEST_SUITE_END();
void setPositionAndStabilise(FGNavRadio* r, const SGGeod& g);
void setPositionAndStabilise(SGSubsystem* r, const SGGeod& g);
public:
// Set up function for each test.
@ -64,6 +67,8 @@ public:
void testILSPaired();
void testILSAdjacentPaired();
void testGlideslopeLongDistance();
void testNewRadioBasic();
};
#endif // _FG_NAVRADIO_UNIT_TESTS_HXX