QtTestLib: Use Q_NULLPTR instead of 0 in all public headers

This is in preparation of adding -Wzero-as-null-pointer-constant (or similar)
to the headers check.

Since QtTestLib has a lot of templates and macros, not all uses of 0 as nullptr
might have been detected by the headersclean check.

Task-number: QTBUG-45291
Change-Id: I21e9d8822e3a708010938e8d5ef2fd42ae6c8c68
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
bb10
Marc Mutz 2015-06-30 22:11:15 +02:00
parent 283f19924d
commit 82f48c7d32
11 changed files with 59 additions and 51 deletions

View File

@ -82,7 +82,7 @@ public:
}
if (!QMetaObject::connect(obj, sigIndex, this, memberOffset,
Qt::DirectConnection, 0)) {
Qt::DirectConnection, Q_NULLPTR)) {
qWarning("QSignalSpy: QMetaObject::connect returned false. Unable to connect.");
return;
}

View File

@ -205,7 +205,7 @@ inline bool qCompare(QList<T> const &t1, QList<T> const &t2, const char *actual,
delete [] val2;
}
}
return compare_helper(isOk, msg, 0, 0, actual, expected, file, line);
return compare_helper(isOk, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
}
template <>

View File

@ -86,24 +86,24 @@ inline bool qCompare(QImage const &t1, QImage const &t2,
qsnprintf(msg, 1024, "Compared QImages differ.\n"
" Actual (%s).isNull(): %d\n"
" Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
return compare_helper(false, msg, 0, 0, actual, expected, file, line);
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
}
if (t1Null && t2Null)
return compare_helper(true, 0, 0, 0, actual, expected, file, line);
return compare_helper(true, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
if (t1.width() != t2.width() || t1.height() != t2.height()) {
qsnprintf(msg, 1024, "Compared QImages differ in size.\n"
" Actual (%s): %dx%d\n"
" Expected (%s): %dx%d",
actual, t1.width(), t1.height(),
expected, t2.width(), t2.height());
return compare_helper(false, msg, 0, 0, actual, expected, file, line);
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
}
if (t1.format() != t2.format()) {
qsnprintf(msg, 1024, "Compared QImages differ in format.\n"
" Actual (%s): %d\n"
" Expected (%s): %d",
actual, t1.format(), expected, t2.format());
return compare_helper(false, msg, 0, 0, actual, expected, file, line);
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
}
return compare_helper(t1 == t2, "Compared values are not the same",
toString(t1), toString(t2), actual, expected, file, line);
@ -120,17 +120,17 @@ inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, c
qsnprintf(msg, 1024, "Compared QPixmaps differ.\n"
" Actual (%s).isNull(): %d\n"
" Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
return compare_helper(false, msg, 0, 0, actual, expected, file, line);
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
}
if (t1Null && t2Null)
return compare_helper(true, 0, 0, 0, actual, expected, file, line);
return compare_helper(true, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
if (t1.width() != t2.width() || t1.height() != t2.height()) {
qsnprintf(msg, 1024, "Compared QPixmaps differ in size.\n"
" Actual (%s): %dx%d\n"
" Expected (%s): %dx%d",
actual, t1.width(), t1.height(),
expected, t2.width(), t2.height());
return compare_helper(false, msg, 0, 0, actual, expected, file, line);
return compare_helper(false, msg, Q_NULLPTR, Q_NULLPTR, actual, expected, file, line);
}
return qCompare(t1.toImage(), t2.toImage(), actual, expected, file, line);
}

View File

@ -126,7 +126,7 @@ public:
static void cleanup()
{
delete instance();
instance() = 0;
instance() = Q_NULLPTR;
}
static void clearEvents() { eventList().clear(); }
static EventList events() { return eventList(); }
@ -162,8 +162,8 @@ private:
~QTestAccessibility()
{
QAccessible::installUpdateHandler(0);
QAccessible::installRootObjectHandler(0);
QAccessible::installUpdateHandler(Q_NULLPTR);
QAccessible::installRootObjectHandler(Q_NULLPTR);
}
static void rootObjectHandler(QObject *object)
@ -268,7 +268,7 @@ private:
static QTestAccessibility *&instance()
{
static QTestAccessibility *ta = 0;
static QTestAccessibility *ta = Q_NULLPTR;
return ta;
}

View File

@ -235,7 +235,7 @@ namespace QTest
template <typename T> // Fallback
inline typename QtPrivate::QEnableIf<!QtPrivate::IsQEnumHelper<T>::Value, char*>::Type toString(const T &)
{
return 0;
return Q_NULLPTR;
}
} // namespace Internal
@ -252,10 +252,10 @@ namespace QTest
Q_TESTLIB_EXPORT char *toString(const char *);
Q_TESTLIB_EXPORT char *toString(const void *);
Q_TESTLIB_EXPORT int qExec(QObject *testObject, int argc = 0, char **argv = 0);
Q_TESTLIB_EXPORT int qExec(QObject *testObject, int argc = 0, char **argv = Q_NULLPTR);
Q_TESTLIB_EXPORT int qExec(QObject *testObject, const QStringList &arguments);
Q_TESTLIB_EXPORT void setMainSourcePath(const char *file, const char *builddir = 0);
Q_TESTLIB_EXPORT void setMainSourcePath(const char *file, const char *builddir = Q_NULLPTR);
Q_TESTLIB_EXPORT bool qVerify(bool statement, const char *statementStr, const char *description,
const char *file, int line);
@ -263,15 +263,15 @@ namespace QTest
Q_TESTLIB_EXPORT void qSkip(const char *message, const char *file, int line);
Q_TESTLIB_EXPORT bool qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode,
const char *file, int line);
Q_TESTLIB_EXPORT void qWarn(const char *message, const char *file = 0, int line = 0);
Q_TESTLIB_EXPORT void qWarn(const char *message, const char *file = Q_NULLPTR, int line = 0);
Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const char *message);
#ifndef QT_NO_REGULAREXPRESSION
Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const QRegularExpression &messagePattern);
#endif
Q_TESTLIB_EXPORT QSharedPointer<QTemporaryDir> qExtractTestData(const QString &dirName);
Q_TESTLIB_EXPORT QString qFindTestData(const char* basepath, const char* file = 0, int line = 0, const char* builddir = 0);
Q_TESTLIB_EXPORT QString qFindTestData(const QString& basepath, const char* file = 0, int line = 0, const char* builddir = 0);
Q_TESTLIB_EXPORT QString qFindTestData(const char* basepath, const char* file = Q_NULLPTR, int line = 0, const char* builddir = Q_NULLPTR);
Q_TESTLIB_EXPORT QString qFindTestData(const QString& basepath, const char* file = Q_NULLPTR, int line = 0, const char* builddir = Q_NULLPTR);
Q_TESTLIB_EXPORT void *qData(const char *tagName, int typeId);
Q_TESTLIB_EXPORT void *qGlobalData(const char *tagName, int typeId);

