tst_qeventdispatcher: port to QDeadlineTimer
Easier logic for these use-cases. Change-Id: I97a18c45d9bd8cfcfee5d379d271366276d5a435 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
6d4385b697
commit
909893344c
@ -18,6 +18,10 @@ static bool glibDisabled = []() {
|
|||||||
}();
|
}();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PreciseTimerInterval = 10,
|
PreciseTimerInterval = 10,
|
||||||
CoarseTimerInterval = 200,
|
CoarseTimerInterval = 200,
|
||||||
@ -87,11 +91,9 @@ bool tst_QEventDispatcher::event(QEvent *e)
|
|||||||
// drain the system event queue after the test starts to avoid destabilizing the test functions
|
// drain the system event queue after the test starts to avoid destabilizing the test functions
|
||||||
void tst_QEventDispatcher::initTestCase()
|
void tst_QEventDispatcher::initTestCase()
|
||||||
{
|
{
|
||||||
QElapsedTimer elapsedTimer;
|
QDeadlineTimer deadline(CoarseTimerInterval * 1ms);
|
||||||
elapsedTimer.start();
|
while (!deadline.hasExpired() && eventDispatcher->processEvents(QEventLoop::AllEvents))
|
||||||
while (!elapsedTimer.hasExpired(CoarseTimerInterval) && eventDispatcher->processEvents(QEventLoop::AllEvents)) {
|
;
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// consume pending posted events to avoid impact on the next test function
|
// consume pending posted events to avoid impact on the next test function
|
||||||
@ -292,9 +294,8 @@ void tst_QEventDispatcher::sendPostedEvents()
|
|||||||
QFETCH(int, processEventsFlagsInt);
|
QFETCH(int, processEventsFlagsInt);
|
||||||
QEventLoop::ProcessEventsFlags processEventsFlags = QEventLoop::ProcessEventsFlags(processEventsFlagsInt);
|
QEventLoop::ProcessEventsFlags processEventsFlags = QEventLoop::ProcessEventsFlags(processEventsFlagsInt);
|
||||||
|
|
||||||
QElapsedTimer elapsedTimer;
|
QDeadlineTimer deadline(200ms);
|
||||||
elapsedTimer.start();
|
while (!deadline.hasExpired()) {
|
||||||
while (!elapsedTimer.hasExpired(200)) {
|
|
||||||
receivedEventType = -1;
|
receivedEventType = -1;
|
||||||
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
|
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user