Port promise tests to qtwasmtestlib

The promise tests have been ported to qtwasmtestlib so that they do not
have to use asyncify anymore.

Task-number: QTBUG-99611
Change-Id: Id1b5742c90e36a89540e7a2387cb4110c21ace9b
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Mikolaj Boc 2022-06-30 16:11:18 +02:00
parent df764df3ea
commit 3c07f12415
5 changed files with 173 additions and 258 deletions

View File

@ -15,17 +15,3 @@ qt_internal_add_test(tst_localfileapi
Qt::Gui Qt::Gui
Qt::Widgets Qt::Widgets
) )
qt_internal_add_test(tst_qstdweb
SOURCES
tst_qstdweb.cpp
DEFINES
QT_NO_FOREACH
QT_NO_KEYWORDS
LIBRARIES
Qt::GuiPrivate
PUBLIC_LIBRARIES
Qt::Core
Qt::Gui
Qt::Widgets
)

View File

@ -3,5 +3,6 @@ add_subdirectory(rasterwindow)
if(QT_FEATURE_widgets) if(QT_FEATURE_widgets)
add_subdirectory(cursors) add_subdirectory(cursors)
add_subdirectory(localfiles) add_subdirectory(localfiles)
add_subdirectory(qstdweb)
add_subdirectory(clipboard) add_subdirectory(clipboard)
endif() endif()

View File

@ -0,0 +1,22 @@
qt_internal_add_manual_test(promise_auto
SOURCES
promise_main.cpp
../qtwasmtestlib/qtwasmtestlib.cpp
PUBLIC_LIBRARIES
Qt::Core
Qt::CorePrivate
)
include_directories(../qtwasmtestlib/)
add_custom_command(
TARGET promise_auto POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/promise_auto.html
${CMAKE_CURRENT_BINARY_DIR}/promise_auto.html)
add_custom_command(
TARGET promise_auto POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/../qtwasmtestlib/qtwasmtestlib.js
${CMAKE_CURRENT_BINARY_DIR}/qtwasmtestlib.js)

View File

@ -0,0 +1,10 @@
<!doctype html>
<script type="text/javascript" src="qtwasmtestlib.js"></script>
<script type="text/javascript" src="promise_auto.js"></script>
<script>
window.onload = () => {
runTestCase(document.getElementById("log"));
};
</script>
<p>Running promise auto test.</p>
<div id="log"></div>

View File

