first commit
This commit is contained in:
12
test_suite/system_tests/Main/CMakeLists.txt
Normal file
12
test_suite/system_tests/Main/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
set(TESTSUITE_SOURCES
|
||||
${TESTSUITE_SOURCES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/testOptions.cxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
set(TESTSUITE_HEADERS
|
||||
${TESTSUITE_HEADERS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/testOptions.hxx
|
||||
PARENT_SCOPE
|
||||
)
|
||||
24
test_suite/system_tests/Main/TestSuite.cxx
Normal file
24
test_suite/system_tests/Main/TestSuite.cxx
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "testOptions.hxx"
|
||||
|
||||
|
||||
// Set up the unit tests.
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(OptionsTests, "System tests");
|
||||
171
test_suite/system_tests/Main/testOptions.cxx
Normal file
171
test_suite/system_tests/Main/testOptions.cxx
Normal file
@@ -0,0 +1,171 @@
|
||||
// Written by James Turner, started 2017.
|
||||
//
|
||||
// Copyright (C) 2017 James Turner
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "testOptions.hxx"
|
||||
#include "config.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "test_suite/FGTestApi/NavDataCache.hxx"
|
||||
#include "test_suite/FGTestApi/scene_graph.hxx"
|
||||
#include "test_suite/FGTestApi/testGlobals.hxx"
|
||||
|
||||
#include <simgear/package/Root.hxx>
|
||||
#include <simgear/props/props_io.hxx>
|
||||
|
||||
#include "Main/fg_props.hxx"
|
||||
#include "Main/globals.hxx"
|
||||
#include "Main/options.hxx"
|
||||
#include <Main/fg_init.hxx>
|
||||
|
||||
using namespace std::string_literals;
|
||||
using namespace flightgear;
|
||||
using namespace simgear::pkg;
|
||||
|
||||
void OptionsTests::setUp()
|
||||
{
|
||||
FGTestApi::setUp::initTestGlobals("options");
|
||||
FGTestApi::setUp::initNavDataCache();
|
||||
Options::reset();
|
||||
fgLoadProps("defaults.xml", globals->get_props());
|
||||
}
|
||||
|
||||
|
||||
void OptionsTests::tearDown()
|
||||
{
|
||||
FGTestApi::tearDown::shutdownTestGlobals();
|
||||
}
|
||||
|
||||
void OptionsTests::testLoadDefaultAircraft()
|
||||
{
|
||||
const auto customFGAircraftPath = SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "customAircraftDir";
|
||||
|
||||
{
|
||||
Options* opts = Options::sharedInstance();
|
||||
opts->setShouldLoadDefaultConfig(false);
|
||||
|
||||
const string fgAircraftArg = "--fg-aircraft=" + customFGAircraftPath.utf8Str();
|
||||
const char* args[] = {"dummypath", fgAircraftArg.c_str()};
|
||||
opts->init(2, (char**)args, SGPath());
|
||||
opts->processOptions();
|
||||
}
|
||||
|
||||
fgInitAircraftPaths(false);
|
||||
fgInitAircraft(false, false);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL("c172p"s, string{fgGetString("/sim/aircraft")});
|
||||
CPPUNIT_ASSERT_EQUAL("c172p"s, string{fgGetString("/sim/aircraft-id")});
|
||||
//CPPUNIT_ASSERT_EQUAL(adPath.utf8Str(), string{fgGetString("/sim/aircraft-dir")});
|
||||
}
|
||||
|
||||
void OptionsTests::testOptionAircraftWithAircraftDir()
|
||||
{
|
||||
const auto adPath = SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "customAircraftDir" / "overrideUfo";
|
||||
|
||||
{
|
||||
Options* opts = Options::sharedInstance();
|
||||
opts->setShouldLoadDefaultConfig(false);
|
||||
|
||||
const string aircraftDirArg = "--aircraft-dir=" + adPath.utf8Str();
|
||||
const char* args[] = {"dummypath", "--aircraft=ufo", aircraftDirArg.c_str()};
|
||||
opts->init(3, (char**)args, SGPath());
|
||||
opts->processOptions();
|
||||
}
|
||||
|
||||
fgInitAircraftPaths(false);
|
||||
fgInitAircraft(false, false);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL("ufo"s, string{fgGetString("/sim/aircraft")});
|
||||
CPPUNIT_ASSERT_EQUAL("ufo"s, string{fgGetString("/sim/aircraft-id")});
|
||||
CPPUNIT_ASSERT_EQUAL(adPath.utf8Str(), string{fgGetString("/sim/aircraft-dir")});
|
||||
}
|
||||
|
||||
void OptionsTests::testOptionAircraftWithFGAircraft()
|
||||
{
|
||||
const auto customFGAircraftPath = SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "customAircraftDir";
|
||||
|
||||
{
|
||||
Options* opts = Options::sharedInstance();
|
||||
opts->setShouldLoadDefaultConfig(false);
|
||||
|
||||
const string fgAircraftArg = "--fg-aircraft=" + customFGAircraftPath.utf8Str();
|
||||
const char* args[] = {"dummypath", "--aircraft=ufo", fgAircraftArg.c_str()};
|
||||
opts->init(3, (char**)args, SGPath());
|
||||
opts->processOptions();
|
||||
}
|
||||
|
||||
fgInitAircraftPaths(false);
|
||||
fgInitAircraft(false, false);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL("ufo"s, string{fgGetString("/sim/aircraft")});
|
||||
CPPUNIT_ASSERT_EQUAL("ufo"s, string{fgGetString("/sim/aircraft-id")});
|
||||
|
||||
const auto correctDir = (customFGAircraftPath / "overrideUfo").utf8Str();
|
||||
CPPUNIT_ASSERT_EQUAL(correctDir, string{fgGetString("/sim/aircraft-dir")});
|
||||
}
|
||||
|
||||
void OptionsTests::testOptionAircraftUnqualified()
|
||||
{
|
||||
const auto packageAircraftDir = SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "dummy_package_root";
|
||||
SGSharedPtr<Root> pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION));
|
||||
globals->setPackageRoot(pkgRoot);
|
||||
|
||||
{
|
||||
Options* opts = Options::sharedInstance();
|
||||
opts->setShouldLoadDefaultConfig(false);
|
||||
|
||||
const char* args[] = {"dummypath", "--aircraft=bob"};
|
||||
opts->init(2, (char**)args, SGPath());
|
||||
opts->processOptions();
|
||||
}
|
||||
|
||||
fgInitAircraftPaths(false);
|
||||
fgInitAircraft(false, false);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL("bob"s, string{fgGetString("/sim/aircraft")});
|
||||
CPPUNIT_ASSERT_EQUAL("org.fg.test.catalog1.bob"s, string{fgGetString("/sim/aircraft-id")});
|
||||
|
||||
const auto correctDir = (packageAircraftDir / "org.fg.test.catalog1" / "Aircraft" / "bobCraft").utf8Str();
|
||||
CPPUNIT_ASSERT_EQUAL(correctDir, string{fgGetString("/sim/aircraft-dir")});
|
||||
}
|
||||
|
||||
void OptionsTests::testOptionAircraftFullyQualified()
|
||||
{
|
||||
const auto packageAircraftDir = SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "dummy_package_root";
|
||||
SGSharedPtr<Root> pkgRoot(new Root(packageAircraftDir, FLIGHTGEAR_VERSION));
|
||||
globals->setPackageRoot(pkgRoot);
|
||||
|
||||
{
|
||||
Options* opts = Options::sharedInstance();
|
||||
opts->setShouldLoadDefaultConfig(false);
|
||||
|
||||
const char* args[] = {"dummypath", "--aircraft=org.fg.test.catalog1.bob"};
|
||||
opts->init(2, (char**)args, SGPath());
|
||||
opts->processOptions();
|
||||
}
|
||||
|
||||
fgInitAircraftPaths(false);
|
||||
fgInitAircraft(false, false);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL("bob"s, string{fgGetString("/sim/aircraft")});
|
||||
CPPUNIT_ASSERT_EQUAL("org.fg.test.catalog1.bob"s, string{fgGetString("/sim/aircraft-id")});
|
||||
|
||||
const auto correctDir = (packageAircraftDir / "org.fg.test.catalog1" / "Aircraft" / "bobCraft").utf8Str();
|
||||
CPPUNIT_ASSERT_EQUAL(correctDir, string{fgGetString("/sim/aircraft-dir")});
|
||||
}
|
||||
52
test_suite/system_tests/Main/testOptions.hxx
Normal file
52
test_suite/system_tests/Main/testOptions.hxx
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
// The system tests.
|
||||
class OptionsTests : public CppUnit::TestFixture
|
||||
{
|
||||
// Set up the test suite.
|
||||
CPPUNIT_TEST_SUITE(OptionsTests);
|
||||
CPPUNIT_TEST(testLoadDefaultAircraft);
|
||||
CPPUNIT_TEST(testOptionAircraftWithAircraftDir);
|
||||
CPPUNIT_TEST(testOptionAircraftUnqualified);
|
||||
CPPUNIT_TEST(testOptionAircraftFullyQualified);
|
||||
CPPUNIT_TEST(testOptionAircraftWithFGAircraft);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
// Set up function for each test.
|
||||
void setUp();
|
||||
|
||||
// Clean up after each test.
|
||||
void tearDown();
|
||||
|
||||
// The tests.
|
||||
void testOptionAircraftWithAircraftDir();
|
||||
void testOptionAircraftUnqualified();
|
||||
void testOptionAircraftFullyQualified();
|
||||
void testOptionAircraftWithFGAircraft();
|
||||
void testLoadDefaultAircraft();
|
||||
};
|
||||
Reference in New Issue
Block a user