View File

@ -185,20 +185,20 @@ public:
inline void addKeyEvent(QTest::KeyAction action, char ascii, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
{ append(new QTestKeyEvent(action, ascii, modifiers, msecs)); }
inline void addMousePress(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void addMousePress(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ append(new QTestMouseEvent(QTest::MousePress, button, stateKey, pos, delay)); }
inline void addMouseRelease(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void addMouseRelease(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ append(new QTestMouseEvent(QTest::MouseRelease, button, stateKey, pos, delay)); }
inline void addMouseClick(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void addMouseClick(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ append(new QTestMouseEvent(QTest::MouseClick, button, stateKey, pos, delay)); }
inline void addMouseDClick(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void addMouseDClick(Qt::MouseButton button, Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ append(new QTestMouseEvent(QTest::MouseDClick, button, stateKey, pos, delay)); }
inline void addMouseMove(QPoint pos = QPoint(), int delay=-1)
{ append(new QTestMouseEvent(QTest::MouseMove, Qt::NoButton, 0, pos, delay)); }
{ append(new QTestMouseEvent(QTest::MouseMove, Qt::NoButton, Qt::KeyboardModifiers(), pos, delay)); }
#endif //QT_GUI_LIB
inline void addDelay(int msecs)

View File

@ -50,8 +50,8 @@ class Q_TESTLIB_EXPORT QTestEventLoop : public QObject
Q_OBJECT
public:
inline QTestEventLoop(QObject *aParent = 0)
: QObject(aParent), inLoop(false), _timeout(false), timerId(-1), loop(0) {}
inline QTestEventLoop(QObject *aParent = Q_NULLPTR)
: QObject(aParent), inLoop(false), _timeout(false), timerId(-1), loop(Q_NULLPTR) {}
inline void enterLoopMSecs(int ms);
inline void enterLoop(int secs) { enterLoopMSecs(secs * 1000); }
@ -97,7 +97,7 @@ inline void QTestEventLoop::enterLoopMSecs(int ms)
loop = &l;
l.exec();
loop = 0;
loop = Q_NULLPTR;
}
inline void QTestEventLoop::exitLoop()

View File

@ -97,7 +97,7 @@ namespace QTest
if (action == Press) {
if (modifier & Qt::ShiftModifier)
simulateEvent(window, true, Qt::Key_Shift, 0, QString(), false, delay);
simulateEvent(window, true, Qt::Key_Shift, Qt::KeyboardModifiers(), QString(), false, delay);
if (modifier & Qt::ControlModifier)
simulateEvent(window, true, Qt::Key_Control, modifier & Qt::ShiftModifier, QString(), false, delay);
@ -220,7 +220,7 @@ namespace QTest
if (action == Press) {
if (modifier & Qt::ShiftModifier)
simulateEvent(widget, true, Qt::Key_Shift, 0, QString(), false, delay);
simulateEvent(widget, true, Qt::Key_Shift, Qt::KeyboardModifiers(), QString(), false, delay);
if (modifier & Qt::ControlModifier)
simulateEvent(widget, true, Qt::Key_Control, modifier & Qt::ShiftModifier, QString(), false, delay);

View File

@ -133,20 +133,24 @@ namespace QTest
waitForEvents();
}
inline void mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void mousePress(QWindow *window, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MousePress, window, button, stateKey, pos, delay); }
inline void mouseRelease(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void mouseRelease(QWindow *window, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MouseRelease, window, button, stateKey, pos, delay); }
inline void mouseClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void mouseClick(QWindow *window, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MouseClick, window, button, stateKey, pos, delay); }
inline void mouseDClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void mouseDClick(QWindow *window, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MouseDClick, window, button, stateKey, pos, delay); }
inline void mouseMove(QWindow *window, QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MouseMove, window, Qt::NoButton, 0, pos, delay); }
{ mouseEvent(MouseMove, window, Qt::NoButton, Qt::KeyboardModifiers(), pos, delay); }
#ifdef QT_WIDGETS_LIB
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button,
@ -186,7 +190,7 @@ namespace QTest
me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey);
break;
case MouseRelease:
me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, 0, stateKey);
me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, Qt::MouseButton(), stateKey);
break;
case MouseDClick:
me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey);
@ -212,20 +216,24 @@ namespace QTest
#endif
}
inline void mousePress(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void mousePress(QWidget *widget, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MousePress, widget, button, stateKey, pos, delay); }
inline void mouseRelease(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void mouseRelease(QWidget *widget, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MouseRelease, widget, button, stateKey, pos, delay); }
inline void mouseClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void mouseClick(QWidget *widget, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MouseClick, widget, button, stateKey, pos, delay); }
inline void mouseDClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
inline void mouseDClick(QWidget *widget, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = Qt::KeyboardModifiers(),
QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MouseDClick, widget, button, stateKey, pos, delay); }
inline void mouseMove(QWidget *widget, QPoint pos = QPoint(), int delay=-1)
{ mouseEvent(MouseMove, widget, Qt::NoButton, 0, pos, delay); }
{ mouseEvent(MouseMove, widget, Qt::NoButton, Qt::KeyboardModifiers(), pos, delay); }
#endif // QT_WIDGETS_LIB
}

