summaryrefslogtreecommitdiffstats
path: root/tests/auto/macnativeevents/expectedeventlist.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-04-30 10:44:35 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-04-30 10:48:42 (GMT)
commitcf0ff2f31a3c066d9156efcea63118ae444da430 (patch)
tree8a223b694f033a6c0ae652542e771fdf2e8d5493 /tests/auto/macnativeevents/expectedeventlist.cpp
parent166ee307a5e2984ec0680f4a3774b557a462a2b4 (diff)
downloadQt-cf0ff2f31a3c066d9156efcea63118ae444da430.zip
Qt-cf0ff2f31a3c066d9156efcea63118ae444da430.tar.gz
Qt-cf0ff2f31a3c066d9156efcea63118ae444da430.tar.bz2
Autotest: check that we receive key events on toplevel widgets
Autotest add to test db322e8aec1cae Reviewed-by: denis
Diffstat (limited to 'tests/auto/macnativeevents/expectedeventlist.cpp')
-rw-r--r--tests/auto/macnativeevents/expectedeventlist.cpp43
1 files changed, 35 insertions, 8 deletions
diff --git a/tests/auto/macnativeevents/expectedeventlist.cpp b/tests/auto/macnativeevents/expectedeventlist.cpp
index b1fb9a6..0679dcb 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: {