summaryrefslogtreecommitdiffstats
path: root/tests/auto/macnativeevents
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-04-30 12:44:35 +0200
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-04-30 12:48:42 +0200
commitcf0ff2f31a3c066d9156efcea63118ae444da430 (patch)
tree8a223b694f033a6c0ae652542e771fdf2e8d5493 /tests/auto/macnativeevents
parent166ee307a5e2984ec0680f4a3774b557a462a2b4 (diff)
Autotest: check that we receive key events on toplevel widgets
Autotest add to test db322e8aec1cae Reviewed-by: denis
Diffstat (limited to 'tests/auto/macnativeevents')
-rw-r--r--tests/auto/macnativeevents/expectedeventlist.cpp43
-rw-r--r--tests/auto/macnativeevents/tst_macnativeevents.cpp23
2 files changed, 58 insertions, 8 deletions
diff --git a/tests/auto/macnativeevents/expectedeventlist.cpp b/tests/auto/macnativeevents/expectedeventlist.cpp
index b1fb9a687b..0679dcbc01 100644
--- a/tests/auto/macnativeevents/expectedeventlist.cpp
+++ b/tests/auto/macnativeevents/expectedeventlist.cpp
@@ -97,6 +97,9 @@ void ExpectedEventList::compareMouseEvents(QEvent *received, QEvent *expected)
{
QMouseEvent *e1 = static_cast<QMouseEvent *>(received);
QMouseEvent *e2 = static_cast<QMouseEvent *>(expected);
+
+ // Do a manual check first to be able to write more sensible
+ // debug output if we know we're going to fail:
if (e1->pos() == e2->pos()
&& (e1->globalPos() == e2->globalPos())
&& (e1->button() == e2->button())
@@ -104,6 +107,9 @@ void ExpectedEventList::compareMouseEvents(QEvent *received, QEvent *expected)
&& (e1->modifiers() == e2->modifiers()))
return; // equal
+ // INVARIANT: The two events are not equal. So we fail. Depending
+ // on whether debug mode is no or not, we let QTest fail. Otherwise
+ // we let the test continue for debugging puposes.
int eventListNr = eventCount - eventList.size();
if (!debug) {
qWarning() << "Expected event" << eventListNr << "differs from received event:";
@@ -119,12 +125,34 @@ void ExpectedEventList::compareMouseEvents(QEvent *received, QEvent *expected)
}
}
-void ExpectedEventList::compareKeyEvents(QEvent *event1, QEvent *event2)
+void ExpectedEventList::compareKeyEvents(QEvent *received, QEvent *expected)
{
- QKeyEvent *e1 = static_cast<QKeyEvent *>(event1);
- QKeyEvent *e2 = static_cast<QKeyEvent *>(event2);
- Q_UNUSED(e1);
- Q_UNUSED(e2);
+ QKeyEvent *e1 = static_cast<QKeyEvent *>(received);
+ QKeyEvent *e2 = static_cast<QKeyEvent *>(expected);
+
+ // Do a manual check first to be able to write more sensible
+ // debug output if we know we're going to fail:
+ if (e1->key() == e2->key()
+ && (e1->modifiers() == e2->modifiers())
+ && (e1->count() == e2->count())
+ && (e1->isAutoRepeat() == e2->isAutoRepeat()))
+ return; // equal
+
+ // INVARIANT: The two events are not equal. So we fail. Depending
+ // on whether debug mode is no or not, we let QTest fail. Otherwise
+ // we let the test continue for debugging puposes.
+ int eventListNr = eventCount - eventList.size();
+ if (!debug) {
+ qWarning() << "Expected event" << eventListNr << "differs from received event:";
+ QCOMPARE(e1->key(), e2->key());
+ QCOMPARE(e1->modifiers(), e2->modifiers());
+ QCOMPARE(e1->count(), e2->count());
+ QCOMPARE(e1->isAutoRepeat(), e2->isAutoRepeat());
+ } else {
+ qWarning() << "*** FAIL *** : Expected event" << eventListNr << "differs from received event:";
+ qWarning() << "Received:" << e1 << e1->key();
+ qWarning() << "Expected:" << e2 << e2->key();
+ }
}
bool ExpectedEventList::eventFilter(QObject *, QEvent *received)
@@ -149,10 +177,9 @@ bool ExpectedEventList::eventFilter(QObject *, QEvent *received)
compareMouseEvents(received, expected);
break;
}
- case QEvent::KeyPress: {
- break;
- }
+ case QEvent::KeyPress:
case QEvent::KeyRelease: {
+ compareKeyEvents(received, expected);
break;
}
case QEvent::Resize: {
diff --git a/tests/auto/macnativeevents/tst_macnativeevents.cpp b/tests/auto/macnativeevents/tst_macnativeevents.cpp
index 70a14f5b2a..ffd0596251 100644
--- a/tests/auto/macnativeevents/tst_macnativeevents.cpp
+++ b/tests/auto/macnativeevents/tst_macnativeevents.cpp
@@ -67,6 +67,7 @@ private slots:
void testDragWindow();
void testMouseEnter();
void testChildDialogInFrontOfModalParent();
+ void testKeyPressOnToplevel();
};
void tst_MacNativeEvents::testMouseMoveLocation()
@@ -307,6 +308,28 @@ void tst_MacNativeEvents::testChildDialogInFrontOfModalParent()
QVERIFY(!child.isVisible());
}
+void tst_MacNativeEvents::testKeyPressOnToplevel()
+{
+ // Check that we receive keyevents for
+ // toplevel widgets. For leagacy reasons, and according to Qt on
+ // other platforms (carbon port + linux), we should get these events
+ // even when the focus policy is set to Qt::NoFocus when there is no
+ // other focus widget on screen:
+ QWidget w;
+ w.show();
+
+ NativeEventList native;
+ native.append(new QNativeKeyEvent(QNativeKeyEvent::Key_A, true, Qt::NoModifier));
+ native.append(new QNativeKeyEvent(QNativeKeyEvent::Key_A, false, Qt::NoModifier));
+
+ ExpectedEventList expected(&w);
+ expected.append(new QKeyEvent(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier));
+ expected.append(new QKeyEvent(QEvent::KeyRelease, Qt::Key_A, Qt::NoModifier));
+
+ native.play();
+ QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!");
+}
+
#include "tst_macnativeevents.moc"
QTEST_MAIN(tst_MacNativeEvents)