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; return g_netMgr;
} }
NetworkRequestBuilder buildRequest(const QUrl& url)
{
return NetworkRequestBuilder(url);
}
#endif #endif

View File

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

View File

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