diff options
author | James O'Beirne <james.obeirne@gmail.com> | 2018-03-29 10:56:04 -0400 |
---|---|---|
committer | James O'Beirne <james.obeirne@gmail.com> | 2018-04-25 13:08:53 -0400 |
commit | 9c01be1b85f8ad11a8a0826a4a2bcdc2668a5c1f (patch) | |
tree | c689ea08afebf413262c2cf33e07b000156024dd /src/qt | |
parent | 8cdcaee4c7b256c5c3b70f1cfb04a5fb547311cd (diff) |
[tests] [qt] Introduce qt/test/util with a generalized ConfirmMessage
ConfirmMessage is reused in future tests apart from its single usage here.
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/test/util.cpp | 22 | ||||
-rw-r--r-- | src/qt/test/util.h | 12 | ||||
-rw-r--r-- | src/qt/test/wallettests.cpp | 18 |
3 files changed, 36 insertions, 16 deletions
diff --git a/src/qt/test/util.cpp b/src/qt/test/util.cpp new file mode 100644 index 0000000000..261caaaee5 --- /dev/null +++ b/src/qt/test/util.cpp @@ -0,0 +1,22 @@ +#include <qt/callback.h> + +#include <QApplication> +#include <QMessageBox> +#include <QTimer> +#include <QString> +#include <QPushButton> +#include <QWidget> + +void ConfirmMessage(QString* text, int msec) +{ + QTimer::singleShot(msec, makeCallback([text](Callback* callback) { + for (QWidget* widget : QApplication::topLevelWidgets()) { + if (widget->inherits("QMessageBox")) { + QMessageBox* messageBox = qobject_cast<QMessageBox*>(widget); + if (text) *text = messageBox->text(); + messageBox->defaultButton()->click(); + } + } + delete callback; + }), SLOT(call())); +} diff --git a/src/qt/test/util.h b/src/qt/test/util.h new file mode 100644 index 0000000000..324386c139 --- /dev/null +++ b/src/qt/test/util.h @@ -0,0 +1,12 @@ +#ifndef BITCOIN_QT_TEST_UTIL_H +#define BITCOIN_QT_TEST_UTIL_H + +/** + * 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/wallettests.cpp b/src/qt/test/wallettests.cpp index 56d2d38194..a09d98dfe5 100644 --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -1,4 +1,5 @@ #include <qt/test/wallettests.h> +#include <qt/test/util.h> #include <interfaces/node.h> #include <qt/bitcoinamountfield.h> @@ -35,21 +36,6 @@ namespace { -//! Press "Ok" button in message box dialog. -void ConfirmMessage(QString* text = nullptr) -{ - QTimer::singleShot(0, makeCallback([text](Callback* callback) { - for (QWidget* widget : QApplication::topLevelWidgets()) { - if (widget->inherits("QMessageBox")) { - QMessageBox* messageBox = qobject_cast<QMessageBox*>(widget); - if (text) *text = messageBox->text(); - messageBox->defaultButton()->click(); - } - } - delete callback; - }), SLOT(call())); -} - //! Press "Yes" or "Cancel" buttons in modal send confirmation dialog. void ConfirmSend(QString* text = nullptr, bool cancel = false) { @@ -264,7 +250,7 @@ void TestGUI() QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1); } -} +} // namespace void WalletTests::walletTests() { |