1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/*
* 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 "accountmanager.h"
#include "common/utility.h"
#include "configfile.h"
#include "folderman.h"
#include "gui/networkinformation.h"
#include "testutils/testutils.h"
using namespace OCC;
namespace {
auto Settings_2_4()
{
return QStringLiteral(R"([Accounts]
version=2
0\Folders\1\localPath=
0\Folders\1\journalPath=._sync_2215dfc5505b.db
0\url=https://demo.owncloud.com
0\Folders\1\targetPath=/
0\http_oauth=true
0\serverVersion=10.8.0.4
0\Folders\1\paused=false
0\http_user=admin
0\Folders\1\ignoreHiddenFiles=true
0\authType=http
0\user=admin)");
}
}
class TestFolderMigration : public QObject
{
Q_OBJECT
private:
auto writeSettings(const QTemporaryDir &tmp, const QString &content)
{
QFile settingsFile(ConfigFile::configFile());
OC_ENFORCE(settingsFile.open(QFile::WriteOnly));
settingsFile.write(content.toUtf8());
settingsFile.close();
auto settings = ConfigFile::settingsWithGroup(QStringLiteral("Accounts"));
settings->setValue(QStringLiteral("0/Folders/1/localPath"), tmp.path());
qDebug() << settings->childGroups() << settings->childKeys();
return settings;
}
private Q_SLOTS:
void testFolderMigrationMissingJournalPath_data()
{
QTest::addColumn<QStringList>("journalPaths");
QTest::addColumn<QString>("url");
QTest::newRow("2.4") << QStringList{QStringLiteral("._sync_2215dfc5505b.db")} << QStringLiteral("https://demo.owncloud.com");
QTest::newRow("2.4 url") << QStringList{QStringLiteral("._sync_2215dfc5505b.db")} << QStringLiteral("https://demo.owncloud.com/");
QTest::newRow("2.6") << QStringList{QStringLiteral(".sync_2215dfc5505b.db")} << QStringLiteral("https://demo.owncloud.com");
QTest::newRow("2.6 url") << QStringList{QStringLiteral(".sync_2215dfc5505b.db")} << QStringLiteral("https://demo.owncloud.com/");
QTest::newRow("2.6 multi") << QStringList{QStringLiteral(".sync_2215dfc5505b.db"), QStringLiteral("._sync_2215dfc5505b.db")}
<< QStringLiteral("https://demo.owncloud.com");
QTest::newRow("2.9") << QStringList{QStringLiteral(".sync_journal.db")} << QStringLiteral("https://demo.owncloud.com");
QTest::newRow("2.9 url") << QStringList{QStringLiteral(".sync_journal.db")} << QStringLiteral("https://demo.owncloud.com/");
QTest::newRow("2.9 multi") << QStringList{QStringLiteral(".sync_journal.db"), QStringLiteral(".sync_2215dfc5505b.db"),
QStringLiteral("._sync_2215dfc5505b.db")}
<< "https://demo.owncloud.com";
}
void testFolderMigrationMissingJournalPath()
{
QFETCH(QStringList, journalPaths);
QFETCH(QString, url);
auto tmp = OCC::TestUtils::createTempDir();
const auto settings = writeSettings(tmp, Settings_2_4());
settings->setValue(QStringLiteral("0/url"), url);
settings->remove(QStringLiteral("0/Folders/1/journalPath"));
QVERIFY(!settings->value(QStringLiteral("0/Folders/1/journalPath")).isValid());
for (const auto &journalPath : journalPaths) {
QFile syncDb(tmp.filePath(journalPath));
QVERIFY(syncDb.open(QFile::WriteOnly));
syncDb.write("foo");
syncDb.close();
}
// init folder man
std::ignore = TestUtils::folderMan();
AccountManager::instance()->restore();
settings->beginGroup(QStringLiteral("0/Folders"));
TestUtils::folderMan()->setupFoldersHelper(*settings.get(), AccountManager::instance()->accounts().first());
settings->endGroup();
QCOMPARE(journalPaths.first(), settings->value(QStringLiteral("0/Folders/1/journalPath")));
delete TestUtils::folderMan();
}
};
QTEST_MAIN(TestFolderMigration)
#include "testfoldermigration.moc"
|