1
0
Fork 0

Add test case for SGTime::updateLocal crash

SF-ID: https://sourceforge.net/p/flightgear/codetickets/2780/
This commit is contained in:
James Turner 2022-11-30 14:12:59 +00:00
parent 2c0b3d20a2
commit 5800143b96
5 changed files with 106 additions and 0 deletions

View file

@ -4,6 +4,7 @@ foreach( simgear_test_category
props props
canvas canvas
structure structure
timing
) )
add_subdirectory(${simgear_test_category}) add_subdirectory(${simgear_test_category})

View file

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

View file

@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
* 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");

View file

@ -0,0 +1,49 @@
/*
* SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <algorithm>
#include <memory>
#include "test_SGTime.hxx"
#include "test_suite/dataStore.hxx"
#include <simgear/math/SGGeod.hxx>
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<SGTime> 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);
}

View file

@ -0,0 +1,33 @@
/*
* SPDX-FileCopyrightText: (C) 2022 James Turner <james@flightgear.org>
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <simgear/timing/sg_time.hxx>
// 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:
};