1
0
Fork 0

TestSuite: Migration of the autosaveMigration tests into the CppUnit infrastructure.

This commit is contained in:
Edward d'Auvergne 2018-06-08 21:08:43 +02:00
parent 63d751c15e
commit b0c5a5481d
7 changed files with 79 additions and 28 deletions

View file

@ -109,10 +109,6 @@ if(ENABLE_METAR)
install(TARGETS metar RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS metar RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif() endif()
if (COMMAND flightgear_test)
flightgear_test(autosaveMigration test_autosaveMigration.cxx)
endif()
if (MSVC) if (MSVC)
if (TARGET Qt5::qmake) if (TARGET Qt5::qmake)
# property is the full path to qmake.exe # property is the full path to qmake.exe

View file

@ -778,13 +778,11 @@ static void tryAutosaveMigration(const SGPath& userDataPath, SGPropertyNode* pro
copyProperties(&oldProps, props); copyProperties(&oldProps, props);
// inform the user // inform the user
#if !defined(FG_TESTLIB)
flightgear::modalMessageBox("Settings migrated", flightgear::modalMessageBox("Settings migrated",
"Saved settings were migrated from a previous version of FlightGear. " "Saved settings were migrated from a previous version of FlightGear. "
"If you encounter any problems when using the system, try restoring " "If you encounter any problems when using the system, try restoring "
"the default settings, before reporting a problem. " "the default settings, before reporting a problem. "
"Saved settings can affect the appearance, performance and features of the simulator."); "Saved settings can affect the appearance, performance and features of the simulator.");
#endif
} }
// Load user settings from the autosave file (normally in $FG_HOME) // Load user settings from the autosave file (normally in $FG_HOME)

View file

@ -66,6 +66,7 @@ add_test(AeroMeshSystemTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -s A
# Unit test suites. # Unit test suites.
add_test(AddonManagementUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u AddonManagementTests) add_test(AddonManagementUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u AddonManagementTests)
add_test(AeroElementUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u AeroElementTests) add_test(AeroElementUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u AeroElementTests)
add_test(AutosaveMigrationUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u AutosaveMigrationTests)
add_test(FlightplanUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u FlightplanTests) add_test(FlightplanUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u FlightplanTests)
add_test(LaRCSimMatrixUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u LaRCSimMatrixTests) add_test(LaRCSimMatrixUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u LaRCSimMatrixTests)
add_test(MktimeUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u MktimeTests) add_test(MktimeUnitTests ${TESTSUITE_OUTPUT_DIR}/run_test_suite --ctest -u MktimeTests)

View file

@ -1,12 +1,14 @@
set(TESTSUITE_SOURCES set(TESTSUITE_SOURCES
${TESTSUITE_SOURCES} ${TESTSUITE_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx ${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_posinit.cxx
PARENT_SCOPE PARENT_SCOPE
) )
set(TESTSUITE_HEADERS set(TESTSUITE_HEADERS
${TESTSUITE_HEADERS} ${TESTSUITE_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/test_autosaveMigration.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_posinit.hxx ${CMAKE_CURRENT_SOURCE_DIR}/test_posinit.hxx
PARENT_SCOPE PARENT_SCOPE
) )

View file

@ -17,8 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "test_autosaveMigration.hxx"
#include "test_posinit.hxx" #include "test_posinit.hxx"
// Set up the unit tests. // 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(PosInitTests, "Unit tests");

View file

@ -18,9 +18,10 @@
#include "config.h" #include "config.h"
#include "test_suite/helpers/globals.hxx" #include "test_autosaveMigration.hxx"
#include "test_suite/FGTestApi/globals.hxx"
#include <simgear/misc/test_macros.hxx>
#include <simgear/props/props_io.hxx> #include <simgear/props/props_io.hxx>
#include <simgear/io/iostreams/sgstream.hxx> #include <simgear/io/iostreams/sgstream.hxx>
#include <simgear/misc/sg_dir.hxx> #include <simgear/misc/sg_dir.hxx>
@ -98,12 +99,24 @@ void writeLegacyAutosave2(SGPath userData, int majorVersion, int minorVersion)
of.close(); of.close();
} }
void testMigration() // Set up function for each test.
void AutosaveMigrationTests::setUp()
{ {
fgtest::initTestGlobals("autosaveMigration"); FGTestApi::setUp::initTestGlobals("autosaveMigration");
Options::reset(); 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"; SGPath testUserDataPath = globals->get_fg_home() / "test_autosave_migrate";
if (!testUserDataPath.exists()) { if (!testUserDataPath.exists()) {
SGPath p = testUserDataPath / "foo"; SGPath p = testUserDataPath / "foo";
@ -118,7 +131,7 @@ void testMigration()
writeLegacyAutosave(testUserDataPath, 2016, 1); writeLegacyAutosave(testUserDataPath, 2016, 1);
const string_list versionParts = simgear::strutils::split(VERSION, "."); const string_list versionParts = simgear::strutils::split(VERSION, ".");
SG_VERIFY(versionParts.size() == 3); CPPUNIT_ASSERT(versionParts.size() == 3);
const int currentMajor = simgear::strutils::to_int(versionParts[0]); const int currentMajor = simgear::strutils::to_int(versionParts[0]);
const int currentMinor = simgear::strutils::to_int(versionParts[1]); const int currentMinor = simgear::strutils::to_int(versionParts[1]);
@ -129,7 +142,7 @@ void testMigration()
SGPath p = globals->autosaveFilePath(testUserDataPath); SGPath p = globals->autosaveFilePath(testUserDataPath);
if (p.exists()) { if (p.exists()) {
SG_VERIFY(p.remove()); CPPUNIT_ASSERT(p.remove());
} }
// write some blck-list rules to property tree // write some blck-list rules to property tree
@ -142,24 +155,15 @@ void testMigration()
// execute method under test // execute method under test
globals->loadUserSettings(testUserDataPath); globals->loadUserSettings(testUserDataPath);
SG_CHECK_EQUAL(globals->get_props()->getNode("sim")->getChildren("presets").size(), 2); CPPUNIT_ASSERT_EQUAL((int)globals->get_props()->getNode("sim")->getChildren("presets").size(), 2);
SG_CHECK_EQUAL(globals->get_props()->getNode("sim")->getChildren("gui").size(), 0); CPPUNIT_ASSERT_EQUAL((int)globals->get_props()->getNode("sim")->getChildren("gui").size(), 0);
SG_CHECK_EQUAL(globals->get_props()->getIntValue("sim/window-height"), 42); CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("sim/window-height"), 42);
SG_CHECK_EQUAL(globals->get_props()->getIntValue("sim/presets/foo"), 0); CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("sim/presets/foo"), 0);
SG_CHECK_EQUAL(globals->get_props()->getIntValue("sim/presets[1]/foo"), 13); CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("sim/presets[1]/foo"), 13);
SG_CHECK_EQUAL(globals->get_props()->getIntValue("some-setting"), 888); CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("some-setting"), 888);
// if this is not zero, one of the bad autosaves was read // if this is not zero, one of the bad autosaves was read
SG_CHECK_EQUAL(globals->get_props()->getIntValue("sim/bad"), 0); CPPUNIT_ASSERT_EQUAL(globals->get_props()->getIntValue("sim/bad"), 0);
fgtest::shutdownTestGlobals();
}
int main(int argc, char* argv[])
{
testMigration();
return EXIT_SUCCESS;
} }

View 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