View File

@ -56,7 +56,7 @@ namespace QTest
timer.start();
do {
QCoreApplication::processEvents(QEventLoop::AllEvents, ms);
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete);
QTest::qSleep(10);
} while (timer.elapsed() < ms);
}
@ -71,7 +71,7 @@ namespace QTest
if (remaining <= 0)
break;
QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete);
QTest::qSleep(10);
}
// Try ensuring the platform window receives the real position.
@ -100,7 +100,7 @@ namespace QTest
if (remaining <= 0)
break;
QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete);
QTest::qSleep(10);
}
return window->isExposed();

View File

@ -68,21 +68,21 @@ namespace QTest
if (commitWhenDestroyed)
commit();
}
QTouchEventSequence& press(int touchId, const QPoint &pt, QWindow *window = 0)
QTouchEventSequence& press(int touchId, const QPoint &pt, QWindow *window = Q_NULLPTR)
{
QTouchEvent::TouchPoint &p = point(touchId);
p.setScreenPos(mapToScreen(window, pt));
p.setState(Qt::TouchPointPressed);
return *this;
}
QTouchEventSequence& move(int touchId, const QPoint &pt, QWindow *window = 0)
QTouchEventSequence& move(int touchId, const QPoint &pt, QWindow *window = Q_NULLPTR)
{
QTouchEvent::TouchPoint &p = point(touchId);
p.setScreenPos(mapToScreen(window, pt));
p.setState(Qt::TouchPointMoved);
return *this;
}
QTouchEventSequence& release(int touchId, const QPoint &pt, QWindow *window = 0)
QTouchEventSequence& release(int touchId, const QPoint &pt, QWindow *window = Q_NULLPTR)
{
QTouchEvent::TouchPoint &p = point(touchId);
p.setScreenPos(mapToScreen(window, pt));
@ -97,21 +97,21 @@ namespace QTest
}
#ifdef QT_WIDGETS_LIB
QTouchEventSequence& press(int touchId, const QPoint &pt, QWidget *widget = 0)
QTouchEventSequence& press(int touchId, const QPoint &pt, QWidget *widget = Q_NULLPTR)
{
QTouchEvent::TouchPoint &p = point(touchId);
p.setScreenPos(mapToScreen(widget, pt));
p.setState(Qt::TouchPointPressed);
return *this;
}
QTouchEventSequence& move(int touchId, const QPoint &pt, QWidget *widget = 0)
QTouchEventSequence& move(int touchId, const QPoint &pt, QWidget *widget = Q_NULLPTR)
{
QTouchEvent::TouchPoint &p = point(touchId);
p.setScreenPos(mapToScreen(widget, pt));
p.setState(Qt::TouchPointMoved);
return *this;
}
QTouchEventSequence& release(int touchId, const QPoint &pt, QWidget *widget = 0)
QTouchEventSequence& release(int touchId, const QPoint &pt, QWidget *widget = Q_NULLPTR)
{
QTouchEvent::TouchPoint &p = point(touchId);
p.setScreenPos(mapToScreen(widget, pt));
@ -143,14 +143,14 @@ namespace QTest
private:
#ifdef QT_WIDGETS_LIB
QTouchEventSequence(QWidget *widget, QTouchDevice *aDevice, bool autoCommit)
: targetWidget(widget), targetWindow(0), device(aDevice), commitWhenDestroyed(autoCommit)
: targetWidget(widget), targetWindow(Q_NULLPTR), device(aDevice), commitWhenDestroyed(autoCommit)
{
}
#endif
QTouchEventSequence(QWindow *window, QTouchDevice *aDevice, bool autoCommit)
:
#ifdef QT_WIDGETS_LIB
targetWidget(0),
targetWidget(Q_NULLPTR),
#endif
targetWindow(window), device(aDevice), commitWhenDestroyed(autoCommit)
{