diff options
Diffstat (limited to 'tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h')
-rw-r--r-- | tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h b/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h index 8bf0c20259..2307ed1ccd 100644 --- a/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h +++ b/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// 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 #ifndef QT_WASM_TESTRUNNER_H #define QT_WASM_TESTRUNNER_H @@ -13,11 +13,20 @@ namespace QtWasmTest { enum TestResult { Pass, Fail, + Skip, }; -void completeTestFunction(TestResult result = TestResult::Pass); + +std::string formatMessage(std::string_view file, + int line, + std::string_view message); + +void completeTestFunction(TestResult result, std::string message); +void completeTestFunction(); void initTestCase(QObject *testObject, std::function<void ()> cleanup); template <typename App> -void initTestCase(int argc, char **argv, std::shared_ptr<QObject> testObject) +void initTestCase(int argc, + char **argv, + std::shared_ptr<QObject> testObject) { auto app = std::make_shared<App>(argc, argv); auto cleanup = [testObject, app]() mutable { @@ -28,8 +37,37 @@ void initTestCase(int argc, char **argv, std::shared_ptr<QObject> testObject) }; initTestCase(testObject.get(), cleanup); } +void verify(bool condition, + std::string_view conditionString, + std::string_view file, + int line); +template<class L, class R> +void compare(const L& lhs, + const R& rhs, + std::string_view lhsString, + std::string_view rhsString, + std::string_view file, + int line) { + if (lhs != rhs) { + completeTestFunction( + TestResult::Fail, + formatMessage(file, line, "Comparison failed: " + std::string(lhsString) + " == " + std::string(rhsString))); + } } -#endif +} // namespace QtWasmTest + +#define QWASMVERIFY(condition) \ + QtWasmTest::verify((condition), #condition, __FILE__, __LINE__); +#define QWASMCOMPARE(left, right) \ + QtWasmTest::compare((left), (right), #left, #right, __FILE__, __LINE__); + +#define QWASMSUCCESS() \ + QtWasmTest::completeTestFunction(QtWasmTest::Pass, "") + +#define QWASMFAIL(message) \ + QtWasmTest::completeTestFunction(QtWasmTest::Fail, QtWasmTest::formatMessage(__FILE__, __LINE__, message)) + +#endif |