From: Christian Kamm Date: Wed, 14 Jun 2017 10:03:40 +0000 (+0200) Subject: SyncEngineTest: Add network override X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~710^2~10 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d50d8b86cf135dff833679b073406e4bdd6deae6;p=nextcloud-desktop.git SyncEngineTest: Add network override This is useful for monitoring what kind of network requests are sent to the fake server. Such as "did this sync cause an upload?" and "was there a propfind for this path?". It can also inject custom replies. --- diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index fe4676821..ee15d8e33 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -706,10 +706,17 @@ public: class FakeQNAM : public QNetworkAccessManager { +public: + using Override = std::function; + +private: FileInfo _remoteRootFileInfo; FileInfo _uploadFileInfo; // maps a path to an HTTP error QHash _errorPaths; + // monitor requests and optionally provide custom replies + Override _override; + public: FakeQNAM(FileInfo initialRoot) : _remoteRootFileInfo{std::move(initialRoot)} { } FileInfo ¤tRemoteState() { return _remoteRootFileInfo; } @@ -717,6 +724,8 @@ public: QHash &errorPaths() { return _errorPaths; } + void setOverride(const Override &override) { _override = override; } + protected: QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0) { @@ -728,8 +737,13 @@ protected: bool isUpload = request.url().path().startsWith(sUploadUrl.path()); FileInfo &info = isUpload ? _uploadFileInfo : _remoteRootFileInfo; + if (_override) { + if (auto reply = _override(op, request)) + return reply; + } + auto verb = request.attribute(QNetworkRequest::CustomVerbAttribute); - if (verb == QLatin1String("PROPFIND")) + if (verb == "PROPFIND") // Ignore outgoingData always returning somethign good enough, works for now. return new FakePropfindReply{info, op, request, this}; else if (verb == QLatin1String("GET") || op == QNetworkAccessManager::GetOperation) @@ -825,6 +839,7 @@ public: void clear() { _qnam->errorPaths().clear(); } }; ErrorList serverErrorPaths() { return {_fakeQnam}; } + void setServerOverride(const FakeQNAM::Override &override) { _fakeQnam->setOverride(override); } QString localPath() const { // SyncEngine wants a trailing slash