From ed2dfcf3993c4bb92270adbdc2746ffda162abf3 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 20 Feb 2018 10:36:07 +0100 Subject: Conflicts with user name: Fix tests --- test/syncenginetestutils.h | 1 + 1 file changed, 1 insertion(+) (limited to 'test/syncenginetestutils.h') diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index f7cf4eb46..06c35d300 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -880,6 +880,7 @@ public: _account = OCC::Account::create(); _account->setUrl(QUrl(QStringLiteral("http://admin:admin@localhost/owncloud"))); _account->setCredentials(new FakeCredentials{_fakeQnam}); + _account->setDavDisplayName("fakename"); _journalDb.reset(new OCC::SyncJournalDb(localPath() + "._sync_test.db")); _syncEngine.reset(new OCC::SyncEngine(_account, localPath(), "", _journalDb.get())); -- cgit v1.2.3 From 02b818af04de69e3ccd761fa7c8a037fde7da9d6 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 17 Apr 2018 15:04:36 +0200 Subject: Download: Use the from the reply in the error message if any Issue: #6459 --- test/syncenginetestutils.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'test/syncenginetestutils.h') diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 06c35d300..f07f93fda 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -715,8 +715,8 @@ class FakeErrorReply : public QNetworkReply Q_OBJECT public: FakeErrorReply(QNetworkAccessManager::Operation op, const QNetworkRequest &request, - QObject *parent, int httpErrorCode) - : QNetworkReply{parent}, _httpErrorCode(httpErrorCode) { + QObject *parent, int httpErrorCode, const QByteArray &body = QByteArray()) + : QNetworkReply{parent}, _httpErrorCode(httpErrorCode), _body(body) { setRequest(request); setUrl(request.url()); setOperation(op); @@ -732,9 +732,15 @@ public: } void abort() override { } - qint64 readData(char *, qint64) override { return 0; } + qint64 readData(char *buf, qint64 max) override { + max = qMin(max, _body.size()); + memcpy(buf, _body.constData(), max); + _body = _body.mid(max); + return max; + } int _httpErrorCode; + QByteArray _body; }; // A reply that never responds -- cgit v1.2.3 From 34d40e6c67c8442c285cf16ae06014da29c73ee2 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 2 May 2018 12:42:55 +0200 Subject: Placeholder: Don't contain "stub" --- test/syncenginetestutils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/syncenginetestutils.h') diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index f07f93fda..1a78add5b 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -1000,7 +1000,7 @@ private: qWarning() << "Empty file at:" << diskChild.filePath(); continue; } - char contentChar = f.read(1).at(0); + char contentChar = content.at(0); templateFi.children.insert(diskChild.fileName(), FileInfo{diskChild.fileName(), diskChild.size(), contentChar}); } } -- cgit v1.2.3 From 13cb9ab1c5e645d1103254a8ef00273e87f67044 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 30 May 2018 16:29:29 +0200 Subject: PropagateDownload: Don't discard the body of error message We want to keep the body so we can get the message from it (Issue #6459) TestDownload::testErrorMessage did not fail because the FakeErrorReply did not emit readyRead and did not implement bytesAvailable. --- test/syncenginetestutils.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/syncenginetestutils.h') diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 1a78add5b..3957479d6 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -728,6 +728,8 @@ public: setAttribute(QNetworkRequest::HttpStatusCodeAttribute, _httpErrorCode); setError(InternalServerError, "Internal Server Fake Error"); emit metaDataChanged(); + emit readyRead(); + setFinished(true); emit finished(); } @@ -738,6 +740,9 @@ public: _body = _body.mid(max); return max; } + qint64 bytesAvailable() const override { + return _body.size(); + } int _httpErrorCode; QByteArray _body; -- cgit v1.2.3 From ad2446b0360a22d412f30131bd9d6f2f20ac5134 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 13 Jun 2018 14:20:21 +0200 Subject: Ensure GETFileJob notices finishing #6581 It could happen that readyRead was emitted for incoming data while the download was not yet finished. Then the network job could finish with no more data arriving - so readyRead wasn't emitted again. To fix this, the finished signal also gets connected to the readyRead slot. --- test/syncenginetestutils.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/syncenginetestutils.h') diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 3957479d6..e0982bd15 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -729,10 +729,17 @@ public: setError(InternalServerError, "Internal Server Fake Error"); emit metaDataChanged(); emit readyRead(); + // finishing can come strictly after readyRead was called + QTimer::singleShot(5, this, &FakeErrorReply::slotSetFinished); + } + +public slots: + void slotSetFinished() { setFinished(true); emit finished(); } +public: void abort() override { } qint64 readData(char *buf, qint64 max) override { max = qMin(max, _body.size()); -- cgit v1.2.3 From a0675bd0ab126b72998bb595af7510e07a9ff49d Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 23 Jul 2018 15:19:32 +0200 Subject: Convert p7.pl to a C++ test This is just a translation of test/scripts/txpl/t7.pl to C++ using the test framework. --- test/syncenginetestutils.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/syncenginetestutils.h') diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index e0982bd15..536521b70 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -289,6 +289,7 @@ public: QString name; bool isDir = true; bool isShared = false; + OCC::RemotePermissions permissions; // When uset, defaults to everything QDateTime lastModified = QDateTime::currentDateTime().addDays(-7); QString etag = generateEtag(); QByteArray fileId = generateFileId(); @@ -362,7 +363,9 @@ public: xml.writeTextElement(davUri, QStringLiteral("getlastmodified"), stringDate); xml.writeTextElement(davUri, QStringLiteral("getcontentlength"), QString::number(fileInfo.size)); xml.writeTextElement(davUri, QStringLiteral("getetag"), fileInfo.etag); - xml.writeTextElement(ocUri, QStringLiteral("permissions"), fileInfo.isShared ? QStringLiteral("SRDNVCKW") : QStringLiteral("RDNVCKW")); + xml.writeTextElement(ocUri, QStringLiteral("permissions"), !fileInfo.permissions.isNull() + ? QString(fileInfo.permissions.toString()) + : fileInfo.isShared ? QStringLiteral("SRDNVCKW") : QStringLiteral("RDNVCKW")); xml.writeTextElement(ocUri, QStringLiteral("id"), fileInfo.fileId); xml.writeTextElement(ocUri, QStringLiteral("checksums"), fileInfo.checksums); buffer.write(fileInfo.extraDavProperties); @@ -446,6 +449,7 @@ public: emit uploadProgress(fileInfo->size, fileInfo->size); setRawHeader("OC-ETag", fileInfo->etag.toLatin1()); setRawHeader("ETag", fileInfo->etag.toLatin1()); + setRawHeader("OC-FileID", fileInfo->fileId); setRawHeader("X-OC-MTime", "accepted"); // Prevents Q_ASSERT(!_runningNow) since we'll call PropagateItemJob::done twice in that case. setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200); emit metaDataChanged(); -- cgit v1.2.3 From 56166deb76f56dcc12502bbbadf8a5d10a12c0a2 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 25 Jul 2018 12:21:29 +0200 Subject: Added test that checks what happens when there is an error in the remote discovery (Many of the expected error string are left empty because the current error message is not insterresting --- test/syncenginetestutils.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test/syncenginetestutils.h') diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 536521b70..59bccc12a 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -773,7 +773,14 @@ public: open(QIODevice::ReadOnly); } - void abort() override {} + void abort() override { + // Follow more or less the implementation of QNetworkReplyImpl::abort + close(); + setError(OperationCanceledError, tr("Operation canceled")); + emit error(OperationCanceledError); + setFinished(true); + emit finished(); + } qint64 readData(char *, qint64) override { return 0; } }; -- cgit v1.2.3 From 58d6632eaf32ae7740cfef1152fb1b700397e712 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 26 Jul 2018 16:05:26 +0200 Subject: Data-Fingerprint: Fix backup detection when fingerprint is empty Add a test to test the data fingerprint feature make me realize it was broken. The code was relying in the distinction between empty and null QByteArray, but this was a bad idea as this difference is lost when going through QString. --- test/syncenginetestutils.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/syncenginetestutils.h') diff --git a/test/syncenginetestutils.h b/test/syncenginetestutils.h index 59bccc12a..f1790b588 100644 --- a/test/syncenginetestutils.h +++ b/test/syncenginetestutils.h @@ -1030,6 +1030,23 @@ private: } }; +/* Return the FileInfo for a conflict file for the specified relative filename */ +inline const FileInfo *findConflict(FileInfo &dir, const QString &filename) +{ + QFileInfo info(filename); + const FileInfo *parentDir = dir.find(info.path()); + if (!parentDir) + return nullptr; + QString start = info.baseName() + " (conflicted copy"; + for (const auto &item : parentDir->children) { + if (item.name.startsWith(start)) { + return &item; + } + } + return nullptr; +} + + // QTest::toString overloads namespace OCC { inline char *toString(const SyncFileStatus &s) { -- cgit v1.2.3