Add shorthand method for creating a new NetworkRequestBuilder.

This commit is contained in:
Patrick Sean Klein 2023-05-31 20:40:12 +01:00
parent 0924639092
commit 6a314f848f
No known key found for this signature in database
GPG Key ID: B6D50F39A56F6906
3 changed files with 15 additions and 4 deletions

View File

@ -32,4 +32,9 @@ QNetworkAccessManager* getNetMgr()
}
return g_netMgr;
}
NetworkRequestBuilder buildRequest(const QUrl& url)
{
return NetworkRequestBuilder(url);
}
#endif

View File

@ -22,9 +22,14 @@
#ifdef WITH_XC_NETWORKING
#include "core/NetworkRequest.h"
class QNetworkAccessManager;
QNetworkAccessManager* getNetMgr();
NetworkRequestBuilder buildRequest(const QUrl& targetUrl);
#else
Q_STATIC_ASSERT_X(false, "Qt Networking used when WITH_XC_NETWORKING is disabled!");
#endif

View File

@ -1,4 +1,5 @@
#include "TestNetworkRequest.h"
#include "core/NetworkManager.h"
#include "core/NetworkRequest.h"
#include "mock/MockNetworkAccessManager.h"
#include <QSignalSpy>
@ -41,7 +42,7 @@ void TestNetworkRequest::testNetworkRequest()
}
// Create request
NetworkRequest request = NetworkRequestBuilder(requestedURL).setManager(&manager).build();
NetworkRequest request = buildRequest(requestedURL).setManager(&manager).build();
QString actualContent;
bool didError = false, didSucceed = false;
@ -136,7 +137,7 @@ void TestNetworkRequest::testNetworkRequestTimeout()
reply.withFinishDelayUntil(&timer, &QTimer::timeout);
// Create request
NetworkRequest request = NetworkRequestBuilder(requestedURL).setManager(&manager).setTimeout(timeout).build();
NetworkRequest request = buildRequest(requestedURL).setManager(&manager).setTimeout(timeout).build();
// Start timer
timer.start();
@ -212,7 +213,7 @@ void TestNetworkRequest::testNetworkRequestRedirects()
reply->withBody(QString{"test-content"}.toUtf8());
// Create request
NetworkRequest request = NetworkRequestBuilder(requestedURL).setManager(&manager)
NetworkRequest request = buildRequest(requestedURL).setManager(&manager)
.setMaxRedirects(maxRedirects).build();
bool didSucceed = false, didError = false;
@ -289,7 +290,7 @@ void TestNetworkRequest::testNetworkRequestTimeoutWithRedirects()
reply->withBody(QString{"test-content"}.toUtf8());
// Create request
NetworkRequest request = NetworkRequestBuilder(requestedURL).setManager(&manager)
NetworkRequest request = buildRequest(requestedURL).setManager(&manager)
.setTimeout(timeout)
.setMaxRedirects(NetworkRequest::UNLIMITED_REDIRECTS).build();