Various tests: Replace Q[TRY]_VERIFY(a == b) by Q[TRY]_COMPARE(a, b).

- Replace Q[TRY]_VERIFY(pointer == 0) by Q[TRY]_VERIFY(!pointer).
- Replace Q[TRY]_VERIFY(smartPointer == 0)  by
          Q[TRY]_VERIFY(smartPointer.isNull()).
- Replace Q[TRY]_VERIFY(a == b) by  Q[TRY]_COMPARE(a, b) and
  add casts where necessary. The values will then be logged
  should a test fail.

in tests/auto/other, tests/auto/printsupport and tests/auto/xml.

Change-Id: I28cbdc89d36791f179425f17f90b697c60660938
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-07-24 15:51:48 +02:00
parent 3b04cc6a4a
commit 569785cb00
12 changed files with 63 additions and 63 deletions

View File

@ -354,7 +354,7 @@ void tst_Compiler::detectDataStream()
QVERIFY(QtTestInternal::getSaveOperator<double>() != 0);
QVERIFY(QtTestInternal::getSaveOperator<QString>() != 0);
QVERIFY(QtTestInternal::getSaveOperator<MyString>() != 0);
QVERIFY(QtTestInternal::getSaveOperator<Qxxx>() == 0);
QVERIFY(!QtTestInternal::getSaveOperator<Qxxx>());
}
#else
void tst_Compiler::detectDataStream()
@ -637,7 +637,7 @@ void tst_Compiler::cxx11_alignas()
QSKIP("Compiler does not support C++11 feature");
#else
alignas(double) char c;
QVERIFY(Q_ALIGNOF(c) == Q_ALIGNOF(double));
QCOMPARE(Q_ALIGNOF(c), Q_ALIGNOF(double));
#endif
}

View File

@ -1461,7 +1461,7 @@ void tst_Gestures::ungrabGesture() // a method on QWidget
QPointer<QGesture> customGestureB;
customGestureB = *(b->gestures.begin());
QVERIFY(!customGestureB.isNull());
QVERIFY(customGestureA.data() == customGestureB.data());
QCOMPARE(customGestureA.data(), customGestureB.data());
QCOMPARE(customGestureB->gestureType(), CustomGesture::GestureType);
a->gestures.clear();

View File

@ -457,8 +457,8 @@ void tst_MacNativeEvents::testModifierCtrl()
QWidget w;
w.show();
QVERIFY(kControlUnicode == QKeySequence(Qt::Key_Meta).toString(QKeySequence::NativeText)[0]);
QVERIFY(kCommandUnicode == QKeySequence(Qt::Key_Control).toString(QKeySequence::NativeText)[0]);
QCOMPARE(ushort(kControlUnicode), QKeySequence(Qt::Key_Meta).toString(QKeySequence::NativeText).at(0).unicode());
QCOMPARE(ushort(kCommandUnicode), QKeySequence(Qt::Key_Control).toString(QKeySequence::NativeText).at(0).unicode());
NativeEventList native;
native.append(new QNativeModifierEvent(Qt::ControlModifier));
@ -490,8 +490,8 @@ void tst_MacNativeEvents::testModifierCtrlWithDontSwapCtrlAndMeta()
QWidget w;
w.show();
QVERIFY(kCommandUnicode == QKeySequence(Qt::Key_Meta).toString(QKeySequence::NativeText)[0]);
QVERIFY(kControlUnicode == QKeySequence(Qt::Key_Control).toString(QKeySequence::NativeText)[0]);
QCOMPARE(ushort(kCommandUnicode), QKeySequence(Qt::Key_Meta).toString(QKeySequence::NativeText).at(0).unicode());
QCOMPARE(ushort(kControlUnicode), QKeySequence(Qt::Key_Control).toString(QKeySequence::NativeText).at(0).unicode());
NativeEventList native;
native.append(new QNativeModifierEvent(Qt::ControlModifier));

View File

