Il 21 marzo 2012 22:29, Dominik Haumann <dhaum...@kde.org> ha scritto: > Moin, > > is there a simple way to unit test a freeze? > Like if the test needs more than 5 seconds, fail?
There's no straightforward way to check afaik and I don't really like the thread approach. What are you trying to verify? If the context is the one of a synchronous operation, I am afraid this might be very tricky, since there is no easy way you can interrupt a synchronous call identifying its context. Supposing your routine is asynchronous, QTimer timer; QEventLoop e; connect(&timer, SIGNAL(timeout()), &e, SLOT(quit())); connect(myObject, SIGNAL(finished()), &e, SLOT(quit())); myObject->problematicAsyncCall(); timer.setSingleShot(true); timer.start(5000); e.exec(); QVERIFY(timer.isActive()); In case the freeze is on a synchronous operation, the only thing you can do is crashing the unit test I am afraid. But again, you have a number of problems with synchronization and stuff. Supposing your call does not block Qt's event loop, you could for example create a timer again which connects to a slot performing stuff like: QVERIFY(false); qApp->exit(1); If the event loop is blocked, a thread is the only solution but I see multiple shortcomings with that approach. Hope this helped. > > One way would be to create a thread, start the freeze unit test, and if the > thread does not finish in some time period, kill it and fail. But that's > rather complicated for such a simple thing. Maybe QTest already provides some > nice feature? > > Thanks > Dominik > >>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<