[tests] [qt] Introduce qt/test/util with a generalized ConfirmMessage
ConfirmMessage is reused in future tests apart from its single usage here.
This commit is contained in:
parent
8cdcaee4c7
commit
9c01be1b85
4 changed files with 38 additions and 16 deletions
|
@ -20,6 +20,7 @@ TEST_QT_H = \
|
||||||
qt/test/compattests.h \
|
qt/test/compattests.h \
|
||||||
qt/test/rpcnestedtests.h \
|
qt/test/rpcnestedtests.h \
|
||||||
qt/test/uritests.h \
|
qt/test/uritests.h \
|
||||||
|
qt/test/util.h \
|
||||||
qt/test/paymentrequestdata.h \
|
qt/test/paymentrequestdata.h \
|
||||||
qt/test/paymentservertests.h \
|
qt/test/paymentservertests.h \
|
||||||
qt/test/wallettests.h
|
qt/test/wallettests.h
|
||||||
|
@ -38,6 +39,7 @@ qt_test_test_bitcoin_qt_SOURCES = \
|
||||||
qt/test/rpcnestedtests.cpp \
|
qt/test/rpcnestedtests.cpp \
|
||||||
qt/test/test_main.cpp \
|
qt/test/test_main.cpp \
|
||||||
qt/test/uritests.cpp \
|
qt/test/uritests.cpp \
|
||||||
|
qt/test/util.cpp \
|
||||||
$(TEST_QT_H) \
|
$(TEST_QT_H) \
|
||||||
$(TEST_BITCOIN_CPP) \
|
$(TEST_BITCOIN_CPP) \
|
||||||
$(TEST_BITCOIN_H)
|
$(TEST_BITCOIN_H)
|
||||||
|
|
22
src/qt/test/util.cpp
Normal file
22
src/qt/test/util.cpp
Normal file
|
@ -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
src/qt/test/util.h
Normal file
12
src/qt/test/util.h
Normal file
|
@ -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
|
|
@ -1,4 +1,5 @@
|
||||||
#include <qt/test/wallettests.h>
|
#include <qt/test/wallettests.h>
|
||||||
|
#include <qt/test/util.h>
|
||||||
|
|
||||||
#include <interfaces/node.h>
|
#include <interfaces/node.h>
|
||||||
#include <qt/bitcoinamountfield.h>
|
#include <qt/bitcoinamountfield.h>
|
||||||
|
@ -35,21 +36,6 @@
|
||||||
|
|
||||||
namespace
|
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.
|
//! Press "Yes" or "Cancel" buttons in modal send confirmation dialog.
|
||||||
void ConfirmSend(QString* text = nullptr, bool cancel = false)
|
void ConfirmSend(QString* text = nullptr, bool cancel = false)
|
||||||
{
|
{
|
||||||
|
@ -264,7 +250,7 @@ void TestGUI()
|
||||||
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
|
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
void WalletTests::walletTests()
|
void WalletTests::walletTests()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue