Retire QTest::pixmapsAreEqual().
authorJason McDonald <jason.mcdonald@nokia.com>
Mon, 19 Dec 2011 05:22:51 +0000 (15:22 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 20 Dec 2011 05:17:42 +0000 (06:17 +0100)
QTest::pixmapsAreEqual() was left in the Qt4 API for compatibility with
some old tests written for Qt3.  QCOMPARE() is the preferred way to
compare QPixmaps and provides superior diagnostic output when a
comparison fails.

This commit removes QTest::pixmapsAreEqual() from the testlib API and
replaces the last few remaining calls with QCOMPARE.

Change-Id: I051c0e7d3bda072855fcd262d82e8e540619233b
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
dist/changes-5.0.0
src/testlib/qtest_gui.h
tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
tests/auto/widgets/styles/qstyle/tst_qstyle.cpp

index fe159c4..159ef73 100644 (file)
@@ -57,6 +57,9 @@ information about a particular change.
     internal testlib function that was exposed in the public API due to its use
     in a public macro.  Any calls to this function should be replaced by a call
     to qsnprintf(), which comes from the <QtCore/QByteArray> header.
+  * The QTest::pixmapsAreEqual() function has been removed from the API.
+    Comparison of QPixmap objects should be done using QCOMPARE, which provides
+    more informative output in the event of a failure.
   * The QSKIP macro no longer has the "mode" parameter, which caused problems
     for calculating test metrics, as the SkipAll mode hid information about
     what test data was skipped.  Calling QSKIP in a test function now behaves
index 89f63e2..99b7700 100644 (file)
@@ -94,21 +94,6 @@ inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, c
 
 }
 
-/* compatibility */
-
-inline static bool pixmapsAreEqual(const QPixmap *actual, const QPixmap *expected)
-{
-    if (!actual && !expected)
-        return true;
-    if (!actual || !expected)
-        return false;
-    if (actual->isNull() && expected->isNull())
-        return true;
-    if (actual->isNull() || expected->isNull() || actual->size() != expected->size())
-        return false;
-    return actual->toImage() == expected->toImage();
-}
-
 #ifdef Q_WS_X11
 extern void qt_x11_wait_for_window_manager(QWidget *w);
 #endif
index 3d3f5b4..9e7e932 100644 (file)
@@ -1100,11 +1100,17 @@ void tst_QDataStream::readQCursor(QDataStream *s)
     QVERIFY(d5.shape() == test.shape()); //## lacks operator==
     QVERIFY(d5.hotSpot() == test.hotSpot());
     QVERIFY((d5.bitmap() != 0 && test.bitmap() != 0) || (d5.bitmap() == 0 && test.bitmap() == 0));
-    if (d5.bitmap() != 0)
-        QVERIFY(pixmapsAreEqual(d5.bitmap(), test.bitmap()));
+    if (d5.bitmap() != 0) {
+        QPixmap actual = *(d5.bitmap());
+        QPixmap expected = *(test.bitmap());
+        QCOMPARE(actual, expected);
+    }
     QVERIFY((d5.mask() != 0 && test.mask() != 0) || (d5.mask() == 0 && test.mask() == 0));
-    if (d5.mask() != 0)
-        QVERIFY(pixmapsAreEqual(d5.mask(), test.mask()));
+    if (d5.mask() != 0) {
+        QPixmap actual = *(d5.mask());
+        QPixmap expected = *(test.mask());
+        QCOMPARE(actual, expected);
+    }
 #endif
 }
 
index c15d1e6..8d575c9 100644 (file)
@@ -329,7 +329,7 @@ void tst_QPixmap::convertFromImage()
     pix = QPixmap::fromImage(img2);
 
     QPixmap res = QPixmap::fromImage(img2);
-    QVERIFY( pixmapsAreEqual(&pix, &res) );
+    QCOMPARE(pix, res);
 }
 
 void tst_QPixmap::scroll_data()
@@ -1149,7 +1149,7 @@ void tst_QPixmap::copy()
     trans.fill(Qt::transparent);
 
     QPixmap transCopy = trans.copy();
-    QVERIFY(pixmapsAreEqual(&trans, &transCopy));
+    QCOMPARE(trans, transCopy);
 }
 
 void tst_QPixmap::depthOfNullObjects()
@@ -1317,7 +1317,7 @@ void tst_QPixmap::loadFromDataImage()
     QPixmap directLoadingPixmap;
     directLoadingPixmap.loadFromData(rawData);
 
-    QVERIFY(pixmapsAreEqual(&pixmapWithCopy, &directLoadingPixmap));
+    QCOMPARE(pixmapWithCopy, directLoadingPixmap);
 }
 
 void tst_QPixmap::fromImageReader_data()
@@ -1348,7 +1348,7 @@ void tst_QPixmap::fromImageReader()
 
     QPixmap directLoadingPixmap = QPixmap::fromImageReader(&imageReader);
 
-    QVERIFY(pixmapsAreEqual(&pixmapWithCopy, &directLoadingPixmap));
+    QCOMPARE(pixmapWithCopy, directLoadingPixmap);
 }
 
 void tst_QPixmap::fromImageReaderAnimatedGif_data()
@@ -1376,7 +1376,7 @@ void tst_QPixmap::fromImageReaderAnimatedGif()
         QPixmap refPixmap = QPixmap::fromImage(refImage);
 
         QPixmap directLoadingPixmap = QPixmap::fromImageReader(&pixmapReader);
-        QVERIFY(pixmapsAreEqual(&refPixmap, &directLoadingPixmap));
+        QCOMPARE(refPixmap, directLoadingPixmap);
     }
 }
 
index 5dede99..d5849f1 100644 (file)
@@ -273,7 +273,7 @@ void tst_QStyle::drawItemPixmap()
     QPixmap p(QString(SRCDIR) + "/task_25863.png", "PNG");
     QPixmap actualPix = QPixmap::grabWidget(testWidget);
 
-    QVERIFY(pixmapsAreEqual(&actualPix,&p));
+    QCOMPARE(actualPix, p);
     testWidget->hide();
 }
 
@@ -458,7 +458,7 @@ void comparePixmap(const QString &filename, const QPixmap &pixmap)
     QImage oldFile = readImage(filename);
     QPixmap oldPixmap = QPixmap::fromImage(oldFile);
     if (!oldFile.isNull())
-        QVERIFY(pixmapsAreEqual(&pixmap, &oldPixmap));
+        QCOMPARE(pixmap, oldPixmap);
     else
         writeImage(filename, pixmap.toImage());
 }