tests: add empty-condition test-case
This commit is contained in:
parent
6c949c30d3
commit
168373af8a
6 changed files with 113 additions and 6 deletions
|
@ -1,3 +1,8 @@
|
|||
/*
|
||||
SPDX-Copyright: James Turner
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "test_suite/dataStore.hxx"
|
||||
|
@ -445,7 +450,15 @@ bool executeNasal(const std::string& code)
|
|||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
SGPropertyNode_ptr propsFromString(const std::string& s)
|
||||
{
|
||||
SGPropertyNode_ptr m = new SGPropertyNode;
|
||||
std::istringstream iss(s);
|
||||
readProperties(iss, m);
|
||||
return m;
|
||||
}
|
||||
|
||||
namespace tearDown {
|
||||
|
||||
void shutdownTestGlobals()
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
#ifndef FG_TEST_GLOBALS_HELPERS_HXX
|
||||
#define FG_TEST_GLOBALS_HELPERS_HXX
|
||||
/*
|
||||
SPDX-Copyright: James Turner
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <simgear/math/SGGeod.hxx>
|
||||
#include <simgear/props/propsfwd.hxx>
|
||||
#include <simgear/structure/SGSharedPtr.hxx>
|
||||
|
||||
namespace flightgear
|
||||
|
@ -42,6 +47,8 @@ void populateFPWithNasal(flightgear::FlightPlanRef f,
|
|||
|
||||
// helpers during tests
|
||||
|
||||
SGPropertyNode_ptr propsFromString(const std::string& s);
|
||||
|
||||
const SGGeod getPosition();
|
||||
void setPosition(const SGGeod& g);
|
||||
void setPositionAndStabilise(const SGGeod& g);
|
||||
|
@ -71,5 +78,3 @@ void shutdownTestGlobals();
|
|||
} // End of namespace tearDown.
|
||||
|
||||
} // End of namespace FGTestApi.
|
||||
|
||||
#endif // of FG_TEST_GLOBALS_HELPERS_HXX
|
||||
|
|
|
@ -2,11 +2,13 @@ set(TESTSUITE_SOURCES
|
|||
${TESTSUITE_SOURCES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_props.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_condition.cxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
set(TESTSUITE_HEADERS
|
||||
${TESTSUITE_HEADERS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_props.hxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_condition.hxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "test_condition.hxx"
|
||||
#include "test_props.hxx"
|
||||
|
||||
|
||||
// Set up the tests.
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SimgearPropsTests, "Simgear unit tests");
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SimgearConditionTests, "Simgear unit tests");
|
||||
|
|
50
test_suite/simgear_tests/props/test_condition.cxx
Normal file
50
test_suite/simgear_tests/props/test_condition.cxx
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
SPDX-Copyright: James Turner
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
|
||||
#include "test_condition.hxx"
|
||||
|
||||
#include <simgear/props/condition.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
||||
#include "test_suite/FGTestApi/testGlobals.hxx"
|
||||
|
||||
// Set up function for each test.
|
||||
void SimgearConditionTests::setUp()
|
||||
{
|
||||
// Create a property tree.
|
||||
tree = new SGPropertyNode;
|
||||
}
|
||||
|
||||
|
||||
// Clean up SimgearConditionTests each test.
|
||||
void SimgearConditionTests::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Test property aliasing, to catch possible memory leaks.
|
||||
void SimgearConditionTests::testEmptyCondition()
|
||||
{
|
||||
auto config = FGTestApi::propsFromString(R"(<?xml version="1.0" encoding="UTF-8"?>
|
||||
<PropertyList>
|
||||
<enabled>/foo/bar</enabled>
|
||||
</PropertyList>
|
||||
)");
|
||||
|
||||
sglog().setDeveloperMode(true);
|
||||
|
||||
CPPUNIT_ASSERT_THROW(sgReadCondition(tree, config->getChild("enabled")), sg_exception);
|
||||
|
||||
// repeat in non-developer mode; test the legacy behaviour
|
||||
sglog().setDeveloperMode(false);
|
||||
|
||||
auto n2 = sgReadCondition(tree, config->getChild("enabled"));
|
||||
CPPUNIT_ASSERT(n2);
|
||||
CPPUNIT_ASSERT(n2->test());
|
||||
}
|
36
test_suite/simgear_tests/props/test_condition.hxx
Normal file
36
test_suite/simgear_tests/props/test_condition.hxx
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
SPDX-Copyright: James Turner
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include <simgear/props/condition.hxx>
|
||||
#include <simgear/props/propsfwd.hxx>
|
||||
|
||||
// The unit tests of the simgear property tree.
|
||||
class SimgearConditionTests : public CppUnit::TestFixture
|
||||
{
|
||||
// Set up the test suite.
|
||||
CPPUNIT_TEST_SUITE(SimgearConditionTests);
|
||||
CPPUNIT_TEST(testEmptyCondition);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
// Set up function for each test.
|
||||
void setUp();
|
||||
|
||||
// Clean up after each test.
|
||||
void tearDown();
|
||||
|
||||
// The tests.
|
||||
void testEmptyCondition();
|
||||
|
||||
private:
|
||||
// A property tree.
|
||||
SGPropertyNode_ptr tree;
|
||||
};
|
Loading…
Reference in a new issue