2013-05-05 14:36:42 +04:00
|
|
|
/*
|
|
|
|
This software is in the public domain, furnished "as is", without technical
|
|
|
|
support, and with no warranty, express or implied, as to its usefulness for
|
|
|
|
any purpose.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtTest>
|
2015-05-08 17:41:41 +03:00
|
|
|
#include <QDebug>
|
2013-05-05 14:36:42 +04:00
|
|
|
|
2015-05-08 17:41:41 +03:00
|
|
|
#include "propagatedownload.h"
|
2018-10-12 16:56:26 +03:00
|
|
|
#include "owncloudpropagator_p.h"
|
2023-11-30 17:00:18 +03:00
|
|
|
#include "syncenginetestutils.h"
|
2015-05-08 17:41:41 +03:00
|
|
|
|
|
|
|
using namespace OCC;
|
|
|
|
namespace OCC {
|
2015-05-22 10:17:24 +03:00
|
|
|
QString OWNCLOUDSYNC_EXPORT createDownloadTmpFileName(const QString &previous);
|
2015-05-08 17:41:41 +03:00
|
|
|
}
|
2013-05-05 14:36:42 +04:00
|
|
|
|
2018-10-12 15:52:18 +03:00
|
|
|
class TestNextcloudPropagator : public QObject
|
2013-05-05 14:36:42 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
2024-04-30 11:04:32 +03:00
|
|
|
void initTestCase()
|
|
|
|
{
|
|
|
|
OCC::Logger::instance()->setLogFlush(true);
|
|
|
|
OCC::Logger::instance()->setLogDebug(true);
|
|
|
|
|
|
|
|
QStandardPaths::setTestModeEnabled(true);
|
|
|
|
}
|
|
|
|
|
2013-05-05 14:36:42 +04:00
|
|
|
void testUpdateErrorFromSession()
|
|
|
|
{
|
2020-06-05 01:51:32 +03:00
|
|
|
//OwncloudPropagator propagator(nullptr, QLatin1String("test1"), QLatin1String("test2"), new ProgressDatabase);
|
2013-05-05 14:36:42 +04:00
|
|
|
QVERIFY( true );
|
|
|
|
}
|
2015-05-08 17:41:41 +03:00
|
|
|
|
|
|
|
void testTmpDownloadFileNameGeneration()
|
|
|
|
{
|
|
|
|
QString fn;
|
2015-05-11 16:41:56 +03:00
|
|
|
// without dir
|
|
|
|
for (int i = 1; i <= 1000; i++) {
|
|
|
|
fn+="F";
|
|
|
|
QString tmpFileName = createDownloadTmpFileName(fn);
|
|
|
|
if (tmpFileName.contains('/')) {
|
|
|
|
tmpFileName = tmpFileName.mid(tmpFileName.lastIndexOf('/')+1);
|
|
|
|
}
|
|
|
|
QVERIFY( tmpFileName.length() > 0);
|
|
|
|
QVERIFY( tmpFileName.length() <= 254);
|
|
|
|
}
|
|
|
|
// with absolute dir
|
|
|
|
fn = "/Users/guruz/ownCloud/rocks/GPL";
|
|
|
|
for (int i = 1; i < 1000; i++) {
|
|
|
|
fn+="F";
|
|
|
|
QString tmpFileName = createDownloadTmpFileName(fn);
|
|
|
|
if (tmpFileName.contains('/')) {
|
|
|
|
tmpFileName = tmpFileName.mid(tmpFileName.lastIndexOf('/')+1);
|
|
|
|
}
|
|
|
|
QVERIFY( tmpFileName.length() > 0);
|
|
|
|
QVERIFY( tmpFileName.length() <= 254);
|
|
|
|
}
|
|
|
|
// with relative dir
|
|
|
|
fn = "rocks/GPL";
|
2015-05-08 17:41:41 +03:00
|
|
|
for (int i = 1; i < 1000; i++) {
|
|
|
|
fn+="F";
|
|
|
|
QString tmpFileName = createDownloadTmpFileName(fn);
|
2015-05-11 16:41:56 +03:00
|
|
|
if (tmpFileName.contains('/')) {
|
|
|
|
tmpFileName = tmpFileName.mid(tmpFileName.lastIndexOf('/')+1);
|
|
|
|
}
|
2015-05-08 17:41:41 +03:00
|
|
|
QVERIFY( tmpFileName.length() > 0);
|
|
|
|
QVERIFY( tmpFileName.length() <= 254);
|
|
|
|
}
|
|
|
|
}
|
2015-10-15 15:57:06 +03:00
|
|
|
|
|
|
|
void testParseEtag()
|
|
|
|
{
|
2020-08-12 16:23:11 +03:00
|
|
|
using Test = QPair<const char*, const char*>;
|
2015-10-15 15:57:06 +03:00
|
|
|
QList<Test> tests;
|
|
|
|
tests.append(Test("\"abcd\"", "abcd"));
|
|
|
|
tests.append(Test("\"\"", ""));
|
|
|
|
tests.append(Test("\"fii\"-gzip", "fii"));
|
|
|
|
tests.append(Test("W/\"foo\"", "foo"));
|
|
|
|
|
|
|
|
foreach (const auto& test, tests) {
|
2015-10-15 16:52:58 +03:00
|
|
|
QCOMPARE(parseEtag(test.first), QByteArray(test.second));
|
2015-10-15 15:57:06 +03:00
|
|
|
}
|
|
|
|
}
|
2023-11-30 17:00:18 +03:00
|
|
|
|
|
|
|
void testParseException()
|
|
|
|
{
|
|
|
|
QNetworkRequest request;
|
|
|
|
request.setUrl(QStringLiteral("http://cloud.example.de/"));
|
|
|
|
const auto body = QByteArrayLiteral(
|
|
|
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
|
|
|
"<d:error xmlns:d=\"DAV:\" xmlns:s=\"http://sabredav.org/ns\">\n"
|
|
|
|
"<s:exception>Sabre\\Exception\\UnsupportedMediaType</s:exception>\n"
|
|
|
|
"<s:message>Virus detected!</s:message>\n"
|
|
|
|
"</d:error>");
|
|
|
|
const auto reply = new FakeErrorReply(QNetworkAccessManager::PutOperation,
|
|
|
|
request,
|
|
|
|
this,
|
|
|
|
415, body);
|
|
|
|
const auto exceptionParsed = OCC::getExceptionFromReply(reply);
|
|
|
|
// verify parsing succeeded
|
|
|
|
QVERIFY(!exceptionParsed.first.isEmpty());
|
|
|
|
QVERIFY(!exceptionParsed.second.isEmpty());
|
|
|
|
// verify buffer is not changed
|
|
|
|
QCOMPARE(reply->readAll().size(), body.size());
|
|
|
|
}
|
2013-05-05 14:36:42 +04:00
|
|
|
};
|
|
|
|
|
2018-10-12 15:52:18 +03:00
|
|
|
QTEST_APPLESS_MAIN(TestNextcloudPropagator)
|
|
|
|
#include "testnextcloudpropagator.moc"
|