diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp | 63 | ||||
-rw-r--r-- | tests/auto/qabstractslider/tst_qabstractslider.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp | 70 | ||||
-rw-r--r-- | tests/auto/qdockwidget/tst_qdockwidget.cpp | 5 | ||||
-rw-r--r-- | tests/auto/qgl/tst_qgl.cpp | 236 | ||||
-rw-r--r-- | tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp | 26 | ||||
-rw-r--r-- | tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 27 | ||||
-rw-r--r-- | tests/auto/qimagereader/images/grayscale-ref.tif | bin | 0 -> 256182 bytes | |||
-rw-r--r-- | tests/auto/qimagereader/images/grayscale.tif | bin | 0 -> 64162 bytes | |||
-rw-r--r-- | tests/auto/qimagereader/tst_qimagereader.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qimagewriter/tst_qimagewriter.cpp | 17 | ||||
-rw-r--r-- | tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp | 65 | ||||
-rw-r--r-- | tests/auto/qlabel/tst_qlabel.cpp | 51 | ||||
-rw-r--r-- | tests/auto/qpixmapfilter/tst_qpixmapfilter.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qtreewidget/tst_qtreewidget.cpp | 28 |
16 files changed, 514 insertions, 93 deletions
diff --git a/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp index bdc31af..413419d 100644 --- a/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -865,15 +865,22 @@ void tst_QAbstractItemModel::testMoveSameParentDown_data() QTest::addColumn<int>("startRow"); QTest::addColumn<int>("endRow"); QTest::addColumn<int>("destRow"); + // We can't put the actual parent index for the move in here because m_model is not defined until init() is run. + QTest::addColumn<bool>("topLevel"); // Move from the start to the middle - QTest::newRow("move01") << 0 << 2 << 8; + QTest::newRow("move01") << 0 << 2 << 8 << true; // Move from the start to the end - QTest::newRow("move02") << 0 << 2 << 10; + QTest::newRow("move02") << 0 << 2 << 10 << true; // Move from the middle to the middle - QTest::newRow("move03") << 3 << 5 << 8; + QTest::newRow("move03") << 3 << 5 << 8 << true; // Move from the middle to the end - QTest::newRow("move04") << 3 << 5 << 10; + QTest::newRow("move04") << 3 << 5 << 10 << true; + + QTest::newRow("move05") << 0 << 2 << 8 << false; + QTest::newRow("move06") << 0 << 2 << 10 << false; + QTest::newRow("move07") << 3 << 5 << 8 << false; + QTest::newRow("move08") << 3 << 5 << 10 << false; } void tst_QAbstractItemModel::testMoveSameParentDown() @@ -881,6 +888,9 @@ void tst_QAbstractItemModel::testMoveSameParentDown() QFETCH( int, startRow); QFETCH( int, endRow); QFETCH( int, destRow); + QFETCH( bool, topLevel); + + QModelIndex moveParent = topLevel ? QModelIndex() : m_model->index(5, 0); QList<QPersistentModelIndex> persistentList; QModelIndexList indexList; @@ -913,33 +923,37 @@ void tst_QAbstractItemModel::testMoveSameParentDown() ModelMoveCommand *moveCommand = new ModelMoveCommand(m_model, this); moveCommand->setNumCols(4); + if (!topLevel) + moveCommand->setAncestorRowNumbers(QList<int>() << 5); moveCommand->setStartRow(startRow); moveCommand->setEndRow(endRow); moveCommand->setDestRow(destRow); + if (!topLevel) + moveCommand->setDestAncestors(QList<int>() << 5); moveCommand->doCommand(); QVariantList beforeSignal = beforeSpy.takeAt(0); QVariantList afterSignal = afterSpy.takeAt(0); QCOMPARE(beforeSignal.size(), 5); - QCOMPARE(beforeSignal.at(0).value<QModelIndex>(), QModelIndex()); + QCOMPARE(beforeSignal.at(0).value<QModelIndex>(), moveParent); QCOMPARE(beforeSignal.at(1).toInt(), startRow); QCOMPARE(beforeSignal.at(2).toInt(), endRow); - QCOMPARE(beforeSignal.at(3).value<QModelIndex>(), QModelIndex()); + QCOMPARE(beforeSignal.at(3).value<QModelIndex>(), moveParent); QCOMPARE(beforeSignal.at(4).toInt(), destRow); QCOMPARE(afterSignal.size(), 5); - QCOMPARE(afterSignal.at(0).value<QModelIndex>(), QModelIndex()); + QCOMPARE(afterSignal.at(0).value<QModelIndex>(), moveParent); QCOMPARE(afterSignal.at(1).toInt(), startRow); QCOMPARE(afterSignal.at(2).toInt(), endRow); - QCOMPARE(afterSignal.at(3).value<QModelIndex>(), QModelIndex()); + QCOMPARE(afterSignal.at(3).value<QModelIndex>(), moveParent); QCOMPARE(afterSignal.at(4).toInt(), destRow); for (int i = 0; i < indexList.size(); i++) { QModelIndex idx = indexList.at(i); QModelIndex persistentIndex = persistentList.at(i); - if (idx.parent() == QModelIndex()) + if (idx.parent() == moveParent) { int row = idx.row(); if ( row >= startRow) @@ -976,15 +990,21 @@ void tst_QAbstractItemModel::testMoveSameParentUp_data() QTest::addColumn<int>("startRow"); QTest::addColumn<int>("endRow"); QTest::addColumn<int>("destRow"); + QTest::addColumn<bool>("topLevel"); // Move from the middle to the start - QTest::newRow("move01") << 5 << 7 << 0; + QTest::newRow("move01") << 5 << 7 << 0 << true; // Move from the end to the start - QTest::newRow("move02") << 8 << 9 << 0; + QTest::newRow("move02") << 8 << 9 << 0 << true; // Move from the middle to the middle - QTest::newRow("move03") << 5 << 7 << 2; + QTest::newRow("move03") << 5 << 7 << 2 << true; // Move from the end to the middle - QTest::newRow("move04") << 8 << 9 << 5; + QTest::newRow("move04") << 8 << 9 << 5 << true; + + QTest::newRow("move05") << 5 << 7 << 0 << false; + QTest::newRow("move06") << 8 << 9 << 0 << false; + QTest::newRow("move07") << 5 << 7 << 2 << false; + QTest::newRow("move08") << 8 << 9 << 5 << false; } void tst_QAbstractItemModel::testMoveSameParentUp() @@ -993,6 +1013,9 @@ void tst_QAbstractItemModel::testMoveSameParentUp() QFETCH( int, startRow); QFETCH( int, endRow); QFETCH( int, destRow); + QFETCH( bool, topLevel); + + QModelIndex moveParent = topLevel ? QModelIndex() : m_model->index(5, 0); QList<QPersistentModelIndex> persistentList; QModelIndexList indexList; @@ -1026,26 +1049,30 @@ void tst_QAbstractItemModel::testMoveSameParentUp() ModelMoveCommand *moveCommand = new ModelMoveCommand(m_model, this); moveCommand->setNumCols(4); + if (!topLevel) + moveCommand->setAncestorRowNumbers(QList<int>() << 5); moveCommand->setStartRow(startRow); moveCommand->setEndRow(endRow); moveCommand->setDestRow(destRow); + if (!topLevel) + moveCommand->setDestAncestors(QList<int>() << 5); moveCommand->doCommand(); QVariantList beforeSignal = beforeSpy.takeAt(0); QVariantList afterSignal = afterSpy.takeAt(0); QCOMPARE(beforeSignal.size(), 5); - QCOMPARE(beforeSignal.at(0).value<QModelIndex>(), QModelIndex()); + QCOMPARE(beforeSignal.at(0).value<QModelIndex>(), moveParent); QCOMPARE(beforeSignal.at(1).toInt(), startRow); QCOMPARE(beforeSignal.at(2).toInt(), endRow); - QCOMPARE(beforeSignal.at(3).value<QModelIndex>(), QModelIndex()); + QCOMPARE(beforeSignal.at(3).value<QModelIndex>(), moveParent); QCOMPARE(beforeSignal.at(4).toInt(), destRow); QCOMPARE(afterSignal.size(), 5); - QCOMPARE(afterSignal.at(0).value<QModelIndex>(), QModelIndex()); + QCOMPARE(afterSignal.at(0).value<QModelIndex>(), moveParent); QCOMPARE(afterSignal.at(1).toInt(), startRow); QCOMPARE(afterSignal.at(2).toInt(), endRow); - QCOMPARE(afterSignal.at(3).value<QModelIndex>(), QModelIndex()); + QCOMPARE(afterSignal.at(3).value<QModelIndex>(), moveParent); QCOMPARE(afterSignal.at(4).toInt(), destRow); @@ -1053,7 +1080,7 @@ void tst_QAbstractItemModel::testMoveSameParentUp() { QModelIndex idx = indexList.at(i); QModelIndex persistentIndex = persistentList.at(i); - if (idx.parent() == QModelIndex()) + if (idx.parent() == moveParent) { int row = idx.row(); if ( row >= destRow) diff --git a/tests/auto/qabstractslider/tst_qabstractslider.cpp b/tests/auto/qabstractslider/tst_qabstractslider.cpp index d9574df..ee1ba19 100644 --- a/tests/auto/qabstractslider/tst_qabstractslider.cpp +++ b/tests/auto/qabstractslider/tst_qabstractslider.cpp @@ -742,11 +742,9 @@ void tst_QAbstractSlider::wheelEvent_data() << 1 // delta << int(Qt::Horizontal) // orientation of slider << int(Qt::Vertical) // orientation of wheel - << 0 // expected position after + << 1 // expected position after << QPoint(1,1); - // Scrolling in a slider of a different orientation than the wheel works - // if the mouse pointer is within the widget's rect QTest::newRow("Different orientation2")<< 0 // initial position << 0 // minimum << 100 // maximum diff --git a/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp b/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp index 381f46f..a57c1d6 100644 --- a/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp +++ b/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp @@ -75,6 +75,8 @@ private slots: void resetTextFormat(); void setWeekdayFormat(); + void showPrevNext_data(); + void showPrevNext(); }; // Testing get/set functions @@ -293,5 +295,73 @@ void tst_QCalendarWidget::cleanup() { } + +typedef void (QCalendarWidget::*ShowFunc)(); +Q_DECLARE_METATYPE(ShowFunc) + +void tst_QCalendarWidget::showPrevNext_data() +{ + QTest::addColumn<ShowFunc>("function"); + QTest::addColumn<QDate>("dateOrigin"); + QTest::addColumn<QDate>("expectedDate"); + + QTest::newRow("showNextMonth") << &QCalendarWidget::showNextMonth << QDate(1984,7,30) << QDate(1984,8,30); + QTest::newRow("showPrevMonth") << &QCalendarWidget::showPreviousMonth << QDate(1984,7,30) << QDate(1984,6,30); + QTest::newRow("showNextYear") << &QCalendarWidget::showNextYear << QDate(1984,7,30) << QDate(1985,7,30); + QTest::newRow("showPrevYear") << &QCalendarWidget::showPreviousYear << QDate(1984,7,30) << QDate(1983,7,30); + + QTest::newRow("showNextMonth limit") << &QCalendarWidget::showNextMonth << QDate(2007,12,4) << QDate(2008,1,4); + QTest::newRow("showPreviousMonth limit") << &QCalendarWidget::showPreviousMonth << QDate(2006,1,23) << QDate(2005,12,23); + + QTest::newRow("showNextMonth now") << &QCalendarWidget::showNextMonth << QDate() << QDate::currentDate().addMonths(1); + QTest::newRow("showNextYear now") << &QCalendarWidget::showNextYear << QDate() << QDate::currentDate().addYears(1); + QTest::newRow("showPrevieousMonth now") << &QCalendarWidget::showPreviousMonth << QDate() << QDate::currentDate().addMonths(-1); + QTest::newRow("showPreviousYear now") << &QCalendarWidget::showPreviousYear << QDate() << QDate::currentDate().addYears(-1); + + QTest::newRow("showToday now") << &QCalendarWidget::showToday << QDate(2000,1,31) << QDate::currentDate(); + QTest::newRow("showNextMonth 31") << &QCalendarWidget::showNextMonth << QDate(2000,1,31) << QDate(2000,2,28); + QTest::newRow("selectedDate") << &QCalendarWidget::showSelectedDate << QDate(2008,2,29) << QDate(2008,2,29); + +} + +void tst_QCalendarWidget::showPrevNext() +{ + QFETCH(ShowFunc, function); + QFETCH(QDate, dateOrigin); + QFETCH(QDate, expectedDate); + + QCalendarWidget calWidget; + calWidget.show(); + QTest::qWaitForWindowShown(&calWidget); + if(!dateOrigin.isNull()) { + calWidget.setSelectedDate(dateOrigin); + calWidget.setCurrentPage(dateOrigin.year(), dateOrigin.month()); + + QCOMPARE(calWidget.yearShown(), dateOrigin.year()); + QCOMPARE(calWidget.monthShown(), dateOrigin.month()); + } else { + QCOMPARE(calWidget.yearShown(), QDate::currentDate().year()); + QCOMPARE(calWidget.monthShown(), QDate::currentDate().month()); + } + + (calWidget.*function)(); + + QCOMPARE(calWidget.yearShown(), expectedDate.year()); + QCOMPARE(calWidget.monthShown(), expectedDate.month()); + + // QTBUG-4058 + QTest::qWait(20); + QToolButton *button = qFindChild<QToolButton *>(&calWidget, "qt_calendar_prevmonth"); + QTest::mouseClick(button, Qt::LeftButton); + expectedDate = expectedDate.addMonths(-1); + QCOMPARE(calWidget.yearShown(), expectedDate.year()); + QCOMPARE(calWidget.monthShown(), expectedDate.month()); + + if(!dateOrigin.isNull()) { + //the selectedDate should not have changed + QCOMPARE(calWidget.selectedDate(), dateOrigin); + } +} + QTEST_MAIN(tst_QCalendarWidget) #include "tst_qcalendarwidget.moc" diff --git a/tests/auto/qdockwidget/tst_qdockwidget.cpp b/tests/auto/qdockwidget/tst_qdockwidget.cpp index c9a7f1c..8f72e39 100644 --- a/tests/auto/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/qdockwidget/tst_qdockwidget.cpp @@ -50,6 +50,7 @@ #include <qlineedit.h> #include <QDesktopWidget> #include <QtGui/QPainter> +#include "private/qdockwidget_p.h" bool hasFeature(QDockWidget *dockwidget, QDockWidget::DockWidgetFeature feature) { return (dockwidget->features() & feature) == feature; } @@ -865,7 +866,9 @@ void tst_QDockWidget::taskQTBUG_1665_closableChanged() dock.show(); QTest::qWaitForWindowShown(&dock); - if (dock.windowFlags() & Qt::FramelessWindowHint) + QDockWidgetLayout *l = qobject_cast<QDockWidgetLayout*>(dock.layout()); + + if (l && !l->nativeWindowDeco()) QSKIP("this machine doesn't support native dock widget", SkipAll); QVERIFY(dock.windowFlags() & Qt::WindowCloseButtonHint); diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index c680dec..5dc072d 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -76,6 +76,7 @@ private slots: void partialGLWidgetUpdates_data(); void partialGLWidgetUpdates(); void glWidgetRendering(); + void glFBOSimpleRendering(); void glFBORendering(); void multipleFBOInterleavedRendering(); void glFBOUseInGLWidget(); @@ -711,6 +712,79 @@ void tst_QGL::openGLVersionCheck() #endif //QT_BUILD_INTERNAL } +static bool fuzzyComparePixels(const QRgb testPixel, const QRgb refPixel, const char* file, int line, int x = -1, int y = -1) +{ + static int maxFuzz = 1; + static bool maxFuzzSet = false; + + // On 16 bpp systems, we need to allow for more fuzz: + if (!maxFuzzSet) { + maxFuzzSet = true; + if (appDefaultDepth() < 24) + maxFuzz = 32; + } + + int redFuzz = qAbs(qRed(testPixel) - qRed(refPixel)); + int greenFuzz = qAbs(qGreen(testPixel) - qGreen(refPixel)); + int blueFuzz = qAbs(qBlue(testPixel) - qBlue(refPixel)); + int alphaFuzz = qAbs(qAlpha(testPixel) - qAlpha(refPixel)); + + if (refPixel != 0 && testPixel == 0) { + QString msg; + if (x >= 0) { + msg = QString("Test pixel [%1, %2] is null (black) when it should be (%3,%4,%5,%6)") + .arg(x).arg(y) + .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); + } else { + msg = QString("Test pixel is null (black) when it should be (%2,%3,%4,%5)") + .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); + } + + QTest::qFail(msg.toLatin1(), file, line); + return false; + } + + if (redFuzz > maxFuzz || greenFuzz > maxFuzz || blueFuzz > maxFuzz || alphaFuzz > maxFuzz) { + QString msg; + + if (x >= 0) + msg = QString("Pixel [%1,%2]: ").arg(x).arg(y); + else + msg = QString("Pixel "); + + msg += QString("Max fuzz (%1) exceeded: (%2,%3,%4,%5) vs (%6,%7,%8,%9)") + .arg(maxFuzz) + .arg(qRed(testPixel)).arg(qGreen(testPixel)).arg(qBlue(testPixel)).arg(qAlpha(testPixel)) + .arg(qRed(refPixel)).arg(qGreen(refPixel)).arg(qBlue(refPixel)).arg(qAlpha(refPixel)); + QTest::qFail(msg.toLatin1(), file, line); + return false; + } + return true; +} + +static void fuzzyCompareImages(const QImage &testImage, const QImage &referenceImage, const char* file, int line) +{ + QCOMPARE(testImage.width(), referenceImage.width()); + QCOMPARE(testImage.height(), referenceImage.height()); + + for (int y = 0; y < testImage.height(); y++) { + for (int x = 0; x < testImage.width(); x++) { + if (!fuzzyComparePixels(testImage.pixel(x, y), referenceImage.pixel(x, y), file, line, x, y)) { + // Might as well save the images for easier debugging: + referenceImage.save("referenceImage.png"); + testImage.save("testImage.png"); + return; + } + } + } +} + +#define QFUZZY_COMPARE_IMAGES(A,B) \ + fuzzyCompareImages(A, B, __FILE__, __LINE__) + +#define QFUZZY_COMPARE_PIXELS(A,B) \ + fuzzyComparePixels(A, B, __FILE__, __LINE__) + class UnclippedWidget : public QWidget { public: @@ -723,8 +797,6 @@ public: void tst_QGL::graphicsViewClipping() { - if (appDefaultDepth() < 24) - QSKIP("This test won't work for bit depths < 24", SkipAll); const int size = 64; UnclippedWidget *widget = new UnclippedWidget; widget->setFixedSize(size, size); @@ -734,6 +806,9 @@ void tst_QGL::graphicsViewClipping() scene.addWidget(widget)->setPos(0, 0); QGraphicsView view(&scene); +#ifdef Q_WS_QWS + view.setWindowFlags(Qt::FramelessWindowHint); +#endif view.resize(2*size, 2*size); QGLWidget *viewport = new QGLWidget; @@ -758,7 +833,7 @@ void tst_QGL::graphicsViewClipping() p.fillRect(QRect(0, 0, size, size), Qt::black); p.end(); - QCOMPARE(image, expected); + QFUZZY_COMPARE_IMAGES(image, expected); } void tst_QGL::partialGLWidgetUpdates_data() @@ -849,7 +924,7 @@ void tst_QGL::glPBufferRendering() p.fillRect(32, 32, 64, 64, Qt::blue); p.end(); - QCOMPARE(fb, reference); + QFUZZY_COMPARE_IMAGES(fb, reference); } class GLWidget : public QGLWidget @@ -868,8 +943,8 @@ public: // This test only ensures it's possible to paint onto a QGLWidget. Full // paint engine feature testing is way out of scope! + p.fillRect(-1, -1, width()+2, height()+2, Qt::red); - p.fillRect(0, 0, width(), height(), Qt::red); // No p.end() or swap buffers, should be done automatically } @@ -877,9 +952,11 @@ public: void tst_QGL::glWidgetRendering() { - if (appDefaultDepth() < 24) - QSKIP("This test won't work for bit depths < 24", SkipAll); GLWidget w; +#ifdef Q_WS_QWS + w.setWindowFlags(Qt::FramelessWindowHint); +#endif + w.setGeometry(100, 100, 200, 200); w.show(); #ifdef Q_WS_X11 @@ -894,7 +971,37 @@ void tst_QGL::glWidgetRendering() QImage reference(fb.size(), QImage::Format_RGB32); reference.fill(0xffff0000); - QCOMPARE(fb, reference); + QFUZZY_COMPARE_IMAGES(fb, reference); +} + +void tst_QGL::glFBOSimpleRendering() +{ + if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) + QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle); + + QGLWidget glw; + glw.makeCurrent(); + + // No multisample with combined depth/stencil attachment: + QGLFramebufferObjectFormat fboFormat; + fboFormat.setAttachment(QGLFramebufferObject::NoAttachment); + + // Don't complicate things by using NPOT: + QGLFramebufferObject *fbo = new QGLFramebufferObject(256, 128, fboFormat); + + fbo->bind(); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + glFinish(); + + QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); + QImage reference(fb.size(), QImage::Format_RGB32); + reference.fill(0xffff0000); + + QFUZZY_COMPARE_IMAGES(fb, reference); + + delete fbo; } // NOTE: This tests that CombinedDepthStencil attachment works by assuming the @@ -949,14 +1056,14 @@ void tst_QGL::glFBORendering() // As we're doing more than trivial painting, we can't just compare to // an image rendered with raster. Instead, we sample at well-defined // test-points: - QCOMPARE(fb.pixel(39, 64), QColor(Qt::red).rgb()); - QCOMPARE(fb.pixel(89, 64), QColor(Qt::red).rgb()); - QCOMPARE(fb.pixel(64, 39), QColor(Qt::blue).rgb()); - QCOMPARE(fb.pixel(64, 89), QColor(Qt::blue).rgb()); - - QCOMPARE(fb.pixel(167, 39), QColor(Qt::red).rgb()); - QCOMPARE(fb.pixel(217, 39), QColor(Qt::red).rgb()); - QCOMPARE(fb.pixel(192, 64), QColor(Qt::green).rgb()); + QFUZZY_COMPARE_PIXELS(fb.pixel(39, 64), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb.pixel(89, 64), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb.pixel(64, 39), QColor(Qt::blue).rgb()); + QFUZZY_COMPARE_PIXELS(fb.pixel(64, 89), QColor(Qt::blue).rgb()); + + QFUZZY_COMPARE_PIXELS(fb.pixel(167, 39), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb.pixel(217, 39), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb.pixel(192, 64), QColor(Qt::green).rgb()); } @@ -1047,29 +1154,29 @@ void tst_QGL::multipleFBOInterleavedRendering() // As we're doing more than trivial painting, we can't just compare to // an image rendered with raster. Instead, we sample at well-defined // test-points: - QCOMPARE(fb1.pixel(39, 64), QColor(Qt::red).rgb()); - QCOMPARE(fb1.pixel(89, 64), QColor(Qt::red).rgb()); - QCOMPARE(fb1.pixel(64, 39), QColor(Qt::blue).rgb()); - QCOMPARE(fb1.pixel(64, 89), QColor(Qt::blue).rgb()); - QCOMPARE(fb1.pixel(167, 39), QColor(Qt::red).rgb()); - QCOMPARE(fb1.pixel(217, 39), QColor(Qt::red).rgb()); - QCOMPARE(fb1.pixel(192, 64), QColor(Qt::green).rgb()); - - QCOMPARE(fb2.pixel(39, 64), QColor(Qt::green).rgb()); - QCOMPARE(fb2.pixel(89, 64), QColor(Qt::green).rgb()); - QCOMPARE(fb2.pixel(64, 39), QColor(Qt::red).rgb()); - QCOMPARE(fb2.pixel(64, 89), QColor(Qt::red).rgb()); - QCOMPARE(fb2.pixel(167, 39), QColor(Qt::green).rgb()); - QCOMPARE(fb2.pixel(217, 39), QColor(Qt::green).rgb()); - QCOMPARE(fb2.pixel(192, 64), QColor(Qt::blue).rgb()); - - QCOMPARE(fb3.pixel(39, 64), QColor(Qt::blue).rgb()); - QCOMPARE(fb3.pixel(89, 64), QColor(Qt::blue).rgb()); - QCOMPARE(fb3.pixel(64, 39), QColor(Qt::green).rgb()); - QCOMPARE(fb3.pixel(64, 89), QColor(Qt::green).rgb()); - QCOMPARE(fb3.pixel(167, 39), QColor(Qt::blue).rgb()); - QCOMPARE(fb3.pixel(217, 39), QColor(Qt::blue).rgb()); - QCOMPARE(fb3.pixel(192, 64), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb1.pixel(39, 64), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb1.pixel(89, 64), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb1.pixel(64, 39), QColor(Qt::blue).rgb()); + QFUZZY_COMPARE_PIXELS(fb1.pixel(64, 89), QColor(Qt::blue).rgb()); + QFUZZY_COMPARE_PIXELS(fb1.pixel(167, 39), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb1.pixel(217, 39), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb1.pixel(192, 64), QColor(Qt::green).rgb()); + + QFUZZY_COMPARE_PIXELS(fb2.pixel(39, 64), QColor(Qt::green).rgb()); + QFUZZY_COMPARE_PIXELS(fb2.pixel(89, 64), QColor(Qt::green).rgb()); + QFUZZY_COMPARE_PIXELS(fb2.pixel(64, 39), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb2.pixel(64, 89), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(fb2.pixel(167, 39), QColor(Qt::green).rgb()); + QFUZZY_COMPARE_PIXELS(fb2.pixel(217, 39), QColor(Qt::green).rgb()); + QFUZZY_COMPARE_PIXELS(fb2.pixel(192, 64), QColor(Qt::blue).rgb()); + + QFUZZY_COMPARE_PIXELS(fb3.pixel(39, 64), QColor(Qt::blue).rgb()); + QFUZZY_COMPARE_PIXELS(fb3.pixel(89, 64), QColor(Qt::blue).rgb()); + QFUZZY_COMPARE_PIXELS(fb3.pixel(64, 39), QColor(Qt::green).rgb()); + QFUZZY_COMPARE_PIXELS(fb3.pixel(64, 89), QColor(Qt::green).rgb()); + QFUZZY_COMPARE_PIXELS(fb3.pixel(167, 39), QColor(Qt::blue).rgb()); + QFUZZY_COMPARE_PIXELS(fb3.pixel(217, 39), QColor(Qt::blue).rgb()); + QFUZZY_COMPARE_PIXELS(fb3.pixel(192, 64), QColor(Qt::red).rgb()); } class FBOUseInGLWidget : public QGLWidget @@ -1089,11 +1196,11 @@ protected: QPainter fboPainter; fboPainterBeginOk = fboPainter.begin(fbo); - fboPainter.fillRect(0, 0, 128, 128, Qt::red); + fboPainter.fillRect(-1, -1, 130, 130, Qt::red); fboPainter.end(); fboImage = fbo->toImage(); - widgetPainter.fillRect(rect(), Qt::blue); + widgetPainter.fillRect(-1, -1, width()+2, width()+2, Qt::blue); delete fbo; } @@ -1102,12 +1209,13 @@ protected: void tst_QGL::glFBOUseInGLWidget() { - if (appDefaultDepth() < 24) - QSKIP("This test won't work for bit depths < 24", SkipAll); if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle); FBOUseInGLWidget w; +#ifdef Q_WS_QWS + w.setWindowFlags(Qt::FramelessWindowHint); +#endif w.resize(128, 128); w.show(); @@ -1122,17 +1230,15 @@ void tst_QGL::glFBOUseInGLWidget() QImage widgetFB = w.grabFrameBuffer(false); QImage widgetReference(widgetFB.size(), widgetFB.format()); widgetReference.fill(0xff0000ff); - QCOMPARE(widgetFB, widgetReference); + QFUZZY_COMPARE_IMAGES(widgetFB, widgetReference); QImage fboReference(w.fboImage.size(), w.fboImage.format()); fboReference.fill(0xffff0000); - QCOMPARE(w.fboImage, fboReference); + QFUZZY_COMPARE_IMAGES(w.fboImage, fboReference); } void tst_QGL::glWidgetReparent() { - if (appDefaultDepth() < 24) - QSKIP("This test won't work for bit depths < 24", SkipAll); // Try it as a top-level first: GLWidget *widget = new GLWidget; widget->setGeometry(0, 0, 200, 30); @@ -1222,7 +1328,7 @@ void tst_QGL::glWidgetRenderPixmap() QImage reference(fb.size(), QImage::Format_RGB32); reference.fill(0xffff0000); - QCOMPARE(fb, reference); + QFUZZY_COMPARE_IMAGES(fb, reference); } class ColormapExtended : public QGLColormap @@ -1495,9 +1601,10 @@ protected: void tst_QGL::replaceClipping() { - if (appDefaultDepth() < 24) - QSKIP("This test won't work for bit depths < 24", SkipAll); ReplaceClippingGLWidget glw; +#ifdef Q_WS_QWS + glw.setWindowFlags(Qt::FramelessWindowHint); +#endif glw.resize(300, 300); glw.show(); @@ -1513,7 +1620,13 @@ void tst_QGL::replaceClipping() const QImage widgetFB = glw.grabFrameBuffer(false).convertToFormat(QImage::Format_RGB32); - QCOMPARE(widgetFB, reference); + // Sample pixels in a grid pattern which avoids false failures due to + // off-by-one pixel errors on some buggy GL implementations + for (int x = 25; x < reference.width(); x += 50) { + for (int y = 25; y < reference.width(); y += 50) { + QFUZZY_COMPARE_PIXELS(widgetFB.pixel(x, y), reference.pixel(x, y)); + } + } } class ClipTestGLWidget : public QGLWidget @@ -1521,7 +1634,7 @@ class ClipTestGLWidget : public QGLWidget public: void paint(QPainter *painter) { - painter->fillRect(rect(), Qt::white); + painter->fillRect(-1, -1, width()+2, height()+2, Qt::white); painter->setClipRect(10, 10, width()-20, height()-20); painter->fillRect(rect(), Qt::cyan); @@ -1622,9 +1735,10 @@ protected: void tst_QGL::clipTest() { - if (appDefaultDepth() < 24) - QSKIP("This test won't work for bit depths < 24", SkipAll); ClipTestGLWidget glw; +#ifdef Q_WS_QWS + glw.setWindowFlags(Qt::FramelessWindowHint); +#endif glw.resize(220, 220); glw.show(); @@ -1640,7 +1754,13 @@ void tst_QGL::clipTest() const QImage widgetFB = glw.grabFrameBuffer(false).convertToFormat(QImage::Format_RGB32); - QCOMPARE(widgetFB, reference); + // Sample pixels in a grid pattern which avoids false failures due to + // off-by-one pixel errors on some buggy GL implementations + for (int x = 2; x < reference.width(); x += 5) { + for (int y = 2; y < reference.width(); y += 5) { + QFUZZY_COMPARE_PIXELS(widgetFB.pixel(x, y), reference.pixel(x, y)); + } + } } void tst_QGL::destroyFBOAfterContext() @@ -1722,12 +1842,14 @@ void tst_QGL::shareRegister() QVERIFY(qt_shared_test()->value(glw1->context()) == res1); // Create another context that shares with the first. + QVERIFY(!glw1->isSharing()); QGLWidget *glw2 = new QGLWidget(0, glw1); if (!glw2->isSharing()) { delete glw2; delete glw1; QSKIP("Context sharing is not supported", SkipSingle); } + QVERIFY(glw1->isSharing()); QVERIFY(glw1->context() != glw2->context()); // Check that the first context's resource is also on the second. @@ -1759,6 +1881,7 @@ void tst_QGL::shareRegister() // Create a third context, not sharing with the others. QGLWidget *glw3 = new QGLWidget(); + QVERIFY(!glw3->isSharing()); // Create a guard on the standalone context. QGLSharedResourceGuard guard3(glw3->context()); @@ -1807,6 +1930,9 @@ void tst_QGL::shareRegister() // Delete the first context. delete glw1; + // The second context should no longer register as sharing. + QVERIFY(!glw2->isSharing()); + // The first context's resource should transfer to the second context. QCOMPARE(tst_QGLResource::deletions, 0); QVERIFY(qt_shared_test()->value(glw2->context()) == res1); diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index c7ed309..2ad024f 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -85,6 +85,7 @@ private slots: void simplificationVsOrder(); void parallelSimplificationOfCenter(); void simplificationVsRedundance(); + void spacingPersistency(); }; class RectWidget : public QGraphicsWidget @@ -1866,5 +1867,30 @@ void tst_QGraphicsAnchorLayout::simplificationVsRedundance() QCOMPARE(usedSimplex(l, Qt::Vertical), false); } +/* + Avoid regression where the saved prefSize would be lost. This was + solved by saving the original spacing in the QGraphicsAnchorPrivate class +*/ +void tst_QGraphicsAnchorLayout::spacingPersistency() +{ + QGraphicsWidget w; + QGraphicsWidget *a = createItem(); + QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&w); + + l->addAnchors(l, a, Qt::Horizontal); + QGraphicsAnchor *anchor = l->anchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + + anchor->setSpacing(-30); + QCOMPARE(anchor->spacing(), -30.0); + + anchor->setSpacing(30); + QCOMPARE(anchor->spacing(), 30.0); + + anchor->setSizePolicy(QSizePolicy::Ignored); + w.effectiveSizeHint(Qt::PreferredSize); + + QCOMPARE(anchor->spacing(), 30.0); +} + QTEST_MAIN(tst_QGraphicsAnchorLayout) #include "tst_qgraphicsanchorlayout.moc" diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index 0fbd069..bca59c3 100644 --- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -1722,7 +1722,7 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() QRectF expected = truncate(item.rect); QRectF actual = truncate(widgets[item.index]->geometry()); - QCOMPARE(expected, actual); + QCOMPARE(actual, expected); } // Test mirrored mode @@ -1739,7 +1739,7 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() QRectF expected = truncate(mirroredRect); QRectF actual = truncate(widgets[item.index]->geometry()); - QCOMPARE(expected, actual); + QCOMPARE(actual, expected); delete widgets[item.index]; } diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 6b5ad09..829e55c 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -160,6 +160,7 @@ private slots: void widgetSendsGeometryChanges(); void respectHFW(); void addChildInpolishEvent(); + void polishEvent(); // Task fixes void task236127_bspTreeIndexFails(); @@ -2768,6 +2769,32 @@ void tst_QGraphicsWidget::addChildInpolishEvent() QCOMPARE(PolishWidget::numberOfPolish, 2); } +void tst_QGraphicsWidget::polishEvent() +{ + class MyGraphicsWidget : public QGraphicsWidget + { public: + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) + { events << QEvent::Paint; } + void polishEvent() + { events << QEvent::Polish; } + QList<QEvent::Type> events; + }; + + QGraphicsScene scene; + + MyGraphicsWidget *widget = new MyGraphicsWidget; + scene.addItem(widget); + + QGraphicsView view(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + + // Make sure the item is painted. + QTRY_VERIFY(widget->events.contains(QEvent::Paint)); + + // Make sure the item got polish before paint. + QCOMPARE(widget->events.at(0), QEvent::Polish); +} QTEST_MAIN(tst_QGraphicsWidget) #include "tst_qgraphicswidget.moc" diff --git a/tests/auto/qimagereader/images/grayscale-ref.tif b/tests/auto/qimagereader/images/grayscale-ref.tif Binary files differnew file mode 100644 index 0000000..960531e --- /dev/null +++ b/tests/auto/qimagereader/images/grayscale-ref.tif diff --git a/tests/auto/qimagereader/images/grayscale.tif b/tests/auto/qimagereader/images/grayscale.tif Binary files differnew file mode 100644 index 0000000..5f4e114 --- /dev/null +++ b/tests/auto/qimagereader/images/grayscale.tif diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index 05b506c..15b1c1c 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -157,6 +157,8 @@ private slots: void tiffOrientation_data(); void tiffOrientation(); + + void tiffGrayscale(); #endif void autoDetectImageFormat(); @@ -1376,6 +1378,13 @@ void tst_QImageReader::tiffOrientation() QCOMPARE(expectedImage, orientedImage); } +void tst_QImageReader::tiffGrayscale() +{ + QImage actualImage(prefix + "grayscale.tif"); + QImage expectedImage(prefix + "grayscale-ref.tif"); + + QCOMPARE(expectedImage, actualImage.convertToFormat(expectedImage.format())); +} #endif void tst_QImageReader::dotsPerMeter_data() diff --git a/tests/auto/qimagewriter/tst_qimagewriter.cpp b/tests/auto/qimagewriter/tst_qimagewriter.cpp index ab5572d..5997f39 100644 --- a/tests/auto/qimagewriter/tst_qimagewriter.cpp +++ b/tests/auto/qimagewriter/tst_qimagewriter.cpp @@ -391,16 +391,27 @@ void tst_QImageWriter::readWriteNonDestructive_data() { QTest::addColumn<QImage::Format>("format"); QTest::addColumn<QImage::Format>("expectedFormat"); - QTest::newRow("tiff mono") << QImage::Format_Mono << QImage::Format_Mono; - QTest::newRow("tiff indexed") << QImage::Format_Indexed8 << QImage::Format_Indexed8; - QTest::newRow("tiff rgb32") << QImage::Format_ARGB32 << QImage::Format_ARGB32; + QTest::addColumn<bool>("grayscale"); + QTest::newRow("tiff mono") << QImage::Format_Mono << QImage::Format_Mono << false; + QTest::newRow("tiff indexed") << QImage::Format_Indexed8 << QImage::Format_Indexed8 << false; + QTest::newRow("tiff rgb32") << QImage::Format_ARGB32 << QImage::Format_ARGB32 << false; + QTest::newRow("tiff grayscale") << QImage::Format_Indexed8 << QImage::Format_Indexed8 << true; } void tst_QImageWriter::readWriteNonDestructive() { QFETCH(QImage::Format, format); QFETCH(QImage::Format, expectedFormat); + QFETCH(bool, grayscale); QImage image = QImage(prefix + "colorful.bmp").convertToFormat(format); + + if (grayscale) { + QVector<QRgb> colors; + for (int i = 0; i < 256; ++i) + colors << qRgb(i, i, i); + image.setColorTable(colors); + } + QVERIFY(image.save(prefix + "gen-readWriteNonDestructive.tiff")); QImage image2 = QImage(prefix + "gen-readWriteNonDestructive.tiff"); diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp index 77c259c..269afbd 100644 --- a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -92,6 +92,7 @@ private slots: void task252069_rowIntersectsSelection(); void task232634_childrenDeselectionSignal(); void task260134_layoutChangedWithAllSelected(); + void QTBUG5671_layoutChangedWithAllSelected(); private: QAbstractItemModel *model; @@ -2025,24 +2026,24 @@ void tst_QItemSelectionModel::task220420_selectedIndexes() class QtTestTableModel: public QAbstractTableModel { Q_OBJECT - + public: QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) : QAbstractTableModel(parent), row_count(rows), column_count(columns) {} - + int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } bool isEditable(const QModelIndex &) const { return true; } - + QVariant data(const QModelIndex &idx, int role) const { if (role == Qt::DisplayRole || role == Qt::EditRole) return QString("[%1,%2]").arg(idx.row()).arg(idx.column()); return QVariant(); } - + int row_count; int column_count; friend class tst_QItemSelectionModel; @@ -2055,7 +2056,7 @@ void tst_QItemSelectionModel::task240734_layoutChanged() QItemSelectionModel selectionModel(&model); selectionModel.select(model.index(0,0), QItemSelectionModel::Select); QCOMPARE(selectionModel.selectedIndexes().count() , 1); - + emit model.layoutAboutToBeChanged(); model.row_count = 5; emit model.layoutChanged(); @@ -2107,7 +2108,7 @@ void tst_QItemSelectionModel::merge_data() << QItemSelection(model->index(2, 2) , model->index(3, 4)) << int(QItemSelectionModel::Deselect) << QItemSelection(model->index(2, 1) , model->index(3, 1)); - + QItemSelection r1(model->index(2, 1) , model->index(3, 1)); r1.select(model->index(2, 4) , model->index(3, 4)); QTest::newRow("Toggle") @@ -2274,5 +2275,57 @@ void tst_QItemSelectionModel::task260134_layoutChangedWithAllSelected() } +void tst_QItemSelectionModel::QTBUG5671_layoutChangedWithAllSelected() +{ + struct MyFilterModel : public QSortFilterProxyModel + { // Override sort filter proxy to remove even numbered rows. + bool filtering; + virtual bool filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const + { + return !filtering || !( source_row & 1 ); + } + }; + + //same as task260134_layoutChangedWithAllSelected but with a sightly bigger model + + enum { cNumRows=30, cNumCols=20 }; + + QStandardItemModel model(cNumRows, cNumCols); + MyFilterModel proxy; + proxy.filtering = true; + proxy.setSourceModel(&model); + QItemSelectionModel selection(&proxy); + + // Populate the tree view. + for (unsigned int i = 0; i < cNumCols; i++) + model.setHeaderData( i, Qt::Horizontal, QString::fromLatin1("Column %1").arg(i)); + + for (unsigned int r = 0; r < cNumRows; r++) { + for (unsigned int c = 0; c < cNumCols; c++) { + model.setData(model.index(r, c, QModelIndex()), + QString::fromLatin1("r:%1/c:%2").arg(r, c)); + } + } + + + QCOMPARE(model.rowCount(), int(cNumRows)); + QCOMPARE(proxy.rowCount(), int(cNumRows/2)); + + selection.select( QItemSelection(proxy.index(0,0), proxy.index(proxy.rowCount() - 1, proxy.columnCount() - 1)), QItemSelectionModel::Select); + + QList<QPersistentModelIndex> indexList; + foreach(const QModelIndex &id, selection.selectedIndexes()) + indexList << id; + + proxy.filtering = false; + proxy.invalidate(); + QCOMPARE(proxy.rowCount(), int(cNumRows)); + + //let's check the selection hasn't changed + QCOMPARE(selection.selectedIndexes().count(), indexList.count()); + foreach(QPersistentModelIndex index, indexList) + QVERIFY(selection.isSelected(index)); +} + QTEST_MAIN(tst_QItemSelectionModel) #include "tst_qitemselectionmodel.moc" diff --git a/tests/auto/qlabel/tst_qlabel.cpp b/tests/auto/qlabel/tst_qlabel.cpp index 9d957a5..6b7e106 100644 --- a/tests/auto/qlabel/tst_qlabel.cpp +++ b/tests/auto/qlabel/tst_qlabel.cpp @@ -51,6 +51,7 @@ #include <qmovie.h> #include <qpicture.h> #include <qmessagebox.h> +#include <private/qlabel_p.h> //TESTED_CLASS= //TESTED_FILES= @@ -116,6 +117,9 @@ private slots: void unicodeText_data(); void unicodeText(); + void mnemonic_data(); + void mnemonic(); + private: QLabel *testWidget; QPointer<Widget> test_box; @@ -224,6 +228,7 @@ void tst_QLabel::setBuddy() QVERIFY( !test_edit->hasFocus() ); QTest::keyClick( test_box, 't', Qt::AltModifier ); QVERIFY( test_edit->hasFocus() ); + delete test_box; } void tst_QLabel::text() @@ -245,6 +250,7 @@ void tst_QLabel::setText_data() QTest::newRow( QString(prefix + "data1").toLatin1() ) << QString("This is the first line\nThis is the second line") << QString("Courier"); QTest::newRow( QString(prefix + "data2").toLatin1() ) << QString("This is the first line\nThis is the second line\nThis is the third line") << QString("Helvetica"); QTest::newRow( QString(prefix + "data3").toLatin1() ) << QString("This is <b>bold</b> richtext") << QString("Courier"); + QTest::newRow( QString(prefix + "data4").toLatin1() ) << QString("I Have a &shortcut") << QString("Helvetica"); } void tst_QLabel::setText() @@ -509,5 +515,50 @@ void tst_QLabel::unicodeText() testWidget->show(); } +void tst_QLabel::mnemonic_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("expectedDocText"); + QTest::addColumn<QString>("expectedShortcutCursor"); + + QTest::newRow("1") << QString("Normal") << QString("Normal") << QString(); + QTest::newRow("2") << QString("&Simple") << QString("Simple") << QString("S"); + QTest::newRow("3") << QString("Also &simple") << QString("Also simple") << QString("s"); + QTest::newRow("4") << QString("&&With &Double &&") << QString("&With Double &") << QString("D"); + QTest::newRow("5") << QString("Hep&&Hop") << QString("Hep&Hop") << QString(""); + QTest::newRow("6") << QString("Hep&&&Hop") << QString("Hep&Hop") << QString("H"); +} + + +void tst_QLabel::mnemonic() +{ + // this test that the mnemonics appears correctly when the label has a text control. + + QFETCH(QString, text); + QFETCH(QString, expectedDocText); + QFETCH(QString, expectedShortcutCursor); + + QWidget w; + QHBoxLayout *hbox = new QHBoxLayout; + QLabel *lab = new QLabel(text); + //lab->setText("plop &plop"); + QLineEdit *lineedit = new QLineEdit; + lab->setBuddy(lineedit); + lab->setTextInteractionFlags(Qt::TextSelectableByMouse); + + hbox->addWidget(lab); + hbox->addWidget(lineedit); + hbox->addWidget(new QLineEdit); + w.setLayout(hbox); + w.show(); + QTest::qWaitForWindowShown(&w); + + QLabelPrivate *d = static_cast<QLabelPrivate *>(QObjectPrivate::get(lab)); + QVERIFY(d->control); + QCOMPARE(d->control->document()->toPlainText(), expectedDocText); + QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor); +} + + QTEST_MAIN(tst_QLabel) #include "tst_qlabel.moc" diff --git a/tests/auto/qpixmapfilter/tst_qpixmapfilter.cpp b/tests/auto/qpixmapfilter/tst_qpixmapfilter.cpp index a80c787..751c7dc 100644 --- a/tests/auto/qpixmapfilter/tst_qpixmapfilter.cpp +++ b/tests/auto/qpixmapfilter/tst_qpixmapfilter.cpp @@ -407,7 +407,7 @@ void tst_QPixmapFilter::dropShadowBoundingRectFor() filter.setBlurRadius(2); filter.setOffset(QPointF(0,0)); - int delta = 2 * 2; + qreal delta = 2; QCOMPARE(filter.boundingRectFor(rect1), rect1.adjusted(-delta, -delta, delta, delta)); QCOMPARE(filter.boundingRectFor(rect2), rect2.adjusted(-delta, -delta, delta, delta)); QCOMPARE(filter.boundingRectFor(rect3), rect3.adjusted(-delta, -delta, delta, delta)); diff --git a/tests/auto/qtreewidget/tst_qtreewidget.cpp b/tests/auto/qtreewidget/tst_qtreewidget.cpp index 6defd7b..621072c 100644 --- a/tests/auto/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/qtreewidget/tst_qtreewidget.cpp @@ -167,6 +167,7 @@ private slots: void setCurrentItemExpandsParent(); void task239150_editorWidth(); void setTextUpdate(); + void taskQTBUG2844_visualItemRect(); public slots: void itemSelectionChanged(); @@ -601,9 +602,9 @@ void tst_QTreeWidget::setItemHidden() testWidget->scrollToItem(child); QVERIFY(testWidget->visualItemRect(parent).isValid() - && testWidget->viewport()->rect().contains(testWidget->visualItemRect(parent))); + && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(parent))); QVERIFY(testWidget->visualItemRect(child).isValid() - && testWidget->viewport()->rect().contains(testWidget->visualItemRect(child))); + && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child))); QVERIFY(!testWidget->isItemHidden(parent)); QVERIFY(!testWidget->isItemHidden(child)); @@ -611,9 +612,9 @@ void tst_QTreeWidget::setItemHidden() testWidget->setItemHidden(parent, true); QVERIFY(!(testWidget->visualItemRect(parent).isValid() - && testWidget->viewport()->rect().contains(testWidget->visualItemRect(parent)))); + && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(parent)))); QVERIFY(!(testWidget->visualItemRect(child).isValid() - && testWidget->viewport()->rect().contains(testWidget->visualItemRect(child)))); + && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child)))); QVERIFY(testWidget->isItemHidden(parent)); QVERIFY(!testWidget->isItemHidden(child)); @@ -3271,6 +3272,25 @@ void tst_QTreeWidget::setTextUpdate() QTRY_VERIFY(delegate.numPaints > 0); } +void tst_QTreeWidget::taskQTBUG2844_visualItemRect() +{ + CustomTreeWidget tree; + tree.resize(150, 100); + tree.setColumnCount(3); + QTreeWidgetItem item(&tree); + + QRect itemRect = tree.visualItemRect(&item); + + QRect rectCol0 = tree.visualRect(tree.indexFromItem(&item, 0)); + QRect rectCol1 = tree.visualRect(tree.indexFromItem(&item, 1)); + QRect rectCol2 = tree.visualRect(tree.indexFromItem(&item, 2)); + + QCOMPARE(tree.visualItemRect(&item), rectCol0 | rectCol2); + tree.setColumnHidden(2, true); + QCOMPARE(tree.visualItemRect(&item), rectCol0 | rectCol1); +} + + QTEST_MAIN(tst_QTreeWidget) |