1
0
Fork 0

TestSuite: Migration of the posinit unit tests.

This commit is contained in:
Edward d'Auvergne 2018-03-13 11:10:08 +01:00
parent 85ad420be1
commit 7616f1ec3e
7 changed files with 104 additions and 26 deletions

View file

@ -218,6 +218,5 @@ if(ENABLE_METAR)
endif() endif()
if (COMMAND flightgear_test) if (COMMAND flightgear_test)
flightgear_test(posinit test_posinit.cxx)
flightgear_test(autosaveMigration test_autosaveMigration.cxx) flightgear_test(autosaveMigration test_autosaveMigration.cxx)
endif() endif()

View file

@ -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(LaRCSimMatrixUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u LaRCSimMatrixTests)
add_test(MktimeUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u MktimeTests) 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(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. # GUI test suites.

View file

@ -3,6 +3,7 @@ foreach( unit_test_category
Add-ons Add-ons
general general
FDM FDM
Main
Navaids Navaids
Scripting Scripting
) )

View file

@ -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
)

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "test_posinit.hxx"
// Set up the unit tests.
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PosInitTests, "Unit tests");

View file

@ -16,11 +16,10 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // 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 <simgear/misc/test_macros.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include "Main/positioninit.hxx" #include "Main/positioninit.hxx"
@ -32,7 +31,7 @@
using namespace flightgear; using namespace flightgear;
void testDefaultStartup() void PosInitTests::testDefaultStartup()
{ {
fgtest::initTestGlobals("posinit"); fgtest::initTestGlobals("posinit");
Options::reset(); Options::reset();
@ -55,25 +54,25 @@ void testDefaultStartup()
{ {
SGPath presets = fgtest::fgdataPath() / "location-presets.xml"; SGPath presets = fgtest::fgdataPath() / "location-presets.xml";
SG_VERIFY(presets.exists()); CPPUNIT_ASSERT(presets.exists());
SGPropertyNode_ptr props(new SGPropertyNode); SGPropertyNode_ptr props(new SGPropertyNode);
readProperties(presets, props); readProperties(presets, props);
std::string icao = props->getStringValue("/sim/presets/airport-id"); 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(); SGGeod pos = globals->get_aircraft_position();
FGAirportRef defaultAirport = FGAirport::getByIdent(icao); FGAirportRef defaultAirport = FGAirport::getByIdent(icao);
double dist = SGGeodesy::distanceM(pos, defaultAirport->geod()); double dist = SGGeodesy::distanceM(pos, defaultAirport->geod());
SG_CHECK_LT(dist, 10000); CPPUNIT_ASSERT(dist < 10000);
} }
fgtest::shutdownTestGlobals(); fgtest::shutdownTestGlobals();
} }
void testAirportOnlyStartup() void PosInitTests::testAirportOnlyStartup()
{ {
fgtest::initTestGlobals("posinit"); fgtest::initTestGlobals("posinit");
Options::reset(); Options::reset();
@ -88,18 +87,18 @@ void testAirportOnlyStartup()
opts->processOptions(); opts->processOptions();
} }
SG_VERIFY(fgGetBool("/sim/presets/airport-requested")); CPPUNIT_ASSERT(fgGetBool("/sim/presets/airport-requested"));
initPosition(); 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(), double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
FGAirport::getByIdent("EDDF")->geod()); FGAirport::getByIdent("EDDF")->geod());
SG_CHECK_LT(dist, 10000); CPPUNIT_ASSERT(dist < 10000);
fgtest::shutdownTestGlobals(); fgtest::shutdownTestGlobals();
} }
void testAirportAndMetarStartup() void PosInitTests::testAirportAndMetarStartup()
{ {
fgtest::initTestGlobals("posinit"); fgtest::initTestGlobals("posinit");
@ -116,22 +115,12 @@ void testAirportAndMetarStartup()
initPosition(); 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(), double dist = SGGeodesy::distanceM(globals->get_aircraft_position(),
FGAirport::getByIdent("LOWI")->geod()); FGAirport::getByIdent("LOWI")->geod());
SG_CHECK_LT(dist, 10000); CPPUNIT_ASSERT(dist < 10000);
///sim/atc/runway ///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(); fgtest::shutdownTestGlobals();
} }
int main(int argc, char* argv[])
{
testDefaultStartup();
testAirportOnlyStartup();
testAirportAndMetarStartup();
return EXIT_SUCCESS;
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef _FG_POSINIT_UNIT_TESTS_HXX
#define _FG_POSINIT_UNIT_TESTS_HXX
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
// 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