first commit
This commit is contained in:
16
test_suite/unit_tests/Main/CMakeLists.txt
Normal file
16
test_suite/unit_tests/Main/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
set(TESTSUITE_SOURCES
|
||||
${TESTSUITE_SOURCES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_autosaveMigration.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_posinit.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_timeManager.cxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
set(TESTSUITE_HEADERS
|
||||
${TESTSUITE_HEADERS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_autosaveMigration.hxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_posinit.hxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_timeManager.hxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
28
test_suite/unit_tests/Main/TestSuite.cxx
Normal file
28
test_suite/unit_tests/Main/TestSuite.cxx
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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_autosaveMigration.hxx"
|
||||
#include "test_posinit.hxx"
|
||||
#include "test_timeManager.hxx"
|
||||
|
||||
|
||||
// Set up the unit tests.
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AutosaveMigrationTests, "Unit tests");
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PosInitTests, "Unit tests");
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TimeManagerTests, "Unit tests");
|
||||
169
test_suite/unit_tests/Main/test_autosaveMigration.cxx
Normal file
169
test_suite/unit_tests/Main/test_autosaveMigration.cxx
Normal file
@@ -0,0 +1,169 @@
|
||||
// Written by James Turner, started 2017.
|
||||
//
|
||||
// Copyright (C) 2017 James Turner
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_autosaveMigration.hxx"
|
||||
|
||||
#include "test_suite/FGTestApi/testGlobals.hxx"
|
||||
|
||||
#include <simgear/props/props_io.hxx>
|
||||
#include <simgear/io/iostreams/sgstream.hxx>
|
||||
#include <simgear/misc/sg_dir.hxx>
|
||||
|
||||
#include "Main/globals.hxx"
|
||||
#include "Main/options.hxx"
|
||||
#include "Main/fg_props.hxx"
|
||||
|
||||
using namespace flightgear;
|
||||
|
||||
void writeLegacyAutosave(SGPath userData, int majorVersion, int minorVersion)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "autosave_" << majorVersion << "_" << minorVersion << ".xml";
|
||||
|
||||
sg_ofstream of(userData / os.str());
|
||||
{
|
||||
of << "<?xml version=\"1.0\"?>" \
|
||||
"<PropertyList>" \
|
||||
"<sim>" \
|
||||
"<window-height>42</window-height>" \
|
||||
"<presets>" \
|
||||
"<foo>12</foo>" \
|
||||
"<child><bar>12</bar></child>" \
|
||||
"</presets>" \
|
||||
"<presets n=\"1\">" \
|
||||
"<foo>13</foo>" \
|
||||
"</presets>" \
|
||||
"<rendering>" \
|
||||
"<msaa>10</msaa>" \
|
||||
"<texture-size>512</texture-size>" \
|
||||
"<texture-pack>" \
|
||||
"<foo>abc</foo>" \
|
||||
"<wibble>abc</wibble>" \
|
||||
"</texture-pack>" \
|
||||
"</rendering>" \
|
||||
"<gui>" \
|
||||
"<dialog n=\"1\">" \
|
||||
"<widget>button</widget>" \
|
||||
"</dialog>" \
|
||||
"<dialog n=\"2\">" \
|
||||
"<widget>slider</widget>" \
|
||||
"</dialog>"\
|
||||
"</gui>" \
|
||||
"</sim>" \
|
||||
"<some-setting>888</some-setting>" \
|
||||
"<views>" \
|
||||
"<view>" \
|
||||
"<new-prop>somevalue</new-prop>" \
|
||||
"<old-prop>somevalue</old-prop>" \
|
||||
"</view>" \
|
||||
"</views>" \
|
||||
"</PropertyList>";
|
||||
|
||||
}
|
||||
of.close();
|
||||
}
|
||||
|
||||
void writeLegacyAutosave2(SGPath userData, int majorVersion, int minorVersion)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "autosave_" << majorVersion << "_" << minorVersion << ".xml";
|
||||
|
||||
sg_ofstream of(userData / os.str());
|
||||
{
|
||||
of << "<?xml version=\"1.0\"?>" \
|
||||
"<PropertyList>" \
|
||||
"<sim>" \
|
||||
"<bad>1</bad>" \
|
||||
"</sim>" \
|
||||
"</views>" \
|
||||
"</PropertyList>";
|
||||
|
||||
}
|
||||
of.close();
|
||||
}
|
||||
|
||||
// Set up function for each test.
|
||||
void AutosaveMigrationTests::setUp()
|
||||
{
|
||||
FGTestApi::setUp::initTestGlobals("autosaveMigration");
|
||||
|
||||
Options::reset();
|
||||
}
|
||||
|
||||
|
||||
// Clean up after each test.
|
||||
void AutosaveMigrationTests::tearDown()
|
||||
{
|
||||
FGTestApi::tearDown::shutdownTestGlobals();
|
||||
}
|
||||
|
||||
|
||||
void AutosaveMigrationTests::testMigration()
|
||||
{
|
||||
SGPath testUserDataPath = globals->get_fg_home() / "test_autosave_migrate";
|
||||
if (!testUserDataPath.exists()) {
|
||||
SGPath p = testUserDataPath / "foo";
|
||||
p.create_dir(0755);
|
||||
}
|
||||
|
||||
simgear::Dir homeDir(testUserDataPath);
|
||||
for (auto path : homeDir.children(simgear::Dir::TYPE_FILE, ".xml")) {
|
||||
path.remove();
|
||||
}
|
||||
|
||||
writeLegacyAutosave(testUserDataPath, 2016, 1);
|
||||
|
||||
const string_list versionParts = simgear::strutils::split(VERSION, ".");
|
||||
CPPUNIT_ASSERT(versionParts.size() == 3);
|
||||
const int currentMajor = simgear::strutils::to_int(versionParts[0]);
|
||||
const int currentMinor = simgear::strutils::to_int(versionParts[1]);
|
||||
|
||||
// none of these should not be read
|
||||
writeLegacyAutosave2(testUserDataPath, 2016, 0);
|
||||
writeLegacyAutosave2(testUserDataPath, currentMajor, currentMinor + 1);
|
||||
writeLegacyAutosave2(testUserDataPath, currentMajor+1, currentMinor + 1);
|
||||
|
||||
SGPath p = globals->autosaveFilePath(testUserDataPath);
|
||||
if (p.exists()) {
|
||||
CPPUNIT_ASSERT(p.remove());
|
||||
}
|
||||
|
||||
// write some blck-list rules to property tree
|
||||
SGPropertyNode_ptr blacklist = fgGetNode("/sim/autosave-migration/blacklist", true);
|
||||
blacklist->addChild("path")->setStringValue("/sim[0]/presets[0]/*");
|
||||
blacklist->addChild("path")->setStringValue("/sim[0]/rendering[0]/texture-");
|
||||
blacklist->addChild("path")->setStringValue("/views[0]/view[*]/old-prop");
|
||||
blacklist->addChild("path")->setStringValue("/sim[0]/gui");
|
||||
|
||||
// execute method under test
|
||||
globals->loadUserSettings(testUserDataPath);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((int)globals->get_props()->getNode("sim")->getChildren("presets").size(), 2);
|
||||
CPPUNIT_ASSERT_EQUAL((int)globals->get_props()->getNode("sim")->getChildren("gui").size(), 0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("sim/window-height"), 42);
|
||||
CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("sim/presets/foo"), 0);
|
||||
CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("sim/presets[1]/foo"), 13);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("some-setting"), 888);
|
||||
|
||||
// if this is not zero, one of the bad autosaves was read
|
||||
CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("sim/bad"), 0);
|
||||
}
|
||||
48
test_suite/unit_tests/Main/test_autosaveMigration.hxx
Normal file
48
test_suite/unit_tests/Main/test_autosaveMigration.hxx
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _FG_AUTOSAVE_MIGRATION_UNIT_TESTS_HXX
|
||||
#define _FG_AUTOSAVE_MIGRATION_UNIT_TESTS_HXX
|
||||
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
|
||||
|
||||
// The unit tests.
|
||||
class AutosaveMigrationTests : public CppUnit::TestFixture
|
||||
{
|
||||
// Set up the test suite.
|
||||
CPPUNIT_TEST_SUITE(AutosaveMigrationTests);
|
||||
CPPUNIT_TEST(testMigration);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
// Set up function for each test.
|
||||
void setUp();
|
||||
|
||||
// Clean up after each test.
|
||||
void tearDown();
|
||||
|
||||
// The tests.
|
||||
void testMigration();
|
||||
};
|
||||
|
||||
#endif // _FG_AUTOSAVE_MIGRATION_UNIT_TESTS_HXX
|
||||
1029
test_suite/unit_tests/Main/test_posinit.cxx
Normal file
1029
test_suite/unit_tests/Main/test_posinit.cxx
Normal file
File diff suppressed because it is too large
Load Diff
143
test_suite/unit_tests/Main/test_posinit.hxx
Normal file
143
test_suite/unit_tests/Main/test_posinit.hxx
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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>
|
||||
#include "Airports/airport.hxx"
|
||||
|
||||
|
||||
// The unit tests of the FGNasalSys subsystem.
|
||||
class PosInitTests : public CppUnit::TestFixture
|
||||
{
|
||||
// Set up the test suite.
|
||||
CPPUNIT_TEST_SUITE(PosInitTests);
|
||||
|
||||
// Airport-based tests
|
||||
CPPUNIT_TEST(testAirportAltitudeOffsetStartup);
|
||||
CPPUNIT_TEST(testAirportAndMetarStartup);
|
||||
CPPUNIT_TEST(testAirportAndRunwayStartup);
|
||||
CPPUNIT_TEST(testAirportAndAvailableParkingStartup);
|
||||
CPPUNIT_TEST(testAirportAndParkingStartup);
|
||||
CPPUNIT_TEST(testAirportOnlyStartup);
|
||||
CPPUNIT_TEST(testAirportRunwayOffsetAltitudeStartup);
|
||||
CPPUNIT_TEST(testAirportRunwayOffsetGlideslopeStartup);
|
||||
CPPUNIT_TEST(testDefaultStartup);
|
||||
CPPUNIT_TEST(testRepositionAtParking);
|
||||
CPPUNIT_TEST(testParkAtOccupied);
|
||||
CPPUNIT_TEST(testParkInvalid);
|
||||
CPPUNIT_TEST(testAirportRunwayRepositionAirport);
|
||||
CPPUNIT_TEST(testParkNoAI);
|
||||
|
||||
|
||||
// Navaid tests
|
||||
CPPUNIT_TEST(testVOROnlyStartup);
|
||||
CPPUNIT_TEST(testVOROffsetAltitudeHeadingStartup);
|
||||
CPPUNIT_TEST(testFixOnlyStartup);
|
||||
CPPUNIT_TEST(testFixOffsetAltitudeHeadingStartup);
|
||||
CPPUNIT_TEST(testNDBOnlyStartup);
|
||||
CPPUNIT_TEST(testNDBOffsetAltitudeHeadingStartup);
|
||||
|
||||
CPPUNIT_TEST(testLatLonStartup);
|
||||
//CPPUNIT_TEST(testLatLonOffsetStartup); This is not yet supported.
|
||||
|
||||
// Carrier tests
|
||||
// We are not able to test the carrier code thoroughly as it depends
|
||||
// heavily on finalizePosition(), which requires that the carrier model
|
||||
// itself be loaded into the scenegraph.
|
||||
CPPUNIT_TEST(testCarrierStartup);
|
||||
|
||||
// Reposition tests
|
||||
CPPUNIT_TEST(testAirportRepositionAirport);
|
||||
CPPUNIT_TEST(testRepositionAtSameParking);
|
||||
CPPUNIT_TEST(testRepositionAtOccupied);
|
||||
CPPUNIT_TEST(testRepositionAtInvalid);
|
||||
|
||||
// MP tests
|
||||
CPPUNIT_TEST(testMPRunwayStart);
|
||||
CPPUNIT_TEST(testMPRunwayStartNoGroundnet);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void simulateStartReposition();
|
||||
void simulateFinalizePosition();
|
||||
public:
|
||||
// Set up function for each test.
|
||||
void setUp();
|
||||
|
||||
// Clean up after each test.
|
||||
void tearDown();
|
||||
|
||||
// The tests.
|
||||
void testAirportAltitudeOffsetStartup();
|
||||
void testAirportAndMetarStartup();
|
||||
void testAirportAndAvailableParkingStartup();
|
||||
void testAirportAndParkingStartup();
|
||||
void testAirportAndRunwayStartup();
|
||||
void testAirportOnlyStartup();
|
||||
void testAirportRunwayOffsetAltitudeStartup();
|
||||
void testAirportRunwayOffsetGlideslopeStartup();
|
||||
void testDefaultStartup();
|
||||
void testParkAtOccupied();
|
||||
void testParkInvalid();
|
||||
void testParkNoAI();
|
||||
|
||||
// Navaid tests
|
||||
void testVOROnlyStartup();
|
||||
void testVOROffsetAltitudeHeadingStartup();
|
||||
void testFixOnlyStartup();
|
||||
void testFixOffsetAltitudeHeadingStartup();
|
||||
void testNDBOnlyStartup();
|
||||
void testNDBOffsetAltitudeHeadingStartup();
|
||||
|
||||
//Lat Lon tests
|
||||
void testLatLonStartup();
|
||||
void testLatLonOffsetStartup();
|
||||
|
||||
//Carrier tests
|
||||
void testCarrierStartup();
|
||||
|
||||
//Reposition tests
|
||||
void testAirportRepositionAirport();
|
||||
void testRepositionAtParking();
|
||||
void testRepositionAtSameParking();
|
||||
void testRepositionAtOccupied();
|
||||
void testRepositionAtInvalid();
|
||||
void testAirportRunwayRepositionAirport();
|
||||
|
||||
// MP tests
|
||||
void testMPRunwayStart();
|
||||
void testMPRunwayStartNoGroundnet();
|
||||
private:
|
||||
// Helper functions for tests. Return void as they use CPPUNIT_ASSERT
|
||||
void checkAlt(float value);
|
||||
void checkHeading(float value);
|
||||
void checkPosition(SGGeod expectedPos, float delta=1000.0);
|
||||
void checkClosestAirport(std::string icao);
|
||||
void checkStringProp(std::string property, std::string expected);
|
||||
void checkRunway(std::string expected);
|
||||
void checkOnGround();
|
||||
void checkInAir();
|
||||
};
|
||||
|
||||
#endif // _FG_POSINIT_UNIT_TESTS_HXX
|
||||
237
test_suite/unit_tests/Main/test_timeManager.cxx
Normal file
237
test_suite/unit_tests/Main/test_timeManager.cxx
Normal file
@@ -0,0 +1,237 @@
|
||||
// Written by James Turner, started 2021.
|
||||
//
|
||||
// Copyright (C) 2021 James Turner
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_timeManager.hxx"
|
||||
|
||||
#include "test_suite/FGTestApi/NavDataCache.hxx"
|
||||
#include "test_suite/FGTestApi/TestPilot.hxx"
|
||||
#include "test_suite/FGTestApi/testGlobals.hxx"
|
||||
|
||||
#include <simgear/io/iostreams/sgstream.hxx>
|
||||
#include <simgear/misc/sg_dir.hxx>
|
||||
#include <simgear/props/props_io.hxx>
|
||||
#include <simgear/timing/sg_time.hxx>
|
||||
|
||||
#include "Main/fg_props.hxx"
|
||||
#include "Main/globals.hxx"
|
||||
#include <Airports/airport.hxx>
|
||||
#include <Time/TimeManager.hxx>
|
||||
|
||||
using namespace flightgear;
|
||||
|
||||
|
||||
// Set up function for each test.
|
||||
void TimeManagerTests::setUp()
|
||||
{
|
||||
FGTestApi::setUp::initTestGlobals("timeManager");
|
||||
FGTestApi::setUp::initNavDataCache();
|
||||
}
|
||||
|
||||
|
||||
// Clean up after each test.
|
||||
void TimeManagerTests::tearDown()
|
||||
{
|
||||
FGTestApi::tearDown::shutdownTestGlobals();
|
||||
}
|
||||
|
||||
|
||||
void TimeManagerTests::testBasic()
|
||||
{
|
||||
auto timeManager = globals->get_subsystem<TimeManager>();
|
||||
|
||||
// set standard values
|
||||
fgSetBool("/sim/freeze", false);
|
||||
fgSetBool("/sim/sceneryloaded", true);
|
||||
fgSetDouble("/sim/model-hz", 120.0);
|
||||
|
||||
timeManager->bind();
|
||||
timeManager->init();
|
||||
timeManager->postinit();
|
||||
|
||||
double simDt, realDt;
|
||||
// first run: values are zero
|
||||
timeManager->computeTimeDeltas(simDt, realDt);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, simDt, 1.0e-6);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, realDt, 1.0e-6);
|
||||
|
||||
// manually modify the 'last time' to check delta computation
|
||||
timeManager->_lastStamp = SGTimeStamp::now() - SGTimeStamp::fromMSec(25);
|
||||
timeManager->computeTimeDeltas(simDt, realDt);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.025, simDt, 1.0e-3);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.025, realDt, 1.0e-3);
|
||||
|
||||
timeManager->update(simDt);
|
||||
}
|
||||
|
||||
void TimeManagerTests::testFreezeUnfreeze()
|
||||
{
|
||||
auto timeManager = globals->get_subsystem<TimeManager>();
|
||||
|
||||
// set standard values
|
||||
fgSetBool("/sim/freeze/clock", false);
|
||||
fgSetBool("/sim/sceneryloaded", true);
|
||||
fgSetDouble("/sim/model-hz", 120.0);
|
||||
|
||||
timeManager->postinit();
|
||||
|
||||
double simDt, realDt;
|
||||
// first run: values are zero
|
||||
timeManager->computeTimeDeltas(simDt, realDt);
|
||||
|
||||
// test hack: force dtRemainder to zero so we aren't affected by the
|
||||
// system -> stread clock offset in our test assertions. Without this,
|
||||
// depending on exaclty when thetest suite is run, we would get different
|
||||
// results
|
||||
timeManager->_dtRemainder = 0.0;
|
||||
|
||||
SGTimeStamp n;
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, simDt, 1.0e-6);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, realDt, 1.0e-6);
|
||||
|
||||
timeManager->_lastStamp = SGTimeStamp::now() - SGTimeStamp::fromMSec(15);
|
||||
timeManager->computeTimeDeltas(simDt, realDt);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.008333, simDt, 1.0e-5);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.008333, realDt, 1.0e-5);
|
||||
|
||||
fgSetBool("/sim/freeze/clock", true);
|
||||
timeManager->_lastStamp = SGTimeStamp::now() - SGTimeStamp::fromMSec(20);
|
||||
timeManager->computeTimeDeltas(simDt, realDt);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, simDt, 1.0e-5); // sim time should not advance
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.025, realDt, 1.0e-5);
|
||||
}
|
||||
|
||||
void TimeManagerTests::testTimeZones()
|
||||
{
|
||||
auto timeManager = globals->get_subsystem<TimeManager>();
|
||||
|
||||
auto vabb = fgFindAirportID("VABB");
|
||||
FGTestApi::setPositionAndStabilise(vabb->geod());
|
||||
|
||||
|
||||
// set standard values
|
||||
fgSetBool("/sim/freeze", false);
|
||||
fgSetBool("/sim/sceneryloaded", true);
|
||||
fgSetDouble("/sim/model-hz", 120.0);
|
||||
|
||||
timeManager->postinit();
|
||||
|
||||
// fake Unix time by setting this; it will then
|
||||
// set the 'current unix time' passed to SGTime
|
||||
const auto testDate = 314611200L;
|
||||
fgSetInt("/sim/time/cur-time-override", testDate);
|
||||
|
||||
timeManager->update(0.0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)19800, globals->get_time_params()->get_local_offset());
|
||||
|
||||
auto gmt = globals->get_time_params()->getGmt();
|
||||
CPPUNIT_ASSERT_EQUAL(79, gmt->tm_year);
|
||||
CPPUNIT_ASSERT_EQUAL(11, gmt->tm_mon);
|
||||
CPPUNIT_ASSERT_EQUAL(21, gmt->tm_mday);
|
||||
|
||||
|
||||
// relocate to somewhere, check the time values update
|
||||
|
||||
auto eddf = FGAirport::getByIdent("EDDF");
|
||||
FGTestApi::setPositionAndStabilise(eddf->geod());
|
||||
timeManager->reposition();
|
||||
timeManager->update(0.0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)3600, globals->get_time_params()->get_local_offset());
|
||||
|
||||
|
||||
auto zbaa = FGAirport::getByIdent("ZBAA");
|
||||
FGTestApi::setPositionAndStabilise(zbaa->geod());
|
||||
timeManager->reposition();
|
||||
timeManager->update(0.0);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)28800, globals->get_time_params()->get_local_offset());
|
||||
}
|
||||
|
||||
void TimeManagerTests::testETCTimeZones()
|
||||
{
|
||||
auto timeManager = globals->get_subsystem<TimeManager>();
|
||||
|
||||
auto phto = fgFindAirportID("PHTO");
|
||||
FGTestApi::setPositionAndStabilise(phto->geod());
|
||||
|
||||
timeManager->postinit();
|
||||
|
||||
// fake Unix time by setting this; it will then
|
||||
// set the 'current unix time' passed to SGTime
|
||||
const auto testDate = 314611200L;
|
||||
fgSetInt("/sim/time/cur-time-override", testDate);
|
||||
|
||||
FGTestApi::setPositionAndStabilise(phto->geod());
|
||||
timeManager->reposition();
|
||||
timeManager->update(0.0);
|
||||
|
||||
SGPropertyNode_ptr tzNameNode = fgGetNode("/sim/time/local-timezone", true);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((time_t)-36000, globals->get_time_params()->get_local_offset());
|
||||
CPPUNIT_ASSERT_EQUAL("Pacific/Honolulu"s, string{tzNameNode->getStringValue()});
|
||||
|
||||
auto pilot = SGSharedPtr<FGTestApi::TestPilot>(new FGTestApi::TestPilot);
|
||||
pilot->setSpeedKts(1000);
|
||||
pilot->setCourseTrue(320.0);
|
||||
|
||||
bool ok = FGTestApi::runForTimeWithCheck(600.0, [tzNameNode]() {
|
||||
const string tz = tzNameNode->getStringValue();
|
||||
return tz == "Etc/GMT+10"s;
|
||||
});
|
||||
CPPUNIT_ASSERT(ok);
|
||||
|
||||
ok = FGTestApi::runForTimeWithCheck(600.0, [tzNameNode]() {
|
||||
const string tz = tzNameNode->getStringValue();
|
||||
return tz == "Pacific/Honolulu"s;
|
||||
});
|
||||
CPPUNIT_ASSERT(ok);
|
||||
}
|
||||
|
||||
void TimeManagerTests::testSpecifyTimeOffset()
|
||||
{
|
||||
// disabled for now since this code depends on epehmeris as well
|
||||
// to define sun position
|
||||
return;
|
||||
|
||||
auto timeManager = globals->get_subsystem<TimeManager>();
|
||||
|
||||
// set standard values
|
||||
fgSetBool("/sim/freeze", false);
|
||||
fgSetBool("/sim/sceneryloaded", true);
|
||||
fgSetDouble("/sim/model-hz", 120.0);
|
||||
|
||||
timeManager->postinit();
|
||||
|
||||
const auto testDate = 314611200L;
|
||||
fgSetInt("/sim/time/cur-time-override", testDate);
|
||||
|
||||
auto uudd = fgFindAirportID("UUDD");
|
||||
FGTestApi::setPositionAndStabilise(uudd->geod());
|
||||
|
||||
timeManager->setTimeOffset("dawn", 0);
|
||||
|
||||
timeManager->update(0.0);
|
||||
|
||||
auto localTime = globals->get_time_params()->get_cur_time();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL((time_t) 0, localTime);
|
||||
}
|
||||
52
test_suite/unit_tests/Main/test_timeManager.hxx
Normal file
52
test_suite/unit_tests/Main/test_timeManager.hxx
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
|
||||
|
||||
// The unit tests.
|
||||
class TimeManagerTests : public CppUnit::TestFixture
|
||||
{
|
||||
// Set up the test suite.
|
||||
CPPUNIT_TEST_SUITE(TimeManagerTests);
|
||||
CPPUNIT_TEST(testBasic);
|
||||
CPPUNIT_TEST(testTimeZones);
|
||||
CPPUNIT_TEST(testFreezeUnfreeze);
|
||||
CPPUNIT_TEST(testSpecifyTimeOffset);
|
||||
CPPUNIT_TEST(testETCTimeZones);
|
||||
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 testTimeZones();
|
||||
void testFreezeUnfreeze();
|
||||
void testSpecifyTimeOffset();
|
||||
void testETCTimeZones();
|
||||
};
|
||||
Reference in New Issue
Block a user