From 482e924154a57cf2e37d8224d3c677635aa56317 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Tue, 21 Dec 2010 12:55:49 +0100 Subject: QMessageBox wrong Show/Hide Details button label On LanguageChange event QMessageBox switches Show/Hide Details button label Customer portal case id: 00217646 Merge-request: 973 Reviewed-by: Olivier Goffart --- src/gui/dialogs/qmessagebox.cpp | 2 +- tests/auto/qmessagebox/tst_qmessagebox.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/gui/dialogs/qmessagebox.cpp b/src/gui/dialogs/qmessagebox.cpp index 224a176..af9616d 100644 --- a/src/gui/dialogs/qmessagebox.cpp +++ b/src/gui/dialogs/qmessagebox.cpp @@ -1925,7 +1925,7 @@ void QMessageBoxPrivate::retranslateStrings() { #ifndef QT_NO_TEXTEDIT if (detailsButton) - detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel); + detailsButton->setLabel(detailsText->isHidden() ? ShowLabel : HideLabel); #endif } diff --git a/tests/auto/qmessagebox/tst_qmessagebox.cpp b/tests/auto/qmessagebox/tst_qmessagebox.cpp index d4ca064..54d199c 100644 --- a/tests/auto/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/qmessagebox/tst_qmessagebox.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) #include #endif @@ -119,6 +120,7 @@ private slots: void statics(); void about(); void detailsText(); + void detailsButtonText(); void shortcut(); @@ -661,6 +663,26 @@ void tst_QMessageBox::detailsText() QCOMPARE(box.detailedText(), text); } +void tst_QMessageBox::detailsButtonText() +{ + QMessageBox box; + box.setDetailedText("bla"); + box.open(); + QApplication::postEvent(&box, new QEvent(QEvent::LanguageChange)); + QApplication::processEvents(); + QDialogButtonBox* bb = box.findChild("qt_msgbox_buttonbox"); + QVERIFY(bb); //get the detail button + + QList list = bb->buttons(); + QAbstractButton* btn = NULL; + foreach(btn, list) { + if (btn && (btn->inherits("QPushButton"))) { + if(btn->text() != QMessageBox::tr("OK") && btn->text() != QMessageBox::tr("Show Details...")) + QFAIL("Incorrect messagebox button text!"); + } + } +} + void tst_QMessageBox::incorrectDefaultButton() { keyToSend = Qt::Key_Escape; -- cgit v0.12 From 6210542b3fb2b577512f5e2970f14303d1e5f21a Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 22 Dec 2010 14:04:26 +0100 Subject: tst_qmessagebox: add debug to know why it fails --- tests/auto/qmessagebox/tst_qmessagebox.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/qmessagebox/tst_qmessagebox.cpp b/tests/auto/qmessagebox/tst_qmessagebox.cpp index 54d199c..f6ee764 100644 --- a/tests/auto/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/qmessagebox/tst_qmessagebox.cpp @@ -677,8 +677,10 @@ void tst_QMessageBox::detailsButtonText() QAbstractButton* btn = NULL; foreach(btn, list) { if (btn && (btn->inherits("QPushButton"))) { - if(btn->text() != QMessageBox::tr("OK") && btn->text() != QMessageBox::tr("Show Details...")) + if (btn->text() != QMessageBox::tr("OK") && btn->text() != QMessageBox::tr("Show Details...")) { + qDebug() << btn->text(); QFAIL("Incorrect messagebox button text!"); + } } } } -- cgit v0.12 From a562fd2d201e3b618ed99a316275f20385cc5c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 16 Dec 2010 14:45:21 +0100 Subject: Added int overloads to QPoint operator* and operator*=. For increased performance to avoid having to convert to qreal and back. Separating the qreal overload into float and double overloads is also necessary to avoid compiler errors about ambiguous overloads. Task-number: QTBUG-15872 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/tools/qpoint.cpp | 63 +++++++++++++++++++++++++++++++++++++++++--- src/corelib/tools/qpoint.h | 38 +++++++++++++++++++++----- 2 files changed, 92 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp index c297709..592a83d 100644 --- a/src/corelib/tools/qpoint.cpp +++ b/src/corelib/tools/qpoint.cpp @@ -187,7 +187,19 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QPoint &QPoint::operator*=(qreal factor) + \fn QPoint &QPoint::operator*=(float factor) + + Multiplies this point's coordinates by the given \a factor, and + returns a reference to this point. + + Note that the result is rounded to the nearest integer as points are held as + integers. Use QPointF for floating point accuracy. + + \sa operator/=() +*/ + +/*! + \fn QPoint &QPoint::operator*=(double factor) Multiplies this point's coordinates by the given \a factor, and returns a reference to this point. For example: @@ -200,6 +212,14 @@ QT_BEGIN_NAMESPACE \sa operator/=() */ +/*! + \fn QPoint &QPoint::operator*=(int factor) + + Multiplies this point's coordinates by the given \a factor, and + returns a reference to this point. + + \sa operator/=() +*/ /*! \fn bool operator==(const QPoint &p1, const QPoint &p2) @@ -237,7 +257,7 @@ QT_BEGIN_NAMESPACE */ /*! - \fn const QPoint operator*(const QPoint &point, qreal factor) + \fn const QPoint operator*(const QPoint &point, float factor) \relates QPoint Returns a copy of the given \a point multiplied by the given \a factor. @@ -249,7 +269,44 @@ QT_BEGIN_NAMESPACE */ /*! - \fn const QPoint operator*(qreal factor, const QPoint &point) + \fn const QPoint operator*(const QPoint &point, double factor) + \relates QPoint + + Returns a copy of the given \a point multiplied by the given \a factor. + + Note that the result is rounded to the nearest integer as points + are held as integers. Use QPointF for floating point accuracy. + + \sa QPoint::operator*=() +*/ + +/*! + \fn const QPoint operator*(const QPoint &point, int factor) + \relates QPoint + + Returns a copy of the given \a point multiplied by the given \a factor. + + \sa QPoint::operator*=() +*/ + +/*! + \fn const QPoint operator*(float factor, const QPoint &point) + \overload + \relates QPoint + + Returns a copy of the given \a point multiplied by the given \a factor. +*/ + +/*! + \fn const QPoint operator*(double factor, const QPoint &point) + \overload + \relates QPoint + + Returns a copy of the given \a point multiplied by the given \a factor. +*/ + +/*! + \fn const QPoint operator*(int factor, const QPoint &point) \overload \relates QPoint diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h index 79a7dd8..e57b0ed 100644 --- a/src/corelib/tools/qpoint.h +++ b/src/corelib/tools/qpoint.h @@ -70,15 +70,23 @@ public: QPoint &operator+=(const QPoint &p); QPoint &operator-=(const QPoint &p); - QPoint &operator*=(qreal c); + + QPoint &operator*=(float c); + QPoint &operator*=(double c); + QPoint &operator*=(int c); + QPoint &operator/=(qreal c); friend inline bool operator==(const QPoint &, const QPoint &); friend inline bool operator!=(const QPoint &, const QPoint &); friend inline const QPoint operator+(const QPoint &, const QPoint &); friend inline const QPoint operator-(const QPoint &, const QPoint &); - friend inline const QPoint operator*(const QPoint &, qreal); - friend inline const QPoint operator*(qreal, const QPoint &); + friend inline const QPoint operator*(const QPoint &, float); + friend inline const QPoint operator*(float, const QPoint &); + friend inline const QPoint operator*(const QPoint &, double); + friend inline const QPoint operator*(double, const QPoint &); + friend inline const QPoint operator*(const QPoint &, int); + friend inline const QPoint operator*(int, const QPoint &); friend inline const QPoint operator-(const QPoint &); friend inline const QPoint operator/(const QPoint &, qreal); @@ -141,9 +149,15 @@ inline QPoint &QPoint::operator+=(const QPoint &p) inline QPoint &QPoint::operator-=(const QPoint &p) { xp-=p.xp; yp-=p.yp; return *this; } -inline QPoint &QPoint::operator*=(qreal c) +inline QPoint &QPoint::operator*=(float c) +{ xp = qRound(xp*c); yp = qRound(yp*c); return *this; } + +inline QPoint &QPoint::operator*=(double c) { xp = qRound(xp*c); yp = qRound(yp*c); return *this; } +inline QPoint &QPoint::operator*=(int c) +{ xp = xp*c; yp = yp*c; return *this; } + inline bool operator==(const QPoint &p1, const QPoint &p2) { return p1.xp == p2.xp && p1.yp == p2.yp; } @@ -156,12 +170,24 @@ inline const QPoint operator+(const QPoint &p1, const QPoint &p2) inline const QPoint operator-(const QPoint &p1, const QPoint &p2) { return QPoint(p1.xp-p2.xp, p1.yp-p2.yp); } -inline const QPoint operator*(const QPoint &p, qreal c) +inline const QPoint operator*(const QPoint &p, float c) { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); } -inline const QPoint operator*(qreal c, const QPoint &p) +inline const QPoint operator*(const QPoint &p, double c) { return QPoint(qRound(p.xp*c), qRound(p.yp*c)); } +inline const QPoint operator*(const QPoint &p, int c) +{ return QPoint(p.xp*c, p.yp*c); } + +inline const QPoint operator*(float c, const QPoint &p) +{ return QPoint(qRound(p.xp*c), qRound(p.yp*c)); } + +inline const QPoint operator*(double c, const QPoint &p) +{ return QPoint(qRound(p.xp*c), qRound(p.yp*c)); } + +inline const QPoint operator*(int c, const QPoint &p) +{ return QPoint(p.xp*c, p.yp*c); } + inline const QPoint operator-(const QPoint &p) { return QPoint(-p.xp, -p.yp); } -- cgit v0.12 From ce432e1799111cbed492e46bb62d8dfb40585a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 17 Dec 2010 12:46:44 +0100 Subject: Prevented infinite loop in QMoviePrivate::next(). If we're unable to read the first frame, we shouldn't return an end marker, as that will cause QMoviePrivate::next() to recurse indefinitely when the playCounter is set to -1 (infinite). Reviewed-by: Olivier Goffart --- src/gui/image/qmovie.cpp | 6 +++++- tests/auto/qmovie/animations/corrupt.gif | Bin 0 -> 847 bytes tests/auto/qmovie/qmovie.pro | 1 + tests/auto/qmovie/resources.qrc | 5 +++++ tests/auto/qmovie/tst_qmovie.cpp | 13 +++++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qmovie/animations/corrupt.gif create mode 100644 tests/auto/qmovie/resources.qrc diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp index 911a2b5..eb139fa 100644 --- a/src/gui/image/qmovie.cpp +++ b/src/gui/image/qmovie.cpp @@ -381,10 +381,14 @@ QFrameInfo QMoviePrivate::infoForFrame(int frameNumber) QPixmap aPixmap = QPixmap::fromImage(anImage); int aDelay = reader->nextImageDelay(); return QFrameInfo(aPixmap, aDelay); - } else { + } else if (frameNumber != 0) { // We've read all frames now. Return an end marker haveReadAll = true; return QFrameInfo::endMarker(); + } else { + // No readable frames + haveReadAll = true; + return QFrameInfo(); } } diff --git a/tests/auto/qmovie/animations/corrupt.gif b/tests/auto/qmovie/animations/corrupt.gif new file mode 100644 index 0000000..c1545eb Binary files /dev/null and b/tests/auto/qmovie/animations/corrupt.gif differ diff --git a/tests/auto/qmovie/qmovie.pro b/tests/auto/qmovie/qmovie.pro index 6973955..855eb9e 100644 --- a/tests/auto/qmovie/qmovie.pro +++ b/tests/auto/qmovie/qmovie.pro @@ -12,6 +12,7 @@ wince*: { DEPLOYMENT += addFiles } +RESOURCES += resources.qrc symbian: { addFiles.files = animations\\* diff --git a/tests/auto/qmovie/resources.qrc b/tests/auto/qmovie/resources.qrc new file mode 100644 index 0000000..ce459a0 --- /dev/null +++ b/tests/auto/qmovie/resources.qrc @@ -0,0 +1,5 @@ + + + animations/corrupt.gif + + diff --git a/tests/auto/qmovie/tst_qmovie.cpp b/tests/auto/qmovie/tst_qmovie.cpp index 80a551b..d43d4cb 100644 --- a/tests/auto/qmovie/tst_qmovie.cpp +++ b/tests/auto/qmovie/tst_qmovie.cpp @@ -72,6 +72,7 @@ private slots: void jumpToFrame_data(); void jumpToFrame(); void changeMovieFile(); + void infiniteLoop(); }; // Testing get/set functions @@ -208,5 +209,17 @@ void tst_QMovie::changeMovieFile() QVERIFY(movie.currentFrameNumber() == -1); } +void tst_QMovie::infiniteLoop() +{ + QLabel label; + label.show(); + QMovie *movie = new QMovie(QLatin1String(":animations/corrupt.gif"), QByteArray(), &label); + label.setMovie(movie); + movie->start(); + + QTestEventLoop::instance().enterLoop(1); + QTestEventLoop::instance().timeout(); +} + QTEST_MAIN(tst_QMovie) #include "tst_qmovie.moc" -- cgit v0.12 From a31d271bdd4594ea455736a0000cd3493b0efc93 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Thu, 30 Dec 2010 10:36:06 +1000 Subject: tst_qmessagebox: simulate key events more robustly Don't use QTimer::singleShot because it provides no method of cancelling the event when failures occur. Always verify that the simulated key event is consumed as expected. --- tests/auto/qmessagebox/tst_qmessagebox.cpp | 103 ++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 32 deletions(-) diff --git a/tests/auto/qmessagebox/tst_qmessagebox.cpp b/tests/auto/qmessagebox/tst_qmessagebox.cpp index f6ee764..a39d458 100644 --- a/tests/auto/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/qmessagebox/tst_qmessagebox.cpp @@ -107,7 +107,7 @@ class tst_QMessageBox : public QObject public: tst_QMessageBox(); int exec(QMessageBox *msgBox, int key = -1); - int sendReturn(); + void sendKeySoon(); public slots: void sendKey(); @@ -136,8 +136,12 @@ private slots: void setInformativeText(); void iconPixmap(); + void init(); + void initTestCase(); + private: int keyToSend; + QTimer keySendTimer; }; tst_QMessageBox::tst_QMessageBox() : keyToSend(-1) @@ -152,22 +156,16 @@ int tst_QMessageBox::exec(QMessageBox *msgBox, int key) QTimer::singleShot(1000, msgBox, SLOT(close())); } else { keyToSend = key; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); } return msgBox->exec(); } -int tst_QMessageBox::sendReturn() -{ - keyToSend = Qt::Key_Return; - QTimer::singleShot(1000, this, SLOT(sendKey())); - return 0; -} - void tst_QMessageBox::sendKey() { if (keyToSend == -2) { QApplication::activeModalWidget()->close(); + keyToSend = -1; return; } if (keyToSend == -1) @@ -177,6 +175,24 @@ void tst_QMessageBox::sendKey() keyToSend = -1; } +void tst_QMessageBox::sendKeySoon() +{ + keySendTimer.start(); +} + +void tst_QMessageBox::init() +{ + // if there is any pending key send from the last test, cancel it. + keySendTimer.stop(); +} + +void tst_QMessageBox::initTestCase() +{ + keySendTimer.setInterval(1000); + keySendTimer.setSingleShot(true); + QVERIFY(QObject::connect(&keySendTimer, SIGNAL(timeout()), this, SLOT(sendKey()))); +} + void tst_QMessageBox::sanityTest() { QMessageBox msgBox; @@ -317,32 +333,36 @@ void tst_QMessageBox::statics() for (int i = 0; i < 4; i++) { keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); QMessageBox::StandardButton sb = (*statics[i])(0, "caption", "text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel, QMessageBox::NoButton); QCOMPARE(sb, QMessageBox::Cancel); + QCOMPARE(keyToSend, -1); keyToSend = -2; // close() - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); sb = (*statics[i])(0, "caption", "text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel, QMessageBox::NoButton); QCOMPARE(sb, QMessageBox::Cancel); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); sb = (*statics[i])(0, "caption", "text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help, QMessageBox::Yes); QCOMPARE(sb, QMessageBox::Yes); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); sb = (*statics[i])(0, "caption", "text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help, QMessageBox::No); QCOMPARE(sb, QMessageBox::No); + QCOMPARE(keyToSend, -1); } } @@ -361,16 +381,18 @@ void tst_QMessageBox::shortcut() void tst_QMessageBox::about() { keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); QMessageBox::about(0, "Caption", "This is an auto test"); + QCOMPARE(keyToSend, -1); #if !defined(Q_OS_WINCE) keyToSend = Qt::Key_Enter; #else keyToSend = Qt::Key_Escape; #endif - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); QMessageBox::aboutQt(0, "Caption"); + QCOMPARE(keyToSend, -1); } // Old message box enums @@ -392,7 +414,7 @@ void tst_QMessageBox::staticSourceCompat() // source compat tests for < 4.2 keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes, QMessageBox::No); int expectedButton = int(QMessageBox::Yes); #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) @@ -403,43 +425,51 @@ void tst_QMessageBox::staticSourceCompat() expectedButton = int(QMessageBox::No); #endif QCOMPARE(ret, expectedButton); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No); QCOMPARE(ret, int(QMessageBox::Yes)); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default); QCOMPARE(ret, int(QMessageBox::No)); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape); QCOMPARE(ret, int(QMessageBox::Yes)); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default); QCOMPARE(ret, int(QMessageBox::No)); + QCOMPARE(keyToSend, -1); // the button text versions keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 1); QCOMPARE(ret, 1); + QCOMPARE(keyToSend, -1); if (0) { // dont run these tests since the dialog wont close! keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 1); QCOMPARE(ret, -1); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 0, 1); QCOMPARE(ret, 1); + QCOMPARE(keyToSend, -1); } } @@ -472,7 +502,7 @@ void tst_QMessageBox::staticBinaryCompat() // binary compat tests for < 4.2 keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", Old_Yes, Old_No, 0); int expectedButton = int(Old_Yes); #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) @@ -483,33 +513,39 @@ void tst_QMessageBox::staticBinaryCompat() expectedButton = int(Old_No); #endif QCOMPARE(ret, expectedButton); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", Old_Yes | Old_Escape, Old_No, 0); QCOMPARE(ret, int(Old_Yes)); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Enter; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", Old_Yes | Old_Default, Old_No, 0); QCOMPARE(ret, int(Old_Yes)); + QCOMPARE(keyToSend, -1); #if 0 keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", Old_Yes, Old_No | Old_Default, 0); QCOMPARE(ret, -1); + QCOMPARE(keyToSend, -1); #endif keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", Old_Yes | Old_Escape, Old_No | Old_Default, 0); QCOMPARE(ret, Old_Yes); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); ret = QMessageBox::information(0, "title", "text", Old_Yes | Old_Default, Old_No | Old_Escape, 0); QCOMPARE(ret, Old_No); + QCOMPARE(keyToSend, -1); } @@ -688,22 +724,25 @@ void tst_QMessageBox::detailsButtonText() void tst_QMessageBox::incorrectDefaultButton() { keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); //Do not crash here QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); QMessageBox::question( 0, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save ); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); QMessageBox::question( 0, "", "I've been hit!",QFlag(QMessageBox::Ok | QMessageBox::Cancel),QMessageBox::Save ); + QCOMPARE(keyToSend, -1); keyToSend = Qt::Key_Escape; - QTimer::singleShot(1000, this, SLOT(sendKey())); + sendKeySoon(); QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); //do not crash here -> call old function of QMessageBox in this case QMessageBox::question( 0, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save | QMessageBox::Cancel,QMessageBox::Ok); + QCOMPARE(keyToSend, -1); } void tst_QMessageBox::updateSize() -- cgit v0.12 From 6981c17455f949fd4fccbaf1bd42ab48f95d4212 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Thu, 30 Dec 2010 10:46:05 +1000 Subject: tst_qmessagebox: make the failure message better for detailsButtonText --- tests/auto/qmessagebox/tst_qmessagebox.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/auto/qmessagebox/tst_qmessagebox.cpp b/tests/auto/qmessagebox/tst_qmessagebox.cpp index a39d458..9e497fa 100644 --- a/tests/auto/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/qmessagebox/tst_qmessagebox.cpp @@ -714,8 +714,7 @@ void tst_QMessageBox::detailsButtonText() foreach(btn, list) { if (btn && (btn->inherits("QPushButton"))) { if (btn->text() != QMessageBox::tr("OK") && btn->text() != QMessageBox::tr("Show Details...")) { - qDebug() << btn->text(); - QFAIL("Incorrect messagebox button text!"); + QFAIL(qPrintable(QString("Unexpected messagebox button text: %1").arg(btn->text()))); } } } -- cgit v0.12 From 89866e1112bba004847573c5494aa3b6ec75049f Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Thu, 30 Dec 2010 15:25:38 +1000 Subject: tst_qmessagebox: fix `about' test on mac QMessageBox::about and aboutQt are modeless on Mac (only). This means that if we simulate key events, we need to explicitly run the event loop until they are consumed. Prior to a31d271bdd4594ea455736a0000cd3493b0efc93, this buggy test was causing detailsButtonText to fail. --- tests/auto/qmessagebox/tst_qmessagebox.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/auto/qmessagebox/tst_qmessagebox.cpp b/tests/auto/qmessagebox/tst_qmessagebox.cpp index 9e497fa..4bc1a28 100644 --- a/tests/auto/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/qmessagebox/tst_qmessagebox.cpp @@ -55,6 +55,8 @@ #include #endif +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES= @@ -383,7 +385,13 @@ void tst_QMessageBox::about() keyToSend = Qt::Key_Escape; sendKeySoon(); QMessageBox::about(0, "Caption", "This is an auto test"); + // On Mac, about and aboutQt are not modal, so we need to + // explicitly run the event loop +#ifdef Q_WS_MAC + QTRY_COMPARE(keyToSend, -1); +#else QCOMPARE(keyToSend, -1); +#endif #if !defined(Q_OS_WINCE) keyToSend = Qt::Key_Enter; @@ -392,7 +400,11 @@ void tst_QMessageBox::about() #endif sendKeySoon(); QMessageBox::aboutQt(0, "Caption"); +#ifdef Q_WS_MAC + QTRY_COMPARE(keyToSend, -1); +#else QCOMPARE(keyToSend, -1); +#endif } // Old message box enums -- cgit v0.12