diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2011-06-24 15:26:20 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2011-06-27 11:12:24 (GMT) |
commit | 2ff9617cd6093a758dddea5ce50d1efd6e98ded8 (patch) | |
tree | 51e57e6ff6a25915b67cbd99b25e82be78b6e9a4 /tests/auto/qeventloop | |
parent | 9fc7e0ee3ff00c04f9301cbb45de09851cb55fa4 (diff) | |
download | Qt-2ff9617cd6093a758dddea5ce50d1efd6e98ded8.zip Qt-2ff9617cd6093a758dddea5ce50d1efd6e98ded8.tar.gz Qt-2ff9617cd6093a758dddea5ce50d1efd6e98ded8.tar.bz2 |
Fix event delevery order
Some functions (such as QObject::moveToThread) did not keep
the event ordered by priority.
And because qUpperBound is used to add events, that mean new
events would not be inserted in order.
Task-number: QTBUG19637
Change-Id: I38eb9addb1cdd45b8566e000361ac6e5f1f2c2b8
Reviewed-on: http://codereview.qt.nokia.com/733
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
(cherry picked from commit 7eeabcf70db658bca847498f618a94a375c95f5f)
Diffstat (limited to 'tests/auto/qeventloop')
-rw-r--r-- | tests/auto/qeventloop/tst_qeventloop.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/auto/qeventloop/tst_qeventloop.cpp b/tests/auto/qeventloop/tst_qeventloop.cpp index 7a8c441..bcc205e 100644 --- a/tests/auto/qeventloop/tst_qeventloop.cpp +++ b/tests/auto/qeventloop/tst_qeventloop.cpp @@ -59,6 +59,8 @@ #include <unistd.h> #endif +#include "../../shared/util.h" + //TESTED_CLASS= //TESTED_FILES= @@ -208,6 +210,7 @@ private slots: void quit(); void processEventsExcludeSocket(); void processEventsExcludeTimers(); + void deliverInDefinedOrder_QTBUG19637(); // keep this test last: void nestedLoops(); @@ -842,5 +845,77 @@ void tst_QEventLoop::symbianNestedActiveSchedulerLoop() #endif } +Q_DECLARE_METATYPE(QThread*) + +namespace DeliverInDefinedOrder_QTBUG19637 { + enum { NbThread = 3, NbObject = 500, NbEventQueue = 5, NbEvent = 50 }; + + struct CustomEvent : public QEvent { + CustomEvent(int q, int v) : QEvent(Type(User + q)), value(v) {} + int value; + }; + + struct Object : public QObject { + Q_OBJECT + public: + Object() : count(0) { + for (int i = 0; i < NbEventQueue; i++) + lastReceived[i] = -1; + } + int lastReceived[NbEventQueue]; + int count; + virtual void customEvent(QEvent* e) { + QVERIFY(e->type() >= QEvent::User); + QVERIFY(e->type() < QEvent::User + 5); + uint idx = e->type() - QEvent::User; + int value = static_cast<CustomEvent *>(e)->value; + QVERIFY(lastReceived[idx] < value); + lastReceived[idx] = value; + count++; + } + + public slots: + void moveToThread(QThread *t) { + QObject::moveToThread(t); + } + }; + +} + +void tst_QEventLoop::deliverInDefinedOrder_QTBUG19637() +{ + using namespace DeliverInDefinedOrder_QTBUG19637; + qMetaTypeId<QThread*>(); + QThread threads[NbThread]; + Object objects[NbObject]; + for (int t = 0; t < NbThread; t++) { + threads[t].start(); + } + + int event = 0; + + for (int o = 0; o < NbObject; o++) { + objects[o].moveToThread(&threads[o % NbThread]); + for (int e = 0; e < NbEvent; e++) { + int q = e % NbEventQueue; + QCoreApplication::postEvent(&objects[o], new CustomEvent(q, ++event) , q); + if (e % 7) + QMetaObject::invokeMethod(&objects[o], "moveToThread", Qt::QueuedConnection, Q_ARG(QThread*, &threads[(e+o)%NbThread])); + } + } + + QTest::qWait(30); + for (int o = 0; o < NbObject; o++) { + QTRY_COMPARE(objects[o].count, int(NbEvent)); + } + + for (int t = 0; t < NbThread; t++) { + threads[t].quit(); + threads[t].wait(); + } + +} + + QTEST_MAIN(tst_QEventLoop) #include "tst_qeventloop.moc" |