@ -569,7 +569,7 @@ void ModelTest::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto
QVERIFY(topLeft.isValid());
QVERIFY(bottomRight.isValid());
QModelIndex commonParent = bottomRight.parent();
QVERIFY(topLeft.parent() == commonParent);
QCOMPARE(topLeft.parent(), commonParent);
QVERIFY(topLeft.row() <= bottomRight.row());
QVERIFY(topLeft.column() <= bottomRight.column());
int rowCount = model->rowCount(commonParent);

View File

@ -462,7 +462,7 @@ void tst_NetworkSelfTest::remotePortsOpen()
else
QFAIL(QString("Error connecting to server on port %1: %2").arg(portNumber).arg(socket.errorString()).toLocal8Bit());
}
QVERIFY(socket.state() == QAbstractSocket::ConnectedState);
QCOMPARE(socket.state(), QAbstractSocket::ConnectedState);
}
static QList<Chat> ftpChat(const QByteArray &userSuffix = QByteArray())

View File

@ -452,15 +452,15 @@ void tst_QAccessibility::statesStructTest()
QVERIFY(s1.modal == 0);
QAccessible::State s2;
QVERIFY(s2 == s1);
QCOMPARE(s2, s1);
s2.busy = true;
QVERIFY(!(s2 == s1));
s1.busy = true;
QVERIFY(s2 == s1);
QCOMPARE(s2, s1);
s1 = QAccessible::State();
QVERIFY(!(s2 == s1));
s1 = s2;
QVERIFY(s2 == s1);
QCOMPARE(s2, s1);
QVERIFY(s1.busy == 1);
}
@ -523,9 +523,9 @@ void tst_QAccessibility::navigateHierarchy()
QVERIFY(ifaceW->isValid());
QAccessibleInterface *target = ifaceW->child(14);
QVERIFY(target == 0);
QVERIFY(!target);
target = ifaceW->child(-1);
QVERIFY(target == 0);
QVERIFY(!target);
target = ifaceW->child(0);
QAccessibleInterface *interfaceW1(ifaceW->child(0));
QVERIFY(target);
@ -541,7 +541,7 @@ void tst_QAccessibility::navigateHierarchy()
QCOMPARE(target->object(), (QObject*)w3);
QAccessibleInterface *child = target->child(1);
QVERIFY(child == 0);
QVERIFY(!child);
child = target->child(0);
QVERIFY(child != 0);
QVERIFY(child->isValid());
@ -959,7 +959,7 @@ void tst_QAccessibility::mainWindowTest()
QWindow window;
window.setGeometry(80, 80, 40, 40);
window.show();
QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
QTRY_COMPARE(QGuiApplication::focusWindow(), &window);
// We currently don't have an accessible interface for QWindow
// the active state is either in the QMainWindow or QQuickView
@ -1650,7 +1650,7 @@ void tst_QAccessibility::spinBoxTest()
// make sure that the line edit is not there
const int numChildren = interface->childCount();
QCOMPARE(numChildren, 0);
QVERIFY(interface->child(0) == Q_NULLPTR);
QVERIFY(!interface->child(0));
QVERIFY(interface->valueInterface());
QCOMPARE(interface->valueInterface()->currentValue().toInt(), 3);
@ -2486,7 +2486,7 @@ void tst_QAccessibility::groupBoxTest()
QCOMPARE(iface->text(QAccessible::Name), QLatin1String("Test QGroupBox"));
QCOMPARE(iface->text(QAccessible::Description), QLatin1String("This group box will be used to test accessibility"));
QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > relations = rButtonIface->relations();
QVERIFY(relations.size() == 1);
QCOMPARE(relations.size(), 1);
QPair<QAccessibleInterface*, QAccessible::Relation> relation = relations.first();
QCOMPARE(relation.first->object(), groupBox);
QCOMPARE(relation.second, QAccessible::Label);
@ -3531,13 +3531,13 @@ void tst_QAccessibility::dockWidgetTest()
QPoint buttonPoint = pb2->mapToGlobal(QPoint(pb2->width()/2, pb2->height()/2));
QAccessibleInterface *childAt = accDock2->childAt(buttonPoint.x(), buttonPoint.y());
QVERIFY(childAt);
QVERIFY(childAt->object() == pb2);
QCOMPARE(childAt->object(), pb2);
QWidget *close1 = qobject_cast<QWidget*>(dock1Close->object());
QPoint close1ButtonPoint = close1->mapToGlobal(QPoint(close1->width()/2, close1->height()/2));
QAccessibleInterface *childAt2 = accDock1->childAt(close1ButtonPoint.x(), close1ButtonPoint.y());
QVERIFY(childAt2);
QVERIFY(childAt2->object() == close1);
QCOMPARE(childAt2->object(), close1);
// custom title bar widget
QDockWidget *dock3 = new QDockWidget(mw);

