summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kundrát <jkt@flaska.net>2010-11-14 00:06:07 +0100
committerQt by Nokia <qt-info@nokia.com>2011-09-26 03:02:34 +0200
commit2bf03fa04b7b9df5078c70c95b7fd0b55bc68339 (patch)
tree44d79e9014d0af69abd801a856e08471a00bfc30
parentd5ad900c77af563a1f3cfb0d252fd173249493fb (diff)
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>
-rw-r--r--src/testlib/qtest.h8
-rw-r--r--src/testlib/qtestcase.cpp18
2 files changed, 25 insertions, 1 deletions
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