From 007db5166ec70fc20c7a2284d2b243ebd798028e Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Sun, 28 Aug 2022 20:06:40 +0200 Subject: [PATCH] Initial scripting engine testing code --- tests/script-engine/src/ScriptEngineTests.cpp | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/script-engine/src/ScriptEngineTests.cpp diff --git a/tests/script-engine/src/ScriptEngineTests.cpp b/tests/script-engine/src/ScriptEngineTests.cpp new file mode 100644 index 0000000000..8b708ba368 --- /dev/null +++ b/tests/script-engine/src/ScriptEngineTests.cpp @@ -0,0 +1,89 @@ +#include +#include + +#include "ScriptEngineTests.h" +#include "DependencyManager.h" + +#include "ScriptEngines.h" +#include "ScriptEngine.h" +#include "ScriptCache.h" +#include "ResourceManager.h" +#include "ResourceRequestObserver.h" +#include "StatTracker.h" + +#include "NodeList.h" + +QTEST_MAIN(ScriptEngineTests) + + +// script factory generates scriptmanager -- singleton +// +// default scripts -- all in one thread, but chat spawns a separate thread +// // https://apidocs.overte.org/Script.html#.executeOnScriptThread +// +// scriptmanager +// every thread has a manager, and its own engine +// provides non-qt interface? +// +// special threads for entity scripts -- 12 (fixed? dynamic?) + + + + +void ScriptEngineTests::initTestCase() { + // AudioClient starts networking, but for the purposes of the tests here we don't care, + // so just got to use some port. + int listenPort = 10000; + + DependencyManager::registerInheritance(); + DependencyManager::set(NodeType::Agent, listenPort); + DependencyManager::set(ScriptManager::CLIENT_SCRIPT, QUrl("")); + DependencyManager::set(); + DependencyManager::set(); + DependencyManager::set(); + DependencyManager::set(); + DependencyManager::set(); + + + QSharedPointer ac = DependencyManager::get(); + QVERIFY(!ac.isNull()); + + connect(ac.get(), &ScriptEngines::scriptLoadError, [](const QString& filename, const QString& error){ + qWarning() << "Failed to load script" << filename << ":" << error; + }); + + connect(ac.get(), &ScriptEngines::printedMessage, [](const QString& message, const QString& engineName){ + qDebug() << "Printed message from engine" << engineName << ": " << message; + }); + + connect(ac.get(), &ScriptEngines::infoMessage, [](const QString& message, const QString& engineName){ + qInfo() << "Info message from engine" << engineName << ": " << message; + }); + + connect(ac.get(), &ScriptEngines::warningMessage, [](const QString& message, const QString& engineName){ + qWarning() << "Warning from engine" << engineName << ": " << message; + }); + + connect(ac.get(), &ScriptEngines::errorMessage, [](const QString& message, const QString& engineName){ + qCritical() << "Error from engine" << engineName << ": " << message; + }); + +} + +void ScriptEngineTests::scriptTest() { + QSharedPointer ac = DependencyManager::get(); + QVERIFY(!ac.isNull()); + + + ac->loadOneScript("test-missing.js"); + ac->loadOneScript("test-hello.js"); + ac->loadOneScript("test-divide-by-zero.js"); + qDebug() << ac->getRunning(); + + + QSignalSpy spy(ac.get(), SIGNAL(scriptCountChanged)); + spy.wait(5000); + ac->shutdownScripting(); + + +}