Skip to content

Commit

Permalink
Ensure unit test are using absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Feb 26, 2021
1 parent b7497ff commit 39fde5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
25 changes: 18 additions & 7 deletions test/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ QString FileInfo::path() const
return (parentPath.isEmpty() ? QString() : (parentPath + QLatin1Char('/'))) + name;
}

QString FileInfo::absolutePath() const
{
if (parentPath.endsWith(QLatin1Char('/'))) {
return parentPath + name;
} else {
return parentPath + QLatin1Char('/') + name;
}
}

void FileInfo::fixupParentPathRecursively()
{
auto p = path();
Expand Down Expand Up @@ -293,7 +302,7 @@ FakePropfindReply::FakePropfindReply(FileInfo &remoteRootFileInfo, QNetworkAcces
QMetaObject::invokeMethod(this, "respond404", Qt::QueuedConnection);
return;
}
QString prefix = request.url().path().left(request.url().path().size() - fileName.size());
const QString prefix = request.url().path().left(request.url().path().size() - fileName.size());

// Don't care about the request and just return a full propfind
const QString davUri { QStringLiteral("DAV:") };
Expand All @@ -307,8 +316,8 @@ FakePropfindReply::FakePropfindReply(FileInfo &remoteRootFileInfo, QNetworkAcces
xml.writeStartElement(davUri, QStringLiteral("multistatus"));
auto writeFileResponse = [&](const FileInfo &fileInfo) {
xml.writeStartElement(davUri, QStringLiteral("response"));

xml.writeTextElement(davUri, QStringLiteral("href"), prefix + QString::fromUtf8(QUrl::toPercentEncoding(fileInfo.path(), "/")));
const auto href = OCC::Utility::concatUrlPath(prefix, QString::fromUtf8(QUrl::toPercentEncoding(fileInfo.absolutePath(), "/"))).path();
xml.writeTextElement(davUri, QStringLiteral("href"), href);
xml.writeStartElement(davUri, QStringLiteral("propstat"));
xml.writeStartElement(davUri, QStringLiteral("prop"));

Expand Down Expand Up @@ -504,9 +513,11 @@ FakeGetReply::FakeGetReply(FileInfo &remoteRootFileInfo, QNetworkAccessManager::
QString fileName = getFilePathFromUrl(request.url());
Q_ASSERT(!fileName.isEmpty());
fileInfo = remoteRootFileInfo.find(fileName);
if (!fileInfo)
qWarning() << "Could not find file" << fileName << "on the remote";
QMetaObject::invokeMethod(this, "respond", Qt::QueuedConnection);
if (!fileInfo) {
qDebug() << "meh;";
}
Q_ASSERT_X(fileInfo, Q_FUNC_INFO, "Could not find file on the remote");
QMetaObject::invokeMethod(this, &FakeGetReply::respond, Qt::QueuedConnection);
}

void FakeGetReply::respond()
Expand Down Expand Up @@ -760,7 +771,7 @@ FakeErrorReply::FakeErrorReply(QNetworkAccessManager::Operation op, const QNetwo
open(QIODevice::ReadOnly);
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, httpErrorCode);
setError(InternalServerError, QStringLiteral("Internal Server Fake Error"));
QMetaObject::invokeMethod(this, "respond", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, &FakeErrorReply::respond, Qt::QueuedConnection);
}

void FakeErrorReply::respond()
Expand Down
1 change: 1 addition & 0 deletions test/syncenginetestutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class FileInfo : public FileModifier
}

QString path() const;
QString absolutePath() const;

void fixupParentPathRecursively();

Expand Down

0 comments on commit 39fde5b

Please sign in to comment.