Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2017-12-11 19:03:24 +0300
committerOlivier Goffart <olivier@woboq.com>2017-12-14 13:56:12 +0300
commit4369853ddb21525a9b83f83ef3d44dd838a17d8d (patch)
tree5085b13ae00287dee76632a30dacbced80c797ee /test/syncenginetestutils.h
parentd8707297090592a8178289848adea18e3c565a04 (diff)
TestSystem: Add QIODevice in the serverOverride function, and add a DelayedReply
Preparing to add test that needs the QIODevice. Also make the DelayedReply so we can generalize the existing delay on FakeChunkMoveReply to any reply.
Diffstat (limited to 'test/syncenginetestutils.h')
-rw-r--r--test/syncenginetestutils.h38
1 files changed, 31 insertions, 7 deletions
diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h
index c9f4e088a..9122040be 100644
--- a/test/syncenginetestutils.h
+++ b/test/syncenginetestutils.h
@@ -441,7 +441,8 @@ public:
QMetaObject::invokeMethod(this, "respond", Qt::QueuedConnection);
}
- Q_INVOKABLE void respond() {
+ Q_INVOKABLE virtual void respond()
+ {
emit uploadProgress(fileInfo->size, fileInfo->size);
setRawHeader("OC-ETag", fileInfo->etag.toLatin1());
setRawHeader("ETag", fileInfo->etag.toLatin1());
@@ -615,7 +616,7 @@ class FakeChunkMoveReply : public QNetworkReply
public:
FakeChunkMoveReply(FileInfo &uploadsFileInfo, FileInfo &remoteRootFileInfo,
QNetworkAccessManager::Operation op, const QNetworkRequest &request,
- quint64 delayMs, QObject *parent)
+ QObject *parent)
: QNetworkReply{ parent }
{
setRequest(request);
@@ -675,10 +676,11 @@ public:
fileInfo->lastModified = OCC::Utility::qDateTimeFromTime_t(request.rawHeader("X-OC-Mtime").toLongLong());
remoteRootFileInfo.find(fileName, /*invalidate_etags=*/true);
- QTimer::singleShot(delayMs, this, &FakeChunkMoveReply::respond);
+ QTimer::singleShot(0, this, &FakeChunkMoveReply::respond);
}
- Q_INVOKABLE void respond() {
+ Q_INVOKABLE virtual void respond()
+ {
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 201);
setRawHeader("OC-ETag", fileInfo->etag.toLatin1());
setRawHeader("ETag", fileInfo->etag.toLatin1());
@@ -744,10 +746,32 @@ public:
qint64 readData(char *, qint64) override { return 0; }
};
+// A delayed reply
+template <class OriginalReply>
+class DelayedReply : public OriginalReply
+{
+public:
+ template <typename... Args>
+ explicit DelayedReply(quint64 delayMS, Args &&... args)
+ : OriginalReply(std::forward<Args>(args)...)
+ , _delayMs(delayMS)
+ {
+ }
+ quint64 _delayMs;
+
+ void respond() override
+ {
+ QTimer::singleShot(_delayMs, static_cast<OriginalReply *>(this), [this] {
+ // Explicit call to bases's respond();
+ this->OriginalReply::respond();
+ });
+ }
+};
+
class FakeQNAM : public QNetworkAccessManager
{
public:
- using Override = std::function<QNetworkReply *(Operation, const QNetworkRequest &)>;
+ using Override = std::function<QNetworkReply *(Operation, const QNetworkRequest &, QIODevice *)>;
private:
FileInfo _remoteRootFileInfo;
@@ -770,7 +794,7 @@ protected:
QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
QIODevice *outgoingData = 0) {
if (_override) {
- if (auto reply = _override(op, request))
+ if (auto reply = _override(op, request, outgoingData))
return reply;
}
const QString fileName = getFilePathFromUrl(request.url());
@@ -796,7 +820,7 @@ protected:
else if (verb == QLatin1String("MOVE") && !isUpload)
return new FakeMoveReply{info, op, request, this};
else if (verb == QLatin1String("MOVE") && isUpload)
- return new FakeChunkMoveReply{ info, _remoteRootFileInfo, op, request, 0, this };
+ return new FakeChunkMoveReply{ info, _remoteRootFileInfo, op, request, this };
else {
qDebug() << verb << outgoingData;
Q_UNREACHABLE();