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 <qt_sanity_bot@ovi.com>
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
This commit is contained in:
Jan Kundrát 2010-11-14 00:06:07 +01:00 committed by Qt by Nokia
parent d5ad900c77
commit 2bf03fa04b
2 changed files with 25 additions and 1 deletions

View File

@ -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

View File

@ -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