From 251b3aeb2bf8d2b84d09fd677a5d620f84d59459 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 13 Mar 2021 15:57:05 +0000 Subject: [PATCH] TimeManager: add unit-test for ETC time zones Ensure when entering/exiting oceanic areas, we switch to/from an ETC time-zone correctly --- .../unit_tests/Main/test_timeManager.cxx | 44 +++++++++++++++++++ .../unit_tests/Main/test_timeManager.hxx | 2 + 2 files changed, 46 insertions(+) diff --git a/test_suite/unit_tests/Main/test_timeManager.cxx b/test_suite/unit_tests/Main/test_timeManager.cxx index 3798607dd..2f309e988 100644 --- a/test_suite/unit_tests/Main/test_timeManager.cxx +++ b/test_suite/unit_tests/Main/test_timeManager.cxx @@ -21,6 +21,7 @@ #include "test_timeManager.hxx" #include "test_suite/FGTestApi/NavDataCache.hxx" +#include "test_suite/FGTestApi/TestPilot.hxx" #include "test_suite/FGTestApi/testGlobals.hxx" #include @@ -169,6 +170,49 @@ void TimeManagerTests::testTimeZones() CPPUNIT_ASSERT_EQUAL((time_t)28800, globals->get_time_params()->get_local_offset()); } +void TimeManagerTests::testETCTimeZones() +{ + auto phto = fgFindAirportID("PHTO"); + FGTestApi::setPositionAndStabilise(phto->geod()); + auto timeManager = new TimeManager; + + timeManager->bind(); + timeManager->init(); + 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); + + globals->add_subsystem("time", timeManager); + + 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(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 diff --git a/test_suite/unit_tests/Main/test_timeManager.hxx b/test_suite/unit_tests/Main/test_timeManager.hxx index 814f41f9e..d2dfc5ed5 100644 --- a/test_suite/unit_tests/Main/test_timeManager.hxx +++ b/test_suite/unit_tests/Main/test_timeManager.hxx @@ -33,6 +33,7 @@ class TimeManagerTests : public CppUnit::TestFixture CPPUNIT_TEST(testTimeZones); CPPUNIT_TEST(testFreezeUnfreeze); CPPUNIT_TEST(testSpecifyTimeOffset); + CPPUNIT_TEST(testETCTimeZones); CPPUNIT_TEST_SUITE_END(); public: @@ -47,4 +48,5 @@ public: void testTimeZones(); void testFreezeUnfreeze(); void testSpecifyTimeOffset(); + void testETCTimeZones(); };