diff --git a/core/autotests/addressbook/CMakeLists.txt b/core/autotests/addressbook/CMakeLists.txt index 4c0fcda..a38634f 100644 --- a/core/autotests/addressbook/CMakeLists.txt +++ b/core/autotests/addressbook/CMakeLists.txt @@ -1,16 +1,16 @@ add_definitions( -DPIMDATAEXPORTER_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) -set( exportaddressbookjobinterfacetest_SRCS exportaddressbookjobinterfacetest.cpp) +set( exportaddressbookjobinterfacetest_SRCS exportaddressbookjobinterfacetest.cpp exportaddressbookjobinterfacetestimpl.cpp) add_executable( exportaddressbookjobinterfacetest ${exportaddressbookjobinterfacetest_SRCS}) add_test(NAME exportaddressbookjobinterfacetest COMMAND exportaddressbookjobinterfacetest) ecm_mark_as_test(exportaddressbookjobinterfacetest) target_link_libraries(exportaddressbookjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore test_resourceconverter) ##### -set( importaddressbookjobinterfacetest_SRCS importaddressbookjobinterfacetest.cpp) +set( importaddressbookjobinterfacetest_SRCS importaddressbookjobinterfacetest.cpp importaddressbookjobinterfacetestimpl.cpp) add_executable( importaddressbookjobinterfacetest ${importaddressbookjobinterfacetest_SRCS}) add_test(NAME importaddressbookjobinterfacetest COMMAND importaddressbookjobinterfacetest) ecm_mark_as_test(importaddressbookjobinterfacetest) target_link_libraries(importaddressbookjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore test_resourceconverter) diff --git a/core/autotests/addressbook/exportaddressbookjobinterfacetest.cpp b/core/autotests/addressbook/exportaddressbookjobinterfacetest.cpp index 7fb8601..4dc9839 100644 --- a/core/autotests/addressbook/exportaddressbookjobinterfacetest.cpp +++ b/core/autotests/addressbook/exportaddressbookjobinterfacetest.cpp @@ -1,149 +1,69 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "exportaddressbookjobinterfacetest.h" -#include "archivestorage.h" +#include "exportaddressbookjobinterfacetestimpl.h" #include "testexportfile.h" -#include "resourceconvertertest.h" -#include #include -#include -#include QTEST_MAIN(ExportAddressbookJobInterfaceTest) -ExportAddressbookJobInterfaceTestImpl::ExportAddressbookJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ExportAddressbookJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ExportAddressbookJobInterfaceTestImpl::~ExportAddressbookJobInterfaceTestImpl() -{ -} - -Akonadi::Collection::Id ExportAddressbookJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -void ExportAddressbookJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) -{ - SaveResoureConfigTest saveResourceConfig; - saveResourceConfig.setArchive(mArchiveStorage->archive()); - saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceAddressbookArchiveName(), - { QLatin1String("akonadi_vcarddir_resource_"), QLatin1String("akonadi_contacts_resource_") }); - slotAddressbookJobTerminated(); -} - -QVector ExportAddressbookJobInterfaceTestImpl::listOfResource() -{ - return mListAkonadiInstanceInfo; -} - -void ExportAddressbookJobInterfaceTestImpl::convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey) -{ - ResourceConverterTest resourceConverter; - resourceConverter.setTestPath(mPathConfig); - resourceConverter.convertCollectionToRealPath(group, currentKey); -} - -void ExportAddressbookJobInterfaceTestImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) -{ - ResourceConverterTest resourceConverter; - resourceConverter.setTestPath(mPathConfig); - resourceConverter.convertCollectionListToRealPath(group, currentKey); -} - -QString ExportAddressbookJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} - -QString ExportAddressbookJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - Q_UNREACHABLE(); - return {}; -} - -QString ExportAddressbookJobInterfaceTestImpl::resourcePath(const QString &agentIdentifier, const QString &defaultPath) const -{ - ResourceConverterTest converter; - converter.setTestPath(mPathConfig); - const QString url = converter.resourcePath(agentIdentifier, defaultPath); - return url; -} - -void ExportAddressbookJobInterfaceTestImpl::backupAddressBookResourceFile(const QString &agentIdentifier, const QString &defaultPath) -{ - TestBackupResourceFileJob *job = new TestBackupResourceFileJob(this); - job->setDefaultPath(defaultPath); - job->setIdentifier(agentIdentifier); - job->setTestPath(mPathConfig); - job->setZip(archive()); - connect(job, &TestBackupResourceFileJob::error, this, &ExportAddressbookJobInterfaceTestImpl::error); - connect(job, &TestBackupResourceFileJob::info, this, &ExportAddressbookJobInterfaceTestImpl::info); - job->start(); -} ExportAddressbookJobInterfaceTest::ExportAddressbookJobInterfaceTest(QObject *parent) : QObject(parent) { } void ExportAddressbookJobInterfaceTest::exportAddressBook_data() { QTest::addColumn("configpath"); QTest::addColumn("options"); const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); Utils::StoredTypes options = {Utils::StoredType::Config}; QTest::newRow("addressbookonlyconfig") << pathConfig + QByteArray("addressbookonlyconfig/") << options; options = {Utils::StoredType::Config | Utils::StoredType::Resources}; QTest::newRow("addressbookconfigandresources") << pathConfig + QByteArray("addressbookconfigandresources/") << options; } void ExportAddressbookJobInterfaceTest::exportAddressBook() { QFETCH(QByteArray, configpath); QFETCH(Utils::StoredTypes, options); TestExportFile *file = new TestExportFile(this); file->setPathConfig(configpath); QVector lstInfo; Utils::AkonadiInstanceInfo info; info.identifier = QStringLiteral("akonadi_vcarddir_resource_1"); lstInfo << info; info.identifier = QStringLiteral("akonadi_contacts_resource_1"); lstInfo << info; info.identifier = QStringLiteral("akonadi_vcard_resource_1"); lstInfo << info; //Add extra resource. info.identifier = QStringLiteral("akonadi_kolab_resource_2"); lstInfo << info; ExportAddressbookJobInterfaceTestImpl *exportNote = new ExportAddressbookJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); exportNote->setListOfResource(lstInfo); exportNote->setPathConfig(QLatin1String(configpath)); file->setAbstractImportExportJob(exportNote); file->start(); delete exportNote; } diff --git a/core/autotests/addressbook/exportaddressbookjobinterfacetest.h b/core/autotests/addressbook/exportaddressbookjobinterfacetest.h index 6f2d712..7656cf2 100644 --- a/core/autotests/addressbook/exportaddressbookjobinterfacetest.h +++ b/core/autotests/addressbook/exportaddressbookjobinterfacetest.h @@ -1,57 +1,37 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EXPORTADDRESSBOOKJOBINTERFACETEST_H #define EXPORTADDRESSBOOKJOBINTERFACETEST_H #include -#include "addressbook/exportaddressbookjobinterface.h" -#include "exportimportutil.h" -class ExportAddressbookJobInterfaceTestImpl : public ExportAddressbookJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ExportAddressbookJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ExportAddressbookJobInterfaceTestImpl(); - -protected: - void convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey) override; - void convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) override; - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; - Q_REQUIRED_RESULT QVector listOfResource() override; - Q_REQUIRED_RESULT QString resourcePath(const QString &agentIdentifier, const QString &defaultPath = QString()) const override; - void backupAddressBookResourceFile(const QString &agentIdentifier, const QString &defaultPath) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; -}; class ExportAddressbookJobInterfaceTest : public QObject { Q_OBJECT public: explicit ExportAddressbookJobInterfaceTest(QObject *parent = nullptr); ~ExportAddressbookJobInterfaceTest() = default; private Q_SLOTS: void exportAddressBook(); void exportAddressBook_data(); }; #endif // EXPORTADDRESSBOOKJOBINTERFACETEST_H diff --git a/core/autotests/addressbook/exportaddressbookjobinterfacetest.cpp b/core/autotests/addressbook/exportaddressbookjobinterfacetestimpl.cpp similarity index 68% copy from core/autotests/addressbook/exportaddressbookjobinterfacetest.cpp copy to core/autotests/addressbook/exportaddressbookjobinterfacetestimpl.cpp index 7fb8601..276f82a 100644 --- a/core/autotests/addressbook/exportaddressbookjobinterfacetest.cpp +++ b/core/autotests/addressbook/exportaddressbookjobinterfacetestimpl.cpp @@ -1,149 +1,101 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include "exportaddressbookjobinterfacetest.h" +#include "exportaddressbookjobinterfacetestimpl.h" #include "archivestorage.h" -#include "testexportfile.h" #include "resourceconvertertest.h" +#include "saveresourceconfigtest.h" +#include "testbackupresourcefilejob.h" #include -#include -#include -#include - -QTEST_MAIN(ExportAddressbookJobInterfaceTest) ExportAddressbookJobInterfaceTestImpl::ExportAddressbookJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ExportAddressbookJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ExportAddressbookJobInterfaceTestImpl::~ExportAddressbookJobInterfaceTestImpl() { } Akonadi::Collection::Id ExportAddressbookJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } void ExportAddressbookJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) { SaveResoureConfigTest saveResourceConfig; saveResourceConfig.setArchive(mArchiveStorage->archive()); saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceAddressbookArchiveName(), { QLatin1String("akonadi_vcarddir_resource_"), QLatin1String("akonadi_contacts_resource_") }); slotAddressbookJobTerminated(); } QVector ExportAddressbookJobInterfaceTestImpl::listOfResource() { return mListAkonadiInstanceInfo; } void ExportAddressbookJobInterfaceTestImpl::convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey) { ResourceConverterTest resourceConverter; resourceConverter.setTestPath(mPathConfig); resourceConverter.convertCollectionToRealPath(group, currentKey); } void ExportAddressbookJobInterfaceTestImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) { ResourceConverterTest resourceConverter; resourceConverter.setTestPath(mPathConfig); resourceConverter.convertCollectionListToRealPath(group, currentKey); } QString ExportAddressbookJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } QString ExportAddressbookJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { Q_UNREACHABLE(); return {}; } QString ExportAddressbookJobInterfaceTestImpl::resourcePath(const QString &agentIdentifier, const QString &defaultPath) const { ResourceConverterTest converter; converter.setTestPath(mPathConfig); const QString url = converter.resourcePath(agentIdentifier, defaultPath); return url; } void ExportAddressbookJobInterfaceTestImpl::backupAddressBookResourceFile(const QString &agentIdentifier, const QString &defaultPath) { TestBackupResourceFileJob *job = new TestBackupResourceFileJob(this); job->setDefaultPath(defaultPath); job->setIdentifier(agentIdentifier); job->setTestPath(mPathConfig); job->setZip(archive()); connect(job, &TestBackupResourceFileJob::error, this, &ExportAddressbookJobInterfaceTestImpl::error); connect(job, &TestBackupResourceFileJob::info, this, &ExportAddressbookJobInterfaceTestImpl::info); job->start(); } - -ExportAddressbookJobInterfaceTest::ExportAddressbookJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ExportAddressbookJobInterfaceTest::exportAddressBook_data() -{ - QTest::addColumn("configpath"); - QTest::addColumn("options"); - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - QTest::newRow("addressbookonlyconfig") << pathConfig + QByteArray("addressbookonlyconfig/") << options; - options = {Utils::StoredType::Config | Utils::StoredType::Resources}; - QTest::newRow("addressbookconfigandresources") << pathConfig + QByteArray("addressbookconfigandresources/") << options; -} - -void ExportAddressbookJobInterfaceTest::exportAddressBook() -{ - QFETCH(QByteArray, configpath); - QFETCH(Utils::StoredTypes, options); - TestExportFile *file = new TestExportFile(this); - file->setPathConfig(configpath); - QVector lstInfo; - Utils::AkonadiInstanceInfo info; - - info.identifier = QStringLiteral("akonadi_vcarddir_resource_1"); - lstInfo << info; - info.identifier = QStringLiteral("akonadi_contacts_resource_1"); - lstInfo << info; - info.identifier = QStringLiteral("akonadi_vcard_resource_1"); - lstInfo << info; - //Add extra resource. - info.identifier = QStringLiteral("akonadi_kolab_resource_2"); - lstInfo << info; - - ExportAddressbookJobInterfaceTestImpl *exportNote = new ExportAddressbookJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - exportNote->setListOfResource(lstInfo); - exportNote->setPathConfig(QLatin1String(configpath)); - file->setAbstractImportExportJob(exportNote); - file->start(); - delete exportNote; -} diff --git a/core/autotests/addressbook/exportaddressbookjobinterfacetest.h b/core/autotests/addressbook/exportaddressbookjobinterfacetestimpl.h similarity index 83% copy from core/autotests/addressbook/exportaddressbookjobinterfacetest.h copy to core/autotests/addressbook/exportaddressbookjobinterfacetestimpl.h index 6f2d712..3e5a2c0 100644 --- a/core/autotests/addressbook/exportaddressbookjobinterfacetest.h +++ b/core/autotests/addressbook/exportaddressbookjobinterfacetestimpl.h @@ -1,57 +1,45 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef EXPORTADDRESSBOOKJOBINTERFACETEST_H -#define EXPORTADDRESSBOOKJOBINTERFACETEST_H +#ifndef EXPORTADDRESSBOOKJOBINTERFACETESTIMPL_H +#define EXPORTADDRESSBOOKJOBINTERFACETESTIMPL_H -#include #include "addressbook/exportaddressbookjobinterface.h" #include "exportimportutil.h" class ExportAddressbookJobInterfaceTestImpl : public ExportAddressbookJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ExportAddressbookJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ExportAddressbookJobInterfaceTestImpl(); protected: void convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey) override; void convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) override; Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; Q_REQUIRED_RESULT QVector listOfResource() override; Q_REQUIRED_RESULT QString resourcePath(const QString &agentIdentifier, const QString &defaultPath = QString()) const override; void backupAddressBookResourceFile(const QString &agentIdentifier, const QString &defaultPath) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; }; -class ExportAddressbookJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ExportAddressbookJobInterfaceTest(QObject *parent = nullptr); - ~ExportAddressbookJobInterfaceTest() = default; -private Q_SLOTS: - void exportAddressBook(); - void exportAddressBook_data(); -}; - -#endif // EXPORTADDRESSBOOKJOBINTERFACETEST_H +#endif // EXPORTADDRESSBOOKJOBINTERFACETESTIMPL_H diff --git a/core/autotests/addressbook/importaddressbookjobinterfacetest.cpp b/core/autotests/addressbook/importaddressbookjobinterfacetest.cpp index 28176b3..0e485ac 100644 --- a/core/autotests/addressbook/importaddressbookjobinterfacetest.cpp +++ b/core/autotests/addressbook/importaddressbookjobinterfacetest.cpp @@ -1,107 +1,63 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "importaddressbookjobinterfacetest.h" -#include "archivestorage.h" -#include "resourceconvertertest.h" +#include "importaddressbookjobinterfacetestimpl.h" #include "testimportfile.h" #include #include QTEST_MAIN(ImportAddressbookJobInterfaceTest) -ImportAddressbookJobInterfaceTestImpl::ImportAddressbookJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ImportAddressbookJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ImportAddressbookJobInterfaceTestImpl::~ImportAddressbookJobInterfaceTestImpl() -{ - //Clean up temp repo - QVERIFY(QDir(extractPath()).removeRecursively()); -} - -Akonadi::Collection::Id ImportAddressbookJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -QString ImportAddressbookJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); -} - -void ImportAddressbookJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) -{ - mLogCreateResource->logSynchronizeResource(lst); - slotNextStep(); -} - -QString ImportAddressbookJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); -} - -QString ImportAddressbookJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} - ImportAddressbookJobInterfaceTest::ImportAddressbookJobInterfaceTest(QObject *parent) : QObject(parent) { } void ImportAddressbookJobInterfaceTest::importAddressbook_data() { QTest::addColumn("zipFilePath"); QTest::addColumn("testPath"); QTest::addColumn("options"); const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); Utils::StoredTypes options = {Utils::StoredType::Config}; QTest::newRow("addressbookonlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/addressbookonlyconfig/") << options; options = {Utils::StoredType::Config| Utils::StoredType::Resources}; QTest::newRow("addressbookconfigandresources") << QString::fromLatin1(pathConfig) << QStringLiteral("/addressbookconfigandresources/") << options; } void ImportAddressbookJobInterfaceTest::importAddressbook() { QFETCH(QString, zipFilePath); QFETCH(QString, testPath); QFETCH(Utils::StoredTypes, options); TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); file->setPathConfig(zipFilePath + testPath); file->setExtractPath(QDir::tempPath() + testPath); file->setExcludePath(Utils::addressbookPath()); ImportAddressbookJobInterfaceTestImpl *impl = new ImportAddressbookJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); impl->setPathConfig(file->pathConfig()); impl->setExtractPath(file->extractPath()); file->setAbstractImportExportJob(impl); file->setLoggingFilePath(impl->loggingFilePath()); file->start(); delete impl; delete file; } diff --git a/core/autotests/addressbook/importaddressbookjobinterfacetest.h b/core/autotests/addressbook/importaddressbookjobinterfacetest.h index f5ba3fc..c4f12c2 100644 --- a/core/autotests/addressbook/importaddressbookjobinterfacetest.h +++ b/core/autotests/addressbook/importaddressbookjobinterfacetest.h @@ -1,54 +1,35 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef IMPORTADDRESSBOOKJOBINTERFACETEST_H #define IMPORTADDRESSBOOKJOBINTERFACETEST_H #include -#include "exportimportutil.h" - -#include "addressbook/importaddressbookjobinterface.h" - -class ImportAddressbookJobInterfaceTestImpl : public ImportAddressbookJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ImportAddressbookJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ImportAddressbookJobInterfaceTestImpl(); - -protected: - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; - void synchronizeResource(const QStringList &lst) override; - Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; -}; - class ImportAddressbookJobInterfaceTest : public QObject { Q_OBJECT public: explicit ImportAddressbookJobInterfaceTest(QObject *parent = nullptr); ~ImportAddressbookJobInterfaceTest() = default; private Q_SLOTS: void importAddressbook(); void importAddressbook_data(); }; #endif // IMPORTADDRESSBOOKJOBINTERFACETEST_H diff --git a/core/autotests/addressbook/importaddressbookjobinterfacetest.cpp b/core/autotests/addressbook/importaddressbookjobinterfacetestimpl.cpp similarity index 60% copy from core/autotests/addressbook/importaddressbookjobinterfacetest.cpp copy to core/autotests/addressbook/importaddressbookjobinterfacetestimpl.cpp index 28176b3..aab82d1 100644 --- a/core/autotests/addressbook/importaddressbookjobinterfacetest.cpp +++ b/core/autotests/addressbook/importaddressbookjobinterfacetestimpl.cpp @@ -1,107 +1,68 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "importaddressbookjobinterfacetest.h" +#include "importaddressbookjobinterfacetestimpl.h" #include "archivestorage.h" #include "resourceconvertertest.h" -#include "testimportfile.h" -#include #include -QTEST_MAIN(ImportAddressbookJobInterfaceTest) + +#include ImportAddressbookJobInterfaceTestImpl::ImportAddressbookJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ImportAddressbookJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ImportAddressbookJobInterfaceTestImpl::~ImportAddressbookJobInterfaceTestImpl() { //Clean up temp repo QVERIFY(QDir(extractPath()).removeRecursively()); } Akonadi::Collection::Id ImportAddressbookJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } QString ImportAddressbookJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); } void ImportAddressbookJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) { mLogCreateResource->logSynchronizeResource(lst); slotNextStep(); } QString ImportAddressbookJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); } QString ImportAddressbookJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } - -ImportAddressbookJobInterfaceTest::ImportAddressbookJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ImportAddressbookJobInterfaceTest::importAddressbook_data() -{ - QTest::addColumn("zipFilePath"); - QTest::addColumn("testPath"); - QTest::addColumn("options"); - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - - QTest::newRow("addressbookonlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/addressbookonlyconfig/") << options; - options = {Utils::StoredType::Config| Utils::StoredType::Resources}; - QTest::newRow("addressbookconfigandresources") << QString::fromLatin1(pathConfig) << QStringLiteral("/addressbookconfigandresources/") << options; -} - -void ImportAddressbookJobInterfaceTest::importAddressbook() -{ - QFETCH(QString, zipFilePath); - QFETCH(QString, testPath); - QFETCH(Utils::StoredTypes, options); - - TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); - file->setPathConfig(zipFilePath + testPath); - file->setExtractPath(QDir::tempPath() + testPath); - file->setExcludePath(Utils::addressbookPath()); - ImportAddressbookJobInterfaceTestImpl *impl = new ImportAddressbookJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - impl->setPathConfig(file->pathConfig()); - impl->setExtractPath(file->extractPath()); - file->setAbstractImportExportJob(impl); - file->setLoggingFilePath(impl->loggingFilePath()); - file->start(); - delete impl; - delete file; -} diff --git a/core/autotests/addressbook/importaddressbookjobinterfacetest.h b/core/autotests/addressbook/importaddressbookjobinterfacetestimpl.h similarity index 80% copy from core/autotests/addressbook/importaddressbookjobinterfacetest.h copy to core/autotests/addressbook/importaddressbookjobinterfacetestimpl.h index f5ba3fc..3dd1a35 100644 --- a/core/autotests/addressbook/importaddressbookjobinterfacetest.h +++ b/core/autotests/addressbook/importaddressbookjobinterfacetestimpl.h @@ -1,54 +1,44 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef IMPORTADDRESSBOOKJOBINTERFACETEST_H -#define IMPORTADDRESSBOOKJOBINTERFACETEST_H -#include +#ifndef IMPORTADDRESSBOOKJOBINTERFACETESTIMPL_H +#define IMPORTADDRESSBOOKJOBINTERFACETESTIMPL_H + #include "exportimportutil.h" +#include "core/utils.h" #include "addressbook/importaddressbookjobinterface.h" class ImportAddressbookJobInterfaceTestImpl : public ImportAddressbookJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ImportAddressbookJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ImportAddressbookJobInterfaceTestImpl(); protected: Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; void synchronizeResource(const QStringList &lst) override; Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; }; -class ImportAddressbookJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ImportAddressbookJobInterfaceTest(QObject *parent = nullptr); - ~ImportAddressbookJobInterfaceTest() = default; -private Q_SLOTS: - void importAddressbook(); - void importAddressbook_data(); -}; - -#endif // IMPORTADDRESSBOOKJOBINTERFACETEST_H +#endif // IMPORTADDRESSBOOKJOBINTERFACETESTIMPL_H diff --git a/core/autotests/akregator/CMakeLists.txt b/core/autotests/akregator/CMakeLists.txt index e4a1353..a2f70f7 100644 --- a/core/autotests/akregator/CMakeLists.txt +++ b/core/autotests/akregator/CMakeLists.txt @@ -1,17 +1,17 @@ add_definitions( -DPIMDATAEXPORTER_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) -set( exportakregatorjobinterfacetest_SRCS exportakregatorjobinterfacetest.cpp) +set( exportakregatorjobinterfacetest_SRCS exportakregatorjobinterfacetest.cpp exportakregatorjobinterfacetestimpl.cpp) add_executable( exportakregatorjobinterfacetest ${exportakregatorjobinterfacetest_SRCS}) add_test(NAME exportakregatorjobinterfacetest COMMAND exportakregatorjobinterfacetest) ecm_mark_as_test(exportakregatorjobinterfacetest) target_link_libraries(exportakregatorjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore test_resourceconverter) ##### -set( importakregatorjobinterfacetest_SRCS importakregatorjobinterfacetest.cpp) +set( importakregatorjobinterfacetest_SRCS importakregatorjobinterfacetest.cpp importakregatorjobinterfacetestimpl.cpp) add_executable( importakregatorjobinterfacetest ${importakregatorjobinterfacetest_SRCS}) add_test(NAME importakregatorjobinterfacetest COMMAND importakregatorjobinterfacetest) ecm_mark_as_test(importakregatorjobinterfacetest) target_link_libraries(importakregatorjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore test_resourceconverter) diff --git a/core/autotests/akregator/exportakregatorjobinterfacetest.cpp b/core/autotests/akregator/exportakregatorjobinterfacetest.cpp index 1fca5a2..1b0619f 100644 --- a/core/autotests/akregator/exportakregatorjobinterfacetest.cpp +++ b/core/autotests/akregator/exportakregatorjobinterfacetest.cpp @@ -1,79 +1,58 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "exportakregatorjobinterfacetest.h" +#include "exportakregatorjobinterfacetestimpl.h" #include "archivestorage.h" -#include "resourceconvertertest.h" #include "testexportfile.h" -#include "compareexportfile.h" #include #include #include QTEST_MAIN(ExportAkregatorJobInterfaceTest) -ExportAkregatorJobInterfaceTestImpl::ExportAkregatorJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ExportAkregatorJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ExportAkregatorJobInterfaceTestImpl::~ExportAkregatorJobInterfaceTestImpl() -{ -} - -QString ExportAkregatorJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - Q_UNREACHABLE(); - return {}; -} - -QString ExportAkregatorJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - Q_UNREACHABLE(); - return {}; -} ExportAkregatorJobInterfaceTest::ExportAkregatorJobInterfaceTest(QObject *parent) : QObject(parent) { } void ExportAkregatorJobInterfaceTest::exportAkregator_data() { QTest::addColumn("configpath"); QTest::addColumn("options"); const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); Utils::StoredTypes options = {Utils::StoredType::Config}; //TODO options = {Utils::StoredType::Config | Utils::StoredType::Resources}; QTest::newRow("fullresource") << pathConfig + QByteArray("fullresource/") << options; } void ExportAkregatorJobInterfaceTest::exportAkregator() { QFETCH(QByteArray, configpath); QFETCH(Utils::StoredTypes, options); TestExportFile *file = new TestExportFile(this); file->setPathConfig(configpath); ExportAkregatorJobInterfaceTestImpl *exportAkregator = new ExportAkregatorJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); file->setAbstractImportExportJob(exportAkregator); file->start(); delete exportAkregator; } diff --git a/core/autotests/akregator/exportakregatorjobinterfacetest.h b/core/autotests/akregator/exportakregatorjobinterfacetest.h index f66297e..7377d7a 100644 --- a/core/autotests/akregator/exportakregatorjobinterfacetest.h +++ b/core/autotests/akregator/exportakregatorjobinterfacetest.h @@ -1,49 +1,38 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EXPORTAKREGATORJOBINTERFACETEST_H #define EXPORTAKREGATORJOBINTERFACETEST_H #include -#include "akregator/exportakregatorjobinterface.h" -class ExportAkregatorJobInterfaceTestImpl : public ExportAkregatorJobInterface -{ - Q_OBJECT -public: - explicit ExportAkregatorJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ExportAkregatorJobInterfaceTestImpl(); -protected: - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; -}; class ExportAkregatorJobInterfaceTest : public QObject { Q_OBJECT public: explicit ExportAkregatorJobInterfaceTest(QObject *parent = nullptr); ~ExportAkregatorJobInterfaceTest() = default; private Q_SLOTS: void exportAkregator_data(); void exportAkregator(); }; #endif // EXPORTAKREGATORJOBINTERFACETEST_H diff --git a/core/autotests/akregator/exportakregatorjobinterfacetest.cpp b/core/autotests/akregator/exportakregatorjobinterfacetestimpl.cpp similarity index 53% copy from core/autotests/akregator/exportakregatorjobinterfacetest.cpp copy to core/autotests/akregator/exportakregatorjobinterfacetestimpl.cpp index 1fca5a2..4c4a596 100644 --- a/core/autotests/akregator/exportakregatorjobinterfacetest.cpp +++ b/core/autotests/akregator/exportakregatorjobinterfacetestimpl.cpp @@ -1,79 +1,41 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "exportakregatorjobinterfacetest.h" -#include "archivestorage.h" -#include "resourceconvertertest.h" -#include "testexportfile.h" -#include "compareexportfile.h" -#include -#include -#include - -QTEST_MAIN(ExportAkregatorJobInterfaceTest) +#include "exportakregatorjobinterfacetestimpl.h" ExportAkregatorJobInterfaceTestImpl::ExportAkregatorJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ExportAkregatorJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ExportAkregatorJobInterfaceTestImpl::~ExportAkregatorJobInterfaceTestImpl() { } QString ExportAkregatorJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { Q_UNREACHABLE(); return {}; } QString ExportAkregatorJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { Q_UNREACHABLE(); return {}; } - -ExportAkregatorJobInterfaceTest::ExportAkregatorJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ExportAkregatorJobInterfaceTest::exportAkregator_data() -{ - QTest::addColumn("configpath"); - QTest::addColumn("options"); - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - //TODO - options = {Utils::StoredType::Config | Utils::StoredType::Resources}; - QTest::newRow("fullresource") << pathConfig + QByteArray("fullresource/") << options; -} - -void ExportAkregatorJobInterfaceTest::exportAkregator() -{ - QFETCH(QByteArray, configpath); - QFETCH(Utils::StoredTypes, options); - TestExportFile *file = new TestExportFile(this); - file->setPathConfig(configpath); - - ExportAkregatorJobInterfaceTestImpl *exportAkregator = new ExportAkregatorJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - file->setAbstractImportExportJob(exportAkregator); - file->start(); - delete exportAkregator; -} diff --git a/core/autotests/akregator/exportakregatorjobinterfacetest.h b/core/autotests/akregator/exportakregatorjobinterfacetestimpl.h similarity index 77% copy from core/autotests/akregator/exportakregatorjobinterfacetest.h copy to core/autotests/akregator/exportakregatorjobinterfacetestimpl.h index f66297e..d597600 100644 --- a/core/autotests/akregator/exportakregatorjobinterfacetest.h +++ b/core/autotests/akregator/exportakregatorjobinterfacetestimpl.h @@ -1,49 +1,35 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef EXPORTAKREGATORJOBINTERFACETEST_H -#define EXPORTAKREGATORJOBINTERFACETEST_H - -#include +#ifndef EXPORTAKREGATORJOBINTERFACETESTIMPL_H +#define EXPORTAKREGATORJOBINTERFACETESTIMPL_H #include "akregator/exportakregatorjobinterface.h" class ExportAkregatorJobInterfaceTestImpl : public ExportAkregatorJobInterface { Q_OBJECT public: explicit ExportAkregatorJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ExportAkregatorJobInterfaceTestImpl(); protected: Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; }; - -class ExportAkregatorJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ExportAkregatorJobInterfaceTest(QObject *parent = nullptr); - ~ExportAkregatorJobInterfaceTest() = default; -private Q_SLOTS: - void exportAkregator_data(); - void exportAkregator(); -}; - -#endif // EXPORTAKREGATORJOBINTERFACETEST_H +#endif // EXPORTAKREGATORJOBINTERFACETESTIMPL_H diff --git a/core/autotests/akregator/importakregatorjobinterfacetest.cpp b/core/autotests/akregator/importakregatorjobinterfacetest.cpp index 7ac4375..8a9c156 100644 --- a/core/autotests/akregator/importakregatorjobinterfacetest.cpp +++ b/core/autotests/akregator/importakregatorjobinterfacetest.cpp @@ -1,79 +1,59 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "importakregatorjobinterfacetest.h" +#include "importakregatorjobinterfacetestimpl.h" #include "archivestorage.h" -#include "resourceconvertertest.h" #include "testimportfile.h" #include #include QTEST_MAIN(ImportAkregatorJobInterfaceTest) -ImportAkregatorJobInterfaceTestImpl::ImportAkregatorJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ImportAkregatorJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ImportAkregatorJobInterfaceTestImpl::~ImportAkregatorJobInterfaceTestImpl() -{ -} - -Akonadi::Collection::Id ImportAkregatorJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - Q_UNREACHABLE(); - return -1; -} - -QString ImportAkregatorJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - Q_UNREACHABLE(); - return {}; -} ImportAkregatorJobInterfaceTest::ImportAkregatorJobInterfaceTest(QObject *parent) : QObject(parent) { } void ImportAkregatorJobInterfaceTest::importAkegator_data() { QTest::addColumn("zipFilePath"); QTest::addColumn("testPath"); QTest::addColumn("options"); const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); Utils::StoredTypes options = {Utils::StoredType::Config}; QTest::newRow("test1") << QString::fromLatin1(pathConfig) << QStringLiteral("/akregatorconfig/") << options; options = {Utils::StoredType::Config|Utils::StoredType::Resources}; QTest::newRow("test1resource") << QString::fromLatin1(pathConfig) << QStringLiteral("/akregatorresource/") << options; } void ImportAkregatorJobInterfaceTest::importAkegator() { QFETCH(QString, zipFilePath); QFETCH(QString, testPath); QFETCH(Utils::StoredTypes, options); TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); file->setPathConfig(zipFilePath + testPath); file->setExtractPath(QDir::tempPath() + testPath); ImportAkregatorJobInterfaceTestImpl *impl = new ImportAkregatorJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); file->setAbstractImportExportJob(impl); file->start(); delete impl; delete file; } diff --git a/core/autotests/akregator/importakregatorjobinterfacetest.h b/core/autotests/akregator/importakregatorjobinterfacetest.h index 3584714..2d06ba2 100644 --- a/core/autotests/akregator/importakregatorjobinterfacetest.h +++ b/core/autotests/akregator/importakregatorjobinterfacetest.h @@ -1,50 +1,38 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef IMPORTAKREGATORJOBINTERFACETEST_H #define IMPORTAKREGATORJOBINTERFACETEST_H #include -#include "akregator/importakregatorjobinterface.h" -class ImportAkregatorJobInterfaceTestImpl : public ImportAkregatorJobInterface -{ - Q_OBJECT -public: - explicit ImportAkregatorJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ImportAkregatorJobInterfaceTestImpl(); - -protected: - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; -}; class ImportAkregatorJobInterfaceTest : public QObject { Q_OBJECT public: explicit ImportAkregatorJobInterfaceTest(QObject *parent = nullptr); ~ImportAkregatorJobInterfaceTest() = default; private Q_SLOTS: void importAkegator_data(); void importAkegator(); }; #endif // IMPORTAKREGATORJOBINTERFACETEST_H diff --git a/core/autotests/akregator/importakregatorjobinterfacetestimpl.cpp b/core/autotests/akregator/importakregatorjobinterfacetestimpl.cpp new file mode 100644 index 0000000..c6ba892 --- /dev/null +++ b/core/autotests/akregator/importakregatorjobinterfacetestimpl.cpp @@ -0,0 +1,41 @@ +/* + Copyright (C) 2020 Laurent Montel + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "importakregatorjobinterfacetestimpl.h" + +ImportAkregatorJobInterfaceTestImpl::ImportAkregatorJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) + : ImportAkregatorJobInterface(parent, typeSelected, archiveStorage, numberOfStep) +{ +} + +ImportAkregatorJobInterfaceTestImpl::~ImportAkregatorJobInterfaceTestImpl() +{ +} + +Akonadi::Collection::Id ImportAkregatorJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) +{ + Q_UNREACHABLE(); + return -1; +} + +QString ImportAkregatorJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) +{ + Q_UNREACHABLE(); + return {}; +} diff --git a/core/autotests/akregator/importakregatorjobinterfacetest.h b/core/autotests/akregator/importakregatorjobinterfacetestimpl.h similarity index 76% copy from core/autotests/akregator/importakregatorjobinterfacetest.h copy to core/autotests/akregator/importakregatorjobinterfacetestimpl.h index 3584714..86149c9 100644 --- a/core/autotests/akregator/importakregatorjobinterfacetest.h +++ b/core/autotests/akregator/importakregatorjobinterfacetestimpl.h @@ -1,50 +1,37 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef IMPORTAKREGATORJOBINTERFACETEST_H -#define IMPORTAKREGATORJOBINTERFACETEST_H - -#include +#ifndef IMPORTAKREGATORJOBINTERFACETESTIMPL_H +#define IMPORTAKREGATORJOBINTERFACETESTIMPL_H #include "akregator/importakregatorjobinterface.h" class ImportAkregatorJobInterfaceTestImpl : public ImportAkregatorJobInterface { Q_OBJECT public: explicit ImportAkregatorJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ImportAkregatorJobInterfaceTestImpl(); protected: Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; }; -class ImportAkregatorJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ImportAkregatorJobInterfaceTest(QObject *parent = nullptr); - ~ImportAkregatorJobInterfaceTest() = default; -private Q_SLOTS: - void importAkegator_data(); - void importAkegator(); -}; - -#endif // IMPORTAKREGATORJOBINTERFACETEST_H +#endif // IMPORTAKREGATORJOBINTERFACETESTIMPL_H diff --git a/core/autotests/alarm/CMakeLists.txt b/core/autotests/alarm/CMakeLists.txt index 3ab9e74..4f2c86b 100644 --- a/core/autotests/alarm/CMakeLists.txt +++ b/core/autotests/alarm/CMakeLists.txt @@ -1,17 +1,17 @@ add_definitions( -DPIMDATAEXPORTER_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) -set( exportalarmjobinterfacetest_SRCS exportalarmjobinterfacetest.cpp) +set( exportalarmjobinterfacetest_SRCS exportalarmjobinterfacetest.cpp exportalarmjobinterfacetestimpl.cpp) add_executable( exportalarmjobinterfacetest ${exportalarmjobinterfacetest_SRCS}) add_test(NAME exportalarmjobinterfacetest COMMAND exportalarmjobinterfacetest) ecm_mark_as_test(exportalarmjobinterfacetest) target_link_libraries(exportalarmjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore test_resourceconverter) ##### -set( importalarmjobinterfacetest_SRCS importalarmjobinterfacetest.cpp) +set( importalarmjobinterfacetest_SRCS importalarmjobinterfacetest.cpp importalarmjobinterfacetestimpl.cpp) add_executable( importalarmjobinterfacetest ${importalarmjobinterfacetest_SRCS}) add_test(NAME importalarmjobinterfacetest COMMAND importalarmjobinterfacetest) ecm_mark_as_test(importalarmjobinterfacetest) target_link_libraries(importalarmjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore test_resourceconverter) diff --git a/core/autotests/alarm/exportalarmjobinterfacetest.cpp b/core/autotests/alarm/exportalarmjobinterfacetest.cpp index 0a2e719..9bb2563 100644 --- a/core/autotests/alarm/exportalarmjobinterfacetest.cpp +++ b/core/autotests/alarm/exportalarmjobinterfacetest.cpp @@ -1,139 +1,70 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "exportalarmjobinterfacetest.h" +#include "exportalarmjobinterfacetestimpl.h" #include "archivestorage.h" #include "testexportfile.h" -#include "resourceconvertertest.h" #include #include #include -#include -#include QTEST_MAIN(ExportAlarmJobInterfaceTest) -ExportAlarmJobInterfaceTestImpl::ExportAlarmJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ExportAlarmJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ExportAlarmJobInterfaceTestImpl::~ExportAlarmJobInterfaceTestImpl() -{ -} - -QVector ExportAlarmJobInterfaceTestImpl::listOfResource() -{ - return mListAkonadiInstanceInfo; -} - -Akonadi::Collection::Id ExportAlarmJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -void ExportAlarmJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) -{ - SaveResoureConfigTest saveResourceConfig; - saveResourceConfig.setArchive(mArchiveStorage->archive()); - saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceAlarmArchiveName(), { QLatin1String("akonadi_kalarm_dir_resource_")}); - slotAlarmJobTerminated(); -} -QString ExportAlarmJobInterfaceTestImpl::resourcePath(const QString &identifier) const -{ - ResourceConverterTest converter; - converter.setTestPath(mPathConfig); - const QString url = converter.resourcePath(identifier); - return url; -} - -void ExportAlarmJobInterfaceTestImpl::backupAlarmResourceFile(const QString &agentIdentifier, const QString &defaultPath) -{ - TestBackupResourceFileJob *job = new TestBackupResourceFileJob(this); - job->setDefaultPath(defaultPath); - job->setIdentifier(agentIdentifier); - job->setTestPath(mPathConfig); - job->setZip(archive()); - connect(job, &TestBackupResourceFileJob::error, this, &ExportAlarmJobInterfaceTestImpl::error); - connect(job, &TestBackupResourceFileJob::info, this, &ExportAlarmJobInterfaceTestImpl::info); - job->start(); -} - -QString ExportAlarmJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} - -void ExportAlarmJobInterfaceTestImpl::convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertCollectionIdsToRealPath(selectFolderNoteGroup, selectFolderNoteGroupStr); -} - -QString ExportAlarmJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - Q_UNREACHABLE(); - return {}; -} ExportAlarmJobInterfaceTest::ExportAlarmJobInterfaceTest(QObject *parent) : QObject(parent) { } void ExportAlarmJobInterfaceTest::exportAlarm_data() { QTest::addColumn("configpath"); QTest::addColumn("options"); Utils::StoredTypes options = {Utils::StoredType::Config}; const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); QTest::newRow("alarmonlyconfig") << pathConfig + QByteArray("alarmonlyconfig/") << options; options = {Utils::StoredType::Config|Utils::StoredType::Resources}; QTest::newRow("alarmconfigresources") << pathConfig + QByteArray("alarmconfigresources/") << options; } void ExportAlarmJobInterfaceTest::exportAlarm() { QFETCH(QByteArray, configpath); QFETCH(Utils::StoredTypes, options); TestExportFile *file = new TestExportFile(this); file->setPathConfig(configpath); QVector lstInfo; Utils::AkonadiInstanceInfo info; info.identifier = QLatin1String("akonadi_kalarm_dir_resource_1"); lstInfo << info; info.identifier = QLatin1String("akonadi_kalarm_dir_resource_2"); lstInfo << info; //Add extra resource. info.identifier = QStringLiteral("akonadi_kolab_resource_2"); lstInfo << info; ExportAlarmJobInterfaceTestImpl *exportNote = new ExportAlarmJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); exportNote->setListOfResource(lstInfo); exportNote->setPathConfig(QLatin1String(configpath)); file->setAbstractImportExportJob(exportNote); file->start(); delete exportNote; } diff --git a/core/autotests/alarm/exportalarmjobinterfacetest.h b/core/autotests/alarm/exportalarmjobinterfacetest.h index 4878103..8be1bef 100644 --- a/core/autotests/alarm/exportalarmjobinterfacetest.h +++ b/core/autotests/alarm/exportalarmjobinterfacetest.h @@ -1,56 +1,37 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef ExportAlarmJobInterfaceTest_H #define ExportAlarmJobInterfaceTest_H #include -#include "alarm/exportalarmjobinterface.h" -#include "exportimportutil.h" - -class ExportAlarmJobInterfaceTestImpl : public ExportAlarmJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ExportAlarmJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ExportAlarmJobInterfaceTestImpl(); -protected: - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; - Q_REQUIRED_RESULT QVector listOfResource() override; - Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override; - void backupAlarmResourceFile(const QString &agentIdentifier, const QString &defaultPath) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; - void convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) override; -}; class ExportAlarmJobInterfaceTest : public QObject { Q_OBJECT public: explicit ExportAlarmJobInterfaceTest(QObject *parent = nullptr); ~ExportAlarmJobInterfaceTest() = default; private Q_SLOTS: void exportAlarm(); void exportAlarm_data(); }; #endif // ExportAlarmJobInterfaceTest_H diff --git a/core/autotests/alarm/exportalarmjobinterfacetest.cpp b/core/autotests/alarm/exportalarmjobinterfacetestimpl.cpp similarity index 67% copy from core/autotests/alarm/exportalarmjobinterfacetest.cpp copy to core/autotests/alarm/exportalarmjobinterfacetestimpl.cpp index 0a2e719..1ab9c79 100644 --- a/core/autotests/alarm/exportalarmjobinterfacetest.cpp +++ b/core/autotests/alarm/exportalarmjobinterfacetestimpl.cpp @@ -1,139 +1,95 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "exportalarmjobinterfacetest.h" +#include "exportalarmjobinterfacetestimpl.h" #include "archivestorage.h" -#include "testexportfile.h" #include "resourceconvertertest.h" +#include "testbackupresourcefilejob.h" +#include "saveresourceconfigtest.h" #include -#include -#include -#include -#include - -QTEST_MAIN(ExportAlarmJobInterfaceTest) ExportAlarmJobInterfaceTestImpl::ExportAlarmJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ExportAlarmJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ExportAlarmJobInterfaceTestImpl::~ExportAlarmJobInterfaceTestImpl() { } QVector ExportAlarmJobInterfaceTestImpl::listOfResource() { return mListAkonadiInstanceInfo; } Akonadi::Collection::Id ExportAlarmJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } void ExportAlarmJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) { SaveResoureConfigTest saveResourceConfig; saveResourceConfig.setArchive(mArchiveStorage->archive()); saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceAlarmArchiveName(), { QLatin1String("akonadi_kalarm_dir_resource_")}); slotAlarmJobTerminated(); } QString ExportAlarmJobInterfaceTestImpl::resourcePath(const QString &identifier) const { ResourceConverterTest converter; converter.setTestPath(mPathConfig); const QString url = converter.resourcePath(identifier); return url; } void ExportAlarmJobInterfaceTestImpl::backupAlarmResourceFile(const QString &agentIdentifier, const QString &defaultPath) { TestBackupResourceFileJob *job = new TestBackupResourceFileJob(this); job->setDefaultPath(defaultPath); job->setIdentifier(agentIdentifier); job->setTestPath(mPathConfig); job->setZip(archive()); connect(job, &TestBackupResourceFileJob::error, this, &ExportAlarmJobInterfaceTestImpl::error); connect(job, &TestBackupResourceFileJob::info, this, &ExportAlarmJobInterfaceTestImpl::info); job->start(); } QString ExportAlarmJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } void ExportAlarmJobInterfaceTestImpl::convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertCollectionIdsToRealPath(selectFolderNoteGroup, selectFolderNoteGroupStr); } QString ExportAlarmJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { Q_UNREACHABLE(); return {}; } -ExportAlarmJobInterfaceTest::ExportAlarmJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ExportAlarmJobInterfaceTest::exportAlarm_data() -{ - QTest::addColumn("configpath"); - QTest::addColumn("options"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); - QTest::newRow("alarmonlyconfig") << pathConfig + QByteArray("alarmonlyconfig/") << options; - options = {Utils::StoredType::Config|Utils::StoredType::Resources}; - QTest::newRow("alarmconfigresources") << pathConfig + QByteArray("alarmconfigresources/") << options; -} - -void ExportAlarmJobInterfaceTest::exportAlarm() -{ - QFETCH(QByteArray, configpath); - QFETCH(Utils::StoredTypes, options); - TestExportFile *file = new TestExportFile(this); - file->setPathConfig(configpath); - QVector lstInfo; - Utils::AkonadiInstanceInfo info; - info.identifier = QLatin1String("akonadi_kalarm_dir_resource_1"); - lstInfo << info; - info.identifier = QLatin1String("akonadi_kalarm_dir_resource_2"); - lstInfo << info; - //Add extra resource. - info.identifier = QStringLiteral("akonadi_kolab_resource_2"); - lstInfo << info; - - ExportAlarmJobInterfaceTestImpl *exportNote = new ExportAlarmJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - exportNote->setListOfResource(lstInfo); - exportNote->setPathConfig(QLatin1String(configpath)); - file->setAbstractImportExportJob(exportNote); - file->start(); - delete exportNote; -} diff --git a/core/autotests/alarm/exportalarmjobinterfacetest.h b/core/autotests/alarm/exportalarmjobinterfacetestimpl.h similarity index 84% copy from core/autotests/alarm/exportalarmjobinterfacetest.h copy to core/autotests/alarm/exportalarmjobinterfacetestimpl.h index 4878103..c7a92e9 100644 --- a/core/autotests/alarm/exportalarmjobinterfacetest.h +++ b/core/autotests/alarm/exportalarmjobinterfacetestimpl.h @@ -1,56 +1,43 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef ExportAlarmJobInterfaceTest_H -#define ExportAlarmJobInterfaceTest_H - -#include +#ifndef EXPORTALARMJOBINTERFACETESTIMPL_H +#define EXPORTALARMJOBINTERFACETESTIMPL_H #include "alarm/exportalarmjobinterface.h" #include "exportimportutil.h" class ExportAlarmJobInterfaceTestImpl : public ExportAlarmJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ExportAlarmJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ExportAlarmJobInterfaceTestImpl(); protected: Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; Q_REQUIRED_RESULT QVector listOfResource() override; Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override; void backupAlarmResourceFile(const QString &agentIdentifier, const QString &defaultPath) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; void convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) override; }; -class ExportAlarmJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ExportAlarmJobInterfaceTest(QObject *parent = nullptr); - ~ExportAlarmJobInterfaceTest() = default; -private Q_SLOTS: - void exportAlarm(); - void exportAlarm_data(); -}; - -#endif // ExportAlarmJobInterfaceTest_H +#endif // EXPORTALARMJOBINTERFACETESTIMPL_H diff --git a/core/autotests/alarm/importalarmjobinterfacetest.cpp b/core/autotests/alarm/importalarmjobinterfacetest.cpp index a6b161a..0721a6e 100644 --- a/core/autotests/alarm/importalarmjobinterfacetest.cpp +++ b/core/autotests/alarm/importalarmjobinterfacetest.cpp @@ -1,104 +1,62 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "importalarmjobinterfacetest.h" +#include "importalarmjobinterfacetestimpl.h" #include "archivestorage.h" -#include "resourceconvertertest.h" #include "testimportfile.h" #include #include QTEST_MAIN(ImportAlarmJobInterfaceTest) -ImportAlarmJobInterfaceTestImpl::ImportAlarmJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ImportAlarmJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ImportAlarmJobInterfaceTestImpl::~ImportAlarmJobInterfaceTestImpl() -{ - //Clean up temp repo - QVERIFY(QDir(QDir::tempPath() + QLatin1Char('/') + Utils::storeAlarm()).removeRecursively()); -} - -Akonadi::Collection::Id ImportAlarmJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -QString ImportAlarmJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); -} - -void ImportAlarmJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) -{ - mLogCreateResource->logSynchronizeResource(lst); - slotNextStep(); -} - -QString ImportAlarmJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); -} - -QString ImportAlarmJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} ImportAlarmJobInterfaceTest::ImportAlarmJobInterfaceTest(QObject *parent) : QObject(parent) { } void ImportAlarmJobInterfaceTest::importAlarmConfig_data() { QTest::addColumn("zipFilePath"); QTest::addColumn("testPath"); QTest::addColumn("options"); Utils::StoredTypes options = {Utils::StoredType::Config}; const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); QTest::newRow("alarmonlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/alarmonlyconfig/") << options; options = {Utils::StoredType::Config|Utils::StoredType::Resources}; QTest::newRow("alarmconfigresources") << QString::fromLatin1(pathConfig) << QStringLiteral("/alarmconfigresources/") << options; } void ImportAlarmJobInterfaceTest::importAlarmConfig() { QFETCH(QString, zipFilePath); QFETCH(QString, testPath); QFETCH(Utils::StoredTypes, options); TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); file->setPathConfig(zipFilePath + testPath); file->setExtractPath(QDir::tempPath() + testPath); file->setExcludePath(Utils::alarmPath()); ImportAlarmJobInterfaceTestImpl *impl = new ImportAlarmJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); impl->setPathConfig(file->pathConfig()); file->setAbstractImportExportJob(impl); file->setLoggingFilePath(impl->loggingFilePath()); file->start(); delete impl; delete file; } diff --git a/core/autotests/alarm/importalarmjobinterfacetest.h b/core/autotests/alarm/importalarmjobinterfacetest.h index 28f37de..9805c1e 100644 --- a/core/autotests/alarm/importalarmjobinterfacetest.h +++ b/core/autotests/alarm/importalarmjobinterfacetest.h @@ -1,54 +1,37 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef IMPORTALARMJOBINTERFACETEST_H #define IMPORTALARMJOBINTERFACETEST_H #include -#include "exportimportutil.h" -#include "alarm/importalarmjobinterface.h" - -class ImportAlarmJobInterfaceTestImpl : public ImportAlarmJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ImportAlarmJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ImportAlarmJobInterfaceTestImpl(); - -protected: - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; - void synchronizeResource(const QStringList &lst) override; - Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; -}; class ImportAlarmJobInterfaceTest : public QObject { Q_OBJECT public: explicit ImportAlarmJobInterfaceTest(QObject *parent = nullptr); ~ImportAlarmJobInterfaceTest() = default; private Q_SLOTS: void importAlarmConfig(); void importAlarmConfig_data(); }; #endif // IMPORTALARMJOBINTERFACETEST_H diff --git a/core/autotests/alarm/importalarmjobinterfacetest.cpp b/core/autotests/alarm/importalarmjobinterfacetestimpl.cpp similarity index 62% copy from core/autotests/alarm/importalarmjobinterfacetest.cpp copy to core/autotests/alarm/importalarmjobinterfacetestimpl.cpp index a6b161a..e7aa372 100644 --- a/core/autotests/alarm/importalarmjobinterfacetest.cpp +++ b/core/autotests/alarm/importalarmjobinterfacetestimpl.cpp @@ -1,104 +1,69 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "importalarmjobinterfacetest.h" + +#include "importalarmjobinterfacetestimpl.h" #include "archivestorage.h" #include "resourceconvertertest.h" -#include "testimportfile.h" -#include + +#include #include -QTEST_MAIN(ImportAlarmJobInterfaceTest) ImportAlarmJobInterfaceTestImpl::ImportAlarmJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ImportAlarmJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ImportAlarmJobInterfaceTestImpl::~ImportAlarmJobInterfaceTestImpl() { //Clean up temp repo QVERIFY(QDir(QDir::tempPath() + QLatin1Char('/') + Utils::storeAlarm()).removeRecursively()); } Akonadi::Collection::Id ImportAlarmJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } QString ImportAlarmJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); } void ImportAlarmJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) { mLogCreateResource->logSynchronizeResource(lst); slotNextStep(); } QString ImportAlarmJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); } QString ImportAlarmJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } - -ImportAlarmJobInterfaceTest::ImportAlarmJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ImportAlarmJobInterfaceTest::importAlarmConfig_data() -{ - QTest::addColumn("zipFilePath"); - QTest::addColumn("testPath"); - QTest::addColumn("options"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); - QTest::newRow("alarmonlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/alarmonlyconfig/") << options; - options = {Utils::StoredType::Config|Utils::StoredType::Resources}; - QTest::newRow("alarmconfigresources") << QString::fromLatin1(pathConfig) << QStringLiteral("/alarmconfigresources/") << options; -} - -void ImportAlarmJobInterfaceTest::importAlarmConfig() -{ - QFETCH(QString, zipFilePath); - QFETCH(QString, testPath); - QFETCH(Utils::StoredTypes, options); - TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); - file->setPathConfig(zipFilePath + testPath); - file->setExtractPath(QDir::tempPath() + testPath); - file->setExcludePath(Utils::alarmPath()); - ImportAlarmJobInterfaceTestImpl *impl = new ImportAlarmJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - impl->setPathConfig(file->pathConfig()); - file->setAbstractImportExportJob(impl); - file->setLoggingFilePath(impl->loggingFilePath()); - file->start(); - delete impl; - delete file; -} diff --git a/core/autotests/alarm/importalarmjobinterfacetest.h b/core/autotests/alarm/importalarmjobinterfacetestimpl.h similarity index 81% copy from core/autotests/alarm/importalarmjobinterfacetest.h copy to core/autotests/alarm/importalarmjobinterfacetestimpl.h index 28f37de..4a12bf6 100644 --- a/core/autotests/alarm/importalarmjobinterfacetest.h +++ b/core/autotests/alarm/importalarmjobinterfacetestimpl.h @@ -1,54 +1,43 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef IMPORTALARMJOBINTERFACETEST_H -#define IMPORTALARMJOBINTERFACETEST_H -#include +#ifndef IMPORTALARMJOBINTERFACETESTIMPL_H +#define IMPORTALARMJOBINTERFACETESTIMPL_H + #include "exportimportutil.h" #include "alarm/importalarmjobinterface.h" class ImportAlarmJobInterfaceTestImpl : public ImportAlarmJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ImportAlarmJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ImportAlarmJobInterfaceTestImpl(); protected: Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; void synchronizeResource(const QStringList &lst) override; Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; }; -class ImportAlarmJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ImportAlarmJobInterfaceTest(QObject *parent = nullptr); - ~ImportAlarmJobInterfaceTest() = default; -private Q_SLOTS: - void importAlarmConfig(); - void importAlarmConfig_data(); -}; - -#endif // IMPORTALARMJOBINTERFACETEST_H +#endif // IMPORTALARMJOBINTERFACETESTIMPL_H diff --git a/core/autotests/calendar/CMakeLists.txt b/core/autotests/calendar/CMakeLists.txt index 8f2594e..e33cad5 100644 --- a/core/autotests/calendar/CMakeLists.txt +++ b/core/autotests/calendar/CMakeLists.txt @@ -1,17 +1,17 @@ add_definitions( -DPIMDATAEXPORTER_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) -set( exportcalendarsjobinterfacetest_SRCS exportcalendarsjobinterfacetest.cpp) +set( exportcalendarsjobinterfacetest_SRCS exportcalendarsjobinterfacetest.cpp exportcalendarsjobinterfacetestimpl.cpp) add_executable( exportcalendarsjobinterfacetest ${exportcalendarsjobinterfacetest_SRCS}) add_test(NAME exportcalendarsjobinterfacetest COMMAND exportcalendarsjobinterfacetest) ecm_mark_as_test(exportcalendarsjobinterfacetest) target_link_libraries(exportcalendarsjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore test_resourceconverter) ##### -set( importcalendarjobinterfacetest_SRCS importcalendarjobinterfacetest.cpp) +set( importcalendarjobinterfacetest_SRCS importcalendarjobinterfacetest.cpp importcalendarjobinterfacetestimpl.cpp) add_executable( importcalendarjobinterfacetest ${importcalendarjobinterfacetest_SRCS}) add_test(NAME importcalendarjobinterfacetest COMMAND importcalendarjobinterfacetest) ecm_mark_as_test(importcalendarjobinterfacetest) target_link_libraries(importcalendarjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore test_resourceconverter) diff --git a/core/autotests/calendar/exportcalendarsjobinterfacetest.cpp b/core/autotests/calendar/exportcalendarsjobinterfacetest.cpp index ee5b87d..dfb52aa 100644 --- a/core/autotests/calendar/exportcalendarsjobinterfacetest.cpp +++ b/core/autotests/calendar/exportcalendarsjobinterfacetest.cpp @@ -1,148 +1,69 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "exportcalendarsjobinterfacetest.h" +#include "exportcalendarsjobinterfacetestimpl.h" #include "archivestorage.h" -#include "resourceconvertertest.h" #include "testexportfile.h" #include #include -#include -#include QTEST_MAIN(ExportCalendarsJobInterfaceTest) -ExportCalendarsJobInterfaceTestImpl::ExportCalendarsJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ExportCalendarJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ExportCalendarsJobInterfaceTestImpl::~ExportCalendarsJobInterfaceTestImpl() -{ -} - -Akonadi::Collection::Id ExportCalendarsJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -QString ExportCalendarsJobInterfaceTestImpl::convertToFullCollectionPath(const qlonglong collectionValue) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertToFullCollectionPath(collectionValue); -} - -void ExportCalendarsJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) -{ - qDebug() << " void ExportCalendarsJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier)" << identifier; - SaveResoureConfigTest saveResourceConfig; - saveResourceConfig.setArchive(mArchiveStorage->archive()); - saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceCalendarArchiveName(), { QLatin1String("akonadi_icaldir_resource_")}); - slotCalendarJobTerminated(); -} - -QVector ExportCalendarsJobInterfaceTestImpl::listOfResource() -{ - return mListAkonadiInstanceInfo; -} - -void ExportCalendarsJobInterfaceTestImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) -{ - ResourceConverterTest converter; - converter.setTestPath(mPathConfig); - converter.convertCollectionListToRealPath(group, currentKey); -} - -QString ExportCalendarsJobInterfaceTestImpl::resourcePath(const QString &identifier) const -{ - ResourceConverterTest converter; - converter.setTestPath(mPathConfig); - const QString url = converter.resourcePath(identifier); - return url; -} - -void ExportCalendarsJobInterfaceTestImpl::backupCalendarResourceFile(const QString &agentIdentifier, const QString &defaultPath) -{ - TestBackupResourceFileJob *job = new TestBackupResourceFileJob(this); - job->setDefaultPath(defaultPath); - job->setIdentifier(agentIdentifier); - job->setTestPath(mPathConfig); - job->setZip(archive()); - connect(job, &TestBackupResourceFileJob::error, this, &ExportCalendarsJobInterfaceTestImpl::error); - connect(job, &TestBackupResourceFileJob::info, this, &ExportCalendarsJobInterfaceTestImpl::info); - job->start(); -} - -QString ExportCalendarsJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} - -QString ExportCalendarsJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - Q_UNREACHABLE(); - return {}; -} - ExportCalendarsJobInterfaceTest::ExportCalendarsJobInterfaceTest(QObject *parent) : QObject(parent) { } void ExportCalendarsJobInterfaceTest::exportCalendar_data() { QTest::addColumn("configpath"); QTest::addColumn("options"); Utils::StoredTypes options = {Utils::StoredType::Config}; const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); QTest::newRow("calendaronlyconfig") << pathConfig + QByteArray("calendaronlyconfig/") << options; options = {Utils::StoredType::Config|Utils::StoredType::Resources}; QTest::newRow("calendarconfigandresources") << pathConfig + QByteArray("calendarconfigandresources/") << options; } void ExportCalendarsJobInterfaceTest::exportCalendar() { QFETCH(QByteArray, configpath); QFETCH(Utils::StoredTypes, options); TestExportFile *file = new TestExportFile(this); file->setPathConfig(configpath); QVector lstInfo; Utils::AkonadiInstanceInfo info; info.identifier = QLatin1String("akonadi_icaldir_resource_1"); lstInfo << info; info.identifier = QLatin1String("akonadi_ical_resource_2"); lstInfo << info; //Add extra resource. info.identifier = QLatin1String("akonadi_contacts_resource_1"); lstInfo << info; info.identifier = QStringLiteral("akonadi_kontact_resource_2"); lstInfo << info; ExportCalendarsJobInterfaceTestImpl *exportNote = new ExportCalendarsJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); exportNote->setListOfResource(lstInfo); exportNote->setPathConfig(QLatin1String(configpath)); file->setAbstractImportExportJob(exportNote); file->start(); delete exportNote; } diff --git a/core/autotests/calendar/exportcalendarsjobinterfacetest.h b/core/autotests/calendar/exportcalendarsjobinterfacetest.h index 8429821..24fba98 100644 --- a/core/autotests/calendar/exportcalendarsjobinterfacetest.h +++ b/core/autotests/calendar/exportcalendarsjobinterfacetest.h @@ -1,57 +1,38 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EXPORTCALENDARSJOBINTERFACETEST_H #define EXPORTCALENDARSJOBINTERFACETEST_H #include -#include "calendar/exportcalendarjobinterface.h" -#include "exportimportutil.h" -class ExportCalendarsJobInterfaceTestImpl : public ExportCalendarJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ExportCalendarsJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ExportCalendarsJobInterfaceTestImpl(); - -protected: - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - Q_REQUIRED_RESULT QString convertToFullCollectionPath(const qlonglong collectionValue) override; - void convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) override; - void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; - Q_REQUIRED_RESULT QVector listOfResource() override; - Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override; - void backupCalendarResourceFile(const QString &agentIdentifier, const QString &defaultPath) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; -}; + class ExportCalendarsJobInterfaceTest : public QObject { Q_OBJECT public: explicit ExportCalendarsJobInterfaceTest(QObject *parent = nullptr); ~ExportCalendarsJobInterfaceTest() = default; private Q_SLOTS: void exportCalendar_data(); void exportCalendar(); }; #endif // EXPORTCALENDARSJOBINTERFACETEST_H diff --git a/core/autotests/calendar/exportcalendarsjobinterfacetest.cpp b/core/autotests/calendar/exportcalendarsjobinterfacetestimpl.cpp similarity index 68% copy from core/autotests/calendar/exportcalendarsjobinterfacetest.cpp copy to core/autotests/calendar/exportcalendarsjobinterfacetestimpl.cpp index ee5b87d..eedd4e6 100644 --- a/core/autotests/calendar/exportcalendarsjobinterfacetest.cpp +++ b/core/autotests/calendar/exportcalendarsjobinterfacetestimpl.cpp @@ -1,148 +1,103 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "exportcalendarsjobinterfacetest.h" + +#include "exportcalendarsjobinterfacetestimpl.h" #include "archivestorage.h" #include "resourceconvertertest.h" -#include "testexportfile.h" +#include "testbackupresourcefilejob.h" +#include "saveresourceconfigtest.h" #include -#include -#include -#include - -QTEST_MAIN(ExportCalendarsJobInterfaceTest) ExportCalendarsJobInterfaceTestImpl::ExportCalendarsJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ExportCalendarJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ExportCalendarsJobInterfaceTestImpl::~ExportCalendarsJobInterfaceTestImpl() { } Akonadi::Collection::Id ExportCalendarsJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } QString ExportCalendarsJobInterfaceTestImpl::convertToFullCollectionPath(const qlonglong collectionValue) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertToFullCollectionPath(collectionValue); } void ExportCalendarsJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) { qDebug() << " void ExportCalendarsJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier)" << identifier; SaveResoureConfigTest saveResourceConfig; saveResourceConfig.setArchive(mArchiveStorage->archive()); saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceCalendarArchiveName(), { QLatin1String("akonadi_icaldir_resource_")}); slotCalendarJobTerminated(); } QVector ExportCalendarsJobInterfaceTestImpl::listOfResource() { return mListAkonadiInstanceInfo; } void ExportCalendarsJobInterfaceTestImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) { ResourceConverterTest converter; converter.setTestPath(mPathConfig); converter.convertCollectionListToRealPath(group, currentKey); } QString ExportCalendarsJobInterfaceTestImpl::resourcePath(const QString &identifier) const { ResourceConverterTest converter; converter.setTestPath(mPathConfig); const QString url = converter.resourcePath(identifier); return url; } void ExportCalendarsJobInterfaceTestImpl::backupCalendarResourceFile(const QString &agentIdentifier, const QString &defaultPath) { TestBackupResourceFileJob *job = new TestBackupResourceFileJob(this); job->setDefaultPath(defaultPath); job->setIdentifier(agentIdentifier); job->setTestPath(mPathConfig); job->setZip(archive()); connect(job, &TestBackupResourceFileJob::error, this, &ExportCalendarsJobInterfaceTestImpl::error); connect(job, &TestBackupResourceFileJob::info, this, &ExportCalendarsJobInterfaceTestImpl::info); job->start(); } QString ExportCalendarsJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } QString ExportCalendarsJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { Q_UNREACHABLE(); return {}; } - -ExportCalendarsJobInterfaceTest::ExportCalendarsJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ExportCalendarsJobInterfaceTest::exportCalendar_data() -{ - QTest::addColumn("configpath"); - QTest::addColumn("options"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); - QTest::newRow("calendaronlyconfig") << pathConfig + QByteArray("calendaronlyconfig/") << options; - options = {Utils::StoredType::Config|Utils::StoredType::Resources}; - QTest::newRow("calendarconfigandresources") << pathConfig + QByteArray("calendarconfigandresources/") << options; -} - -void ExportCalendarsJobInterfaceTest::exportCalendar() -{ - QFETCH(QByteArray, configpath); - QFETCH(Utils::StoredTypes, options); - TestExportFile *file = new TestExportFile(this); - file->setPathConfig(configpath); - QVector lstInfo; - Utils::AkonadiInstanceInfo info; - info.identifier = QLatin1String("akonadi_icaldir_resource_1"); - lstInfo << info; - info.identifier = QLatin1String("akonadi_ical_resource_2"); - lstInfo << info; - //Add extra resource. - info.identifier = QLatin1String("akonadi_contacts_resource_1"); - lstInfo << info; - info.identifier = QStringLiteral("akonadi_kontact_resource_2"); - lstInfo << info; - - ExportCalendarsJobInterfaceTestImpl *exportNote = new ExportCalendarsJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - exportNote->setListOfResource(lstInfo); - exportNote->setPathConfig(QLatin1String(configpath)); - file->setAbstractImportExportJob(exportNote); - file->start(); - delete exportNote; -} diff --git a/core/autotests/calendar/exportcalendarsjobinterfacetest.h b/core/autotests/calendar/exportcalendarsjobinterfacetestimpl.h similarity index 83% copy from core/autotests/calendar/exportcalendarsjobinterfacetest.h copy to core/autotests/calendar/exportcalendarsjobinterfacetestimpl.h index 8429821..1f86cc5 100644 --- a/core/autotests/calendar/exportcalendarsjobinterfacetest.h +++ b/core/autotests/calendar/exportcalendarsjobinterfacetestimpl.h @@ -1,57 +1,44 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef EXPORTCALENDARSJOBINTERFACETEST_H -#define EXPORTCALENDARSJOBINTERFACETEST_H - -#include +#ifndef EXPORTCALENDARSJOBINTERFACETESTIMPL_H +#define EXPORTCALENDARSJOBINTERFACETESTIMPL_H #include "calendar/exportcalendarjobinterface.h" #include "exportimportutil.h" class ExportCalendarsJobInterfaceTestImpl : public ExportCalendarJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ExportCalendarsJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ExportCalendarsJobInterfaceTestImpl(); protected: Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; Q_REQUIRED_RESULT QString convertToFullCollectionPath(const qlonglong collectionValue) override; void convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) override; void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; Q_REQUIRED_RESULT QVector listOfResource() override; Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override; void backupCalendarResourceFile(const QString &agentIdentifier, const QString &defaultPath) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; }; -class ExportCalendarsJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ExportCalendarsJobInterfaceTest(QObject *parent = nullptr); - ~ExportCalendarsJobInterfaceTest() = default; -private Q_SLOTS: - void exportCalendar_data(); - void exportCalendar(); -}; - -#endif // EXPORTCALENDARSJOBINTERFACETEST_H +#endif // EXPORTCALENDARSJOBINTERFACETESTIMPL_H diff --git a/core/autotests/calendar/importcalendarjobinterfacetest.cpp b/core/autotests/calendar/importcalendarjobinterfacetest.cpp index d478129..60fe205 100644 --- a/core/autotests/calendar/importcalendarjobinterfacetest.cpp +++ b/core/autotests/calendar/importcalendarjobinterfacetest.cpp @@ -1,105 +1,63 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "importcalendarjobinterfacetest.h" +#include "importcalendarjobinterfacetestimpl.h" #include "archivestorage.h" -#include "resourceconvertertest.h" #include "testimportfile.h" #include #include QTEST_MAIN(ImportCalendarJobInterfaceTest) -ImportCalendarJobInterfaceTestImpl::ImportCalendarJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ImportCalendarJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ImportCalendarJobInterfaceTestImpl::~ImportCalendarJobInterfaceTestImpl() -{ - //Clean up temp repo - QVERIFY(QDir(QDir::tempPath() + QLatin1Char('/') + Utils::storeCalendar()).removeRecursively()); -} - -Akonadi::Collection::Id ImportCalendarJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -QString ImportCalendarJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); -} - -void ImportCalendarJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) -{ - mLogCreateResource->logSynchronizeResource(lst); - slotNextStep(); -} - -QString ImportCalendarJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); -} - -QString ImportCalendarJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} ImportCalendarJobInterfaceTest::ImportCalendarJobInterfaceTest(QObject *parent) : QObject(parent) { } void ImportCalendarJobInterfaceTest::importCalendar_data() { QTest::addColumn("zipFilePath"); QTest::addColumn("testPath"); QTest::addColumn("options"); Utils::StoredTypes options = {Utils::StoredType::Config}; const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); QTest::newRow("calendaronlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/calendaronlyconfig/") << options; options = {Utils::StoredType::Config|Utils::StoredType::Resources}; QTest::newRow("calendarconfigandresource") << QString::fromLatin1(pathConfig) << QStringLiteral("/calendarconfigandresource/") << options; } void ImportCalendarJobInterfaceTest::importCalendar() { QFETCH(QString, zipFilePath); QFETCH(QString, testPath); QFETCH(Utils::StoredTypes, options); TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); file->setPathConfig(zipFilePath + testPath); file->setExtractPath(QDir::tempPath() + testPath); file->setExcludePath(Utils::calendarPath()); ImportCalendarJobInterfaceTestImpl *impl = new ImportCalendarJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); impl->setPathConfig(file->pathConfig()); file->setAbstractImportExportJob(impl); file->setLoggingFilePath(impl->loggingFilePath()); file->start(); delete impl; delete file; } diff --git a/core/autotests/calendar/importcalendarjobinterfacetest.h b/core/autotests/calendar/importcalendarjobinterfacetest.h index 96e3ad4..0aba698 100644 --- a/core/autotests/calendar/importcalendarjobinterfacetest.h +++ b/core/autotests/calendar/importcalendarjobinterfacetest.h @@ -1,54 +1,37 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef IMPORTCALENDARJOBINTERFACETEST_H #define IMPORTCALENDARJOBINTERFACETEST_H #include -#include "exportimportutil.h" -#include "calendar/importcalendarjobinterface.h" - -class ImportCalendarJobInterfaceTestImpl : public ImportCalendarJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ImportCalendarJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ImportCalendarJobInterfaceTestImpl(); - -protected: - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; - void synchronizeResource(const QStringList &lst) override; - Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; -}; class ImportCalendarJobInterfaceTest : public QObject { Q_OBJECT public: explicit ImportCalendarJobInterfaceTest(QObject *parent = nullptr); ~ImportCalendarJobInterfaceTest() = default; private Q_SLOTS: void importCalendar(); void importCalendar_data(); }; #endif // IMPORTCALENDARJOBINTERFACETEST_H diff --git a/core/autotests/calendar/importcalendarjobinterfacetest.cpp b/core/autotests/calendar/importcalendarjobinterfacetestimpl.cpp similarity index 62% copy from core/autotests/calendar/importcalendarjobinterfacetest.cpp copy to core/autotests/calendar/importcalendarjobinterfacetestimpl.cpp index d478129..bc26721 100644 --- a/core/autotests/calendar/importcalendarjobinterfacetest.cpp +++ b/core/autotests/calendar/importcalendarjobinterfacetestimpl.cpp @@ -1,105 +1,66 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "importcalendarjobinterfacetest.h" +#include "importcalendarjobinterfacetestimpl.h" #include "archivestorage.h" #include "resourceconvertertest.h" -#include "testimportfile.h" -#include #include -QTEST_MAIN(ImportCalendarJobInterfaceTest) ImportCalendarJobInterfaceTestImpl::ImportCalendarJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ImportCalendarJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ImportCalendarJobInterfaceTestImpl::~ImportCalendarJobInterfaceTestImpl() { //Clean up temp repo QVERIFY(QDir(QDir::tempPath() + QLatin1Char('/') + Utils::storeCalendar()).removeRecursively()); } Akonadi::Collection::Id ImportCalendarJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } QString ImportCalendarJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); } void ImportCalendarJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) { mLogCreateResource->logSynchronizeResource(lst); slotNextStep(); } QString ImportCalendarJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); } QString ImportCalendarJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } - -ImportCalendarJobInterfaceTest::ImportCalendarJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ImportCalendarJobInterfaceTest::importCalendar_data() -{ - QTest::addColumn("zipFilePath"); - QTest::addColumn("testPath"); - QTest::addColumn("options"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); - QTest::newRow("calendaronlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/calendaronlyconfig/") << options; - options = {Utils::StoredType::Config|Utils::StoredType::Resources}; - QTest::newRow("calendarconfigandresource") << QString::fromLatin1(pathConfig) << QStringLiteral("/calendarconfigandresource/") << options; -} - -void ImportCalendarJobInterfaceTest::importCalendar() -{ - QFETCH(QString, zipFilePath); - QFETCH(QString, testPath); - QFETCH(Utils::StoredTypes, options); - TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); - file->setPathConfig(zipFilePath + testPath); - file->setExtractPath(QDir::tempPath() + testPath); - file->setExcludePath(Utils::calendarPath()); - ImportCalendarJobInterfaceTestImpl *impl = new ImportCalendarJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - impl->setPathConfig(file->pathConfig()); - file->setAbstractImportExportJob(impl); - file->setLoggingFilePath(impl->loggingFilePath()); - file->start(); - delete impl; - delete file; -} diff --git a/core/autotests/calendar/importcalendarjobinterfacetest.h b/core/autotests/calendar/importcalendarjobinterfacetestimpl.h similarity index 81% copy from core/autotests/calendar/importcalendarjobinterfacetest.h copy to core/autotests/calendar/importcalendarjobinterfacetestimpl.h index 96e3ad4..b13cc4c 100644 --- a/core/autotests/calendar/importcalendarjobinterfacetest.h +++ b/core/autotests/calendar/importcalendarjobinterfacetestimpl.h @@ -1,54 +1,42 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef IMPORTCALENDARJOBINTERFACETEST_H -#define IMPORTCALENDARJOBINTERFACETEST_H +#ifndef IMPORTCALENDARJOBINTERFACETESTIMPL_H +#define IMPORTCALENDARJOBINTERFACETESTIMPL_H -#include #include "exportimportutil.h" #include "calendar/importcalendarjobinterface.h" class ImportCalendarJobInterfaceTestImpl : public ImportCalendarJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ImportCalendarJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ImportCalendarJobInterfaceTestImpl(); protected: Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; void synchronizeResource(const QStringList &lst) override; Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; }; -class ImportCalendarJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ImportCalendarJobInterfaceTest(QObject *parent = nullptr); - ~ImportCalendarJobInterfaceTest() = default; -private Q_SLOTS: - void importCalendar(); - void importCalendar_data(); -}; - -#endif // IMPORTCALENDARJOBINTERFACETEST_H +#endif // IMPORTCALENDARJOBINTERFACETESTIMPL_H diff --git a/core/autotests/mail/CMakeLists.txt b/core/autotests/mail/CMakeLists.txt index ed0b981..2fc3b45 100644 --- a/core/autotests/mail/CMakeLists.txt +++ b/core/autotests/mail/CMakeLists.txt @@ -1,17 +1,17 @@ add_definitions( -DPIMDATAEXPORTER_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) -set( exportmailjobinterfacetest_SRCS exportmailjobinterfacetest.cpp) +set( exportmailjobinterfacetest_SRCS exportmailjobinterfacetest.cpp exportmailjobinterfacetestimpl.cpp) add_executable( exportmailjobinterfacetest ${exportmailjobinterfacetest_SRCS}) add_test(NAME exportmailjobinterfacetest COMMAND exportmailjobinterfacetest) ecm_mark_as_test(exportmailjobinterfacetest) target_link_libraries(exportmailjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore test_resourceconverter) ##### -set( importmailjobinterfacetest_SRCS importmailjobinterfacetest.cpp) +set( importmailjobinterfacetest_SRCS importmailjobinterfacetest.cpp importmailjobinterfacetestimpl.cpp) add_executable( importmailjobinterfacetest ${importmailjobinterfacetest_SRCS}) add_test(NAME importmailjobinterfacetest COMMAND importmailjobinterfacetest) ecm_mark_as_test(importmailjobinterfacetest) target_link_libraries(importmailjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore KF5::AkonadiMime test_resourceconverter KF5::IdentityManagement) diff --git a/core/autotests/mail/exportmailjobinterfacetest.cpp b/core/autotests/mail/exportmailjobinterfacetest.cpp index 6a84961..0a1c9b7 100644 --- a/core/autotests/mail/exportmailjobinterfacetest.cpp +++ b/core/autotests/mail/exportmailjobinterfacetest.cpp @@ -1,190 +1,75 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "exportmailjobinterfacetest.h" +#include "exportmailjobinterfacetestimpl.h" #include "archivestorage.h" -#include "resourceconvertertest.h" #include "testexportfile.h" #include #include -#include -#include QTEST_MAIN(ExportMailJobInterfaceTest) -ExportMailJobInterfaceTestImpl::ExportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ExportMailJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ExportMailJobInterfaceTestImpl::~ExportMailJobInterfaceTestImpl() -{ -} - -void ExportMailJobInterfaceTestImpl::convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey) -{ - ResourceConverterTest resourceConverter; - resourceConverter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); - resourceConverter.convertCollectionToRealPath(group, currentKey); -} - -void ExportMailJobInterfaceTestImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) -{ - ResourceConverterTest resourceConverter; - resourceConverter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); - resourceConverter.convertCollectionListToRealPath(group, currentKey); -} - -void ExportMailJobInterfaceTestImpl::convertCollectionIdsToRealPath(KConfigGroup &group, const QString ¤tKey, const QString &prefixCollection) -{ - ResourceConverterTest resourceConverter; - resourceConverter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); - resourceConverter.convertCollectionIdsToRealPath(group, currentKey, prefixCollection); -} - -Akonadi::Collection::Id ExportMailJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -QVector ExportMailJobInterfaceTestImpl::filters() -{ - qDebug() << " not implement yet ExportMailJobInterfaceTestImpl::filters()"; - //TODO implement it - return {}; -} - -void ExportMailJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) -{ - SaveResoureConfigTest saveResourceConfig; - saveResourceConfig.setArchive(mArchiveStorage->archive()); - saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceMailArchiveName(), - { QLatin1String("akonadi_maildir_resource_"), QLatin1String("akonadi_mixedmaildir_resource_")}); - slotMailsJobTerminated(); -} - -QVector ExportMailJobInterfaceTestImpl::listOfResource() -{ - return mListAkonadiInstanceInfo; -} - -QString ExportMailJobInterfaceTestImpl::storeResources(KZip *archive, const QString &identifier, const QString &path) -{ - ResourceConverterTest converter; - return converter.storeResources(archive, identifier, path); -} - -QString ExportMailJobInterfaceTestImpl::convertToFullCollectionPath(const qlonglong collectionValue) -{ - ResourceConverterTest converter; - converter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); - return converter.convertToFullCollectionPath(collectionValue); -} - -QString ExportMailJobInterfaceTestImpl::resourcePath(const QString &identifier) const -{ - ResourceConverterTest converter; - converter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); - const QString url = converter.resourcePath(identifier); - return url; -} - -void ExportMailJobInterfaceTestImpl::exportFilters() -{ - qDebug() << " void ExportMailJobInterfaceTestImpl::exportFilters() not implemented yet"; -} - -void ExportMailJobInterfaceTestImpl::backupMailResourceFile(const QString &agentIdentifier, const QString &defaultPath) -{ - TestBackupResourceFileJob *job = new TestBackupResourceFileJob(this); - job->setDefaultPath(defaultPath); - job->setIdentifier(agentIdentifier); - job->setTestPath(mPathConfig); - job->setZip(archive()); - connect(job, &TestBackupResourceFileJob::error, this, &ExportMailJobInterfaceTestImpl::error); - connect(job, &TestBackupResourceFileJob::info, this, &ExportMailJobInterfaceTestImpl::info); - job->start(); -} - -QString ExportMailJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} - -QString ExportMailJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - Q_UNREACHABLE(); - return {}; -} - -QVector ExportMailJobInterfaceTestImpl::listIdentityUoid() const -{ - return {10, 11, 12, 13, 14}; -} ExportMailJobInterfaceTest::ExportMailJobInterfaceTest(QObject *parent) : QObject(parent) { } void ExportMailJobInterfaceTest::exportMail_data() { QTest::addColumn("configpath"); QTest::addColumn("options"); const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); Utils::StoredTypes options = {Utils::StoredType::Config}; QTest::newRow("mailonlyconfig") << pathConfig + QByteArray("mailonlyconfig/") << options; options = {Utils::StoredType::Config|Utils::StoredType::Resources}; QTest::newRow("mailconfigandresource") << pathConfig + QByteArray("mailconfigandresource/") << options; options = {Utils::StoredType::MailTransport}; QTest::newRow("mailtransport") << pathConfig + QByteArray("mailtransport/") << options; options = {Utils::StoredType::Identity}; QTest::newRow("identities") << pathConfig + QByteArray("identities/") << options; } void ExportMailJobInterfaceTest::exportMail() { QFETCH(QByteArray, configpath); QFETCH(Utils::StoredTypes, options); TestExportFile *file = new TestExportFile(this); file->setPathConfig(configpath); QVector lstInfo; Utils::AkonadiInstanceInfo info; info.identifier = QLatin1String("akonadi_mbox_resource_1"); lstInfo << info; info.identifier = QLatin1String("akonadi_maildir_resource_1"); lstInfo << info; info.identifier = QLatin1String("akonadi_mixedmaildir_resource_1"); lstInfo << info; //Add extra resource. info.identifier = QStringLiteral("akonadi_kolab_resource_2"); lstInfo << info; ExportMailJobInterfaceTestImpl *exportNote = new ExportMailJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); exportNote->setListOfResource(lstInfo); exportNote->setPathConfig(QLatin1String(configpath)); file->setAbstractImportExportJob(exportNote); file->start(); delete exportNote; } diff --git a/core/autotests/mail/exportmailjobinterfacetest.h b/core/autotests/mail/exportmailjobinterfacetest.h index 90a863c..43fb261 100644 --- a/core/autotests/mail/exportmailjobinterfacetest.h +++ b/core/autotests/mail/exportmailjobinterfacetest.h @@ -1,69 +1,36 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EXPORTMAILJOBINTERFACETEST_H #define EXPORTMAILJOBINTERFACETEST_H #include -#include "exportimportutil.h" - -#include "mail/exportmailjobinterface.h" - -class ExportMailJobInterfaceTestImpl : public ExportMailJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ExportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ExportMailJobInterfaceTestImpl(); - -protected: - void convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey) override; - void convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) override; - - void convertCollectionIdsToRealPath(KConfigGroup &group, const QString ¤tKey, const QString &prefixCollection) override; - - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - - Q_REQUIRED_RESULT QVector filters() override; - - Q_REQUIRED_RESULT QString convertToFullCollectionPath(const qlonglong collectionValue) override; - void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; - Q_REQUIRED_RESULT QVector listOfResource() override; - Q_REQUIRED_RESULT QString storeResources(KZip *archive, const QString &identifier, const QString &path) override; - Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override; - void backupMailResourceFile(const QString &agentIdentifier, const QString &defaultPath) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; - Q_REQUIRED_RESULT QVector listIdentityUoid() const override; - - void exportFilters() override; -}; class ExportMailJobInterfaceTest : public QObject { Q_OBJECT public: explicit ExportMailJobInterfaceTest(QObject *parent = nullptr); ~ExportMailJobInterfaceTest() = default; private Q_SLOTS: void exportMail(); void exportMail_data(); }; #endif // EXPORTMAILJOBINTERFACETEST_H diff --git a/core/autotests/mail/exportmailjobinterfacetest.cpp b/core/autotests/mail/exportmailjobinterfacetestimpl.cpp similarity index 72% copy from core/autotests/mail/exportmailjobinterfacetest.cpp copy to core/autotests/mail/exportmailjobinterfacetestimpl.cpp index 6a84961..564d6ee 100644 --- a/core/autotests/mail/exportmailjobinterfacetest.cpp +++ b/core/autotests/mail/exportmailjobinterfacetestimpl.cpp @@ -1,190 +1,141 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "exportmailjobinterfacetest.h" + +#include "exportmailjobinterfacetestimpl.h" #include "archivestorage.h" #include "resourceconvertertest.h" -#include "testexportfile.h" +#include "saveresourceconfigtest.h" +#include "testbackupresourcefilejob.h" #include #include -#include -#include - -QTEST_MAIN(ExportMailJobInterfaceTest) ExportMailJobInterfaceTestImpl::ExportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ExportMailJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ExportMailJobInterfaceTestImpl::~ExportMailJobInterfaceTestImpl() { } void ExportMailJobInterfaceTestImpl::convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey) { ResourceConverterTest resourceConverter; resourceConverter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); resourceConverter.convertCollectionToRealPath(group, currentKey); } void ExportMailJobInterfaceTestImpl::convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) { ResourceConverterTest resourceConverter; resourceConverter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); resourceConverter.convertCollectionListToRealPath(group, currentKey); } void ExportMailJobInterfaceTestImpl::convertCollectionIdsToRealPath(KConfigGroup &group, const QString ¤tKey, const QString &prefixCollection) { ResourceConverterTest resourceConverter; resourceConverter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); resourceConverter.convertCollectionIdsToRealPath(group, currentKey, prefixCollection); } Akonadi::Collection::Id ExportMailJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } QVector ExportMailJobInterfaceTestImpl::filters() { qDebug() << " not implement yet ExportMailJobInterfaceTestImpl::filters()"; //TODO implement it return {}; } void ExportMailJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) { SaveResoureConfigTest saveResourceConfig; saveResourceConfig.setArchive(mArchiveStorage->archive()); saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceMailArchiveName(), { QLatin1String("akonadi_maildir_resource_"), QLatin1String("akonadi_mixedmaildir_resource_")}); slotMailsJobTerminated(); } QVector ExportMailJobInterfaceTestImpl::listOfResource() { return mListAkonadiInstanceInfo; } QString ExportMailJobInterfaceTestImpl::storeResources(KZip *archive, const QString &identifier, const QString &path) { ResourceConverterTest converter; return converter.storeResources(archive, identifier, path); } QString ExportMailJobInterfaceTestImpl::convertToFullCollectionPath(const qlonglong collectionValue) { ResourceConverterTest converter; converter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); return converter.convertToFullCollectionPath(collectionValue); } QString ExportMailJobInterfaceTestImpl::resourcePath(const QString &identifier) const { ResourceConverterTest converter; converter.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR)); const QString url = converter.resourcePath(identifier); return url; } void ExportMailJobInterfaceTestImpl::exportFilters() { qDebug() << " void ExportMailJobInterfaceTestImpl::exportFilters() not implemented yet"; } void ExportMailJobInterfaceTestImpl::backupMailResourceFile(const QString &agentIdentifier, const QString &defaultPath) { TestBackupResourceFileJob *job = new TestBackupResourceFileJob(this); job->setDefaultPath(defaultPath); job->setIdentifier(agentIdentifier); job->setTestPath(mPathConfig); job->setZip(archive()); connect(job, &TestBackupResourceFileJob::error, this, &ExportMailJobInterfaceTestImpl::error); connect(job, &TestBackupResourceFileJob::info, this, &ExportMailJobInterfaceTestImpl::info); job->start(); } QString ExportMailJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } QString ExportMailJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { Q_UNREACHABLE(); return {}; } QVector ExportMailJobInterfaceTestImpl::listIdentityUoid() const { return {10, 11, 12, 13, 14}; } - -ExportMailJobInterfaceTest::ExportMailJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ExportMailJobInterfaceTest::exportMail_data() -{ - QTest::addColumn("configpath"); - QTest::addColumn("options"); - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - QTest::newRow("mailonlyconfig") << pathConfig + QByteArray("mailonlyconfig/") << options; - options = {Utils::StoredType::Config|Utils::StoredType::Resources}; - QTest::newRow("mailconfigandresource") << pathConfig + QByteArray("mailconfigandresource/") << options; - options = {Utils::StoredType::MailTransport}; - QTest::newRow("mailtransport") << pathConfig + QByteArray("mailtransport/") << options; - options = {Utils::StoredType::Identity}; - QTest::newRow("identities") << pathConfig + QByteArray("identities/") << options; -} - -void ExportMailJobInterfaceTest::exportMail() -{ - QFETCH(QByteArray, configpath); - QFETCH(Utils::StoredTypes, options); - TestExportFile *file = new TestExportFile(this); - file->setPathConfig(configpath); - QVector lstInfo; - Utils::AkonadiInstanceInfo info; - - info.identifier = QLatin1String("akonadi_mbox_resource_1"); - lstInfo << info; - info.identifier = QLatin1String("akonadi_maildir_resource_1"); - lstInfo << info; - info.identifier = QLatin1String("akonadi_mixedmaildir_resource_1"); - lstInfo << info; - //Add extra resource. - info.identifier = QStringLiteral("akonadi_kolab_resource_2"); - lstInfo << info; - - ExportMailJobInterfaceTestImpl *exportNote = new ExportMailJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - exportNote->setListOfResource(lstInfo); - exportNote->setPathConfig(QLatin1String(configpath)); - file->setAbstractImportExportJob(exportNote); - file->start(); - delete exportNote; -} diff --git a/core/autotests/mail/exportmailjobinterfacetest.h b/core/autotests/mail/exportmailjobinterfacetestimpl.h similarity index 87% copy from core/autotests/mail/exportmailjobinterfacetest.h copy to core/autotests/mail/exportmailjobinterfacetestimpl.h index 90a863c..52660e6 100644 --- a/core/autotests/mail/exportmailjobinterfacetest.h +++ b/core/autotests/mail/exportmailjobinterfacetestimpl.h @@ -1,69 +1,57 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef EXPORTMAILJOBINTERFACETEST_H -#define EXPORTMAILJOBINTERFACETEST_H -#include +#ifndef EXPORTMAILJOBINTERFACETESTIMPL_H +#define EXPORTMAILJOBINTERFACETESTIMPL_H + #include "exportimportutil.h" #include "mail/exportmailjobinterface.h" class ExportMailJobInterfaceTestImpl : public ExportMailJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ExportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ExportMailJobInterfaceTestImpl(); protected: void convertCollectionToRealPath(KConfigGroup &group, const QString ¤tKey) override; void convertCollectionListToRealPath(KConfigGroup &group, const QString ¤tKey) override; void convertCollectionIdsToRealPath(KConfigGroup &group, const QString ¤tKey, const QString &prefixCollection) override; Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; Q_REQUIRED_RESULT QVector filters() override; Q_REQUIRED_RESULT QString convertToFullCollectionPath(const qlonglong collectionValue) override; void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; Q_REQUIRED_RESULT QVector listOfResource() override; Q_REQUIRED_RESULT QString storeResources(KZip *archive, const QString &identifier, const QString &path) override; Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override; void backupMailResourceFile(const QString &agentIdentifier, const QString &defaultPath) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; Q_REQUIRED_RESULT QVector listIdentityUoid() const override; void exportFilters() override; }; - -class ExportMailJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ExportMailJobInterfaceTest(QObject *parent = nullptr); - ~ExportMailJobInterfaceTest() = default; -private Q_SLOTS: - void exportMail(); - void exportMail_data(); -}; - -#endif // EXPORTMAILJOBINTERFACETEST_H +#endif // EXPORTMAILJOBINTERFACETESTIMPL_H diff --git a/core/autotests/mail/importmailjobinterfacetest.cpp b/core/autotests/mail/importmailjobinterfacetest.cpp index d325741..e45f4d1 100644 --- a/core/autotests/mail/importmailjobinterfacetest.cpp +++ b/core/autotests/mail/importmailjobinterfacetest.cpp @@ -1,167 +1,71 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "importmailjobinterfacetest.h" +#include "importmailjobinterfacetestimpl.h" #include "archivestorage.h" -#include "resourceconvertertest.h" #include "testimportfile.h" #include "utils.h" -#include "mail/smtpmailtransport.h" -#include -#include #include #include QTEST_MAIN(ImportMailJobInterfaceTest) -ImportMailJobInterfaceTestImpl::ImportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ImportMailJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ImportMailJobInterfaceTestImpl::~ImportMailJobInterfaceTestImpl() -{ - //Clean up temp repo. FIXME ! - QVERIFY(QDir(extractPath()).removeRecursively()); -} - -void ImportMailJobInterfaceTestImpl::start() -{ - QDir().mkpath(extractPath()); - //Create temporary file for identities - ImportMailJobInterface::start(); -} - -Akonadi::Collection::Id ImportMailJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -void ImportMailJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) -{ - mLogCreateResource->logSynchronizeResource(lst); - slotNextStep(); -} - -QString ImportMailJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); -} - -void ImportMailJobInterfaceTestImpl::registerSpecialCollection(Akonadi::SpecialMailCollections::Type type, qint64 colId) -{ - mLogCreateResource->logRegisterSpecialCollection(type, colId); -} -void ImportMailJobInterfaceTestImpl::importFilters(const QVector &filters) -{ - qDebug() << " void ImportMailJobInterfaceTestImpl::importFilters(const QVector &filters)"; -} - -QString ImportMailJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); -} - -QString ImportMailJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} - -void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) -{ - qDebug() << " void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) not implemented yet" << oldUid << " name " << name; - KIdentityManagement::Identity identity; - identity.setUoid(mIdentityUoid++); - group.writeEntry(QStringLiteral("Name"), name); - group.sync(); - - identity.readConfig(group); - - if (oldUid != -1) { - mHashIdentity.insert(oldUid, identity.uoid()); - if (oldUid == defaultIdentities) { - //TODO - //mIdentityManager->setAsDefault(identity->uoid()); - } - } -// identity.writeConfig(); - //TODO write identity ? - //TODO log it. - //mIdentityManager->commit(); -} - -void ImportMailJobInterfaceTestImpl::importCustomMailTransport(const QString &identifierValue, const KConfigGroup &group, int defaultTransport, int transportId) -{ - qDebug() << "importCustomMailTransport(const QString &identifierValue, const KConfigGroup &group, int defaultTransport, int transportId) not implemented yet"; -} - -void ImportMailJobInterfaceTestImpl::importSmtpMailTransport(const KConfigGroup &group, int defaultTransport, int transportId) -{ - SmtpMailTransport smtpMailTransport(group); - qDebug() << "ImportMailJobInterfaceTestImpl::importSmtpMailTransport(const KConfigGroup &group, int defaultTransport, int transportId) not implement yet"; - qDebug() << " defaultTransport " << defaultTransport << " transportId " << transportId; -} ImportMailJobInterfaceTest::ImportMailJobInterfaceTest(QObject *parent) : QObject(parent) { } void ImportMailJobInterfaceTest::importMail_data() { QTest::addColumn("zipFilePath"); QTest::addColumn("testPath"); QTest::addColumn("options"); Utils::StoredTypes options = {Utils::StoredType::Config}; const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); QTest::newRow("mailonlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/mailonlyconfig/") << options; options = {Utils::StoredType::Config|Utils::StoredType::Resources}; QTest::newRow("mailconfigandresource") << QString::fromLatin1(pathConfig) << QStringLiteral("mailconfigandresource/") << options; options = {Utils::StoredType::MailTransport}; QTest::newRow("mailtransport") << QString::fromLatin1(pathConfig) << QStringLiteral("mailtransport/") << options; options = {Utils::StoredType::Identity}; QTest::newRow("identities") << QString::fromLatin1(pathConfig) << QStringLiteral("identities/") << options; } void ImportMailJobInterfaceTest::importMail() { QFETCH(QString, zipFilePath); QFETCH(QString, testPath); QFETCH(Utils::StoredTypes, options); TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); file->setPathConfig(zipFilePath + testPath); file->setExtractPath(QDir::tempPath() + QLatin1Char('/') + testPath); file->setExcludePath(Utils::mailsPath()); // ??? ImportMailJobInterfaceTestImpl *impl = new ImportMailJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); impl->setPathConfig(file->pathConfig()); impl->setExtractPath(file->extractPath()); file->setAbstractImportExportJob(impl); file->setLoggingFilePath(impl->loggingFilePath()); file->start(); delete impl; delete file; } diff --git a/core/autotests/mail/importmailjobinterfacetest.h b/core/autotests/mail/importmailjobinterfacetest.h index 093ec76..f502fb9 100644 --- a/core/autotests/mail/importmailjobinterfacetest.h +++ b/core/autotests/mail/importmailjobinterfacetest.h @@ -1,65 +1,36 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef IMPORTMAILJOBINTERFACETEST_H #define IMPORTMAILJOBINTERFACETEST_H #include -#include "exportimportutil.h" - -#include "mail/importmailjobinterface.h" - -class ImportMailJobInterfaceTestImpl : public ImportMailJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ImportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ImportMailJobInterfaceTestImpl(); - void start() override; - -protected: - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - void synchronizeResource(const QStringList &lst) override; - - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; - void registerSpecialCollection(Akonadi::SpecialMailCollections::Type type, qint64 colId) override; - void importFilters(const QVector &filters) override; - - Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; - void addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) override; - void importCustomMailTransport(const QString &identifierValue, const KConfigGroup &group, int defaultTransport, int transportId) override; - void importSmtpMailTransport(const KConfigGroup &group, int defaultTransport, int transportId) override; -private: - uint mIdentityUoid = 1; - -}; class ImportMailJobInterfaceTest : public QObject { Q_OBJECT public: explicit ImportMailJobInterfaceTest(QObject *parent = nullptr); ~ImportMailJobInterfaceTest() = default; private Q_SLOTS: void importMail(); void importMail_data(); }; #endif // IMPORTMAILJOBINTERFACETEST_H diff --git a/core/autotests/mail/importmailjobinterfacetest.cpp b/core/autotests/mail/importmailjobinterfacetestimpl.cpp similarity index 72% copy from core/autotests/mail/importmailjobinterfacetest.cpp copy to core/autotests/mail/importmailjobinterfacetestimpl.cpp index d325741..c2edf91 100644 --- a/core/autotests/mail/importmailjobinterfacetest.cpp +++ b/core/autotests/mail/importmailjobinterfacetestimpl.cpp @@ -1,167 +1,124 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "importmailjobinterfacetest.h" +#include "importmailjobinterfacetestimpl.h" #include "archivestorage.h" #include "resourceconvertertest.h" #include "testimportfile.h" #include "utils.h" #include "mail/smtpmailtransport.h" #include #include #include #include -QTEST_MAIN(ImportMailJobInterfaceTest) + ImportMailJobInterfaceTestImpl::ImportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ImportMailJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ImportMailJobInterfaceTestImpl::~ImportMailJobInterfaceTestImpl() { //Clean up temp repo. FIXME ! QVERIFY(QDir(extractPath()).removeRecursively()); } void ImportMailJobInterfaceTestImpl::start() { QDir().mkpath(extractPath()); //Create temporary file for identities ImportMailJobInterface::start(); } Akonadi::Collection::Id ImportMailJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } void ImportMailJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) { mLogCreateResource->logSynchronizeResource(lst); slotNextStep(); } QString ImportMailJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); } void ImportMailJobInterfaceTestImpl::registerSpecialCollection(Akonadi::SpecialMailCollections::Type type, qint64 colId) { mLogCreateResource->logRegisterSpecialCollection(type, colId); } void ImportMailJobInterfaceTestImpl::importFilters(const QVector &filters) { qDebug() << " void ImportMailJobInterfaceTestImpl::importFilters(const QVector &filters)"; } QString ImportMailJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); } QString ImportMailJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) { qDebug() << " void ImportMailJobInterfaceTestImpl::addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) not implemented yet" << oldUid << " name " << name; KIdentityManagement::Identity identity; identity.setUoid(mIdentityUoid++); group.writeEntry(QStringLiteral("Name"), name); group.sync(); identity.readConfig(group); if (oldUid != -1) { mHashIdentity.insert(oldUid, identity.uoid()); if (oldUid == defaultIdentities) { //TODO //mIdentityManager->setAsDefault(identity->uoid()); } } // identity.writeConfig(); //TODO write identity ? //TODO log it. //mIdentityManager->commit(); } void ImportMailJobInterfaceTestImpl::importCustomMailTransport(const QString &identifierValue, const KConfigGroup &group, int defaultTransport, int transportId) { qDebug() << "importCustomMailTransport(const QString &identifierValue, const KConfigGroup &group, int defaultTransport, int transportId) not implemented yet"; } void ImportMailJobInterfaceTestImpl::importSmtpMailTransport(const KConfigGroup &group, int defaultTransport, int transportId) { SmtpMailTransport smtpMailTransport(group); qDebug() << "ImportMailJobInterfaceTestImpl::importSmtpMailTransport(const KConfigGroup &group, int defaultTransport, int transportId) not implement yet"; qDebug() << " defaultTransport " << defaultTransport << " transportId " << transportId; } - -ImportMailJobInterfaceTest::ImportMailJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ImportMailJobInterfaceTest::importMail_data() -{ - QTest::addColumn("zipFilePath"); - QTest::addColumn("testPath"); - QTest::addColumn("options"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); - - QTest::newRow("mailonlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/mailonlyconfig/") << options; - options = {Utils::StoredType::Config|Utils::StoredType::Resources}; - QTest::newRow("mailconfigandresource") << QString::fromLatin1(pathConfig) << QStringLiteral("mailconfigandresource/") << options; - options = {Utils::StoredType::MailTransport}; - QTest::newRow("mailtransport") << QString::fromLatin1(pathConfig) << QStringLiteral("mailtransport/") << options; - options = {Utils::StoredType::Identity}; - QTest::newRow("identities") << QString::fromLatin1(pathConfig) << QStringLiteral("identities/") << options; -} - -void ImportMailJobInterfaceTest::importMail() -{ - QFETCH(QString, zipFilePath); - QFETCH(QString, testPath); - QFETCH(Utils::StoredTypes, options); - TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); - file->setPathConfig(zipFilePath + testPath); - file->setExtractPath(QDir::tempPath() + QLatin1Char('/') + testPath); - file->setExcludePath(Utils::mailsPath()); // ??? - ImportMailJobInterfaceTestImpl *impl = new ImportMailJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - impl->setPathConfig(file->pathConfig()); - impl->setExtractPath(file->extractPath()); - file->setAbstractImportExportJob(impl); - file->setLoggingFilePath(impl->loggingFilePath()); - file->start(); - delete impl; - delete file; -} - - diff --git a/core/autotests/mail/importmailjobinterfacetest.h b/core/autotests/mail/importmailjobinterfacetestimpl.h similarity index 86% copy from core/autotests/mail/importmailjobinterfacetest.h copy to core/autotests/mail/importmailjobinterfacetestimpl.h index 093ec76..eaf5b42 100644 --- a/core/autotests/mail/importmailjobinterfacetest.h +++ b/core/autotests/mail/importmailjobinterfacetestimpl.h @@ -1,65 +1,53 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef IMPORTMAILJOBINTERFACETEST_H -#define IMPORTMAILJOBINTERFACETEST_H +#ifndef IMPORTMAILJOBINTERFACETESTIMPL_H +#define IMPORTMAILJOBINTERFACETESTIMPL_H -#include #include "exportimportutil.h" #include "mail/importmailjobinterface.h" class ImportMailJobInterfaceTestImpl : public ImportMailJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ImportMailJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ImportMailJobInterfaceTestImpl(); void start() override; protected: Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; void synchronizeResource(const QStringList &lst) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; void registerSpecialCollection(Akonadi::SpecialMailCollections::Type type, qint64 colId) override; void importFilters(const QVector &filters) override; Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; void addNewIdentity(const QString &name, KConfigGroup &group, int defaultIdentities, int oldUid) override; void importCustomMailTransport(const QString &identifierValue, const KConfigGroup &group, int defaultTransport, int transportId) override; void importSmtpMailTransport(const KConfigGroup &group, int defaultTransport, int transportId) override; private: uint mIdentityUoid = 1; }; -class ImportMailJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ImportMailJobInterfaceTest(QObject *parent = nullptr); - ~ImportMailJobInterfaceTest() = default; -private Q_SLOTS: - void importMail(); - void importMail_data(); -}; - -#endif // IMPORTMAILJOBINTERFACETEST_H +#endif // IMPORTMAILJOBINTERFACETESTIMPL_H diff --git a/core/autotests/notes/CMakeLists.txt b/core/autotests/notes/CMakeLists.txt index 970c9a0..8685cf7 100644 --- a/core/autotests/notes/CMakeLists.txt +++ b/core/autotests/notes/CMakeLists.txt @@ -1,16 +1,16 @@ add_definitions( -DPIMDATAEXPORTER_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" ) -set( exportnotesjobinterfacetest_SRCS exportnotesjobinterfacetest.cpp) +set( exportnotesjobinterfacetest_SRCS exportnotesjobinterfacetest.cpp exportnotesjobinterfacetestimpl.cpp) add_executable( exportnotesjobinterfacetest ${exportnotesjobinterfacetest_SRCS}) add_test(NAME exportnotesjobinterfacetest COMMAND exportnotesjobinterfacetest) ecm_mark_as_test(exportnotesjobinterfacetest) target_link_libraries( exportnotesjobinterfacetest Qt5::Test pimdataexporterprivate test_resourceconverter KF5::ConfigCore KF5::Archive KF5::AkonadiCore) ####### -set( importnotesjobinterfacetest_SRCS importnotesjobinterfacetest.cpp) +set( importnotesjobinterfacetest_SRCS importnotesjobinterfacetest.cpp importnotesjobinterfacetestimpl.cpp) add_executable( importnotesjobinterfacetest ${importnotesjobinterfacetest_SRCS}) add_test(NAME importnotesjobinterfacetest COMMAND importnotesjobinterfacetest) ecm_mark_as_test(importnotesjobinterfacetest) target_link_libraries( importnotesjobinterfacetest Qt5::Test pimdataexporterprivate test_resourceconverter KF5::ConfigCore KF5::Archive) diff --git a/core/autotests/notes/exportnotesjobinterfacetest.cpp b/core/autotests/notes/exportnotesjobinterfacetest.cpp index 587d106..0997bfa 100644 --- a/core/autotests/notes/exportnotesjobinterfacetest.cpp +++ b/core/autotests/notes/exportnotesjobinterfacetest.cpp @@ -1,128 +1,70 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "exportnotesjobinterfacetest.h" +#include "exportnotesjobinterfacetestimpl.h" #include "archivestorage.h" -#include "resourceconvertertest.h" #include "testexportfile.h" -#include #include #include #include -#include QTEST_MAIN(ExportNotesJobInterfaceTest) -ExportNotesJobInterfaceTestImpl::ExportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ExportNotesJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ExportNotesJobInterfaceTestImpl::~ExportNotesJobInterfaceTestImpl() -{ -} - -void ExportNotesJobInterfaceTestImpl::convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - resourceConverterTest.convertCollectionIdsToRealPath(selectFolderNoteGroup, selectFolderNoteGroupStr); -} - -QVector ExportNotesJobInterfaceTestImpl::listOfResource() -{ - return mListAkonadiInstanceInfo; -} - -void ExportNotesJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) -{ - SaveResoureConfigTest saveResourceConfig; - saveResourceConfig.setArchive(mArchiveStorage->archive()); - saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceNoteArchiveName(), {QLatin1String("akonadi_akonotes_resource_")}); - slotNoteJobTerminated(); -} - -Akonadi::Collection::Id ExportNotesJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -QString ExportNotesJobInterfaceTestImpl::resourcePath(const QString &identifier) const -{ - ResourceConverterTest converter; - converter.setTestPath(mPathConfig); - const QString url = converter.resourcePath(identifier); - return url; -} - -QString ExportNotesJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} - -QString ExportNotesJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - Q_UNREACHABLE(); - return {}; -} ExportNotesJobInterfaceTest::ExportNotesJobInterfaceTest(QObject *parent) : QObject(parent) { } void ExportNotesJobInterfaceTest::exportNote_data() { QTest::addColumn("configpath"); QTest::addColumn("options"); const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); Utils::StoredTypes options = {Utils::StoredType::Config}; QTest::newRow("test1") << pathConfig + QByteArray("test1/") << options; QTest::newRow("full") << pathConfig + QByteArray("full/") << options; options = {Utils::StoredType::Config|Utils::StoredType::Resources}; QTest::newRow("noteconfigandresource") << pathConfig + QByteArray("noteconfigandresource/") << options; } void ExportNotesJobInterfaceTest::exportNote() { QFETCH(QByteArray, configpath); QFETCH(Utils::StoredTypes, options); TestExportFile *file = new TestExportFile(this); file->setPathConfig(configpath); QVector lstInfo; Utils::AkonadiInstanceInfo info; info.identifier = QStringLiteral("akonadi_akonotes_resource_1"); lstInfo << info; info.identifier = QStringLiteral("akonadi_akonotes_resource_2"); lstInfo << info; //Add extra resource. info.identifier = QStringLiteral("akonadi_kontact_resource_2"); lstInfo << info; ExportNotesJobInterfaceTestImpl *exportNote = new ExportNotesJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); exportNote->setListOfResource(lstInfo); exportNote->setPathConfig(QLatin1String(configpath)); file->setAbstractImportExportJob(exportNote); file->start(); delete exportNote; } diff --git a/core/autotests/notes/exportnotesjobinterfacetest.h b/core/autotests/notes/exportnotesjobinterfacetest.h index 527a729..1b38c02 100644 --- a/core/autotests/notes/exportnotesjobinterfacetest.h +++ b/core/autotests/notes/exportnotesjobinterfacetest.h @@ -1,56 +1,35 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EXPORTNOTESJOBINTERFACETEST_H #define EXPORTNOTESJOBINTERFACETEST_H #include -#include "exportimportutil.h" - -#include "notes/exportnotesjobinterface.h" - -class ExportNotesJobInterfaceTestImpl : public ExportNotesJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ExportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ExportNotesJobInterfaceTestImpl(); - -protected: - void convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) override; - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; - Q_REQUIRED_RESULT QVector listOfResource() override; - Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; -}; - class ExportNotesJobInterfaceTest : public QObject { Q_OBJECT public: explicit ExportNotesJobInterfaceTest(QObject *parent = nullptr); ~ExportNotesJobInterfaceTest() = default; private Q_SLOTS: void exportNote_data(); void exportNote(); }; #endif // EXPORTNOTESJOBINTERFACETEST_H diff --git a/core/autotests/notes/exportnotesjobinterfacetest.cpp b/core/autotests/notes/exportnotesjobinterfacetestimpl.cpp similarity index 64% copy from core/autotests/notes/exportnotesjobinterfacetest.cpp copy to core/autotests/notes/exportnotesjobinterfacetestimpl.cpp index 587d106..616c354 100644 --- a/core/autotests/notes/exportnotesjobinterfacetest.cpp +++ b/core/autotests/notes/exportnotesjobinterfacetestimpl.cpp @@ -1,128 +1,82 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#include "exportnotesjobinterfacetest.h" +#include "exportnotesjobinterfacetestimpl.h" #include "archivestorage.h" #include "resourceconvertertest.h" -#include "testexportfile.h" -#include +#include "saveresourceconfigtest.h" #include #include #include -#include - -QTEST_MAIN(ExportNotesJobInterfaceTest) ExportNotesJobInterfaceTestImpl::ExportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ExportNotesJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ExportNotesJobInterfaceTestImpl::~ExportNotesJobInterfaceTestImpl() { } void ExportNotesJobInterfaceTestImpl::convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); resourceConverterTest.convertCollectionIdsToRealPath(selectFolderNoteGroup, selectFolderNoteGroupStr); } QVector ExportNotesJobInterfaceTestImpl::listOfResource() { return mListAkonadiInstanceInfo; } void ExportNotesJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) { SaveResoureConfigTest saveResourceConfig; saveResourceConfig.setArchive(mArchiveStorage->archive()); saveResourceConfig.exportResourceToArchive(archivePath, url, identifier, Utils::resourceNoteArchiveName(), {QLatin1String("akonadi_akonotes_resource_")}); slotNoteJobTerminated(); } Akonadi::Collection::Id ExportNotesJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } QString ExportNotesJobInterfaceTestImpl::resourcePath(const QString &identifier) const { ResourceConverterTest converter; converter.setTestPath(mPathConfig); const QString url = converter.resourcePath(identifier); return url; } QString ExportNotesJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } QString ExportNotesJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { Q_UNREACHABLE(); return {}; } - -ExportNotesJobInterfaceTest::ExportNotesJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ExportNotesJobInterfaceTest::exportNote_data() -{ - QTest::addColumn("configpath"); - QTest::addColumn("options"); - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/export/"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - QTest::newRow("test1") << pathConfig + QByteArray("test1/") << options; - QTest::newRow("full") << pathConfig + QByteArray("full/") << options; - options = {Utils::StoredType::Config|Utils::StoredType::Resources}; - QTest::newRow("noteconfigandresource") << pathConfig + QByteArray("noteconfigandresource/") << options; -} - -void ExportNotesJobInterfaceTest::exportNote() -{ - QFETCH(QByteArray, configpath); - QFETCH(Utils::StoredTypes, options); - TestExportFile *file = new TestExportFile(this); - file->setPathConfig(configpath); - QVector lstInfo; - Utils::AkonadiInstanceInfo info; - info.identifier = QStringLiteral("akonadi_akonotes_resource_1"); - lstInfo << info; - info.identifier = QStringLiteral("akonadi_akonotes_resource_2"); - lstInfo << info; - //Add extra resource. - info.identifier = QStringLiteral("akonadi_kontact_resource_2"); - lstInfo << info; - - ExportNotesJobInterfaceTestImpl *exportNote = new ExportNotesJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - exportNote->setListOfResource(lstInfo); - exportNote->setPathConfig(QLatin1String(configpath)); - file->setAbstractImportExportJob(exportNote); - file->start(); - delete exportNote; -} diff --git a/core/autotests/notes/exportnotesjobinterfacetest.h b/core/autotests/notes/exportnotesjobinterfacetestimpl.h similarity index 83% copy from core/autotests/notes/exportnotesjobinterfacetest.h copy to core/autotests/notes/exportnotesjobinterfacetestimpl.h index 527a729..53fefbb 100644 --- a/core/autotests/notes/exportnotesjobinterfacetest.h +++ b/core/autotests/notes/exportnotesjobinterfacetestimpl.h @@ -1,56 +1,47 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef EXPORTNOTESJOBINTERFACETEST_H -#define EXPORTNOTESJOBINTERFACETEST_H +#ifndef EXPORTNOTESJOBINTERFACETESTIMPL_H +#define EXPORTNOTESJOBINTERFACETESTIMPL_H -#include #include "exportimportutil.h" - +#include "core/utils.h" #include "notes/exportnotesjobinterface.h" +#include + class ExportNotesJobInterfaceTestImpl : public ExportNotesJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ExportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ExportNotesJobInterfaceTestImpl(); protected: void convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) override; Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override; Q_REQUIRED_RESULT QVector listOfResource() override; Q_REQUIRED_RESULT QString resourcePath(const QString &identifier) const override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) override; }; -class ExportNotesJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ExportNotesJobInterfaceTest(QObject *parent = nullptr); - ~ExportNotesJobInterfaceTest() = default; -private Q_SLOTS: - void exportNote_data(); - void exportNote(); -}; -#endif // EXPORTNOTESJOBINTERFACETEST_H +#endif // EXPORTNOTESJOBINTERFACETESTIMPL_H diff --git a/core/autotests/notes/importnotesjobinterfacetest.cpp b/core/autotests/notes/importnotesjobinterfacetest.cpp index b34e4d6..cd5ce19 100644 --- a/core/autotests/notes/importnotesjobinterfacetest.cpp +++ b/core/autotests/notes/importnotesjobinterfacetest.cpp @@ -1,105 +1,62 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "importnotesjobinterfacetest.h" +#include "importnotesjobinterfacetestimpl.h" #include "archivestorage.h" -#include "notes/importnotesjobinterface.h" -#include "resourceconvertertest.h" #include "testimportfile.h" #include #include QTEST_MAIN(ImportNotesJobInterfaceTest) -ImportNotesJobInterfaceTestImpl::ImportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) - : ImportNotesJobInterface(parent, typeSelected, archiveStorage, numberOfStep) -{ -} - -ImportNotesJobInterfaceTestImpl::~ImportNotesJobInterfaceTestImpl() -{ - //Clean up temp repo - QVERIFY(QDir(QDir::tempPath() + QLatin1Char('/') + Utils::backupnote()).removeRecursively()); -} - -Akonadi::Collection::Id ImportNotesJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.convertFolderPathToCollectionId(path); -} - -QString ImportNotesJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) -{ - return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); -} - -void ImportNotesJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) -{ - mLogCreateResource->logSynchronizeResource(lst); - slotNextStep(); -} - -QString ImportNotesJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); -} - -QString ImportNotesJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) -{ - ResourceConverterTest resourceConverterTest; - resourceConverterTest.setTestPath(mPathConfig); - return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); -} ImportNotesJobInterfaceTest::ImportNotesJobInterfaceTest(QObject *parent) : QObject(parent) { } void ImportNotesJobInterfaceTest::importNote_data() { QTest::addColumn("zipFilePath"); QTest::addColumn("testPath"); QTest::addColumn("options"); const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); Utils::StoredTypes options = {Utils::StoredType::Config}; QTest::newRow("test1") << QString::fromLatin1(pathConfig) << QStringLiteral("/test1/") << options; options = {Utils::StoredType::Config|Utils::StoredType::Resources}; QTest::newRow("test1resource") << QString::fromLatin1(pathConfig) << QStringLiteral("/test1resource/") << options; } void ImportNotesJobInterfaceTest::importNote() { QFETCH(QString, zipFilePath); QFETCH(QString, testPath); QFETCH(Utils::StoredTypes, options); TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); file->setPathConfig(zipFilePath + testPath); file->setExtractPath(QDir::tempPath() + testPath); file->setExcludePath(Utils::notePath()); ImportNotesJobInterfaceTestImpl *impl = new ImportNotesJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); impl->setPathConfig(file->pathConfig()); file->setAbstractImportExportJob(impl); file->setLoggingFilePath(impl->loggingFilePath()); file->start(); delete impl; delete file; } diff --git a/core/autotests/notes/importnotesjobinterfacetest.h b/core/autotests/notes/importnotesjobinterfacetest.h index 3a5aae8..f7fea19 100644 --- a/core/autotests/notes/importnotesjobinterfacetest.h +++ b/core/autotests/notes/importnotesjobinterfacetest.h @@ -1,54 +1,37 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef IMPORTNOTESJOBINTERFACETEST_H #define IMPORTNOTESJOBINTERFACETEST_H #include -#include "exportimportutil.h" -#include "notes/importnotesjobinterface.h" - -class ImportNotesJobInterfaceTestImpl : public ImportNotesJobInterface, public ExportImportUtil -{ - Q_OBJECT -public: - explicit ImportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); - ~ImportNotesJobInterfaceTestImpl(); - -protected: - Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; - Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; - void synchronizeResource(const QStringList &lst) override; - Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; - Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; -}; class ImportNotesJobInterfaceTest : public QObject { Q_OBJECT public: explicit ImportNotesJobInterfaceTest(QObject *parent = nullptr); ~ImportNotesJobInterfaceTest() = default; private Q_SLOTS: void importNote(); void importNote_data(); }; #endif // IMPORTNOTESJOBINTERFACETEST_H diff --git a/core/autotests/notes/importnotesjobinterfacetest.cpp b/core/autotests/notes/importnotesjobinterfacetestimpl.cpp similarity index 62% copy from core/autotests/notes/importnotesjobinterfacetest.cpp copy to core/autotests/notes/importnotesjobinterfacetestimpl.cpp index b34e4d6..6bc986d 100644 --- a/core/autotests/notes/importnotesjobinterfacetest.cpp +++ b/core/autotests/notes/importnotesjobinterfacetestimpl.cpp @@ -1,105 +1,66 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "importnotesjobinterfacetest.h" -#include "archivestorage.h" -#include "notes/importnotesjobinterface.h" +#include "importnotesjobinterfacetestimpl.h" #include "resourceconvertertest.h" -#include "testimportfile.h" -#include #include -QTEST_MAIN(ImportNotesJobInterfaceTest) +#include ImportNotesJobInterfaceTestImpl::ImportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep) : ImportNotesJobInterface(parent, typeSelected, archiveStorage, numberOfStep) { } ImportNotesJobInterfaceTestImpl::~ImportNotesJobInterfaceTestImpl() { //Clean up temp repo QVERIFY(QDir(QDir::tempPath() + QLatin1Char('/') + Utils::backupnote()).removeRecursively()); } Akonadi::Collection::Id ImportNotesJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.convertFolderPathToCollectionId(path); } QString ImportNotesJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree) { return mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree); } void ImportNotesJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) { mLogCreateResource->logSynchronizeResource(lst); slotNextStep(); } QString ImportNotesJobInterfaceTestImpl::adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptResourcePath(resourceConfig, storedData); } QString ImportNotesJobInterfaceTestImpl::adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) { ResourceConverterTest resourceConverterTest; resourceConverterTest.setTestPath(mPathConfig); return resourceConverterTest.adaptNewResourceUrl(overwriteResources, resourceConfig, storePath); } - -ImportNotesJobInterfaceTest::ImportNotesJobInterfaceTest(QObject *parent) - : QObject(parent) -{ -} - -void ImportNotesJobInterfaceTest::importNote_data() -{ - QTest::addColumn("zipFilePath"); - QTest::addColumn("testPath"); - QTest::addColumn("options"); - const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/"); - Utils::StoredTypes options = {Utils::StoredType::Config}; - QTest::newRow("test1") << QString::fromLatin1(pathConfig) << QStringLiteral("/test1/") << options; - options = {Utils::StoredType::Config|Utils::StoredType::Resources}; - QTest::newRow("test1resource") << QString::fromLatin1(pathConfig) << QStringLiteral("/test1resource/") << options; -} - -void ImportNotesJobInterfaceTest::importNote() -{ - QFETCH(QString, zipFilePath); - QFETCH(QString, testPath); - QFETCH(Utils::StoredTypes, options); - TestImportFile *file = new TestImportFile(zipFilePath + testPath, this); - file->setPathConfig(zipFilePath + testPath); - file->setExtractPath(QDir::tempPath() + testPath); - file->setExcludePath(Utils::notePath()); - ImportNotesJobInterfaceTestImpl *impl = new ImportNotesJobInterfaceTestImpl(this, options, file->archiveStorage(), 1); - impl->setPathConfig(file->pathConfig()); - file->setAbstractImportExportJob(impl); - file->setLoggingFilePath(impl->loggingFilePath()); - file->start(); - delete impl; - delete file; -} diff --git a/core/autotests/notes/importnotesjobinterfacetest.h b/core/autotests/notes/importnotesjobinterfacetestimpl.h similarity index 82% copy from core/autotests/notes/importnotesjobinterfacetest.h copy to core/autotests/notes/importnotesjobinterfacetestimpl.h index 3a5aae8..a0bef21 100644 --- a/core/autotests/notes/importnotesjobinterfacetest.h +++ b/core/autotests/notes/importnotesjobinterfacetestimpl.h @@ -1,54 +1,42 @@ /* Copyright (C) 2020 Laurent Montel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef IMPORTNOTESJOBINTERFACETEST_H -#define IMPORTNOTESJOBINTERFACETEST_H +#ifndef IMPORTNOTESJOBINTERFACETESTIMPL_H +#define IMPORTNOTESJOBINTERFACETESTIMPL_H -#include #include "exportimportutil.h" - +#include "core/utils.h" #include "notes/importnotesjobinterface.h" class ImportNotesJobInterfaceTestImpl : public ImportNotesJobInterface, public ExportImportUtil { Q_OBJECT public: explicit ImportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep); ~ImportNotesJobInterfaceTestImpl(); protected: Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override; Q_REQUIRED_RESULT QString createResource(const QString &resources, const QString &name, const QMap &settings, bool synchronizeTree = false) override; void synchronizeResource(const QStringList &lst) override; Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData) override; Q_REQUIRED_RESULT QString adaptNewResourceUrl(bool overwriteResources, const KSharedConfig::Ptr &resourceConfig, const QString &storePath) override; }; -class ImportNotesJobInterfaceTest : public QObject -{ - Q_OBJECT -public: - explicit ImportNotesJobInterfaceTest(QObject *parent = nullptr); - ~ImportNotesJobInterfaceTest() = default; -private Q_SLOTS: - void importNote(); - void importNote_data(); -}; - -#endif // IMPORTNOTESJOBINTERFACETEST_H +#endif // IMPORTNOTESJOBINTERFACETESTIMPL_H