Move QTRY_VERIFY/QTRY_COMPARE into testlib.

These functions have lived in tests/shared/util.h for a long time, but
they really belong in qtestlib.

Change-Id: I60d569d002dea220b51563931d8b7aa77a20b98b
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
Jason McDonald 2011-10-17 18:51:44 +10:00 committed by Qt by Nokia
parent 757b0529c4
commit ae1810658b
74 changed files with 66 additions and 190 deletions

View File

@ -109,7 +109,7 @@ QT_BEGIN_NAMESPACE
Example:
\snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 0
\sa QCOMPARE()
\sa QCOMPARE(), QTRY_VERIFY()
*/
/*! \macro QVERIFY2(condition, message)
@ -159,7 +159,43 @@ QT_BEGIN_NAMESPACE
Example:
\snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 2
\sa QVERIFY(), QTest::toString()
\sa QVERIFY(), QTRY_COMPARE(), QTest::toString()
*/
/*! \macro QTRY_VERIFY(condition)
\relates QTest
The QTRY_VERIFY() macro is similar to QVERIFY(), but checks the \a condition
repeatedly, until either the condition becomes true or a maximum timeout is
reached. Between each evaluation, events will be processed. If the timeout
is reached, a failure is recorded in the test log and the test won't be
executed further.
The timeout is fixed at five seconds.
\note This macro can only be used in a test function that is invoked
by the test framework.
\sa QVERIFY(), QCOMPARE(), QTRY_COMPARE()
*/
/*! \macro QTRY_COMPARE(actual, expected)
\relates QTest
The QTRY_COMPARE() macro is similar to QCOMPARE(), but performs the comparison
of the \a actual and \a expected values repeatedly, until either the two values
are equal or a maximum timeout is reached. Between each comparison, events
will be processed. If the timeout is reached, a failure is recorded in the
test log and the test won't be executed further.
The timeout is fixed at five seconds.
\note This macro can only be used in a test function that is invoked
by the test framework.
\sa QCOMPARE(), QVERIFY(), QTRY_VERIFY()
*/
/*! \macro QFETCH(type, name)

View File

@ -82,6 +82,34 @@ do {\
return;\
} while (0)
// Will try to wait for the expression to become true while allowing event processing
#define QTRY_VERIFY(__expr) \
do { \
const int __step = 50; \
const int __timeout = 5000; \
if (!(__expr)) { \
QTest::qWait(0); \
} \
for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
QTest::qWait(__step); \
} \
QVERIFY(__expr); \
} while (0)
// Will try to wait for the comparison to become successful while allowing event processing
#define QTRY_COMPARE(__expr, __expected) \
do { \
const int __step = 50; \
const int __timeout = 5000; \
if ((__expr) != (__expected)) { \
QTest::qWait(0); \
} \
for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
QTest::qWait(__step); \
} \
QCOMPARE(__expr, __expected); \
} while (0)
#define QSKIP(statement, mode) \
do {\
QTest::qSkip(statement, QTest::mode, __FILE__, __LINE__);\

View File

@ -40,12 +40,9 @@
****************************************************************************/
#include <QtTest/QtTest>
#include "../../../../shared/util.h"
#include <QtCore/qpropertyanimation.h>
#include <QtCore/qvariantanimation.h>
#include <QtWidgets/qwidget.h>
#include "../../../../shared/util.h"
//TESTED_CLASS=QPropertyAnimation
//TESTED_FILES=

View File

@ -40,8 +40,6 @@
****************************************************************************/
#include <QtTest/QtTest>
#include "../../../../shared/util.h"
#include <QtCore/qanimationgroup.h>
#include <QtCore/qsequentialanimationgroup.h>

View File

@ -46,7 +46,6 @@
#include <qfuturewatcher.h>
#include <qtconcurrentrun.h>
#include <qtconcurrentmap.h>
#include "../../../../shared/util.h"
#include <private/qfutureinterface_p.h>
using namespace QtConcurrent;

View File

@ -51,7 +51,6 @@
#include <QtCore/QtDebug>
#include <QtCore/QString>
#include <QtGui/QKeySequence>
#include "../../../../shared/util.h"
#include <cctype>
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)

View File

@ -54,8 +54,6 @@
#include <QTcpServer>
#include <QTcpSocket>
#include "../../../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -50,9 +50,6 @@
#include <unistd.h>
#endif
#include "../../../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -42,7 +42,6 @@
#include <QtTest/QtTest>
#include <QtTest/qtesttouch.h>
#include "../../shared/util.h"
#include <qevent.h>
#include <qwidget.h>

