Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/qt/test/addressbooktests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <chrono>

#include <QAbstractButton>
#include <QApplication>
#include <QLineEdit>
#include <QMessageBox>
Expand All @@ -48,11 +49,14 @@ void EditAddressAndSubmit(
const QString& label, const QString& address, QString expected_msg)
{
QString warning_text;
// A successful edit opens no message box, and the answer must not wait
// for the next one, which belongs to whoever opens it
QObject scope;

dialog->findChild<QLineEdit*>("labelEdit")->setText(label);
dialog->findChild<QValidatedLineEdit*>("addressEdit")->setText(address);

ConfirmMessage(&warning_text, 5ms);
ConfirmMessage(&warning_text, 5ms, &scope);
dialog->accept();
QCOMPARE(warning_text, expected_msg);
}
Expand Down Expand Up @@ -168,6 +172,13 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
check_addbook_size(4);
QCOMPARE(table_view->model()->rowCount(), 3);

// The next message box is answered by whoever opens it
QMessageBox later(QMessageBox::Question, QString(), QString(), QMessageBox::Yes | QMessageBox::No);
later.setDefaultButton(QMessageBox::Yes);
QTimer::singleShot(100ms, &later, [&later] { later.button(QMessageBox::No)->click(); });
later.exec();
QCOMPARE(later.clickedButton(), later.button(QMessageBox::No));

auto search_line = address_book.findChild<QLineEdit*>("searchLineEdit");

search_line->setText(r_label);
Expand Down
4 changes: 2 additions & 2 deletions src/qt/test/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include <QTimer>
#include <QWidget>

void ConfirmMessage(QString* text, std::chrono::milliseconds msec)
void ConfirmMessage(QString* text, std::chrono::milliseconds msec, QObject* context)
{
QTimer::singleShot(msec, [text]() {
QTimer::singleShot(msec, context, [text]() {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
for (QWidget* widget : QApplication::topLevelWidgets()) {
if (widget->inherits("QMessageBox")) {
QMessageBox* messageBox = qobject_cast<QMessageBox*>(widget);
Expand Down
5 changes: 4 additions & 1 deletion src/qt/test/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <qglobal.h>

QT_BEGIN_NAMESPACE
class QObject;
class QString;
QT_END_NAMESPACE

Expand All @@ -18,7 +19,9 @@ QT_END_NAMESPACE
*
* @param text - Optionally store dialog text.
* @param msec - Number of milliseconds to pause before triggering the callback.
* @param context - Optionally cancel the callback when this object is destroyed,
* so it cannot answer a later message box or outlive `text`.
*/
void ConfirmMessage(QString* text, std::chrono::milliseconds msec);
void ConfirmMessage(QString* text, std::chrono::milliseconds msec, QObject* context = nullptr);

#endif // BITCOIN_QT_TEST_UTIL_H
Loading