diff --git a/test_suite/system_tests/CMakeLists.txt b/test_suite/system_tests/CMakeLists.txt
index d891d816f..6861a6a71 100644
--- a/test_suite/system_tests/CMakeLists.txt
+++ b/test_suite/system_tests/CMakeLists.txt
@@ -3,6 +3,7 @@ foreach( system_test_category
FDM
Instrumentation
Navaids
+ Main
)
add_subdirectory(${system_test_category})
diff --git a/test_suite/system_tests/Main/CMakeLists.txt b/test_suite/system_tests/Main/CMakeLists.txt
new file mode 100644
index 000000000..c1c4cfe6e
--- /dev/null
+++ b/test_suite/system_tests/Main/CMakeLists.txt
@@ -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
+)
diff --git a/test_suite/system_tests/Main/TestSuite.cxx b/test_suite/system_tests/Main/TestSuite.cxx
new file mode 100644
index 000000000..59df765ae
--- /dev/null
+++ b/test_suite/system_tests/Main/TestSuite.cxx
@@ -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 .
+ */
+
+#include "testOptions.hxx"
+
+
+// Set up the unit tests.
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(OptionsTests, "System tests");
diff --git a/test_suite/system_tests/Main/testOptions.cxx b/test_suite/system_tests/Main/testOptions.cxx
new file mode 100644
index 000000000..2cae99786
--- /dev/null
+++ b/test_suite/system_tests/Main/testOptions.cxx
@@ -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
+#include
+
+#include "test_suite/FGTestApi/NavDataCache.hxx"
+#include "test_suite/FGTestApi/scene_graph.hxx"
+#include "test_suite/FGTestApi/testGlobals.hxx"
+
+#include
+#include
+
+#include "Main/fg_props.hxx"
+#include "Main/globals.hxx"
+#include "Main/options.hxx"
+#include
+
+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);
+
+ 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);
+
+ 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);
+
+ 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 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);
+
+ 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 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);
+
+ 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")});
+}
diff --git a/test_suite/system_tests/Main/testOptions.hxx b/test_suite/system_tests/Main/testOptions.hxx
new file mode 100644
index 000000000..97c50ce1a
--- /dev/null
+++ b/test_suite/system_tests/Main/testOptions.hxx
@@ -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 .
+ */
+
+
+#pragma once
+
+#include
+#include
+
+
+// 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();
+};
diff --git a/test_suite/test_data/customAircraftDir/overrideUfo/README.md b/test_suite/test_data/customAircraftDir/overrideUfo/README.md
new file mode 100644
index 000000000..b929eeeae
--- /dev/null
+++ b/test_suite/test_data/customAircraftDir/overrideUfo/README.md
@@ -0,0 +1,4 @@
+This is a simulation of a user-provided custom aircraft dir.
+
+It contains a fake UFO which intentinoally is different to the one in FGData,
+for checking precedence of paths and options.
diff --git a/test_suite/test_data/customAircraftDir/overrideUfo/ufo-set.xml b/test_suite/test_data/customAircraftDir/overrideUfo/ufo-set.xml
new file mode 100644
index 000000000..6f1b0eecd
--- /dev/null
+++ b/test_suite/test_data/customAircraftDir/overrideUfo/ufo-set.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+ Better UFO than FG data
+
+ 42
+
diff --git a/test_suite/test_data/dummy_package_root/org.fg.test.catalog1/Aircraft/bobCraft/bob-set.xml b/test_suite/test_data/dummy_package_root/org.fg.test.catalog1/Aircraft/bobCraft/bob-set.xml
new file mode 100644
index 000000000..e69de29bb
diff --git a/test_suite/test_data/dummy_package_root/org.fg.test.catalog1/catalog.xml b/test_suite/test_data/dummy_package_root/org.fg.test.catalog1/catalog.xml
new file mode 100644
index 000000000..4537637dd
--- /dev/null
+++ b/test_suite/test_data/dummy_package_root/org.fg.test.catalog1/catalog.xml
@@ -0,0 +1,25 @@
+
+
+
+ org.fg.test.catalog1
+ First test catalog
+ http://localhost:2000/catalogTest1/catalog.xml
+ 4
+
+ *
+
+
+
+ bob
+ The Bob Craft
+ 8
+ 593
+
+ a469c4b837f0521db48616cfe65ac1ea
+ http://localhost:2000/catalogTest1/alpha.zip
+
+ bobCraft
+
+
+
+