Skip to content

Commit

Permalink
[tests] [qt] Introduce qt/test/util with a generalized ConfirmMessage
Browse files Browse the repository at this point in the history
ConfirmMessage is reused in future tests apart from its single usage here.
  • Loading branch information
jamesob committed Apr 25, 2018
1 parent 8cdcaee commit 9c01be1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.qttest.include
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ TEST_QT_H = \
qt/test/compattests.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
Expand All @@ -38,6 +39,7 @@ qt_test_test_bitcoin_qt_SOURCES = \
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)
Expand Down
22 changes: 22 additions & 0 deletions src/qt/test/util.cpp
Original file line number Diff line number Diff line change
@@ -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()));
}
12 changes: 12 additions & 0 deletions src/qt/test/util.h
Original file line number Diff line number Diff line change
@@ -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
18 changes: 2 additions & 16 deletions src/qt/test/wallettests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <qt/test/wallettests.h>
#include <qt/test/util.h>

#include <interfaces/node.h>
#include <qt/bitcoinamountfield.h>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -264,7 +250,7 @@ void TestGUI()
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
}

}
} // namespace

void WalletTests::walletTests()
{
Expand Down

0 comments on commit 9c01be1

Please sign in to comment.