Skip to content

Commit 9c01be1

Browse files
committed
[tests] [qt] Introduce qt/test/util with a generalized ConfirmMessage
ConfirmMessage is reused in future tests apart from its single usage here.
1 parent 8cdcaee commit 9c01be1

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

src/Makefile.qttest.include

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ TEST_QT_H = \
2020
qt/test/compattests.h \
2121
qt/test/rpcnestedtests.h \
2222
qt/test/uritests.h \
23+
qt/test/util.h \
2324
qt/test/paymentrequestdata.h \
2425
qt/test/paymentservertests.h \
2526
qt/test/wallettests.h
@@ -38,6 +39,7 @@ qt_test_test_bitcoin_qt_SOURCES = \
3839
qt/test/rpcnestedtests.cpp \
3940
qt/test/test_main.cpp \
4041
qt/test/uritests.cpp \
42+
qt/test/util.cpp \
4143
$(TEST_QT_H) \
4244
$(TEST_BITCOIN_CPP) \
4345
$(TEST_BITCOIN_H)

src/qt/test/util.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <qt/callback.h>
2+
3+
#include <QApplication>
4+
#include <QMessageBox>
5+
#include <QTimer>
6+
#include <QString>
7+
#include <QPushButton>
8+
#include <QWidget>
9+
10+
void ConfirmMessage(QString* text, int msec)
11+
{
12+
QTimer::singleShot(msec, makeCallback([text](Callback* callback) {
13+
for (QWidget* widget : QApplication::topLevelWidgets()) {
14+
if (widget->inherits("QMessageBox")) {
15+
QMessageBox* messageBox = qobject_cast<QMessageBox*>(widget);
16+
if (text) *text = messageBox->text();
17+
messageBox->defaultButton()->click();
18+
}
19+
}
20+
delete callback;
21+
}), SLOT(call()));
22+
}

src/qt/test/util.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef BITCOIN_QT_TEST_UTIL_H
2+
#define BITCOIN_QT_TEST_UTIL_H
3+
4+
/**
5+
* Press "Ok" button in message box dialog.
6+
*
7+
* @param text - Optionally store dialog text.
8+
* @param msec - Number of miliseconds to pause before triggering the callback.
9+
*/
10+
void ConfirmMessage(QString* text = nullptr, int msec = 0);
11+
12+
#endif // BITCOIN_QT_TEST_UTIL_H

src/qt/test/wallettests.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <qt/test/wallettests.h>
2+
#include <qt/test/util.h>
23

34
#include <interfaces/node.h>
45
#include <qt/bitcoinamountfield.h>
@@ -35,21 +36,6 @@
3536

3637
namespace
3738
{
38-
//! Press "Ok" button in message box dialog.
39-
void ConfirmMessage(QString* text = nullptr)
40-
{
41-
QTimer::singleShot(0, makeCallback([text](Callback* callback) {
42-
for (QWidget* widget : QApplication::topLevelWidgets()) {
43-
if (widget->inherits("QMessageBox")) {
44-
QMessageBox* messageBox = qobject_cast<QMessageBox*>(widget);
45-
if (text) *text = messageBox->text();
46-
messageBox->defaultButton()->click();
47-
}
48-
}
49-
delete callback;
50-
}), SLOT(call()));
51-
}
52-
5339
//! Press "Yes" or "Cancel" buttons in modal send confirmation dialog.
5440
void ConfirmSend(QString* text = nullptr, bool cancel = false)
5541
{
@@ -264,7 +250,7 @@ void TestGUI()
264250
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
265251
}
266252

267-
}
253+
} // namespace
268254

269255
void WalletTests::walletTests()
270256
{

0 commit comments

Comments
 (0)