View File

@ -173,7 +173,7 @@ void tst_QComplexText::bidiCursor_qtbug2795()
qreal x2 = line2.cursorToX(0) - line2.cursorToX(str.size());
// The cursor should remain at the same position after a digit is appended
QVERIFY(x1 == x2);
QCOMPARE(x1, x2);
}
void tst_QComplexText::bidiCursorMovement_data()

View File

@ -132,7 +132,7 @@ void compareScreenshots(const QString &image1, const QString &image2)
//screenShot.save("scr2.png", "PNG");
//original.save("orig1.png", "PNG");
QVERIFY(original == screenShot);
QCOMPARE(original, screenShot);
}
void takeScreenShot(const QString filename)

View File

@ -425,12 +425,12 @@ void tst_QPrinter::outputFormatFromSuffix()
if (QPrinterInfo::availablePrinters().size() == 0)
QSKIP("No printers available.");
QPrinter p;
QVERIFY(p.outputFormat() == QPrinter::NativeFormat);
QCOMPARE(p.outputFormat(), QPrinter::NativeFormat);
p.setOutputFileName("test.pdf");
TempFileCleanup tmpFile("test.pdf");
QVERIFY(p.outputFormat() == QPrinter::PdfFormat);
QCOMPARE(p.outputFormat(), QPrinter::PdfFormat);
p.setOutputFileName(QString());
QVERIFY(p.outputFormat() == QPrinter::NativeFormat);
QCOMPARE(p.outputFormat(), QPrinter::NativeFormat);
}
void tst_QPrinter::testPageMargins_data()

View File

