merge bitcoin-core/gui#337: Use Regex Search in Apptests

This commit is contained in:
Kittywhiskers Van Gogh 2021-05-16 20:36:59 -04:00
parent 3a18f087bf
commit 17a7e9ba85
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD

View File

@ -12,7 +12,6 @@
#include <qt/rpcconsole.h> #include <qt/rpcconsole.h>
#include <shutdown.h> #include <shutdown.h>
#include <test/util/setup_common.h> #include <test/util/setup_common.h>
#include <univalue.h>
#include <validation.h> #include <validation.h>
#if defined(HAVE_CONFIG_H) #if defined(HAVE_CONFIG_H)
@ -21,9 +20,11 @@
#include <QAction> #include <QAction>
#include <QLineEdit> #include <QLineEdit>
#include <QRegularExpression>
#include <QScopedPointer> #include <QScopedPointer>
#include <QSettings> #include <QSettings>
#include <QSignalSpy> #include <QSignalSpy>
#include <QString>
#include <QTest> #include <QTest>
#include <QTextEdit> #include <QTextEdit>
#include <QtGlobal> #include <QtGlobal>
@ -31,6 +32,13 @@
#include <QtTest/QtTestGui> #include <QtTest/QtTestGui>
namespace { namespace {
//! Regex find a string group inside of the console output
QString FindInConsole(const QString& output, const QString& pattern)
{
const QRegularExpression re(pattern);
return re.match(output).captured(1);
}
//! Call getblockchaininfo RPC and check first field of JSON output. //! Call getblockchaininfo RPC and check first field of JSON output.
void TestRpcCommand(RPCConsole* console) void TestRpcCommand(RPCConsole* console)
{ {
@ -42,10 +50,9 @@ void TestRpcCommand(RPCConsole* console)
QTest::keyClick(lineEdit, Qt::Key_Return); QTest::keyClick(lineEdit, Qt::Key_Return);
QVERIFY(mw_spy.wait(1000)); QVERIFY(mw_spy.wait(1000));
QCOMPARE(mw_spy.count(), 4); QCOMPARE(mw_spy.count(), 4);
QString output = messagesWidget->toPlainText(); const QString output = messagesWidget->toPlainText();
UniValue value; const QString pattern = QStringLiteral("\"chain\": \"(\\w+)\"");
value.read(output.right(output.size() - output.indexOf("{")).toStdString()); QCOMPARE(FindInConsole(output, pattern), QString("regtest"));
QCOMPARE(value["chain"].get_str(), std::string("regtest"));
} }
} // namespace } // namespace