Showing the changes to tests/script-engine/src/ScriptEngineTests.cpp (1 of 2 files). Show all
Unified · Split
| @@ -87,11 +87,6 @@ ScriptManagerPointer ScriptEngineTests::makeManager(const QString &scriptSource, · 86 unmodified lines | |||
| 87 | qInfo() << "Running state changed. Running = " << sm->isRunning() << "; Stopped = " << sm->isStopped() << "; Finished = " << sm->isFinished(); | 87 | qInfo() << "Running state changed. Running = " << sm->isRunning() << "; Stopped = " << sm->isStopped() << "; Finished = " << sm->isFinished(); |
| 88 | }); | 88 | }); |
| 89 | 89 | ||
| 90 | connect(sm->engine().get(), &ScriptEngine::exception, [](std::shared_ptr<ScriptException> exception){ | ||
| 91 | qWarning() << "Exception from engine (direct): " << exception; | ||
| 92 | }); | ||
| 93 | |||
| 94 | |||
| 95 | connect(sm.get(), &ScriptManager::unhandledException, [](std::shared_ptr<ScriptException> exception){ | 90 | connect(sm.get(), &ScriptManager::unhandledException, [](std::shared_ptr<ScriptException> exception){ |
| 96 | qWarning() << "Exception from engine: " << exception; | 91 | qWarning() << "Exception from engine: " << exception; |
| 97 | }); | 92 | }); |
| @@ -127,9 +122,26 @@ void ScriptEngineTests::testSyntaxError() { · 29 unmodified lines | |||
| 127 | auto sm = makeManager("this is not good syntax", "testSyntaxError.js"); | 122 | auto sm = makeManager("this is not good syntax", "testSyntaxError.js"); |
| 128 | bool exceptionHappened = false; | 123 | bool exceptionHappened = false; |
| 129 | 124 | ||
| 125 | connect(sm.get(), &ScriptManager::unhandledException, [&exceptionHappened](std::shared_ptr<ScriptException> exception){ | ||
| 126 | exceptionHappened = true; | ||
| 127 | }); | ||
| 128 | |||
| 129 | |||
| 130 | sm->run(); | ||
| 131 | |||
| 132 | std::shared_ptr<ScriptException> ex = sm->getUncaughtException(); | ||
| 133 | |||
| 134 | qDebug() << "Exception:" << ex; | ||
| 135 | |||
| 136 | QVERIFY(exceptionHappened); | ||
| 137 | QVERIFY(ex); | ||
| 138 | QVERIFY(ex && ex->errorMessage.contains("SyntaxError")); | ||
| 139 | } | ||
| 130 | 140 | ||
| 131 | //QSignalSpy spy(sm.get(), &ScriptManager::unhandledException); | ||
| 132 | 141 | ||
| 142 | void ScriptEngineTests::testRuntimeError() { | ||
| 143 | auto sm = makeManager("nonexisting();", "testRuntimeError.js"); | ||
| 144 | bool exceptionHappened = false; | ||
| 133 | 145 | ||
| 134 | connect(sm.get(), &ScriptManager::unhandledException, [&exceptionHappened](std::shared_ptr<ScriptException> exception){ | 146 | connect(sm.get(), &ScriptManager::unhandledException, [&exceptionHappened](std::shared_ptr<ScriptException> exception){ |
| 135 | exceptionHappened = true; | 147 | exceptionHappened = true; |
| @@ -137,7 +149,6 @@ void ScriptEngineTests::testSyntaxError() { · 1 unmodified line | |||
| 137 | 149 | ||
| 138 | 150 | ||
| 139 | sm->run(); | 151 | sm->run(); |
| 140 | //spy.wait(1000); | ||
| 141 | 152 | ||
| 142 | std::shared_ptr<ScriptException> ex = sm->getUncaughtException(); | 153 | std::shared_ptr<ScriptException> ex = sm->getUncaughtException(); |
| 143 | 154 | ||
| @@ -145,8 +156,23 @@ void ScriptEngineTests::testSyntaxError() { · 1 unmodified line | |||
| 145 | 156 | ||
| 146 | QVERIFY(exceptionHappened); | 157 | QVERIFY(exceptionHappened); |
| 147 | QVERIFY(ex); | 158 | QVERIFY(ex); |
| 159 | QVERIFY(ex && ex->errorMessage.contains("ReferenceError")); | ||
| 160 | |||
| 161 | } | ||
| 162 | |||
| 163 | void ScriptEngineTests::testJSThrow() { | ||
| 164 | auto sm = makeManager("throw(42);", "testThrow.js"); | ||
| 165 | sm->run(); | ||
| 166 | |||
| 167 | std::shared_ptr<ScriptException> ex = sm->getUncaughtException(); | ||
| 148 | 168 | ||
| 149 | //QVERIFY(spy.count() == 1); | 169 | qDebug() << "Exception:" << ex; |
| 170 | |||
| 171 | auto runtime_ex = std::dynamic_pointer_cast<ScriptRuntimeException>(ex); | ||
| 172 | |||
| 173 | QVERIFY(ex); | ||
| 174 | QVERIFY(runtime_ex); | ||
| 175 | QVERIFY(runtime_ex && runtime_ex->thrownValue.toInt32() == 42); | ||
| 150 | } | 176 | } |
| 151 | 177 | ||
| 152 | void ScriptEngineTests::scriptTest() { | 178 | void ScriptEngineTests::scriptTest() { |