Showing the changes to tests/script-engine/src/ScriptEngineTests.cpp (1 of 1 file). Show all
Unified · Split
| @@ -0,0 +1,89 @@ | |||
| 1 | #include <QSignalSpy> | ||
| 2 | #include <QDebug> | ||
| 3 | |||
| 4 | #include "ScriptEngineTests.h" | ||
| 5 | #include "DependencyManager.h" | ||
| 6 | |||
| 7 | #include "ScriptEngines.h" | ||
| 8 | #include "ScriptEngine.h" | ||
| 9 | #include "ScriptCache.h" | ||
| 10 | #include "ResourceManager.h" | ||
| 11 | #include "ResourceRequestObserver.h" | ||
| 12 | #include "StatTracker.h" | ||
| 13 | |||
| 14 | #include "NodeList.h" | ||
| 15 | |||
| 16 | QTEST_MAIN(ScriptEngineTests) | ||
| 17 | |||
| 18 | |||
| 19 | // script factory generates scriptmanager -- singleton | ||
| 20 | // | ||
| 21 | // default scripts -- all in one thread, but chat spawns a separate thread | ||
| 22 | // // https://apidocs.overte.org/Script.html#.executeOnScriptThread | ||
| 23 | // | ||
| 24 | // scriptmanager | ||
| 25 | // every thread has a manager, and its own engine | ||
| 26 | // provides non-qt interface? | ||
| 27 | // | ||
| 28 | // special threads for entity scripts -- 12 (fixed? dynamic?) | ||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | void ScriptEngineTests::initTestCase() { | ||
| 34 | // AudioClient starts networking, but for the purposes of the tests here we don't care, | ||
| 35 | // so just got to use some port. | ||
| 36 | int listenPort = 10000; | ||
| 37 | |||
| 38 | DependencyManager::registerInheritance<LimitedNodeList, NodeList>(); | ||
| 39 | DependencyManager::set<NodeList>(NodeType::Agent, listenPort); | ||
| 40 | DependencyManager::set<ScriptEngines>(ScriptManager::CLIENT_SCRIPT, QUrl("")); | ||
| 41 | DependencyManager::set<ScriptCache>(); | ||
| 42 | DependencyManager::set<ResourceManager>(); | ||
| 43 | DependencyManager::set<ResourceRequestObserver>(); | ||
| 44 | DependencyManager::set<StatTracker>(); | ||
| 45 | DependencyManager::set<ScriptInitializers>(); | ||
| 46 | |||
| 47 | |||
| 48 | QSharedPointer<ScriptEngines> ac = DependencyManager::get<ScriptEngines>(); | ||
| 49 | QVERIFY(!ac.isNull()); | ||
| 50 | |||
| 51 | connect(ac.get(), &ScriptEngines::scriptLoadError, [](const QString& filename, const QString& error){ | ||
| 52 | qWarning() << "Failed to load script" << filename << ":" << error; | ||
| 53 | }); | ||
| 54 | |||
| 55 | connect(ac.get(), &ScriptEngines::printedMessage, [](const QString& message, const QString& engineName){ | ||
| 56 | qDebug() << "Printed message from engine" << engineName << ": " << message; | ||
| 57 | }); | ||
| 58 | |||
| 59 | connect(ac.get(), &ScriptEngines::infoMessage, [](const QString& message, const QString& engineName){ | ||
| 60 | qInfo() << "Info message from engine" << engineName << ": " << message; | ||
| 61 | }); | ||
| 62 | |||
| 63 | connect(ac.get(), &ScriptEngines::warningMessage, [](const QString& message, const QString& engineName){ | ||
| 64 | qWarning() << "Warning from engine" << engineName << ": " << message; | ||
| 65 | }); | ||
| 66 | |||
| 67 | connect(ac.get(), &ScriptEngines::errorMessage, [](const QString& message, const QString& engineName){ | ||
| 68 | qCritical() << "Error from engine" << engineName << ": " << message; | ||
| 69 | }); | ||
| 70 | |||
| 71 | } | ||
| 72 | |||
| 73 | void ScriptEngineTests::scriptTest() { | ||
| 74 | QSharedPointer<ScriptEngines> ac = DependencyManager::get<ScriptEngines>(); | ||
| 75 | QVERIFY(!ac.isNull()); | ||
| 76 | |||
| 77 | |||
| 78 | ac->loadOneScript("test-missing.js"); | ||
| 79 | ac->loadOneScript("test-hello.js"); | ||
| 80 | ac->loadOneScript("test-divide-by-zero.js"); | ||
| 81 | qDebug() << ac->getRunning(); | ||
| 82 | |||
| 83 | |||
| 84 | QSignalSpy spy(ac.get(), SIGNAL(scriptCountChanged)); | ||
| 85 | spy.wait(5000); | ||
| 86 | ac->shutdownScripting(); | ||
| 87 | |||
| 88 | |||
| 89 | } | ||