qt5base-lts/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h
Morten Johan Sørvig 122aa530d6 wasm: add qtwasmtestlib
qtwasmtestlib supports writing asynchronous tests for
the web platform.

Asynchronous test functions differ from normal test
functions in that they allow returning from the test
function before the test has completed:

void TestObject::testTimer()
{
    QTimer::singleShot(100, [](){
        completeTestFunction(); // Test pass if we get here
    });
}

Currently one logging backend is supported which
writes the results to an html element. See the README
file for further documentation.

Change-Id: Ia633ad3f41a653e40d6bf35dd09d62a97c608f84
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-06-29 15:09:02 +02:00

36 lines
887 B
C++

// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef QT_WASM_TESTRUNNER_H
#define QT_WASM_TESTRUNNER_H
#include <QtCore/qobject.h>
#include <functional>
namespace QtWasmTest {
enum TestResult {
Pass,
Fail,
};
void completeTestFunction(TestResult result = TestResult::Pass);
void initTestCase(QObject *testObject, std::function<void ()> cleanup);
template <typename App>
void initTestCase(int argc, char **argv, std::shared_ptr<QObject> testObject)
{
auto app = std::make_shared<App>(argc, argv);
auto cleanup = [testObject, app]() mutable {
// C++ lambda capture destruction order is unspecified;
// delete test before app by calling reset().
testObject.reset();
app.reset();
};
initTestCase(testObject.get(), cleanup);
}
}
#endif