diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index a7d7305df..df2ab90c1 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -64,7 +64,12 @@ using std::vector; void postinitNasalGUI(naRef globals, naContext c); -static FGNasalSys* nasalSys = 0; +static FGNasalSys* nasalSys = nullptr; + +// this is used by the test-suite to simplify +// how much Nasal modules we load by default +bool global_nasalMinimalInit = false; + // Listener class for loading Nasal modules on demand class FGNasalModuleListener : public SGPropertyChangeListener @@ -1016,14 +1021,16 @@ void FGNasalSys::init() naSave(_context, _string); initNasalString(_globals, _string, _context); - initNasalPositioned(_globals, _context); - initNasalPositioned_cppbind(_globals, _context); - initNasalAircraft(_globals, _context); - NasalClipboard::init(this); - initNasalCanvas(_globals, _context); - initNasalCondition(_globals, _context); - initNasalHTTP(_globals, _context); - initNasalSGPath(_globals, _context); + if (!global_nasalMinimalInit) { + initNasalPositioned(_globals, _context); + initNasalPositioned_cppbind(_globals, _context); + initNasalAircraft(_globals, _context); + NasalClipboard::init(this); + initNasalCanvas(_globals, _context); + initNasalCondition(_globals, _context); + initNasalHTTP(_globals, _context); + initNasalSGPath(_globals, _context); + } NasalTimerObj::init("Timer") .method("start", &TimerObj::start) @@ -1039,6 +1046,13 @@ void FGNasalSys::init() .method("elapsedUSec", &TimeStampObj::elapsedUSec) ; + // everything after here, skip if we're doing minimal init, so + // we don'tload FG_DATA/Nasal or add-ons + if (global_nasalMinimalInit) { + _inited = true; + return; + } + flightgear::addons::initAddonClassesForNasal(_globals, _context); // Now load the various source files in the Nasal directory diff --git a/test_suite/simgear_tests/canvas/testCanvas.cxx b/test_suite/simgear_tests/canvas/testCanvas.cxx index 1b5652595..d4077cc8c 100644 --- a/test_suite/simgear_tests/canvas/testCanvas.cxx +++ b/test_suite/simgear_tests/canvas/testCanvas.cxx @@ -10,6 +10,8 @@ #include #include +extern bool global_nasalMinimalInit; + void verifyPixel(osg::Image* img, int x, int y, const uint8_t* pixel) { @@ -19,6 +21,7 @@ void verifyPixel(osg::Image* img, int x, int y, const uint8_t* pixel) void CanvasTests::setUp() { + global_nasalMinimalInit = false; FGTestApi::setUp::initTestGlobals("canvas"); // Canvas needs loadxml command diff --git a/test_suite/unit_tests/Scripting/CMakeLists.txt b/test_suite/unit_tests/Scripting/CMakeLists.txt index e9b173d33..540e7a95e 100644 --- a/test_suite/unit_tests/Scripting/CMakeLists.txt +++ b/test_suite/unit_tests/Scripting/CMakeLists.txt @@ -2,11 +2,13 @@ set(TESTSUITE_SOURCES ${TESTSUITE_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/TestSuite.cxx ${CMAKE_CURRENT_SOURCE_DIR}/testNasalSys.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/testGC.cxx PARENT_SCOPE ) set(TESTSUITE_HEADERS ${TESTSUITE_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/testNasalSys.hxx + ${CMAKE_CURRENT_SOURCE_DIR}/testGC.hxx PARENT_SCOPE ) diff --git a/test_suite/unit_tests/Scripting/TestSuite.cxx b/test_suite/unit_tests/Scripting/TestSuite.cxx index b217ad467..4cdf0e602 100644 --- a/test_suite/unit_tests/Scripting/TestSuite.cxx +++ b/test_suite/unit_tests/Scripting/TestSuite.cxx @@ -18,7 +18,8 @@ */ #include "testNasalSys.hxx" - +#include "testGC.hxx" // Set up the unit tests. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NasalSysTests, "Unit tests"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NasalGCTests, "Unit tests"); diff --git a/test_suite/unit_tests/Scripting/testGC.cxx b/test_suite/unit_tests/Scripting/testGC.cxx new file mode 100644 index 000000000..d9a118f64 --- /dev/null +++ b/test_suite/unit_tests/Scripting/testGC.cxx @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2020 James Turner + * + * 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 "testGC.hxx" + +#include "test_suite/FGTestApi/testGlobals.hxx" + +#include
+#include
+#include + +#include
+ +extern bool global_nasalMinimalInit; + +// Set up function for each test. +void NasalGCTests::setUp() +{ + FGTestApi::setUp::initTestGlobals("NasalGC"); + + fgInitAllowedPaths(); + auto nasalNode = globals->get_props()->getNode("nasal", true); + + globals->add_subsystem("prop-interpolator", new FGInterpolator, SGSubsystemMgr::INIT); + + global_nasalMinimalInit = true; + globals->add_new_subsystem(SGSubsystemMgr::INIT); +} + + +// Clean up after each test. +void NasalGCTests::tearDown() +{ + FGTestApi::tearDown::shutdownTestGlobals(); +} + + +// Test test +void NasalGCTests::testDummy() +{ + bool ok = FGTestApi::executeNasal(R"( + var foo = { + "name": "PFD-Test", + "size": [512, 512], + "view": [768, 1024], + "mipmapping": 1 + }; + + globals.foo1 = foo; + )"); + CPPUNIT_ASSERT(ok); +} diff --git a/test_suite/unit_tests/Scripting/testGC.hxx b/test_suite/unit_tests/Scripting/testGC.hxx new file mode 100644 index 000000000..a40276685 --- /dev/null +++ b/test_suite/unit_tests/Scripting/testGC.hxx @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2020 James Turner + * + * 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 + + +class NasalGCTests : public CppUnit::TestFixture +{ + // Set up the test suite. + CPPUNIT_TEST_SUITE(NasalGCTests); + CPPUNIT_TEST(testDummy); + CPPUNIT_TEST_SUITE_END(); + +public: + // Set up function for each test. + void setUp(); + + // Clean up after each test. + void tearDown(); + + // The tests. + void testDummy(); +};