test: migrate QNetworkReply test to QRegularExpression

This is part of the migration of qtbase from QRexExp to
QRegularExpression.

Task-number: QTBUG-72587
Change-Id: Ibdd3f63d9069c3f01dfe8431bcc64bde4f2aa569
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Samuel Gaist 2019-06-10 16:49:19 +02:00
parent 605dc42a0f
commit 16cc3ea585
2 changed files with 8 additions and 5 deletions

View File

@ -109,8 +109,8 @@ public:
static bool compareReplyFtp(QByteArray const& actual)
{
// output would be e.g. "220 (vsFTPd 2.3.5)\r\n221 Goodbye.\r\n"
QRegExp ftpVersion(QStringLiteral("220 \\(vsFTPd \\d+\\.\\d+.\\d+\\)\\r\\n221 Goodbye.\\r\\n"));
return ftpVersion.exactMatch(actual);
QRegularExpression ftpVersion(QRegularExpression::anchoredPattern(QStringLiteral("220 \\(vsFTPd \\d+\\.\\d+.\\d+\\)\\r\\n221 Goodbye.\\r\\n")));
return ftpVersion.match(actual).hasMatch();
}
static bool hasIPv6()

View File

@ -34,6 +34,8 @@
#include <QtCore/QEventLoop>
#include <QtCore/QFile>
#include <QtCore/QRandomGenerator>
#include <QtCore/QRegularExpression>
#include <QtCore/QRegularExpressionMatch>
#include <QtCore/QSharedPointer>
#include <QtCore/QScopedPointer>
#include <QtCore/QTemporaryFile>
@ -7917,9 +7919,10 @@ void tst_QNetworkReply::synchronousAuthenticationCache()
"Content-Type: text/plain\r\n"
"\r\n"
"auth";
QRegExp rx("Authorization: Basic ([^\r\n]*)\r\n");
if (rx.indexIn(receivedData) > 0) {
if (QByteArray::fromBase64(rx.cap(1).toLatin1()) == "login:password") {
QRegularExpression rx("Authorization: Basic ([^\r\n]*)\r\n");
QRegularExpressionMatch match = rx.match(receivedData);
if (match.hasMatch()) {
if (QByteArray::fromBase64(match.captured(1).toLatin1()) == "login:password") {
dataToTransmit =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/plain\r\n"