void tst_Alive::addMouseDClick() const { class DClickListener : public QWidget { public: DClickListener() : isTested(false) { } bool isTested; protected: virtual void mouseDoubleClickEvent(QMouseEvent * event) { isTested = true; QCOMPARE(event->type(), QEvent::MouseButtonDblClick); } }; DClickListener listener; QTestEventList list; list.addMouseDClick(Qt::LeftButton); list.simulate(&listener); /* Check that we have been called at all. */ QVERIFY(listener.isTested); }
bool KeyHandler::executeInteraction(TargetData data) { QWidget* target = data.target; TasCommand& command = *data.command; QString commandName = command.name(); bool wasConsumed = false; if (commandName == "KeyPress") { doKeyEvent(target, QEvent::KeyPress, (Qt::Key)command.text().toUInt()); wasConsumed = true; } else if (commandName == "KeyRelease") { doKeyEvent(target, QEvent::KeyRelease, (Qt::Key)command.text().toUInt()); wasConsumed = true; } else if (commandName == "KeyClick") { QPointer<QWidget> ptr(target); doKeyEvent(target, QEvent::KeyPress, (Qt::Key)command.text().toUInt()); //make sure that the target is still valid (e.g. close button for dialog..) if(ptr){ doKeyEvent(target, QEvent::KeyRelease, (Qt::Key)command.text().toUInt()); } wasConsumed = true; } else if (commandName == "TypeText") { QTestEventList events; QString keys = command.text(); events.addKeyClicks(keys); events.simulate(target); wasConsumed = true; } return wasConsumed; }