From 2bf03fa04b7b9df5078c70c95b7fd0b55bc68339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Sun, 14 Nov 2010 00:06:07 +0100 Subject: Implement QTEST_GUILESS_MAIN Add support for test cases which require an event loop, but do not need GUI up and running. Such cases are best accommodated by code similar to QTEST_MAIN, but using QCoreApplication instead of QApplication. Change-Id: I04ce82d26b80a4edeba6bf7604a7f8d974232a11 Merge-request: 919 Reviewed-on: http://codereview.qt-project.org/5427 Reviewed-by: Qt Sanity Bot Reviewed-by: Jason McDonald --- src/testlib/qtest.h | 8 ++++++++ src/testlib/qtestcase.cpp | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index e671828b77..66e747a2ac 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -290,6 +290,14 @@ int main(int argc, char *argv[]) \ #endif // QT_GUI_LIB +#define QTEST_GUILESS_MAIN(TestObject) \ +int main(int argc, char *argv[]) \ +{ \ + QCoreApplication app(argc, argv); \ + TestObject tc; \ + return QTest::qExec(&tc, argc, argv); \ +} + QT_END_HEADER #endif diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index b49d5c2aa5..d4703b7b3d 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -314,7 +314,8 @@ QT_BEGIN_NAMESPACE Example: \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 11 - \sa QTEST_APPLESS_MAIN(), QTest::qExec(), QApplication::setNavigationMode() + \sa QTEST_APPLESS_MAIN(), QTEST_GUILESS_MAIN(), QTest::qExec(), + QApplication::setNavigationMode() */ /*! \macro QTEST_APPLESS_MAIN(TestClass) @@ -342,6 +343,21 @@ QT_BEGIN_NAMESPACE \sa QTEST_MAIN() */ +/*! \macro QTEST_GUILESS_MAIN(TestClass) + + \relates QTest + + Implements a main() function that instantiates a QCoreApplication object + and the \a TestClass, and executes all tests in the order they were + defined. Use this macro to build stand-alone executables. + + Behaves like \l QTEST_MAIN(), but instantiates a QCoreApplication instead + of the QApplication object. Use this macro if your test case doesn't need + functionality offered by QApplication, but the event loop is still necessary. + + \sa QTEST_MAIN() +*/ + /*! \macro QBENCHMARK -- cgit v1.2.3