From 02c3c6dc97c3c28e2e79b56180a4a8e399421fb9 Mon Sep 17 00:00:00 2001 From: Edward d'Auvergne Date: Thu, 14 Jun 2018 20:28:22 +0200 Subject: [PATCH] TestSuite: Migration of the old GPS tests to the CppUnit framework. As this code has significant bit-rot and requires a lot of work to compile and run again, it is currently deactivated. The test also writes to the files "/Users/jmt/Desktop/airways.kml" and "/Users/jmt/Desktop/procedures.kml" and would need to be modified to write to a temporary directory and the file contents reread and checked by the test. --- test_suite/CMakeLists.txt | 1 + test_suite/system_tests/CMakeLists.txt | 1 + .../Instrumentation/CMakeLists.txt | 12 +++++ .../Instrumentation/TestSuite.cxx | 24 ++++++++++ .../system_tests}/Instrumentation/testgps.cxx | 43 ++++++++--------- .../system_tests/Instrumentation/testgps.hxx | 48 +++++++++++++++++++ 6 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 test_suite/system_tests/Instrumentation/CMakeLists.txt create mode 100644 test_suite/system_tests/Instrumentation/TestSuite.cxx rename {src => test_suite/system_tests}/Instrumentation/testgps.cxx (95%) create mode 100644 test_suite/system_tests/Instrumentation/testgps.hxx diff --git a/test_suite/CMakeLists.txt b/test_suite/CMakeLists.txt index 2a936f298..d964d9134 100644 --- a/test_suite/CMakeLists.txt +++ b/test_suite/CMakeLists.txt @@ -65,6 +65,7 @@ include(Dart) # System test suites. add_test(AeroMeshSystemTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -s AeroMeshTests) +#add_test(GPSSystemTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -s GPSTests) # Unit test suites. add_test(AddonManagementUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u AddonManagementTests) diff --git a/test_suite/system_tests/CMakeLists.txt b/test_suite/system_tests/CMakeLists.txt index 1c01bd88f..d2b56b6d0 100644 --- a/test_suite/system_tests/CMakeLists.txt +++ b/test_suite/system_tests/CMakeLists.txt @@ -1,6 +1,7 @@ # Add each system test category. foreach( system_test_category FDM + Instrumentation ) add_subdirectory(${system_test_category}) diff --git a/test_suite/system_tests/Instrumentation/CMakeLists.txt b/test_suite/system_tests/Instrumentation/CMakeLists.txt new file mode 100644 index 000000000..3cc2157ba --- /dev/null +++ b/test_suite/system_tests/Instrumentation/CMakeLists.txt @@ -0,0 +1,12 @@ +set(TESTSUITE_SOURCES + ${TESTSUITE_SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx + #${CMAKE_CURRENT_SOURCE_DIR}/testgps.cxx + PARENT_SCOPE +) + +set(TESTSUITE_HEADERS + ${TESTSUITE_HEADERS} + #${CMAKE_CURRENT_SOURCE_DIR}/testgps.hxx + PARENT_SCOPE +) diff --git a/test_suite/system_tests/Instrumentation/TestSuite.cxx b/test_suite/system_tests/Instrumentation/TestSuite.cxx new file mode 100644 index 000000000..3cae512f1 --- /dev/null +++ b/test_suite/system_tests/Instrumentation/TestSuite.cxx @@ -0,0 +1,24 @@ +/* + * 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 . + */ + +#include "testgps.hxx" + + +// Set up the unit tests. +//CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(GPSTests, "System tests"); diff --git a/src/Instrumentation/testgps.cxx b/test_suite/system_tests/Instrumentation/testgps.cxx similarity index 95% rename from src/Instrumentation/testgps.cxx rename to test_suite/system_tests/Instrumentation/testgps.cxx index 2c887c525..5ed79bbf4 100644 --- a/src/Instrumentation/testgps.cxx +++ b/test_suite/system_tests/Instrumentation/testgps.cxx @@ -6,7 +6,6 @@ #include #include
-#include
#include
#include @@ -16,6 +15,12 @@ #include #include +#include "test_suite/helpers/globals.hxx" +#include "test_suite/helpers/NavDataCache.hxx" + +#include "testgps.hxx" + + using std::string; using namespace flightgear; @@ -77,20 +82,22 @@ void createDummyRoute(FGRouteMgr* rm) rmInput->setStringValue("OTR"); } -int main(int argc, char* argv[]) + +void GPSTests::setUp() { - -try{ - globals = new FGGlobals; - - fgInitFGRoot(argc, argv); - if (!fgInitConfig(argc, argv) ) { - SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed" ); - exit(-1); - } + fgtest::initTestGlobals("GPS"); + fgtest::initNavDataCache(); +} - fgInitNav(); +void GPSTests::tearDown() +{ + fgtest::shutdownTestGlobals(); +} + + +void GPSTests::testGPS() +{ fgSetDouble("/environment/magnetic-variation-deg", 0.0); Airway::load(); @@ -101,7 +108,7 @@ try{ SG_LOG(SG_GENERAL, SG_ALERT, "egph: cart location:" << egph->cart()); FGAirport::AirportFilter af; - FGPositioned::List l = FGPositioned::findClosestN(egph->geod(), 20, 2000.0, &af); + FGPositionedList l = FGPositioned::findClosestN(egph->geod(), 20, 2000.0, &af); for (unsigned int i=0; iident() << "/" << l[i]->name()); } @@ -341,14 +348,4 @@ try{ f << "\n" "" << endl; f.close(); - - - return EXIT_SUCCESS; - - - -} catch (sg_exception& ex) { - SG_LOG(SG_GENERAL, SG_ALERT, "exception:" << ex.getFormattedMessage()); -} - return EXIT_FAILURE; } diff --git a/test_suite/system_tests/Instrumentation/testgps.hxx b/test_suite/system_tests/Instrumentation/testgps.hxx new file mode 100644 index 000000000..93a5e486d --- /dev/null +++ b/test_suite/system_tests/Instrumentation/testgps.hxx @@ -0,0 +1,48 @@ +/* + * 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 . + */ + + +#ifndef _FG_GPS_SYSTEM_TESTS_HXX +#define _FG_GPS_SYSTEM_TESTS_HXX + + +#include +#include + + +// The system tests. +class GPSTests : public CppUnit::TestFixture +{ + // Set up the test suite. + CPPUNIT_TEST_SUITE(GPSTests); + CPPUNIT_TEST(testGPS); + CPPUNIT_TEST_SUITE_END(); + +public: + // Set up function for each test. + void setUp(); + + // Clean up after each test. + void tearDown(); + + // The tests. + void testGPS(); +}; + +#endif // _FG_GPS_SYSTEM_TESTS_HXX