From 5800143b9658301e4c62ff8d490aee1fa7b58819 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 30 Nov 2022 14:12:59 +0000 Subject: [PATCH] Add test case for SGTime::updateLocal crash SF-ID: https://sourceforge.net/p/flightgear/codetickets/2780/ --- test_suite/simgear_tests/CMakeLists.txt | 1 + .../simgear_tests/timing/CMakeLists.txt | 12 +++++ test_suite/simgear_tests/timing/TestSuite.cxx | 11 +++++ .../simgear_tests/timing/test_SGTime.cxx | 49 +++++++++++++++++++ .../simgear_tests/timing/test_SGTime.hxx | 33 +++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 test_suite/simgear_tests/timing/CMakeLists.txt create mode 100644 test_suite/simgear_tests/timing/TestSuite.cxx create mode 100644 test_suite/simgear_tests/timing/test_SGTime.cxx create mode 100644 test_suite/simgear_tests/timing/test_SGTime.hxx diff --git a/test_suite/simgear_tests/CMakeLists.txt b/test_suite/simgear_tests/CMakeLists.txt index 32e8dcffd..114031767 100644 --- a/test_suite/simgear_tests/CMakeLists.txt +++ b/test_suite/simgear_tests/CMakeLists.txt @@ -4,6 +4,7 @@ foreach( simgear_test_category props canvas structure + timing ) add_subdirectory(${simgear_test_category}) diff --git a/test_suite/simgear_tests/timing/CMakeLists.txt b/test_suite/simgear_tests/timing/CMakeLists.txt new file mode 100644 index 000000000..ab4fb9524 --- /dev/null +++ b/test_suite/simgear_tests/timing/CMakeLists.txt @@ -0,0 +1,12 @@ +set(TESTSUITE_SOURCES + ${TESTSUITE_SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/test_SGTime.cxx + PARENT_SCOPE +) + +set(TESTSUITE_HEADERS + ${TESTSUITE_HEADERS} + ${CMAKE_CURRENT_SOURCE_DIR}/test_SGTime.hxx + PARENT_SCOPE +) diff --git a/test_suite/simgear_tests/timing/TestSuite.cxx b/test_suite/simgear_tests/timing/TestSuite.cxx new file mode 100644 index 000000000..f637069f9 --- /dev/null +++ b/test_suite/simgear_tests/timing/TestSuite.cxx @@ -0,0 +1,11 @@ +/* + * SPDX-FileCopyrightText: (C) 2022 James Turner + * SPDX-License-Identifier: GPL-2.0-or-later + */ + + +#include "test_SGTime.hxx" + + +// Set up the tests. +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SimgearTimingTests, "Simgear unit tests"); diff --git a/test_suite/simgear_tests/timing/test_SGTime.cxx b/test_suite/simgear_tests/timing/test_SGTime.cxx new file mode 100644 index 000000000..8cd14d55a --- /dev/null +++ b/test_suite/simgear_tests/timing/test_SGTime.cxx @@ -0,0 +1,49 @@ +/* + * SPDX-FileCopyrightText: (C) 2022 James Turner + * SPDX-License-Identifier: GPL-2.0-or-later + */ + + + +#include +#include + +#include "test_SGTime.hxx" +#include "test_suite/dataStore.hxx" + +#include + +using namespace std; + +// Set up function for each test. +void SimgearTimingTests::setUp() +{ +} + +// Clean up after each test. +void SimgearTimingTests::tearDown() +{ + +} + + +void SimgearTimingTests::testBadZoneDetectPosition() +{ + DataStore &data = DataStore::get(); + const SGPath rootPath{data.getFGRoot()}; + if (rootPath.isNull()) { + return; + } + + std::unique_ptr t(new SGTime{rootPath}); + + const auto goodPos = SGGeod::fromDeg(-69.5, 12.0); + CPPUNIT_ASSERT(t->updateLocal(goodPos, rootPath / "Timezone")); + + // discovered while flying with the Shuttle, but actually + // can happen at sea level. + // https://sourceforge.net/p/flightgear/codetickets/2780/ + + const auto pos = SGGeod::fromDeg(-69.0, 12.0); + CPPUNIT_ASSERT(t->updateLocal(pos, rootPath / "Timezone") == false); +} diff --git a/test_suite/simgear_tests/timing/test_SGTime.hxx b/test_suite/simgear_tests/timing/test_SGTime.hxx new file mode 100644 index 000000000..368026511 --- /dev/null +++ b/test_suite/simgear_tests/timing/test_SGTime.hxx @@ -0,0 +1,33 @@ +/* + * SPDX-FileCopyrightText: (C) 2022 James Turner + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#pragma once + +#include +#include + +#include + +// The unit tests of the simgear property tree. +class SimgearTimingTests : public CppUnit::TestFixture +{ + // Set up the test suite. + CPPUNIT_TEST_SUITE(SimgearTimingTests); + CPPUNIT_TEST(testBadZoneDetectPosition); + CPPUNIT_TEST_SUITE_END(); + +public: + // Set up function for each test. + void setUp(); + + // Clean up after each test. + void tearDown(); + + // The tests. + void testBadZoneDetectPosition(); + +private: + +};