| 48 | } |
| 49 | |
| 50 | void GrootTestBase::testMessageBox(int deplay_ms, TestLocation location, |
| 51 | std::function<void()> callable_action, |
| 52 | QMessageBox::StandardButton button_to_press) |
| 53 | { |
| 54 | QMutex semaphore; |
| 55 | semaphore.lock(); |
| 56 | |
| 57 | QTimer::singleShot(deplay_ms, [&]() |
| 58 | { |
| 59 | QWidget* widget = QApplication::activeModalWidget(); |
| 60 | if (!widget){ |
| 61 | QTest::qFail("no modal widget", location.file, location.line); |
| 62 | } |
| 63 | auto message_box = dynamic_cast<QMessageBox*>(widget); |
| 64 | if (!message_box){ |
| 65 | QTest::qFail("no QMessageBox", location.file, location.line); |
| 66 | } |
| 67 | if( button_to_press == QMessageBox::Default || button_to_press == QMessageBox::NoButton) |
| 68 | { |
| 69 | QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); |
| 70 | QCoreApplication::postEvent(widget, event); |
| 71 | } |
| 72 | else{ |
| 73 | emit message_box->button(button_to_press)->clicked(); |
| 74 | } |
| 75 | semaphore.unlock(); |
| 76 | }); |
| 77 | callable_action(); |
| 78 | semaphore.tryLock( deplay_ms * 2 ); |
| 79 | semaphore.unlock(); |
| 80 | } |