@ -1,36 +1,29 @@
// Copyright (C) 2022 The Qt Company Ltd. // Copyright (C) 2022 The Qt Company Ltd.
// Copyright (C) 2016 Intel Corporation.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtCore/qtimer.h> #include <QtCore/QCoreApplication>
#include <QtCore/QEvent>
#include <QtCore/QMutex>
#include <QtCore/QObject>
#include <QtCore/private/qstdweb_p.h> #include <QtCore/private/qstdweb_p.h>
#include <QTest>
#include <emscripten.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#if defined(QT_HAVE_EMSCRIPTEN_ASYNCIFY) #include <qtwasmtestlib.h>
#define SKIP_IF_NO_ASYNCIFY() #include <emscripten.h>
#else
#define SKIP_IF_NO_ASYNCIFY() QSKIP("Needs QT_HAVE_EMSCRIPTEN_ASYNCIFY")
#endif
using namespace emscripten; using namespace emscripten;
class tst_QStdWeb : public QObject class WasmPromiseTest : public QObject
{ {
Q_OBJECT Q_OBJECT
public:
tst_QStdWeb() : m_window(val::global("window")), m_testSupport(val::object()) {
instance = this;
public:
WasmPromiseTest() : m_window(val::global("window")), m_testSupport(val::object()) {
m_window.set("testSupport", m_testSupport); m_window.set("testSupport", m_testSupport);
} }
~tst_QStdWeb() noexcept {}
~WasmPromiseTest() noexcept {}
private: private:
static tst_QStdWeb* instance;
void init() { void init() {
EM_ASM({ EM_ASM({
testSupport.resolve = {}; testSupport.resolve = {};
@ -54,7 +47,7 @@ private:
val m_window; val m_window;
val m_testSupport; val m_testSupport;
private Q_SLOTS: private slots:
void simpleResolve(); void simpleResolve();
void multipleResolve(); void multipleResolve();
void simpleReject(); void simpleReject();
@ -71,91 +64,88 @@ private Q_SLOTS:
void allWithFinallyAndThrow(); void allWithFinallyAndThrow();
}; };
tst_QStdWeb* tst_QStdWeb::instance = nullptr; class BarrierCallback {
public:
BarrierCallback(int number, std::function<void()> onDone)
: m_remaining(number), m_onDone(std::move(onDone)) {}
EM_ASYNC_JS(void, awaitCondition, (), { void operator()() {
await testSupport.waitConditionPromise; if (!--m_remaining) {
}); m_onDone();
}
}
void tst_QStdWeb::simpleResolve() private:
int m_remaining;
std::function<void()> m_onDone;
};
// Post event to the main thread and verify that it is processed.
void WasmPromiseTest::simpleResolve()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [](val result) { .thenFunc = [](val result) {
QVERIFY(result.isString()); QWASMVERIFY(result.isString());
QCOMPARE("Some lovely data", result.as<std::string>()); QWASMCOMPARE("Some lovely data", result.as<std::string>());
EM_ASM({
testSupport.finishWaiting(); QWASMSUCCESS();
});
}, },
.catchFunc = [](val error) { .catchFunc = [](val error) {
Q_UNUSED(error); Q_UNUSED(error);
QFAIL("Unexpected catch");
QWASMFAIL("Unexpected catch");
} }
}, std::string("simpleResolve")); }, std::string("simpleResolve"));
EM_ASM({ EM_ASM({
testSupport.resolve["simpleResolve"]("Some lovely data"); testSupport.resolve["simpleResolve"]("Some lovely data");
}); });
awaitCondition();
} }
void tst_QStdWeb::multipleResolve() void WasmPromiseTest::multipleResolve()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { auto onThen = std::make_shared<BarrierCallback>(3, []() {
.thenFunc = [](val result) { QWASMSUCCESS();
QVERIFY(result.isString()); });
QCOMPARE("Data 1", result.as<std::string>());
EM_ASM({ qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
if (!--testSupport.promisesLeft) { .thenFunc = [=](val result) {
testSupport.finishWaiting(); QWASMVERIFY(result.isString());
} QWASMCOMPARE("Data 1", result.as<std::string>());
});
(*onThen)();
}, },
.catchFunc = [](val error) { .catchFunc = [](val error) {
Q_UNUSED(error); Q_UNUSED(error);
QFAIL("Unexpected catch"); QWASMFAIL("Unexpected catch");
} }
}, std::string("1")); }, std::string("1"));
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [](val result) { .thenFunc = [=](val result) {
QVERIFY(result.isString()); QWASMVERIFY(result.isString());
QCOMPARE("Data 2", result.as<std::string>()); QWASMCOMPARE("Data 2", result.as<std::string>());
EM_ASM({ (*onThen)();
if (!--testSupport.promisesLeft) {
testSupport.finishWaiting();
}
});
}, },
.catchFunc = [](val error) { .catchFunc = [](val error) {
Q_UNUSED(error); Q_UNUSED(error);
QFAIL("Unexpected catch"); QWASMFAIL("Unexpected catch");
} }
}, std::string("2")); }, std::string("2"));
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [](val result) { .thenFunc = [=](val result) {
QVERIFY(result.isString()); QWASMVERIFY(result.isString());
QCOMPARE("Data 3", result.as<std::string>()); QWASMCOMPARE("Data 3", result.as<std::string>());
EM_ASM({ (*onThen)();
if (!--testSupport.promisesLeft) {
testSupport.finishWaiting();
}
});
}, },
.catchFunc = [](val error) { .catchFunc = [](val error) {
Q_UNUSED(error); Q_UNUSED(error);
QFAIL("Unexpected catch"); QWASMFAIL("Unexpected catch");
} }
}, std::string("3")); }, std::string("3"));
@ -164,89 +154,70 @@ void tst_QStdWeb::multipleResolve()
testSupport.resolve["1"]("Data 1"); testSupport.resolve["1"]("Data 1");
testSupport.resolve["2"]("Data 2"); testSupport.resolve["2"]("Data 2");
}); });
awaitCondition();
} }
void tst_QStdWeb::simpleReject() void WasmPromiseTest::simpleReject()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [](val result) { .thenFunc = [](val result) {
Q_UNUSED(result); Q_UNUSED(result);
QFAIL("Unexpected then"); QWASMFAIL("Unexpected then");
}, },
.catchFunc = [](val result) { .catchFunc = [](val result) {
QVERIFY(result.isString()); QWASMVERIFY(result.isString());
QCOMPARE("Evil error", result.as<std::string>()); QWASMCOMPARE("Evil error", result.as<std::string>());
EM_ASM({ QWASMSUCCESS();
testSupport.finishWaiting();
});
} }
}, std::string("simpleReject")); }, std::string("simpleReject"));
EM_ASM({ EM_ASM({
testSupport.reject["simpleReject"]("Evil error"); testSupport.reject["simpleReject"]("Evil error");
}); });
awaitCondition();
} }
void tst_QStdWeb::multipleReject() void WasmPromiseTest::multipleReject()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
auto onThen = std::make_shared<BarrierCallback>(3, []() {
QWASMSUCCESS();
});
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [](val result) { .thenFunc = [](val result) {
Q_UNUSED(result); Q_UNUSED(result);
QFAIL("Unexpected then"); QWASMFAIL("Unexpected then");
}, },
.catchFunc = [](val error) { .catchFunc = [=](val error) {
QVERIFY(error.isString()); QWASMVERIFY(error.isString());
QCOMPARE("Error 1", error.as<std::string>()); QWASMCOMPARE("Error 1", error.as<std::string>());
EM_ASM({ (*onThen)();
if (!--testSupport.promisesLeft) {
testSupport.finishWaiting();
}
});
} }
}, std::string("1")); }, std::string("1"));
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [](val result) { .thenFunc = [](val result) {
Q_UNUSED(result); Q_UNUSED(result);
QFAIL("Unexpected then"); QWASMFAIL("Unexpected then");
}, },
.catchFunc = [](val error) { .catchFunc = [=](val error) {
QVERIFY(error.isString()); QWASMVERIFY(error.isString());
QCOMPARE("Error 2", error.as<std::string>()); QWASMCOMPARE("Error 2", error.as<std::string>());
EM_ASM({ (*onThen)();
if (!--testSupport.promisesLeft) {
testSupport.finishWaiting();
}
});
} }
}, std::string("2")); }, std::string("2"));
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [](val result) { .thenFunc = [](val result) {
Q_UNUSED(result); Q_UNUSED(result);
QFAIL("Unexpected then"); QWASMFAIL("Unexpected then");
}, },
.catchFunc = [](val error) { .catchFunc = [=](val error) {
QVERIFY(error.isString()); QWASMVERIFY(error.isString());
QCOMPARE("Error 3", error.as<std::string>()); QWASMCOMPARE("Error 3", error.as<std::string>());
EM_ASM({ (*onThen)();
if (!--testSupport.promisesLeft) {
testSupport.finishWaiting();
}
});
} }
}, std::string("3")); }, std::string("3"));
@ -255,14 +226,10 @@ void tst_QStdWeb::multipleReject()
testSupport.reject["1"]("Error 1"); testSupport.reject["1"]("Error 1");
testSupport.reject["2"]("Error 2"); testSupport.reject["2"]("Error 2");
}); });
awaitCondition();
} }
void tst_QStdWeb::throwInThen() void WasmPromiseTest::throwInThen()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
@ -273,69 +240,55 @@ void tst_QStdWeb::throwInThen()
}); });
}, },
.catchFunc = [](val error) { .catchFunc = [](val error) {
QCOMPARE("Expected error", error.as<std::string>()); QWASMCOMPARE("Expected error", error.as<std::string>());
EM_ASM({ //QWASMSUCCESS();
testSupport.finishWaiting(); QWASMFAIL("Other nasty problem");
});
} }
}, std::string("throwInThen")); }, std::string("throwInThen"));
EM_ASM({ EM_ASM({
testSupport.resolve["throwInThen"](); testSupport.resolve["throwInThen"]();
}); });
awaitCondition();
} }
void tst_QStdWeb::bareFinally() void WasmPromiseTest::bareFinally()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.finallyFunc = []() { .finallyFunc = []() {
EM_ASM({ QWASMSUCCESS();
testSupport.finishWaiting();
});
} }
}, std::string("bareFinally")); }, std::string("bareFinally"));
EM_ASM({ EM_ASM({
testSupport.resolve["bareFinally"](); testSupport.resolve["bareFinally"]();
}); });
awaitCondition();
} }
void tst_QStdWeb::finallyWithThen() void WasmPromiseTest::finallyWithThen()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
auto thenCalled = std::make_shared<bool>();
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [] (val result) { .thenFunc = [thenCalled] (val result) {
Q_UNUSED(result); Q_UNUSED(result);
*thenCalled = true;
}, },
.finallyFunc = []() { .finallyFunc = [thenCalled]() {
EM_ASM({ QWASMVERIFY(*thenCalled);
testSupport.finishWaiting(); QWASMSUCCESS();
});
} }
}, std::string("finallyWithThen")); }, std::string("finallyWithThen"));
EM_ASM({ EM_ASM({
testSupport.resolve["finallyWithThen"](); testSupport.resolve["finallyWithThen"]();
}); });
awaitCondition();
} }
void tst_QStdWeb::finallyWithThrow() void WasmPromiseTest::finallyWithThrow()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
@ -343,23 +296,17 @@ void tst_QStdWeb::finallyWithThrow()
Q_UNUSED(error); Q_UNUSED(error);
}, },
.finallyFunc = []() { .finallyFunc = []() {
EM_ASM({ QWASMSUCCESS();
testSupport.finishWaiting();
});
} }
}, std::string("finallyWithThrow")); }, std::string("finallyWithThrow"));
EM_ASM({ EM_ASM({
testSupport.reject["finallyWithThrow"](); testSupport.reject["finallyWithThrow"]();
}); });
awaitCondition();
} }
void tst_QStdWeb::finallyWithThrowInThen() void WasmPromiseTest::finallyWithThrowInThen()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
@ -370,109 +317,73 @@ void tst_QStdWeb::finallyWithThrowInThen()
}); });
}, },
.catchFunc = [](val result) { .catchFunc = [](val result) {
QVERIFY(result.isString()); QWASMVERIFY(result.isString());
QCOMPARE("Expected error", result.as<std::string>()); QWASMCOMPARE("Expected error", result.as<std::string>());
}, },
.finallyFunc = []() { .finallyFunc = []() {
EM_ASM({ QWASMSUCCESS();
testSupport.finishWaiting();
});
} }
}, std::string("bareFinallyWithThen")); }, std::string("bareFinallyWithThen"));
EM_ASM({ EM_ASM({
testSupport.resolve["bareFinallyWithThen"](); testSupport.resolve["bareFinallyWithThen"]();
}); });
awaitCondition();
} }
void tst_QStdWeb::nested() void WasmPromiseTest::nested()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [this](val result) { .thenFunc = [this](val result) {
QVERIFY(result.isString()); QWASMVERIFY(result.isString());
QCOMPARE("Outer data", result.as<std::string>()); QWASMCOMPARE("Outer data", result.as<std::string>());
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [this](val innerResult) { .thenFunc = [this](val innerResult) {
QVERIFY(innerResult.isString()); QWASMVERIFY(innerResult.isString());
QCOMPARE("Inner data", innerResult.as<std::string>()); QWASMCOMPARE("Inner data", innerResult.as<std::string>());
qstdweb::Promise::make(m_testSupport, "makeTestPromise", { qstdweb::Promise::make(m_testSupport, "makeTestPromise", {
.thenFunc = [](val innerResult) { .thenFunc = [](val innerResult) {
QVERIFY(innerResult.isString()); QWASMVERIFY(innerResult.isString());
QCOMPARE("Innermost data", innerResult.as<std::string>()); QWASMCOMPARE("Innermost data", innerResult.as<std::string>());
EM_ASM({ QWASMSUCCESS();
testSupport.finishWaiting();
});
}, },
.catchFunc = [](val error) { .catchFunc = [](val error) {
Q_UNUSED(error); Q_UNUSED(error);
QFAIL("Unexpected catch"); QWASMFAIL("Unexpected catch");
} }
}, std::string("innermost")); }, std::string("innermost"));
EM_ASM({ EM_ASM({
testSupport.finishWaiting(); testSupport.resolve["innermost"]("Innermost data");
}); });
}, },
.catchFunc = [](val error) { .catchFunc = [](val error) {
Q_UNUSED(error); Q_UNUSED(error);
QFAIL("Unexpected catch"); QWASMFAIL("Unexpected catch");
} }
}, std::string("inner")); }, std::string("inner"));
EM_ASM({ EM_ASM({
testSupport.finishWaiting(); testSupport.resolve["inner"]("Inner data");
}); });
}, },
.catchFunc = [](val error) { .catchFunc = [](val error) {
Q_UNUSED(error); Q_UNUSED(error);
QFAIL("Unexpected catch"); QWASMFAIL("Unexpected catch");
} }
}, std::string("outer")); }, std::string("outer"));
EM_ASM({ EM_ASM({
testSupport.resolve["outer"]("Outer data"); testSupport.resolve["outer"]("Outer data");
}); });
awaitCondition();
EM_ASM({
testSupport.waitConditionPromise = new Promise((resolve, reject) => {
testSupport.finishWaiting = resolve;
});
});
EM_ASM({
testSupport.resolve["inner"]("Inner data");
});
awaitCondition();
EM_ASM({
testSupport.waitConditionPromise = new Promise((resolve, reject) => {
testSupport.finishWaiting = resolve;
});
});
EM_ASM({
testSupport.resolve["innermost"]("Innermost data");
});
awaitCondition();
} }
void tst_QStdWeb::all() void WasmPromiseTest::all()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
val promise1 = m_testSupport.call<val>("makeTestPromise", val("promise1")); val promise1 = m_testSupport.call<val>("makeTestPromise", val("promise1"));
@ -484,18 +395,16 @@ void tst_QStdWeb::all()
qstdweb::Promise::all({promise1, promise2, promise3}, { qstdweb::Promise::all({promise1, promise2, promise3}, {
.thenFunc = [thenCalledOnce](val result) { .thenFunc = [thenCalledOnce](val result) {
QVERIFY(*thenCalledOnce); QWASMVERIFY(*thenCalledOnce);
*thenCalledOnce = false; *thenCalledOnce = false;
QVERIFY(result.isArray()); QWASMVERIFY(result.isArray());
QCOMPARE(3, result["length"].as<int>()); QWASMCOMPARE(3, result["length"].as<int>());
QCOMPARE("Data 1", result[0].as<std::string>()); QWASMCOMPARE("Data 1", result[0].as<std::string>());
QCOMPARE("Data 2", result[1].as<std::string>()); QWASMCOMPARE("Data 2", result[1].as<std::string>());
QCOMPARE("Data 3", result[2].as<std::string>()); QWASMCOMPARE("Data 3", result[2].as<std::string>());
EM_ASM({ QWASMSUCCESS();
testSupport.finishWaiting();
});
}, },
.catchFunc = [](val result) { .catchFunc = [](val result) {
Q_UNUSED(result); Q_UNUSED(result);
@ -510,14 +419,10 @@ void tst_QStdWeb::all()
testSupport.resolve["promise1"]("Data 1"); testSupport.resolve["promise1"]("Data 1");
testSupport.resolve["promise2"]("Data 2"); testSupport.resolve["promise2"]("Data 2");
}); });
awaitCondition();
} }
void tst_QStdWeb::allWithThrow() void WasmPromiseTest::allWithThrow()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
val promise1 = m_testSupport.call<val>("makeTestPromise", val("promise1")); val promise1 = m_testSupport.call<val>("makeTestPromise", val("promise1"));
@ -530,16 +435,14 @@ void tst_QStdWeb::allWithThrow()
qstdweb::Promise::all({promise1, promise2, promise3}, { qstdweb::Promise::all({promise1, promise2, promise3}, {
.thenFunc = [](val result) { .thenFunc = [](val result) {
Q_UNUSED(result); Q_UNUSED(result);
QFAIL("Unexpected then"); QWASMFAIL("Unexpected then");
}, },
.catchFunc = [catchCalledOnce](val result) { .catchFunc = [catchCalledOnce](val result) {
QVERIFY(*catchCalledOnce); QWASMVERIFY(*catchCalledOnce);
*catchCalledOnce = false; *catchCalledOnce = false;
QVERIFY(result.isString()); QWASMVERIFY(result.isString());
QCOMPARE("Error 2", result.as<std::string>()); QWASMCOMPARE("Error 2", result.as<std::string>());
EM_ASM({ QWASMSUCCESS();
testSupport.finishWaiting();
});
} }
}); });
@ -548,14 +451,10 @@ void tst_QStdWeb::allWithThrow()
testSupport.resolve["promise1"]("Data 1"); testSupport.resolve["promise1"]("Data 1");
testSupport.reject["promise2"]("Error 2"); testSupport.reject["promise2"]("Error 2");
}); });
awaitCondition();
} }
void tst_QStdWeb::allWithFinally() void WasmPromiseTest::allWithFinally()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
val promise1 = m_testSupport.call<val>("makeTestPromise", val("promise1")); val promise1 = m_testSupport.call<val>("makeTestPromise", val("promise1"));
@ -570,11 +469,9 @@ void tst_QStdWeb::allWithFinally()
Q_UNUSED(result); Q_UNUSED(result);
}, },
.finallyFunc = [finallyCalledOnce]() { .finallyFunc = [finallyCalledOnce]() {
QVERIFY(*finallyCalledOnce); QWASMVERIFY(*finallyCalledOnce);
*finallyCalledOnce = false; *finallyCalledOnce = false;
EM_ASM({ QWASMSUCCESS();
testSupport.finishWaiting();
});
} }
}); });
@ -583,14 +480,10 @@ void tst_QStdWeb::allWithFinally()
testSupport.resolve["promise1"]("Data 1"); testSupport.resolve["promise1"]("Data 1");
testSupport.resolve["promise2"]("Data 2"); testSupport.resolve["promise2"]("Data 2");
}); });
awaitCondition();
} }
void tst_QStdWeb::allWithFinallyAndThrow() void WasmPromiseTest::allWithFinallyAndThrow()
{ {
SKIP_IF_NO_ASYNCIFY();
init(); init();
val promise1 = m_testSupport.call<val>("makeTestPromise", val("promise1")); val promise1 = m_testSupport.call<val>("makeTestPromise", val("promise1"));
@ -608,11 +501,10 @@ void tst_QStdWeb::allWithFinallyAndThrow()
}); });
}, },
.finallyFunc = [finallyCalledOnce]() { .finallyFunc = [finallyCalledOnce]() {
QVERIFY(*finallyCalledOnce); QWASMVERIFY(*finallyCalledOnce);
*finallyCalledOnce = false; *finallyCalledOnce = false;
EM_ASM({ // QWASMSUCCESS();
testSupport.finishWaiting(); QWASMFAIL("Some nasty problem");
});
} }
}); });
@ -621,9 +513,13 @@ void tst_QStdWeb::allWithFinallyAndThrow()
testSupport.resolve["promise1"]("Data 1"); testSupport.resolve["promise1"]("Data 1");
testSupport.resolve["promise2"]("Data 2"); testSupport.resolve["promise2"]("Data 2");
}); });
awaitCondition();
} }
QTEST_APPLESS_MAIN(tst_QStdWeb) int main(int argc, char **argv)
#include "tst_qstdweb.moc" {
auto testObject = std::make_shared<WasmPromiseTest>();
QtWasmTest::initTestCase<QCoreApplication>(argc, argv, testObject);
return 0;
}
#include "promise_main.moc"