diff options
author | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-03-26 09:57:17 (GMT) |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-04-07 10:35:57 (GMT) |
commit | d3ae1a9386a85475ba685cfc9a3009f119cad895 (patch) | |
tree | 9f8f08d08fe59433e82ea1df3fd61e7278796152 | |
parent | 61e26e2fcc086112e5e8897a6d1c20c4b9df5f49 (diff) | |
download | Qt-d3ae1a9386a85475ba685cfc9a3009f119cad895.zip Qt-d3ae1a9386a85475ba685cfc9a3009f119cad895.tar.gz Qt-d3ae1a9386a85475ba685cfc9a3009f119cad895.tar.bz2 |
Autotest: added more tests to macnativeevents (2)
-rw-r--r-- | tests/auto/macnativeevents/expectedeventlist.cpp | 31 | ||||
-rw-r--r-- | tests/auto/macnativeevents/expectedeventlist.h | 1 | ||||
-rw-r--r-- | tests/auto/macnativeevents/nativeeventlist.cpp | 8 | ||||
-rw-r--r-- | tests/auto/macnativeevents/nativeeventlist.h | 3 | ||||
-rw-r--r-- | tests/auto/macnativeevents/tst_macnativeevents.cpp | 107 |
5 files changed, 136 insertions, 14 deletions
diff --git a/tests/auto/macnativeevents/expectedeventlist.cpp b/tests/auto/macnativeevents/expectedeventlist.cpp index 48cfe1f..b1fb9a6 100644 --- a/tests/auto/macnativeevents/expectedeventlist.cpp +++ b/tests/auto/macnativeevents/expectedeventlist.cpp @@ -49,6 +49,7 @@ ExpectedEventList::ExpectedEventList(QObject *target) : QObject(target), eventCount(0) { target->installEventFilter(this); + debug = !qgetenv("NATIVEDEBUG").isEmpty(); } ExpectedEventList::~ExpectedEventList() @@ -92,10 +93,10 @@ bool ExpectedEventList::waitForAllEvents(int maxEventWaitTime) return false; } -void ExpectedEventList::compareMouseEvents(QEvent *expected, QEvent *received) +void ExpectedEventList::compareMouseEvents(QEvent *received, QEvent *expected) { - QMouseEvent *e1 = static_cast<QMouseEvent *>(expected); - QMouseEvent *e2 = static_cast<QMouseEvent *>(received); + QMouseEvent *e1 = static_cast<QMouseEvent *>(received); + QMouseEvent *e2 = static_cast<QMouseEvent *>(expected); if (e1->pos() == e2->pos() && (e1->globalPos() == e2->globalPos()) && (e1->button() == e2->button()) @@ -104,14 +105,18 @@ void ExpectedEventList::compareMouseEvents(QEvent *expected, QEvent *received) return; // equal int eventListNr = eventCount - eventList.size(); - qWarning() << "Expected event" << eventListNr << "about to fail:"; - qWarning() << "Expected:" << e1; - qWarning() << "Received:" << e2; - QCOMPARE(e1->pos(), e2->pos()); - QCOMPARE(e1->globalPos(), e2->globalPos()); - QCOMPARE(e1->button(), e2->button()); - QCOMPARE(e1->buttons(), e2->buttons()); - QCOMPARE(e1->modifiers(), e2->modifiers()); + if (!debug) { + qWarning() << "Expected event" << eventListNr << "differs from received event:"; + QCOMPARE(e1->pos(), e2->pos()); + QCOMPARE(e1->globalPos(), e2->globalPos()); + QCOMPARE(e1->button(), e2->button()); + QCOMPARE(e1->buttons(), e2->buttons()); + QCOMPARE(e1->modifiers(), e2->modifiers()); + } else { + qWarning() << "*** FAIL *** : Expected event" << eventListNr << "differs from received event:"; + qWarning() << "Received:" << e1 << e1->globalPos(); + qWarning() << "Expected:" << e2 << e2->globalPos(); + } } void ExpectedEventList::compareKeyEvents(QEvent *event1, QEvent *event2) @@ -124,6 +129,8 @@ void ExpectedEventList::compareKeyEvents(QEvent *event1, QEvent *event2) bool ExpectedEventList::eventFilter(QObject *, QEvent *received) { + if (debug) + qDebug() << received; if (eventList.isEmpty()) return false; @@ -139,7 +146,7 @@ bool ExpectedEventList::eventFilter(QObject *, QEvent *received) case QEvent::NonClientAreaMouseButtonRelease: case QEvent::NonClientAreaMouseButtonDblClick: case QEvent::NonClientAreaMouseMove: { - compareMouseEvents(expected, received); + compareMouseEvents(received, expected); break; } case QEvent::KeyPress: { diff --git a/tests/auto/macnativeevents/expectedeventlist.h b/tests/auto/macnativeevents/expectedeventlist.h index 3bdbb67..bd9f358 100644 --- a/tests/auto/macnativeevents/expectedeventlist.h +++ b/tests/auto/macnativeevents/expectedeventlist.h @@ -51,6 +51,7 @@ class ExpectedEventList : public QObject { QList<QEvent *> eventList; QBasicTimer timer; + bool debug; int eventCount; void timerEvent(QTimerEvent *); diff --git a/tests/auto/macnativeevents/nativeeventlist.cpp b/tests/auto/macnativeevents/nativeeventlist.cpp index 614e9d0..d5d7b95 100644 --- a/tests/auto/macnativeevents/nativeeventlist.cpp +++ b/tests/auto/macnativeevents/nativeeventlist.cpp @@ -47,6 +47,9 @@ NativeEventList::NativeEventList(int defaultWaitMs) , wait(false) , defaultWaitMs(defaultWaitMs) { + QString multiplier = qgetenv("NATIVEDEBUG"); + if (!multiplier.isEmpty()) + setTimeMultiplier(multiplier.toFloat()); } NativeEventList::~NativeEventList() @@ -105,3 +108,8 @@ void NativeEventList::stop() QAbstractEventDispatcher::instance()->interrupt(); } +void NativeEventList::setTimeMultiplier(float multiplier) +{ + playbackMultiplier = multiplier; +} + diff --git a/tests/auto/macnativeevents/nativeeventlist.h b/tests/auto/macnativeevents/nativeeventlist.h index 886ab78..688665d 100644 --- a/tests/auto/macnativeevents/nativeeventlist.h +++ b/tests/auto/macnativeevents/nativeeventlist.h @@ -61,7 +61,7 @@ class NativeEventList : public QObject void play(Playback playback = WaitUntilFinished); void stop(); - float playbackMultiplier; + void setTimeMultiplier(float multiplier); signals: void done(); @@ -73,6 +73,7 @@ private: void waitNextEvent(); QList<QPair<int, QNativeEvent *> > eventList; + float playbackMultiplier; int currIndex; bool wait; int defaultWaitMs; diff --git a/tests/auto/macnativeevents/tst_macnativeevents.cpp b/tests/auto/macnativeevents/tst_macnativeevents.cpp index c6da3ff..08ab9e6 100644 --- a/tests/auto/macnativeevents/tst_macnativeevents.cpp +++ b/tests/auto/macnativeevents/tst_macnativeevents.cpp @@ -61,6 +61,10 @@ private slots: void testMouseLeftDoubleClick(); void stressTestMouseLeftDoubleClick(); void testMouseDragInside(); + void testMouseDragOutside(); + void testMouseDragToNonClientArea(); + void testDragWindow(); + void testMouseEnter(); }; void tst_MacNativeEvents::testMouseMoveLocation() @@ -77,7 +81,7 @@ void tst_MacNativeEvents::testMouseMoveLocation() expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(p), p, Qt::NoButton, Qt::NoButton, Qt::NoModifier)); native.play(); - QVERIFY2(expected.waitForAllEvents(500), "the test did not receive all expected events!"); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); } void tst_MacNativeEvents::testPushButtonPressRelease() @@ -178,6 +182,107 @@ void tst_MacNativeEvents::testMouseDragInside() QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); } +void tst_MacNativeEvents::testMouseDragOutside() +{ + // Check that if we drag the mouse from inside the + // widget, and release it outside, we still get mouse move + // and release events when the mouse is outside the widget. + QWidget w; + w.show(); + QPoint inside1 = w.geometry().center(); + QPoint inside2 = inside1 - QPoint(10, 0); + QPoint outside1 = w.geometry().topLeft() - QPoint(50, 0); + QPoint outside2 = outside1 - QPoint(10, 0); + + NativeEventList native; + native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(inside2, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(outside1, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(outside2, Qt::LeftButton, 0, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::MouseButtonPress, w.mapFromGlobal(inside1), inside1, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(inside2), inside2, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(outside1), outside1, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(outside2), outside2, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::testMouseDragToNonClientArea() +{ + // Check that if we drag the mouse from inside the + // widget, and release it on the title bar, we still get mouse move + // and release events when the mouse is on the title bar + QWidget w; + w.show(); + QPoint inside1 = w.geometry().center(); + QPoint inside2 = inside1 - QPoint(10, 0); + QPoint titlebar1 = w.geometry().topLeft() - QPoint(-100, 10); + QPoint titlebar2 = titlebar1 - QPoint(10, 0); + + NativeEventList native; + native.append(new QNativeMouseButtonEvent(inside1, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(inside2, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(titlebar1, Qt::LeftButton, Qt::NoModifier)); + native.append(new QNativeMouseButtonEvent(titlebar2, Qt::LeftButton, 0, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::MouseButtonPress, w.mapFromGlobal(inside1), inside1, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(inside2), inside2, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(titlebar1), titlebar1, Qt::NoButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::MouseButtonRelease, w.mapFromGlobal(titlebar2), titlebar2, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::testDragWindow() +{ + // Check that if we drag the mouse from inside the + // widgets title bar, we get a move event on the window + QWidget w; + w.show(); + QPoint titlebar = w.geometry().topLeft() - QPoint(-100, 10); + QPoint moveTo = titlebar + QPoint(100, 0); + + NativeEventList native; + native.append(new QNativeMouseButtonEvent(titlebar, Qt::LeftButton, 1, Qt::NoModifier)); + native.append(new QNativeMouseDragEvent(moveTo, Qt::LeftButton, Qt::NoModifier)); + native.append(500, new QNativeMouseButtonEvent(moveTo, Qt::LeftButton, 0, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QMouseEvent(QEvent::NonClientAreaMouseButtonPress, w.mapFromGlobal(titlebar), titlebar, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier)); + expected.append(new QMouseEvent(QEvent::NonClientAreaMouseButtonRelease, w.mapFromGlobal(titlebar), moveTo, Qt::LeftButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + +void tst_MacNativeEvents::testMouseEnter() +{ + // When a mouse enters a widget, both a mouse enter events and a + // mouse move event should be sendt. Lets test this: + QWidget w; + w.setMouseTracking(true); + w.show(); + QPoint outside = w.geometry().topLeft() - QPoint(50, 0); + QPoint inside = w.geometry().center(); + + NativeEventList native; + native.append(new QNativeMouseMoveEvent(outside, Qt::NoModifier)); + native.append(new QNativeMouseMoveEvent(inside, Qt::NoModifier)); + + ExpectedEventList expected(&w); + expected.append(new QEvent(QEvent::Enter)); + expected.append(new QMouseEvent(QEvent::MouseMove, w.mapFromGlobal(inside), inside, Qt::NoButton, Qt::NoButton, Qt::NoModifier)); + + native.play(); + QVERIFY2(expected.waitForAllEvents(), "the test did not receive all expected events!"); +} + + #include "tst_macnativeevents.moc" QTEST_MAIN(tst_MacNativeEvents) |