Remove Q_ASSERT in gestures autotest

Rather than aborting on a bad gesture event in debug builds and ignoring
the error in release builds, record a count of bad events and fail the
test if the count is non-zero at the end of the test function.

Change-Id: I6ddd46a5a656185c13eae4bbbb496b986a0c92f6
Task-number: QTBUG-17582
Reviewed-by: Rohan McGovern
(cherry picked from commit 5953d930bc07fa6734a11d053d26a3f80e9c1e89)
This commit is contained in:
Jason McDonald 2011-05-04 16:53:16 +10:00 committed by Rohan McGovern
parent 80384827e0
commit d9d1e72d76

View File

@ -1518,17 +1518,20 @@ void tst_Gestures::autoCancelGestures()
{ {
class MockWidget : public GestureWidget { class MockWidget : public GestureWidget {
public: public:
MockWidget(const char *name) : GestureWidget(name) { } MockWidget(const char *name) : GestureWidget(name), badGestureEvents(0) { }
bool event(QEvent *event) bool event(QEvent *event)
{ {
if (event->type() == QEvent::Gesture) { if (event->type() == QEvent::Gesture) {
QGestureEvent *ge = static_cast<QGestureEvent*>(event); QGestureEvent *ge = static_cast<QGestureEvent*>(event);
Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... if (ge->gestures().count() != 1)
++badGestureEvents; // event should contain exactly one gesture
ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext);
} }
return GestureWidget::event(event); return GestureWidget::event(event);
} }
int badGestureEvents;
}; };
const Qt::GestureType secondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); const Qt::GestureType secondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
@ -1563,22 +1566,26 @@ void tst_Gestures::autoCancelGestures()
event.serial = CustomGesture::SerialFinishedThreshold; event.serial = CustomGesture::SerialFinishedThreshold;
QApplication::sendEvent(child, &event); QApplication::sendEvent(child, &event);
QCOMPARE(parent.events.all.count(), 2); QCOMPARE(parent.events.all.count(), 2);
QCOMPARE(parent.badGestureEvents, 0);
} }
void tst_Gestures::autoCancelGestures2() void tst_Gestures::autoCancelGestures2()
{ {
class MockItem : public GestureItem { class MockItem : public GestureItem {
public: public:
MockItem(const char *name) : GestureItem(name) { } MockItem(const char *name) : GestureItem(name), badGestureEvents(0) { }
bool event(QEvent *event) { bool event(QEvent *event) {
if (event->type() == QEvent::Gesture) { if (event->type() == QEvent::Gesture) {
QGestureEvent *ge = static_cast<QGestureEvent*>(event); QGestureEvent *ge = static_cast<QGestureEvent*>(event);
Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... if (ge->gestures().count() != 1)
++badGestureEvents; // event should contain exactly one gesture
ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext);
} }
return GestureItem::event(event); return GestureItem::event(event);
} }
int badGestureEvents;
}; };
const Qt::GestureType secondGesture = QGestureRecognizer ::registerRecognizer(new CustomGestureRecognizer); const Qt::GestureType secondGesture = QGestureRecognizer ::registerRecognizer(new CustomGestureRecognizer);
@ -1614,6 +1621,7 @@ void tst_Gestures::autoCancelGestures2()
event.serial = CustomGesture::SerialFinishedThreshold; event.serial = CustomGesture::SerialFinishedThreshold;
scene.sendEvent(child, &event); scene.sendEvent(child, &event);
QCOMPARE(parent->events.all.count(), 2); QCOMPARE(parent->events.all.count(), 2);
QCOMPARE(parent->badGestureEvents, 0);
} }
void tst_Gestures::graphicsViewParentPropagation() void tst_Gestures::graphicsViewParentPropagation()