diff --git a/src/Main/CMakeLists.txt b/src/Main/CMakeLists.txt index eb1d466b6..6fc49f5f1 100644 --- a/src/Main/CMakeLists.txt +++ b/src/Main/CMakeLists.txt @@ -218,6 +218,5 @@ if(ENABLE_METAR) endif() if (COMMAND flightgear_test) - flightgear_test(posinit test_posinit.cxx) flightgear_test(autosaveMigration test_autosaveMigration.cxx) endif() diff --git a/test_suite/CMakeLists.txt b/test_suite/CMakeLists.txt index 73eacee26..42b2c5613 100644 --- a/test_suite/CMakeLists.txt +++ b/test_suite/CMakeLists.txt @@ -57,6 +57,7 @@ add_test(FlightplanUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u F add_test(LaRCSimMatrixUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u LaRCSimMatrixTests) add_test(MktimeUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u MktimeTests) add_test(NasalSysUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u NasalSysTests) +add_test(PosInitUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u PosInitTests) # GUI test suites. diff --git a/test_suite/unit_tests/CMakeLists.txt b/test_suite/unit_tests/CMakeLists.txt index b587b67f2..f418a519b 100644 --- a/test_suite/unit_tests/CMakeLists.txt +++ b/test_suite/unit_tests/CMakeLists.txt @@ -3,6 +3,7 @@ foreach( unit_test_category Add-ons general FDM + Main Navaids Scripting ) diff --git a/test_suite/unit_tests/Main/CMakeLists.txt b/test_suite/unit_tests/Main/CMakeLists.txt new file mode 100644 index 000000000..43350aca8 --- /dev/null +++ b/test_suite/unit_tests/Main/CMakeLists.txt @@ -0,0 +1,12 @@ +set(TESTSUITE_SOURCES + ${TESTSUITE_SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/test_posinit.cxx + PARENT_SCOPE +) + +set(TESTSUITE_HEADERS + ${TESTSUITE_HEADERS} + ${CMAKE_CURRENT_SOURCE_DIR}/test_posinit.hxx + PARENT_SCOPE +) diff --git a/test_suite/unit_tests/Main/TestSuite.cxx b/test_suite/unit_tests/Main/TestSuite.cxx new file mode 100644 index 000000000..fb2be144b --- /dev/null +++ b/test_suite/unit_tests/Main/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_posinit.hxx" + + +// Set up the unit tests. +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PosInitTests, "Unit tests"); diff --git a/src/Main/test_posinit.cxx b/test_suite/unit_tests/Main/test_posinit.cxx similarity index 77% rename from src/Main/test_posinit.cxx rename to test_suite/unit_tests/Main/test_posinit.cxx index 47883dc45..ea709d160 100644 --- a/src/Main/test_posinit.cxx +++ b/test_suite/unit_tests/Main/test_posinit.cxx @@ -16,11 +16,10 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -#include "config.h" +#include "test_posinit.hxx" -#include "unitTestHelpers.hxx" +#include "tests/unitTestHelpers.hxx" -#include #include #include "Main/positioninit.hxx" @@ -32,7 +31,7 @@ using namespace flightgear; -void testDefaultStartup() +void PosInitTests::testDefaultStartup() { fgtest::initTestGlobals("posinit"); Options::reset(); @@ -55,25 +54,25 @@ void testDefaultStartup() { SGPath presets = fgtest::fgdataPath() / "location-presets.xml"; - SG_VERIFY(presets.exists()); + CPPUNIT_ASSERT(presets.exists()); SGPropertyNode_ptr props(new SGPropertyNode); readProperties(presets, props); std::string icao = props->getStringValue("/sim/presets/airport-id"); - SG_CHECK_EQUAL(globals->get_props()->getStringValue("/sim/airport/closest-airport-id"), icao); + CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/airport/closest-airport-id") == icao); SGGeod pos = globals->get_aircraft_position(); FGAirportRef defaultAirport = FGAirport::getByIdent(icao); double dist = SGGeodesy::distanceM(pos, defaultAirport->geod()); - SG_CHECK_LT(dist, 10000); + CPPUNIT_ASSERT(dist < 10000); } fgtest::shutdownTestGlobals(); } -void testAirportOnlyStartup() +void PosInitTests::testAirportOnlyStartup() { fgtest::initTestGlobals("posinit"); Options::reset(); @@ -88,18 +87,18 @@ void testAirportOnlyStartup() opts->processOptions(); } - SG_VERIFY(fgGetBool("/sim/presets/airport-requested")); + CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested")); initPosition(); - SG_CHECK_EQUAL(globals->get_props()->getStringValue("/sim/airport/closest-airport-id"), std::string("EDDF")); + CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/airport/closest-airport-id") == std::string("EDDF")); double dist = SGGeodesy::distanceM(globals->get_aircraft_position(), FGAirport::getByIdent("EDDF")->geod()); - SG_CHECK_LT(dist, 10000); + CPPUNIT_ASSERT(dist < 10000); fgtest::shutdownTestGlobals(); } -void testAirportAndMetarStartup() +void PosInitTests::testAirportAndMetarStartup() { fgtest::initTestGlobals("posinit"); @@ -116,22 +115,12 @@ void testAirportAndMetarStartup() initPosition(); - SG_CHECK_EQUAL(globals->get_props()->getStringValue("/sim/airport/closest-airport-id"), std::string("LOWI")); + CPPUNIT_ASSERT(globals->get_props()->getStringValue("/sim/airport/closest-airport-id") == std::string("LOWI")); double dist = SGGeodesy::distanceM(globals->get_aircraft_position(), FGAirport::getByIdent("LOWI")->geod()); - SG_CHECK_LT(dist, 10000); + CPPUNIT_ASSERT(dist < 10000); ///sim/atc/runway - SG_CHECK_EQUAL(globals->get_props()->getStringValue("sim/atc/runway"), std::string("26")); + CPPUNIT_ASSERT(globals->get_props()->getStringValue("sim/atc/runway") == std::string("26")); fgtest::shutdownTestGlobals(); } - -int main(int argc, char* argv[]) -{ - - testDefaultStartup(); - testAirportOnlyStartup(); - testAirportAndMetarStartup(); - - return EXIT_SUCCESS; -} diff --git a/test_suite/unit_tests/Main/test_posinit.hxx b/test_suite/unit_tests/Main/test_posinit.hxx new file mode 100644 index 000000000..629a5f303 --- /dev/null +++ b/test_suite/unit_tests/Main/test_posinit.hxx @@ -0,0 +1,52 @@ +/* + * 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_POSINIT_UNIT_TESTS_HXX +#define _FG_POSINIT_UNIT_TESTS_HXX + + +#include +#include + + +// The unit tests of the FGNasalSys subsystem. +class PosInitTests : public CppUnit::TestFixture +{ + // Set up the test suite. + CPPUNIT_TEST_SUITE(PosInitTests); + CPPUNIT_TEST(testAirportAndMetarStartup); + CPPUNIT_TEST(testAirportOnlyStartup); + CPPUNIT_TEST(testDefaultStartup); + CPPUNIT_TEST_SUITE_END(); + +public: + // Set up function for each test. + void setUp() {} + + // Clean up after each test. + void tearDown() {} + + // The tests. + void testAirportAndMetarStartup(); + void testAirportOnlyStartup(); + void testDefaultStartup(); +}; + +#endif // _FG_POSINIT_UNIT_TESTS_HXX