Fix httplogger in unittests with lambdas
authorHannah von Reth <hannah.vonreth@owncloud.com>
Mon, 11 Jan 2021 10:38:14 +0000 (11:38 +0100)
committerMatthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr>
Wed, 11 Aug 2021 17:13:44 +0000 (17:13 +0000)
test/syncenginetestutils.cpp

index d8cee44e67a5309f56c185d7858f377620791e27..7770cde0ec78b788b0081c4d4c7ce1fc90e5ce91 100644 (file)
@@ -797,40 +797,44 @@ FakeQNAM::FakeQNAM(FileInfo initialRoot)
 
 QNetworkReply *FakeQNAM::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
 {
-    if (_override) {
-        if (auto reply = _override(op, request, outgoingData))
-            return reply;
-    }
-    const QString fileName = getFilePathFromUrl(request.url());
-    Q_ASSERT(!fileName.isNull());
-    if (_errorPaths.contains(fileName))
-        return new FakeErrorReply { op, request, this, _errorPaths[fileName] };
-
-    bool isUpload = request.url().path().startsWith(sUploadUrl.path());
-    FileInfo &info = isUpload ? _uploadFileInfo : _remoteRootFileInfo;
-
+    QNetworkReply *reply = nullptr;
     auto newRequest = request;
     newRequest.setRawHeader("X-Request-ID", OCC::AccessManager::generateRequestId());
-    auto verb = request.attribute(QNetworkRequest::CustomVerbAttribute);
-    FakeReply *reply = nullptr;
-    if (verb == QLatin1String("PROPFIND"))
-        // Ignore outgoingData always returning somethign good enough, works for now.
-        reply = new FakePropfindReply { info, op, newRequest, this };
-    else if (verb == QLatin1String("GET") || op == QNetworkAccessManager::GetOperation)
-        reply = new FakeGetReply { info, op, newRequest, this };
-    else if (verb == QLatin1String("PUT") || op == QNetworkAccessManager::PutOperation)
-        reply = new FakePutReply { info, op, newRequest, outgoingData->readAll(), this };
-    else if (verb == QLatin1String("MKCOL"))
-        reply = new FakeMkcolReply { info, op, newRequest, this };
-    else if (verb == QLatin1String("DELETE") || op == QNetworkAccessManager::DeleteOperation)
-        reply = new FakeDeleteReply { info, op, newRequest, this };
-    else if (verb == QLatin1String("MOVE") && !isUpload)
-        reply = new FakeMoveReply { info, op, newRequest, this };
-    else if (verb == QLatin1String("MOVE") && isUpload)
-        reply = new FakeChunkMoveReply { info, _remoteRootFileInfo, op, newRequest, this };
-    else {
-        qDebug() << verb << outgoingData;
-        Q_UNREACHABLE();
+    if (_override) {
+        if (auto _reply = _override(op, newRequest, outgoingData)) {
+            reply = _reply;
+        }
+    }
+    if (!reply) {
+        const QString fileName = getFilePathFromUrl(newRequest.url());
+        Q_ASSERT(!fileName.isNull());
+        if (_errorPaths.contains(fileName)) {
+            reply = new FakeErrorReply { op, newRequest, this, _errorPaths[fileName] };
+        }
+    }
+    if (!reply) {        const bool isUpload = newRequest.url().path().startsWith(sUploadUrl.path());
+        FileInfo &info = isUpload ? _uploadFileInfo : _remoteRootFileInfo;
+
+        auto verb = newRequest.attribute(QNetworkRequest::CustomVerbAttribute);
+        if (verb == QLatin1String("PROPFIND"))
+            // Ignore outgoingData always returning somethign good enough, works for now.
+            reply = new FakePropfindReply { info, op, newRequest, this };
+        else if (verb == QLatin1String("GET") || op == QNetworkAccessManager::GetOperation)
+            reply = new FakeGetReply { info, op, newRequest, this };
+        else if (verb == QLatin1String("PUT") || op == QNetworkAccessManager::PutOperation)
+            reply = new FakePutReply { info, op, newRequest, outgoingData->readAll(), this };
+        else if (verb == QLatin1String("MKCOL"))
+            reply = new FakeMkcolReply { info, op, newRequest, this };
+        else if (verb == QLatin1String("DELETE") || op == QNetworkAccessManager::DeleteOperation)
+            reply = new FakeDeleteReply { info, op, newRequest, this };
+        else if (verb == QLatin1String("MOVE") && !isUpload)
+            reply = new FakeMoveReply { info, op, newRequest, this };
+        else if (verb == QLatin1String("MOVE") && isUpload)
+            reply = new FakeChunkMoveReply { info, _remoteRootFileInfo, op, newRequest, this };
+        else {
+            qDebug() << verb << outgoingData;
+            Q_UNREACHABLE();
+        }
     }
     OCC::HttpLogger::logRequest(reply, op, outgoingData);
     return reply;