View File

@ -41,8 +41,6 @@
#include <QtTest/QtTest>
#include "../../../../shared/util.h"
#include <qpainter.h>
#include <qdrawutil.h>
#include <qapplication.h>

View File

@ -42,7 +42,6 @@
#include <QtTest/QtTest>
#include <QtNetwork/QtNetwork>
#include "../../../../shared/util.h"
#include "../../../network-settings.h"
#ifndef QT_NO_BEARERMANAGEMENT

View File

@ -43,8 +43,6 @@
#include <QtTest/QtTest>
#include <QtNetwork/QtNetwork>
#include <qnetworkdiskcache.h>
#include "../../../../shared/util.h"
#define EXAMPLE_URL "http://user:pass@www.example.com/#foo"
//cached objects are organized into these many subdirs
#define NUM_SUBDIRECTORIES 16

View File

@ -95,7 +95,6 @@
#endif
#include "../../../network-settings.h"
#include "../../../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -45,7 +45,6 @@
#include <qtextstream.h>
#include <QtNetwork/qlocalsocket.h>
#include <QtNetwork/qlocalserver.h>
#include "../../../../shared/util.h"
//TESTED_CLASS=QLocalServer, QLocalSocket
//TESTED_FILES=network/socket/qlocalserver.cpp network/socket/qlocalsocket.cpp

View File

@ -93,7 +93,6 @@
#include "private/qhostinfo_p.h"
#include "../../../network-settings.h"
#include "../../../../shared/util.h"
Q_DECLARE_METATYPE(QAbstractSocket::SocketError)
Q_DECLARE_METATYPE(QAbstractSocket::SocketState)

View File

@ -58,7 +58,6 @@
#include <qscrollbar.h>
#include <qboxlayout.h>
#include <qlineedit.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -41,7 +41,6 @@
#include <QtTest/QtTest>
#include "../../shared/util.h"
#include <QtGui>
#include <QtWidgets>
#include <math.h>

View File

