diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -24,6 +24,7 @@ qt/test/guiutiltests.h \ qt/test/rpcnestedtests.h \ qt/test/uritests.h \ + qt/test/util.h \ qt/test/paymentrequestdata.h \ qt/test/paymentservertests.h \ qt/test/wallettests.h @@ -44,6 +45,7 @@ qt/test/rpcnestedtests.cpp \ qt/test/test_main.cpp \ qt/test/uritests.cpp \ + qt/test/util.cpp \ $(TEST_QT_H) \ $(TEST_BITCOIN_CPP) \ $(TEST_BITCOIN_H) diff --git a/src/qt/test/CMakeLists.txt b/src/qt/test/CMakeLists.txt --- a/src/qt/test/CMakeLists.txt +++ b/src/qt/test/CMakeLists.txt @@ -13,6 +13,7 @@ rpcnestedtests.cpp test_main.cpp uritests.cpp + util.cpp # Test framework ../../test/test_bitcoin.cpp diff --git a/src/qt/test/util.h b/src/qt/test/util.h new file mode 100644 --- /dev/null +++ b/src/qt/test/util.h @@ -0,0 +1,14 @@ +#ifndef BITCOIN_QT_TEST_UTIL_H +#define BITCOIN_QT_TEST_UTIL_H + +class QString; + +/** + * Press "Ok" button in message box dialog. + * + * @param text - Optionally store dialog text. + * @param msec - Number of miliseconds to pause before triggering the callback. + */ +void ConfirmMessage(QString *text = nullptr, int msec = 0); + +#endif // BITCOIN_QT_TEST_UTIL_H diff --git a/src/qt/test/util.cpp b/src/qt/test/util.cpp new file mode 100644 --- /dev/null +++ b/src/qt/test/util.cpp @@ -0,0 +1,20 @@ +#include + +#include +#include +#include +#include +#include +#include + +void ConfirmMessage(QString *text, int msec) { + QTimer::singleShot(msec, [text]() { + for (QWidget *widget : QApplication::topLevelWidgets()) { + if (widget->inherits("QMessageBox")) { + QMessageBox *messageBox = qobject_cast(widget); + if (text) *text = messageBox->text(); + messageBox->defaultButton()->click(); + } + } + }); +} diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -243,7 +244,7 @@ QCOMPARE(requestTableModel->rowCount({}), currentRowCount - 1); } -} +} // namespace void WalletTests::walletTests() { TestGUI();