From 73a9927c221c07cb2e0df9ad13f0e6ad1a3eb2d2 Mon Sep 17 00:00:00 2001 From: Edward d'Auvergne Date: Thu, 1 Mar 2018 13:13:03 +0100 Subject: [PATCH] TestSuite: Migration of the Flightplan tests into the CppUnit infrastructure. --- test_suite/unit_tests/CMakeLists.txt | 1 + test_suite/unit_tests/Navaids/CMakeLists.txt | 14 ++++ test_suite/unit_tests/Navaids/TestSuite.cxx | 24 ++++++ .../unit_tests/Navaids}/test_flightplan.cxx | 76 ++++++++++--------- .../unit_tests/Navaids/test_flightplan.hxx | 54 +++++++++++++ tests/CMakeLists.txt | 1 - 6 files changed, 132 insertions(+), 38 deletions(-) create mode 100644 test_suite/unit_tests/Navaids/CMakeLists.txt create mode 100644 test_suite/unit_tests/Navaids/TestSuite.cxx rename {tests => test_suite/unit_tests/Navaids}/test_flightplan.cxx (63%) create mode 100644 test_suite/unit_tests/Navaids/test_flightplan.hxx diff --git a/test_suite/unit_tests/CMakeLists.txt b/test_suite/unit_tests/CMakeLists.txt index 8bd7e8e6b..92d5fb50e 100644 --- a/test_suite/unit_tests/CMakeLists.txt +++ b/test_suite/unit_tests/CMakeLists.txt @@ -1,6 +1,7 @@ # Add each unit test category. foreach( unit_test_category general + Navaids Scripting ) diff --git a/test_suite/unit_tests/Navaids/CMakeLists.txt b/test_suite/unit_tests/Navaids/CMakeLists.txt new file mode 100644 index 000000000..880e5d898 --- /dev/null +++ b/test_suite/unit_tests/Navaids/CMakeLists.txt @@ -0,0 +1,14 @@ +set(TESTSUITE_SOURCES + ${TESTSUITE_SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/test_flightplan.cxx + ${PROJECT_SOURCE_DIR}/tests/unitTestHelpers.cxx + PARENT_SCOPE +) + +set(TESTSUITE_HEADERS + ${TESTSUITE_HEADERS} + ${CMAKE_CURRENT_SOURCE_DIR}/test_flightplan.hxx + ${PROJECT_SOURCE_DIR}/tests/unitTestHelpers.cxx + PARENT_SCOPE +) diff --git a/test_suite/unit_tests/Navaids/TestSuite.cxx b/test_suite/unit_tests/Navaids/TestSuite.cxx new file mode 100644 index 000000000..8c720a69b --- /dev/null +++ b/test_suite/unit_tests/Navaids/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 "test_flightplan.hxx" + + +// Set up the unit tests. +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(FlightplanTests, "Unit tests"); diff --git a/tests/test_flightplan.cxx b/test_suite/unit_tests/Navaids/test_flightplan.cxx similarity index 63% rename from tests/test_flightplan.cxx rename to test_suite/unit_tests/Navaids/test_flightplan.cxx index 74161453b..021c6578d 100644 --- a/tests/test_flightplan.cxx +++ b/test_suite/unit_tests/Navaids/test_flightplan.cxx @@ -1,8 +1,7 @@ -#include "config.h" +#include "test_flightplan.hxx" -#include "unitTestHelpers.hxx" +#include "tests/unitTestHelpers.hxx" -#include #include #include @@ -16,6 +15,21 @@ using namespace flightgear; + +// Set up function for each test. +void FlightplanTests::setUp() +{ + fgtest::initTestGlobals("flightplan"); +} + + +// Clean up after each test. +void FlightplanTests::tearDown() +{ + fgtest::shutdownTestGlobals(); +} + + FlightPlanRef makeTestFP(const std::string& depICAO, const std::string& depRunway, const std::string& destICAO, const std::string& destRunway, const std::string& waypoints) @@ -37,28 +51,28 @@ FlightPlanRef makeTestFP(const std::string& depICAO, const std::string& depRunwa return f; } -void testBasic() +void FlightplanTests::testBasic() { FlightPlanRef fp1 = makeTestFP("EGCC", "23L", "EHAM", "24", "TNT CLN"); fp1->setIdent("testplan"); - SG_CHECK_EQUAL(fp1->ident(), "testplan"); - SG_CHECK_EQUAL(fp1->departureAirport()->ident(), "EGCC"); - SG_CHECK_EQUAL(fp1->departureRunway()->ident(), "23L"); - SG_CHECK_EQUAL(fp1->destinationAirport()->ident(), "EHAM"); - SG_CHECK_EQUAL(fp1->destinationRunway()->ident(), "24"); + CPPUNIT_ASSERT(fp1->ident() == "testplan"); + CPPUNIT_ASSERT(fp1->departureAirport()->ident() == "EGCC"); + CPPUNIT_ASSERT(fp1->departureRunway()->ident() == "23L"); + CPPUNIT_ASSERT(fp1->destinationAirport()->ident() == "EHAM"); + CPPUNIT_ASSERT(fp1->destinationRunway()->ident() == "24"); - SG_CHECK_EQUAL(fp1->numLegs(), 2); + CPPUNIT_ASSERT_EQUAL(fp1->numLegs(), 2); - SG_CHECK_EQUAL(fp1->legAtIndex(0)->waypoint()->source()->ident(), "TNT"); - SG_CHECK_EQUAL(fp1->legAtIndex(0)->waypoint()->source()->name(), "TRENT VOR-DME"); + CPPUNIT_ASSERT(fp1->legAtIndex(0)->waypoint()->source()->ident() == "TNT"); + CPPUNIT_ASSERT(fp1->legAtIndex(0)->waypoint()->source()->name() == "TRENT VOR-DME"); - SG_CHECK_EQUAL(fp1->legAtIndex(1)->waypoint()->source()->ident(), "CLN"); - SG_CHECK_EQUAL(fp1->legAtIndex(1)->waypoint()->source()->name(), "CLACTON VOR-DME"); + CPPUNIT_ASSERT(fp1->legAtIndex(1)->waypoint()->source()->ident() == "CLN"); + CPPUNIT_ASSERT(fp1->legAtIndex(1)->waypoint()->source()->name() == "CLACTON VOR-DME"); } -void testRoutePathBasic() +void FlightplanTests::testRoutePathBasic() { FlightPlanRef fp1 = makeTestFP("EGHI", "20", "EDDM", "08L", "SFD LYD BNE CIV ELLX LUX SAA KRH WLD"); @@ -85,15 +99,15 @@ void testRoutePathBasic() double distM = SGGeodesy::distanceM(bne->geod(), civ->geod()); double trackDeg = SGGeodesy::courseDeg(bne->geod(), civ->geod()); - SG_CHECK_EQUAL_EP2(trackDeg, rtepath.trackForIndex(3), 0.5); - SG_CHECK_EQUAL_EP2(distM, rtepath.distanceForIndex(3), 2000); // 2km precision, allow for turns + CPPUNIT_ASSERT_DOUBLES_EQUAL(trackDeg, rtepath.trackForIndex(3), 0.5); + CPPUNIT_ASSERT_DOUBLES_EQUAL(distM, rtepath.distanceForIndex(3), 2000); // 2km precision, allow for turns } // https://sourceforge.net/p/flightgear/codetickets/1703/ // https://sourceforge.net/p/flightgear/codetickets/1939/ -void testRoutePathSkipped() +void FlightplanTests::testRoutePathSkipped() { FlightPlanRef fp1 = makeTestFP("EHAM", "24", "EDDM", "08L", "EHEH KBO TAU FFM FFM/100/0.01 FFM/120/0.02 WUR WLD"); @@ -102,22 +116,22 @@ void testRoutePathSkipped() RoutePath rtepath(fp1); // skipped point uses inbound track - SG_CHECK_EQUAL_EP(rtepath.trackForIndex(3), rtepath.trackForIndex(4)); + CPPUNIT_ASSERT_EQUAL(rtepath.trackForIndex(3), rtepath.trackForIndex(4)); - SG_CHECK_EQUAL_EP(0.0, rtepath.distanceForIndex(4)); - SG_CHECK_EQUAL_EP(0.0, rtepath.distanceForIndex(5)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, rtepath.distanceForIndex(4), 1e-9); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, rtepath.distanceForIndex(5), 1e-9); - SG_CHECK_EQUAL_EP2(101000, rtepath.distanceForIndex(6), 1000); + CPPUNIT_ASSERT_DOUBLES_EQUAL(101000, rtepath.distanceForIndex(6), 1000); // this tests skipping two preceeding points works as it should SGGeodVec vec = rtepath.pathForIndex(6); - SG_CHECK_EQUAL(vec.size(), 9); + CPPUNIT_ASSERT(vec.size() == 9); } -void testRoutePathTrivialFlightPlan() +void FlightplanTests::testRoutePathTrivialFlightPlan() { FlightPlanRef fp1 = makeTestFP("EGPH", "24", "EGPH", "06", ""); @@ -131,17 +145,5 @@ void testRoutePathTrivialFlightPlan() rtepath.distanceForIndex(leg); } - SG_CHECK_EQUAL_EP(0.0, fp1->totalDistanceNm()); -} - -int main(int argc, char* argv[]) -{ - fgtest::initTestGlobals("flightplan"); - - testBasic(); - testRoutePathBasic(); - testRoutePathSkipped(); - testRoutePathTrivialFlightPlan(); - - fgtest::shutdownTestGlobals(); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, fp1->totalDistanceNm(), 1e-9); } diff --git a/test_suite/unit_tests/Navaids/test_flightplan.hxx b/test_suite/unit_tests/Navaids/test_flightplan.hxx new file mode 100644 index 000000000..afe488679 --- /dev/null +++ b/test_suite/unit_tests/Navaids/test_flightplan.hxx @@ -0,0 +1,54 @@ +/* + * 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_FLIGHTPLAN_UNIT_TESTS_HXX +#define _FG_FLIGHTPLAN_UNIT_TESTS_HXX + + +#include +#include + + +// The flight plan unit tests. +class FlightplanTests : public CppUnit::TestFixture +{ + // Set up the test suite. + CPPUNIT_TEST_SUITE(FlightplanTests); + CPPUNIT_TEST(testBasic); + CPPUNIT_TEST(testRoutePathBasic); + CPPUNIT_TEST(testRoutePathSkipped); + CPPUNIT_TEST(testRoutePathTrivialFlightPlan); + CPPUNIT_TEST_SUITE_END(); + +public: + // Set up function for each test. + void setUp(); + + // Clean up after each test. + void tearDown(); + + // The tests. + void testBasic(); + void testRoutePathBasic(); + void testRoutePathSkipped(); + void testRoutePathTrivialFlightPlan(); +}; + +#endif // _FG_FLIGHTPLAN_UNIT_TESTS_HXX diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 43e65728d..0d5af06db 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -116,7 +116,6 @@ macro(flightgear_test name sources) endmacro() flightgear_test(test_navs test_navaids2.cxx) -flightgear_test(test_flightplan test_flightplan.cxx) add_executable(test_ls_matrix test_ls_matrix.cxx ${CMAKE_SOURCE_DIR}/src/FDM/LaRCsim/ls_matrix.c) target_link_libraries(test_ls_matrix SimGearCore)