@ -880,7 +880,7 @@ void tst_Moc::preprocessorConditionals()
QVERIFY(mobj->indexOfSignal("signalInIf1()") != -1);
QVERIFY(mobj->indexOfSignal("signalInIf2()") != -1);
QVERIFY(mobj->indexOfSignal("signalInIf3()") != -1);
QVERIFY(mobj->indexOfSignal("doNotExist()") == -1);
QCOMPARE(mobj->indexOfSignal("doNotExist()"), -1);
}
void tst_Moc::blackslashNewlines()
@ -888,7 +888,7 @@ void tst_Moc::blackslashNewlines()
BackslashNewlines tst;
const QMetaObject *mobj = tst.metaObject();
QVERIFY(mobj->indexOfSlot("works()") != -1);
QVERIFY(mobj->indexOfSlot("buggy()") == -1);
QCOMPARE(mobj->indexOfSlot("buggy()"), -1);
}
void tst_Moc::slotWithSillyConst()
@ -928,8 +928,8 @@ void tst_Moc::testExtraDataForEnum()
const QMetaObject * const *objects = mobjUser->d.relatedMetaObjects;
QVERIFY(objects);
QVERIFY(objects[0] == mobjSource);
QVERIFY(objects[1] == 0);
QCOMPARE(objects[0], mobjSource);
QVERIFY(!objects[1]);
}
void tst_Moc::namespaceTypeProperty()
@ -982,7 +982,7 @@ void tst_Moc::namespacedFlags()
const QVariant v = bar.property("flags");
QVERIFY(v.isValid());
QVERIFY(baz.setProperty("flags", v));
QVERIFY(baz.flags() == bar.flags());
QCOMPARE(baz.flags(), bar.flags());
QList<Foo::Bar::Flags> l;
l << baz.flags();
@ -1104,7 +1104,7 @@ void tst_Moc::winNewline()
if (data.at(i) == QLatin1Char('\r')) {
QVERIFY(i < data.count() - 1);
++i;
QVERIFY(data.at(i) == '\n');
QCOMPARE(data.at(i), '\n');
} else {
QVERIFY(data.at(i) != '\n');
}
@ -1255,14 +1255,14 @@ void tst_Moc::invokable()
{
const QMetaObject &mobj = InvokableBeforeReturnType::staticMetaObject;
QCOMPARE(mobj.methodCount(), 6);
QVERIFY(mobj.method(5).methodSignature() == QByteArray("foo()"));
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("foo()"));
}
{
const QMetaObject &mobj = InvokableBeforeInline::staticMetaObject;
QCOMPARE(mobj.methodCount(), 7);
QVERIFY(mobj.method(5).methodSignature() == QByteArray("foo()"));
QVERIFY(mobj.method(6).methodSignature() == QByteArray("bar()"));
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("foo()"));
QCOMPARE(mobj.method(6).methodSignature(), QByteArray("bar()"));
}
}
@ -1271,22 +1271,22 @@ void tst_Moc::singleFunctionKeywordSignalAndSlot()
{
const QMetaObject &mobj = SingleFunctionKeywordBeforeReturnType::staticMetaObject;
QCOMPARE(mobj.methodCount(), 7);
QVERIFY(mobj.method(5).methodSignature() == QByteArray("mySignal()"));
QVERIFY(mobj.method(6).methodSignature() == QByteArray("mySlot()"));
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("mySignal()"));
QCOMPARE(mobj.method(6).methodSignature(), QByteArray("mySlot()"));
}
{
const QMetaObject &mobj = SingleFunctionKeywordBeforeInline::staticMetaObject;
QCOMPARE(mobj.methodCount(), 7);
QVERIFY(mobj.method(5).methodSignature() == QByteArray("mySignal()"));
QVERIFY(mobj.method(6).methodSignature() == QByteArray("mySlot()"));
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("mySignal()"));
QCOMPARE(mobj.method(6).methodSignature(), QByteArray("mySlot()"));
}
{
const QMetaObject &mobj = SingleFunctionKeywordAfterInline::staticMetaObject;
QCOMPARE(mobj.methodCount(), 7);
QVERIFY(mobj.method(5).methodSignature() == QByteArray("mySignal()"));
QVERIFY(mobj.method(6).methodSignature() == QByteArray("mySlot()"));
QCOMPARE(mobj.method(5).methodSignature(), QByteArray("mySignal()"));
QCOMPARE(mobj.method(6).methodSignature(), QByteArray("mySlot()"));
}
}
@ -1740,34 +1740,34 @@ template <class T>
void tst_Moc::revisions_T()
{
int idx = T::staticMetaObject.indexOfProperty("prop1");
QVERIFY(T::staticMetaObject.property(idx).revision() == 0);
QCOMPARE(T::staticMetaObject.property(idx).revision(), 0);
idx = T::staticMetaObject.indexOfProperty("prop2");
QVERIFY(T::staticMetaObject.property(idx).revision() == 2);
QCOMPARE(T::staticMetaObject.property(idx).revision(), 2);
idx = T::staticMetaObject.indexOfMethod("method1()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 0);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 0);
idx = T::staticMetaObject.indexOfMethod("method2()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 4);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 4);
idx = T::staticMetaObject.indexOfSlot("slot1()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 0);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 0);
idx = T::staticMetaObject.indexOfSlot("slot2()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 3);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 3);
idx = T::staticMetaObject.indexOfSlot("slot3()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 6);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 6);
idx = T::staticMetaObject.indexOfSlot("slot4()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 6);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 6);
idx = T::staticMetaObject.indexOfSignal("signal1()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 0);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 0);
idx = T::staticMetaObject.indexOfSignal("signal2()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 5);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 5);
idx = T::staticMetaObject.indexOfSignal("signal3()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 7);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 7);
idx = T::staticMetaObject.indexOfSignal("signal4()");
QVERIFY(T::staticMetaObject.method(idx).revision() == 7);
QCOMPARE(T::staticMetaObject.method(idx).revision(), 7);
idx = T::staticMetaObject.indexOfEnumerator("TestEnum");
QCOMPARE(T::staticMetaObject.enumerator(idx).keyCount(), 2);
@ -1947,7 +1947,7 @@ public:
void tst_Moc::privateClass()
{
QVERIFY(PrivateClass::staticMetaObject.indexOfConstructor("PrivateClass()") == 0);
QCOMPARE(PrivateClass::staticMetaObject.indexOfConstructor("PrivateClass()"), 0);
QVERIFY(PrivateClass::staticMetaObject.indexOfSignal("someSignal()") > 0);
}
@ -3068,7 +3068,7 @@ void tst_Moc::parseDefines()
int index = mo->indexOfSlot("stringMethod()");
QVERIFY(index != -1);
QVERIFY(mo->method(index).returnType() == QMetaType::QString);
QCOMPARE(mo->method(index).returnType(), int(QMetaType::QString));
index = mo->indexOfSlot("combined1()");
QVERIFY(index != -1);
@ -3127,7 +3127,7 @@ void tst_Moc::parseDefines()
QVERIFY(!qstrcmp(mci.value(), "TestValue"));
}
}
QVERIFY(count == 3);
QCOMPARE(count, 3);
index = mo->indexOfSlot("PD_DEFINE_ITSELF_SUFFIX(int)");
QVERIFY(index != -1);
@ -3253,7 +3253,7 @@ void tst_Moc::relatedMetaObjectsWithinNamespaces()
const QMetaObject *testMo = &QTBUG_2151::B::staticMetaObject;
QVERIFY(testMo->d.relatedMetaObjects);
QVERIFY(testMo->d.relatedMetaObjects[0] == relatedMo);
QCOMPARE(testMo->d.relatedMetaObjects[0], relatedMo);
}
void tst_Moc::relatedMetaObjectsInGadget()
@ -3262,7 +3262,7 @@ void tst_Moc::relatedMetaObjectsInGadget()
const QMetaObject *testMo = &QTBUG_35657::B::staticMetaObject;
QVERIFY(testMo->d.relatedMetaObjects);
QVERIFY(testMo->d.relatedMetaObjects[0] == relatedMo);
QCOMPARE(testMo->d.relatedMetaObjects[0], relatedMo);
}
void tst_Moc::relatedMetaObjectsNameConflict_data()

View File

@ -1043,15 +1043,15 @@ void tst_QDom::browseElements()
QVERIFY(!bar.isNull());
QVERIFY(bar.previousSiblingElement("bar").isNull());
QVERIFY(bar.previousSiblingElement().isNull());
QVERIFY(bar.nextSiblingElement("bar").tagName() == "bar");
QCOMPARE(bar.nextSiblingElement("bar").tagName(), QLatin1String("bar"));
QVERIFY(bar.nextSiblingElement("bar").nextSiblingElement("bar").isNull());
QDomElement bop = foo.firstChildElement("bop");
QVERIFY(!bop.isNull());
QVERIFY(bar.nextSiblingElement() == bop);
QVERIFY(bop.nextSiblingElement("bop") == foo.lastChildElement("bop"));
QVERIFY(bop.previousSiblingElement("bar") == foo.firstChildElement("bar"));
QVERIFY(bop.previousSiblingElement("bar") == foo.firstChildElement());
QCOMPARE(bar.nextSiblingElement(), bop);
QCOMPARE(bop.nextSiblingElement("bop"), foo.lastChildElement("bop"));
QCOMPARE(bop.previousSiblingElement("bar"), foo.firstChildElement("bar"));
QCOMPARE(bop.previousSiblingElement("bar"), foo.firstChildElement());
}
void tst_QDom::domNodeMapAndList()

View File

@ -147,7 +147,7 @@ public slots:
void requestFinished(QNetworkReply *reply)
{
QVERIFY(reply->error() == QNetworkReply::NoError);
QCOMPARE(reply->error(), QNetworkReply::NoError);
reply->deleteLater();
}