@ -57,8 +57,6 @@
#include <qsettings.h>
#endif
#include "../../shared/util.h"
class SpecialRadioButton: public QRadioButton
{
public:

View File

@ -44,8 +44,6 @@
#include <QtGui/QtGui>
#include <QtWidgets/QColorDialog>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -52,7 +52,6 @@
#include <qitemdelegate.h>
#include <qscrollbar.h>
#include <private/qcolumnview_p.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -76,7 +76,6 @@
#include <qcleanlooksstyle.h>
#endif
#include <qabstractitemview.h>
#include "../../shared/util.h"
#include <qstyleditemdelegate.h>
#ifndef QT_NO_STYLE_WINDOWS
#include <qwindowsstyle.h>

View File

@ -47,7 +47,6 @@
#include <QList>
#include <QPointer>
#include "../../shared/util.h"
#include "../../shared/filesystem.h"
//TESTED_CLASS=

View File

@ -50,8 +50,6 @@
#include <QVBoxLayout>
#include <QSizeGrip>
#include "../../shared/util.h"
Q_DECLARE_METATYPE(QSize)

View File

@ -53,8 +53,6 @@
#include <qlineedit.h>
#include <qdebug.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=gui/widgets/qspinbox.h gui/widgets/qspinbox.cpp gui/widgets/qabstractspinbox.cpp gui/widgets/qabstractspinbox_p.h gui/widgets/qabstractspinbox.h

View File

@ -60,7 +60,6 @@
#include <qsortfilterproxymodel.h>
#include <qlineedit.h>
#include <qlayout.h>
#include "../../shared/util.h"
#if defined QT_BUILD_INTERNAL
#include "../../../src/widgets/dialogs/qsidebar_p.h"
#include "../../../src/widgets/dialogs/qfilesystemmodel_p.h"

View File

@ -60,7 +60,6 @@
#include <qsortfilterproxymodel.h>
#include <qlineedit.h>
#include <qlayout.h>
#include "../../shared/util.h"
#include "../../../src/widgets/dialogs/qsidebar_p.h"
#include "../../../src/widgets/dialogs/qfilesystemmodel_p.h"
#include "../../../src/widgets/dialogs/qfiledialog_p.h"

View File

@ -48,7 +48,6 @@
#include <QFileIconProvider>
#include <QTreeView>
#include <QHeaderView>
#include "../../shared/util.h"
#include <QTime>
#include <QStyle>
#include <QtGlobal>

View File

@ -50,8 +50,6 @@
#include <qlineedit.h>
#include <QBoxLayout>
#include "../../shared/util.h"
QT_FORWARD_DECLARE_CLASS(QWidget)
//TESTED_CLASS=

View File

@ -49,7 +49,6 @@
#include <QtWidgets/qgraphicswidget.h>
#include <QtWidgets/qstyleoption.h>
#include "../../shared/util.h"
#include <private/qgraphicseffect_p.h>
#include "../platformquirks.h"

View File

@ -48,8 +48,6 @@
#include <private/qgraphicseffect_p.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -67,8 +67,6 @@
#include <QGraphicsLinearLayout>
#include <float.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -45,8 +45,6 @@
#include <QtWidgets>
#include <math.h>
#include "../../shared/util.h"
//TESTED_CLASS=QGraphicsLayout
//TESTED_FILES=

View File

@ -47,7 +47,6 @@
#include <qgraphicsview.h>
#include <qstyleoption.h>
#include <private/qobject_p.h>
#include "../../shared/util.h"
class tst_QGraphicsObject : public QObject {
Q_OBJECT

View File

@ -43,7 +43,6 @@
#include <QtTest/QtTest>
#include <QtGui>
#include <QtWidgets>
#include "../../shared/util.h"
#include <private/qgraphicsproxywidget_p.h>
#include <private/qlayoutengine_p.h> // qSmartMin functions...
#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC)

View File

@ -50,7 +50,6 @@
#include <private/qgraphicsscene_p.h>
#include <private/qgraphicssceneindex_p.h>
#include <math.h>
#include "../../shared/util.h"
#include "../gui/painting/qpathclipper/pathcompare.h"
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)

View File

@ -45,8 +45,6 @@
#include <private/qgraphicsscenebsptreeindex_p.h>
#include <private/qgraphicssceneindex_p.h>
#include <private/qgraphicsscenelinearindex_p.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -43,7 +43,6 @@
#include <QtTest/QtTest>
#include <qgraphicsitem.h>
#include <qgraphicstransform.h>
#include "../../shared/util.h"
class tst_QGraphicsTransform : public QObject {
Q_OBJECT

View File

@ -71,7 +71,6 @@
#include <QtWidgets/QInputContext>
#include <QtWidgets/QDesktopWidget>
#include <private/qgraphicsview_p.h>
#include "../../shared/util.h"
#include "../platformquirks.h"
//TESTED_CLASS=

View File

@ -52,7 +52,6 @@
#include <qboxlayout.h>
#include <qaction.h>
#include <qwidgetaction.h>
#include "../../shared/util.h"
#include "../platformquirks.h"

View File

@ -54,7 +54,6 @@
#include <QtWidgets/QWindowsStyle>
#include <QStyleFactory>
#include "../../shared/util.h"
#include "../platformquirks.h"
//TESTED_CLASS=

View File

@ -49,8 +49,6 @@
#include "qgroupbox.h"
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -41,8 +41,6 @@
#include <QtTest/QtTest>
#include "../../shared/util.h"
#include <QtCore>
#include <QtGui>
#include <QtWidgets>

View File

@ -40,8 +40,6 @@
****************************************************************************/
#include <QtTest/QtTest>
#include "../../shared/util.h"
#include <qinputcontext.h>
#include <qlineedit.h>
#include <qplaintextedit.h>

View File

@ -63,8 +63,6 @@
#include <QPlainTextEdit>
#include <QDialog>
#include "../../shared/util.h"
Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint)
//TESTED_CLASS=

View File

@ -56,8 +56,6 @@
//TESTED_CLASS=
//TESTED_FILES=
#include "../../shared/util.h"
class Widget : public QWidget
{
public:

View File

@ -41,8 +41,6 @@
#include <QtTest/QtTest>
#include "../../shared/util.h"
#include "qlineedit.h"
#include "qapplication.h"
#include "qstringlist.h"

View File

@ -60,8 +60,6 @@
# include <QtGui/QPlatformNativeInterface>
#endif // Q_OS_WIN
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -62,7 +62,6 @@
#endif
#include <QMacStyle>
#include "../../shared/util.h"
#include "../platformquirks.h"
static const Qt::WindowFlags DefaultWindowFlags

View File

@ -63,9 +63,6 @@
#include <QMacStyle>
#endif
#include "../../shared/util.h"
QT_BEGIN_NAMESPACE
#if defined(Q_WS_X11)
extern void qt_x11_wait_for_window_manager(QWidget *w);

View File

@ -56,8 +56,6 @@
#include <qstyle.h>
#include <qdebug.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -56,8 +56,6 @@
#include <qobject.h>
#include "../../shared/util.h"
QT_FORWARD_DECLARE_CLASS(QMainWindow)
#include <qmenubar.h>

View File

@ -55,8 +55,6 @@
#include <QCleanlooksStyle>
#endif
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -48,8 +48,6 @@
#include <qtimer.h>
#include <QStyleFactory>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -54,8 +54,6 @@
#include <QStyleFactory>
#include <QTabWidget>
#include "../../shared/util.h"
Q_DECLARE_METATYPE(QPushButton*)
//TESTED_CLASS=

View File

@ -43,8 +43,6 @@
#include <QtTest/QtTest>
#include "../../shared/util.h"
class tst_QScreen: public QObject
{
Q_OBJECT

View File

@ -41,8 +41,6 @@
#include <QtTest/QtTest>
#include "../../shared/util.h"
#include "dynamictreemodel.h"
#include "modeltest.h"

View File

@ -67,7 +67,6 @@
#include <QKeySequence>
#include <QStackedWidget>
#include <QDebug>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -55,7 +55,6 @@
#include <qtreeview.h>
#include <qlabel.h>
#include <qdebug.h> // for file error messages
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -47,8 +47,6 @@
#include <qwidget.h>
#include <QPushButton>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=gui/kernel/qlayout.cpp gui/kernel/qlayout.h

View File

@ -48,8 +48,6 @@
#include <QMainWindow>
#include <QSizeGrip>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -46,7 +46,6 @@
#include <qpushbutton.h>
#include <qstyle.h>
#include "../../shared/util.h"
class tst_QTabBar : public QObject
{

View File

@ -44,7 +44,6 @@
#include <QtWidgets/QtWidgets>
#include <private/qtablewidget_p.h>
#include <QtTest/QtTest>
#include "../../shared/util.h"
#include "private/qapplication_p.h"
//TESTED_CLASS=

View File

@ -41,7 +41,6 @@
#include <QtTest/QtTest>
#include "../../shared/util.h"
#include <qeventloop.h>
#include <qlist.h>
#include <qpair.h>

View File

@ -49,8 +49,6 @@
#include <qtextbrowser.h>
#include <qtextobject.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -57,8 +57,6 @@
#include <qmenu.h>
#include <private/qtoolbarextension_p.h>
#include "../../shared/util.h"
//TESTED_FILES=
QT_FORWARD_DECLARE_CLASS(QAction)

View File

@ -42,7 +42,6 @@
#include <QtTest/QtTest>
#include <qtooltip.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -39,14 +39,10 @@
**
****************************************************************************/
#include <qabstractitemview.h>
#include <QtTest/QtTest>
#include <QtGui/QtGui>
#include <QtWidgets/QtWidgets>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -51,9 +51,6 @@
#include <QScrollBar>
#include <QStyledItemDelegate>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -73,8 +73,6 @@
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QGraphicsProxyWidget>
#include "../../shared/util.h"
#ifdef Q_WS_QWS
# include <qscreen_qws.h>
#endif

View File

@ -52,9 +52,6 @@
#include <QX11Info>
#endif // Q_WS_X11
#include "../../shared/util.h"
class tst_QWidget_window : public QWidget
{
Q_OBJECT

View File

@ -51,8 +51,6 @@
#include <qmainwindow.h>
#include <qmenubar.h>
#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=

View File

@ -43,8 +43,6 @@
#include <QtTest/QtTest>
#include "../../shared/util.h"
class tst_QWindow: public QObject
{
Q_OBJECT

View File

@ -46,7 +46,6 @@
#include <QWindowsStyle>
#include <QDesktopWidget>
#include <QX11Info>
#include "../../shared/util.h"
#if QT_VERSION < 0x050000
#include <private/qwindowsurface_p.h>

View File

@ -1,70 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
// Functions and macros that really need to be in QTestLib
// Will try to wait for the condition while allowing event processing
#define QTRY_VERIFY(__expr) \
do { \
const int __step = 50; \
const int __timeout = 5000; \
if (!(__expr)) { \
QTest::qWait(0); \
} \
for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \
QTest::qWait(__step); \
} \
QVERIFY(__expr); \
} while(0)
// Will try to wait for the condition while allowing event processing
#define QTRY_COMPARE(__expr, __expected) \
do { \
const int __step = 50; \
const int __timeout = 5000; \
if ((__expr) != (__expected)) { \
QTest::qWait(0); \
} \
for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
QTest::qWait(__step); \
} \
QCOMPARE(__expr, __expected); \
} while(0)