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
path: root/test
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2018-10-09 14:45:27 +0300
committerOlivier Goffart <ogoffart@woboq.com>2018-10-09 15:39:23 +0300
commitd29a05aea5dd5edfad29a113cb380f584d44e2cb (patch)
treedd8c17c3a7e228193e3c9024a19ec6abed305c9f /test
parent067d9b34f78e2378a71614d19603da9df8322888 (diff)
New Discovery Algorithm: Ge tthe size of new folders
Also add a test that this works properly
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/testselectivesync.cpp92
2 files changed, 93 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 71a38b4c4..1f078a665 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -55,6 +55,7 @@ owncloud_add_test(Blacklist "syncenginetestutils.h")
owncloud_add_test(LocalDiscovery "syncenginetestutils.h")
owncloud_add_test(RemoteDiscovery "syncenginetestutils.h")
owncloud_add_test(Permissions "syncenginetestutils.h")
+owncloud_add_test(SelectiveSync "syncenginetestutils.h")
owncloud_add_test(FolderWatcher "${FolderWatcher_SRC}")
if( UNIX AND NOT APPLE )
diff --git a/test/testselectivesync.cpp b/test/testselectivesync.cpp
new file mode 100644
index 000000000..c6278866b
--- /dev/null
+++ b/test/testselectivesync.cpp
@@ -0,0 +1,92 @@
+/*
+ * 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>
+#include "syncenginetestutils.h"
+#include <syncengine.h>
+
+using namespace OCC;
+
+
+class TestSelectiveSync : public QObject
+{
+ Q_OBJECT
+
+private slots:
+
+
+ void testSelectiveSyncBigFolders()
+ {
+ FakeFolder fakeFolder { FileInfo::A12_B12_C12_S12() };
+ SyncOptions options;
+ options._newBigFolderSizeLimit = 20000; // 20 K
+ fakeFolder.syncEngine().setSyncOptions(options);
+
+ QStringList sizeRequests;
+ fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation, const QNetworkRequest &req, QIODevice *device)
+ -> QNetworkReply * {
+ // Record what path we are querying for the size
+ if (req.attribute(QNetworkRequest::CustomVerbAttribute) == "PROPFIND") {
+ if (device->readAll().contains("<size "))
+ sizeRequests << req.url().path();
+ }
+ return nullptr;
+ });
+
+ QSignalSpy newBigFolder(&fakeFolder.syncEngine(), &SyncEngine::newBigFolder);
+
+ QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
+
+ fakeFolder.remoteModifier().createDir("A/newBigDir");
+ fakeFolder.remoteModifier().createDir("A/newBigDir/subDir");
+ fakeFolder.remoteModifier().insert("A/newBigDir/subDir/bigFile", options._newBigFolderSizeLimit + 10);
+ fakeFolder.remoteModifier().insert("A/newBigDir/subDir/smallFile", 10);
+
+ fakeFolder.remoteModifier().createDir("B/newSmallDir");
+ fakeFolder.remoteModifier().createDir("B/newSmallDir/subDir");
+ fakeFolder.remoteModifier().insert("B/newSmallDir/subDir/smallFile", 10);
+
+ // Because the test system don't do that automatically
+ fakeFolder.remoteModifier().find("A/newBigDir")->extraDavProperties = "<oc:size>20020</oc:size>";
+ fakeFolder.remoteModifier().find("A/newBigDir/subDir")->extraDavProperties = "<oc:size>20020</oc:size>";
+ fakeFolder.remoteModifier().find("B/newSmallDir")->extraDavProperties = "<oc:size>10</oc:size>";
+ fakeFolder.remoteModifier().find("B/newSmallDir/subDir")->extraDavProperties = "<oc:size>10</oc:size>";
+
+ QVERIFY(fakeFolder.syncOnce());
+
+ QCOMPARE(newBigFolder.count(), 1);
+ QCOMPARE(newBigFolder.first()[0].toString(), QString("A/newBigDir"));
+ QCOMPARE(newBigFolder.first()[1].toBool(), false);
+ newBigFolder.clear();
+
+ QCOMPARE(sizeRequests.count(), 2); // "A/newBigDir" and "B/newSmallDir";
+ QCOMPARE(sizeRequests.filter("/subDir").count(), 0); // at no point we should request the size of the subdirs
+ sizeRequests.clear();
+
+ auto oldSync = fakeFolder.currentLocalState();
+ // syncing again should do the same
+ fakeFolder.syncEngine().journal()->avoidReadFromDbOnNextSync(QString("A/newBigDir"));
+ QVERIFY(fakeFolder.syncOnce());
+ QCOMPARE(fakeFolder.currentLocalState(), oldSync);
+ QCOMPARE(newBigFolder.count(), 1); // (since we don't have a real Folder, the files were not added to any list)
+ newBigFolder.clear();
+ QCOMPARE(sizeRequests.count(), 1); // "A/newBigDir";
+ sizeRequests.clear();
+
+ // Simulate that we accept all files by seting a wildcard white list
+ fakeFolder.syncEngine().journal()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList,
+ QStringList() << QLatin1String("/"));
+ fakeFolder.syncEngine().journal()->avoidReadFromDbOnNextSync(QString("A/newBigDir"));
+ QVERIFY(fakeFolder.syncOnce());
+ QCOMPARE(newBigFolder.count(), 0);
+ QCOMPARE(sizeRequests.count(), 0);
+ QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
+ }
+};
+
+QTEST_GUILESS_MAIN(TestSelectiveSync)
+#include "testselectivesync.moc"