summaryrefslogtreecommitdiffstats
path: root/tests/auto/qmessagebox/tst_qmessagebox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qmessagebox/tst_qmessagebox.cpp')
-rw-r--r--tests/auto/qmessagebox/tst_qmessagebox.cpp118
1 files changed, 84 insertions, 34 deletions
diff --git a/tests/auto/qmessagebox/tst_qmessagebox.cpp b/tests/auto/qmessagebox/tst_qmessagebox.cpp
index f6ee764..4bc1a28 100644
--- a/tests/auto/qmessagebox/tst_qmessagebox.cpp
+++ b/tests/auto/qmessagebox/tst_qmessagebox.cpp
@@ -55,6 +55,8 @@
#include <QCleanlooksStyle>
#endif
+#include "../../shared/util.h"
+
//TESTED_CLASS=
//TESTED_FILES=
@@ -107,7 +109,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 +138,12 @@ private slots:
void setInformativeText();
void iconPixmap();
+ void init();
+ void initTestCase();
+
private:
int keyToSend;
+ QTimer keySendTimer;
};
tst_QMessageBox::tst_QMessageBox() : keyToSend(-1)
@@ -152,22 +158,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 +177,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 +335,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 +383,28 @@ 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");
+ // 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;
#else
keyToSend = Qt::Key_Escape;
#endif
- QTimer::singleShot(1000, this, SLOT(sendKey()));
+ sendKeySoon();
QMessageBox::aboutQt(0, "Caption");
+#ifdef Q_WS_MAC
+ QTRY_COMPARE(keyToSend, -1);
+#else
+ QCOMPARE(keyToSend, -1);
+#endif
}
// Old message box enums
@@ -392,7 +426,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 +437,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 +514,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 +525,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);
}
@@ -678,8 +726,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())));
}
}
}
@@ -688,22 +735,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()