Commit e6f37cef authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Implement autotest

parent a56b2b1f
......@@ -24,6 +24,10 @@ set(pimdataexporter_alarm_SRCS
alarm/importalarmjob.cpp
)
set(pimdataexporter_interfaces_SRCS
notes/exportnotesjobinterface.cpp
)
set(pimdataexporter_notes_SRCS
notes/exportnotesjobinterfaceimpl.cpp
notes/importnotesjob.cpp
......@@ -48,6 +52,7 @@ set(pimdataexporter_LIB_SRCS
${pimdataexporter_addressbook_SRCS}
${pimdataexporter_jot_SRCS}
${pimdataexporter_akregator_SRCS}
${pimdataexporter_interfaces_SRCS}
abstractimportexportjob.cpp
pimdataexporterkernel.cpp
utils.cpp
......@@ -90,5 +95,6 @@ install(TARGETS pimdataexporterprivate ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRA
if(BUILD_TESTING)
add_subdirectory(autotests)
add_subdirectory(notes/autotests)
endif()
......@@ -20,9 +20,10 @@
#ifndef ARCHIVESTORAGE_H
#define ARCHIVESTORAGE_H
#include <QObject>
#include "pimdataexporter_export.h"
class KZip;
class ArchiveStorage : public QObject
class PIMDATAEXPORTER_EXPORT ArchiveStorage : public QObject
{
Q_OBJECT
public:
......
add_definitions( -DPIMDATAEXPORTER_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" )
set( exportnotesjobinterfacetest_SRCS exportnotesjobinterfacetest.cpp )
add_executable( exportnotesjobinterfacetest ${exportnotesjobinterfacetest_SRCS})
add_test(NAME exportnotesjobinterfacetest COMMAND exportnotesjobinterfacetest)
ecm_mark_as_test(exportnotesjobinterfacetest)
target_link_libraries( exportnotesjobinterfacetest Qt5::Test pimdataexporterprivate KF5::ConfigCore)
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
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 "notes/exportnotesjobinterface.h"
#include "archivestorage.h"
#include <QStandardPaths>
#include <QTest>
#include <QSignalSpy>
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)
{
//TODO
}
void ExportNotesJobInterfaceTestImpl::exportArchiveResource()
{
//TODO
}
ExportNotesJobInterfaceTest::ExportNotesJobInterfaceTest(QObject *parent)
: QObject(parent)
{
}
void ExportNotesJobInterfaceTest::importNoteConfigTest1()
{
//Don't use setTestModeEnabled otherwise we can set env
//QStandardPaths::setTestModeEnabled(true);
qputenv("XDG_DATA_HOME", PIMDATAEXPORTER_DIR "/test1/share");
qputenv("XDG_CONFIG_HOME", PIMDATAEXPORTER_DIR "/test1/config");
//TODO fix file name.
const QString storeArchivePath(QStringLiteral("/tmp/foo.zip"));
ArchiveStorage *archiveStorage = new ArchiveStorage(storeArchivePath, this);
Q_ASSERT(archiveStorage->openArchive(true));
Utils::addVersion(archiveStorage->archive());
Utils::storeDataExportInfo(storeArchivePath, archiveStorage->archive());
ExportNotesJobInterfaceTestImpl *exportNote = new ExportNotesJobInterfaceTestImpl(this, {Utils::StoredType::Config}, archiveStorage, 1);
QSignalSpy finish(exportNote, &ExportNotesJobInterfaceTestImpl::jobFinished);
QSignalSpy error(exportNote, &ExportNotesJobInterfaceTestImpl::error);
exportNote->start();
QVERIFY(finish.wait());
QCOMPARE(error.count(), 0);
delete exportNote;
delete archiveStorage;
}
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
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 <QObject>
#include "notes/exportnotesjobinterface.h"
class ExportNotesJobInterfaceTestImpl : public ExportNotesJobInterface
{
Q_OBJECT
public:
explicit ExportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ExportNotesJobInterfaceTestImpl();
protected:
void exportArchiveResource() override;
void convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) override;
};
class ExportNotesJobInterfaceTest : public QObject
{
Q_OBJECT
public:
explicit ExportNotesJobInterfaceTest(QObject *parent = nullptr);
~ExportNotesJobInterfaceTest() = default;
private Q_SLOTS:
void importNoteConfigTest1();
};
#endif // EXPORTNOTESJOBINTERFACETEST_H
/*
Copyright (C) 2013-2020 Laurent Montel <montel@kde.org>
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 "exportnotesjobinterface.h"
#include "exportresourcearchivejob.h"
#include <KLocalizedString>
#include <KZip>
#include <QTemporaryFile>
#include <KConfigGroup>
#include <QDir>
#include <QTimer>
#include <QStandardPaths>
ExportNotesJobInterface::ExportNotesJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
{
}
ExportNotesJobInterface::~ExportNotesJobInterface()
{
}
void ExportNotesJobInterface::start()
{
Q_EMIT title(i18n("Start export KNotes settings..."));
createProgressDialog(i18n("Export KNotes settings"));
if (mTypeSelected & Utils::Resources) {
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotCheckBackupResource);
} else if (mTypeSelected & Utils::Config) {
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotCheckBackupConfig);
} else {
Q_EMIT jobFinished();
}
}
void ExportNotesJobInterface::backupTheme()
{
const QString notesThemeDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/knotes/print/");
QDir notesThemeDirectory(notesThemeDir);
if (notesThemeDirectory.exists()) {
const bool notesDirAdded = archive()->addLocalDirectory(notesThemeDir, Utils::dataPath() + QStringLiteral("knotes/print"));
if (!notesDirAdded) {
Q_EMIT error(i18n("\"%1\" directory cannot be added to backup file.", notesThemeDir));
}
}
}
void ExportNotesJobInterface::slotCheckBackupResource()
{
setProgressDialogLabel(i18n("Backing up resources..."));
increaseProgressDialog();
backupTheme();
exportArchiveResource();
}
void ExportNotesJobInterface::slotCheckBackupConfig()
{
if (mTypeSelected & Utils::Config) {
backupConfig();
increaseProgressDialog();
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
}
Q_EMIT jobFinished();
}
void ExportNotesJobInterface::backupConfig()
{
setProgressDialogLabel(i18n("Backing up config..."));
const QString knotesStr(QStringLiteral("knotesrc"));
const QString knotesrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + knotesStr;
if (QFileInfo::exists(knotesrc)) {
backupFile(knotesrc, Utils::configsPath(), knotesStr);
}
const QString globalNoteSettingsStr(QStringLiteral("globalnotesettings"));
const QString globalNoteSettingsrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + globalNoteSettingsStr;
if (QFileInfo::exists(globalNoteSettingsrc)) {
KSharedConfigPtr globalnotesettingsrc = KSharedConfig::openConfig(globalNoteSettingsrc);
QTemporaryFile tmp;
tmp.open();
KConfig *knoteConfig = globalnotesettingsrc->copyTo(tmp.fileName());
const QString selectFolderNoteStr(QStringLiteral("SelectNoteFolder"));
if (knoteConfig->hasGroup(selectFolderNoteStr)) {
KConfigGroup selectFolderNoteGroup = knoteConfig->group(selectFolderNoteStr);
const QString selectFolderNoteGroupStr(QStringLiteral("DefaultFolder"));
convertCollectionIdsToRealPath(selectFolderNoteGroup, selectFolderNoteGroupStr);
}
knoteConfig->sync();
backupFile(tmp.fileName(), Utils::configsPath(), globalNoteSettingsStr);
delete knoteConfig;
}
backupUiRcFile(QStringLiteral("knotesappui.rc"), QStringLiteral("knotes"));
backupUiRcFile(QStringLiteral("knotesui.rc"), QStringLiteral("knotes"));
backupUiRcFile(QStringLiteral("knotes_part.rc"), QStringLiteral("knotes"));
backupConfigFile(QStringLiteral("akonadi_notes_agent.notifyrc"));
storeDirectory(QStringLiteral("/knotes/print/theme/"));
Q_EMIT info(i18n("Config backup done."));
}
/*
Copyright (C) 2013-2020 Laurent Montel <montel@kde.org>
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 EXPORTNOTESJOBINTERFACE_H
#define EXPORTNOTESJOBINTERFACE_H
#include "abstractimportexportjob.h"
#include "pimdataexportercore_private_export.h"
class ArchiveStorage;
class PIMDATAEXPORTER_TESTS_EXPORT ExportNotesJobInterface : public AbstractImportExportJob
{
Q_OBJECT
public:
explicit ExportNotesJobInterface(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ExportNotesJobInterface() override;
void start() override;
void slotCheckBackupConfig();
protected:
virtual void exportArchiveResource() = 0;
virtual void convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) = 0;
private:
void slotCheckBackupResource();
void backupConfig();
void backupTheme();
};
#endif // EXPORTNOTESJOBINTERFACE_H
......@@ -32,7 +32,7 @@
#include <QStandardPaths>
ExportNotesJobInterfaceImpl::ExportNotesJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
: AbstractImportExportJob(parent, archiveStorage, typeSelected, numberOfStep)
: ExportNotesJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
{
}
......@@ -40,53 +40,6 @@ ExportNotesJobInterfaceImpl::~ExportNotesJobInterfaceImpl()
{
}
void ExportNotesJobInterfaceImpl::start()
{
Q_EMIT title(i18n("Start export KNotes settings..."));
createProgressDialog(i18n("Export KNotes settings"));
if (mTypeSelected & Utils::Resources) {
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotCheckBackupResource);
} else if (mTypeSelected & Utils::Config) {
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotCheckBackupConfig);
} else {
Q_EMIT jobFinished();
}
}
void ExportNotesJobInterfaceImpl::backupTheme()
{
const QString notesThemeDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/knotes/print/");
QDir notesThemeDirectory(notesThemeDir);
if (notesThemeDirectory.exists()) {
const bool notesDirAdded = archive()->addLocalDirectory(notesThemeDir, Utils::dataPath() + QStringLiteral("knotes/print"));
if (!notesDirAdded) {
Q_EMIT error(i18n("\"%1\" directory cannot be added to backup file.", notesThemeDir));
}
}
}
void ExportNotesJobInterfaceImpl::slotCheckBackupResource()
{
setProgressDialogLabel(i18n("Backing up resources..."));
increaseProgressDialog();
backupTheme();
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotWriteNextArchiveResource);
}
void ExportNotesJobInterfaceImpl::slotCheckBackupConfig()
{
if (mTypeSelected & Utils::Config) {
backupConfig();
increaseProgressDialog();
if (wasCanceled()) {
Q_EMIT jobFinished();
return;
}
}
Q_EMIT jobFinished();
}
void ExportNotesJobInterfaceImpl::slotNoteJobTerminated()
{
if (wasCanceled()) {
......@@ -133,46 +86,13 @@ void ExportNotesJobInterfaceImpl::slotWriteNextArchiveResource()
}
} else {
Q_EMIT info(i18n("Resources backup done."));
QTimer::singleShot(0, this, &ExportNotesJobInterfaceImpl::slotCheckBackupConfig);
QTimer::singleShot(0, this, &ExportNotesJobInterface::slotCheckBackupConfig);
}
}
void ExportNotesJobInterfaceImpl::backupConfig()
void ExportNotesJobInterfaceImpl::exportArchiveResource()
{
setProgressDialogLabel(i18n("Backing up config..."));
const QString knotesStr(QStringLiteral("knotesrc"));
const QString knotesrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + knotesStr;
if (QFileInfo::exists(knotesrc)) {
backupFile(knotesrc, Utils::configsPath(), knotesStr);
}
const QString globalNoteSettingsStr(QStringLiteral("globalnotesettings"));
const QString globalNoteSettingsrc = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + globalNoteSettingsStr;
if (QFileInfo::exists(globalNoteSettingsrc)) {
KSharedConfigPtr globalnotesettingsrc = KSharedConfig::openConfig(globalNoteSettingsrc);
QTemporaryFile tmp;
tmp.open();
KConfig *knoteConfig = globalnotesettingsrc->copyTo(tmp.fileName());
const QString selectFolderNoteStr(QStringLiteral("SelectNoteFolder"));
if (knoteConfig->hasGroup(selectFolderNoteStr)) {
KConfigGroup selectFolderNoteGroup = knoteConfig->group(selectFolderNoteStr);
const QString selectFolderNoteGroupStr(QStringLiteral("DefaultFolder"));
convertCollectionIdsToRealPath(selectFolderNoteGroup, selectFolderNoteGroupStr);
}
knoteConfig->sync();
backupFile(tmp.fileName(), Utils::configsPath(), globalNoteSettingsStr);
delete knoteConfig;
}
backupUiRcFile(QStringLiteral("knotesappui.rc"), QStringLiteral("knotes"));
backupUiRcFile(QStringLiteral("knotesui.rc"), QStringLiteral("knotes"));
backupUiRcFile(QStringLiteral("knotes_part.rc"), QStringLiteral("knotes"));
backupConfigFile(QStringLiteral("akonadi_notes_agent.notifyrc"));
storeDirectory(QStringLiteral("/knotes/print/theme/"));
Q_EMIT info(i18n("Config backup done."));
slotNoteJobTerminated();
}
void ExportNotesJobInterfaceImpl::convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr)
......
......@@ -17,32 +17,29 @@
Boston, MA 02110-1301, USA.
*/
#ifndef EXPORTNOTESJOBINTERFACE_H
#define EXPORTNOTESJOBINTERFACE_H
#ifndef EXPORTNOTESJOBINTERFACEIMPL_H
#define EXPORTNOTESJOBINTERFACEIMPL_H
#include "abstractimportexportjob.h"
#include "exportnotesjobinterface.h"
#include "pimdataexportercore_private_export.h"
class ArchiveStorage;
class PIMDATAEXPORTER_TESTS_EXPORT ExportNotesJobInterfaceImpl : public AbstractImportExportJob
class PIMDATAEXPORTER_TESTS_EXPORT ExportNotesJobInterfaceImpl : public ExportNotesJobInterface
{
Q_OBJECT
public:
explicit ExportNotesJobInterfaceImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep);
~ExportNotesJobInterfaceImpl() override;
void start() override;
protected:
void exportArchiveResource() override;
void convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr) override;
private:
void slotCheckBackupResource();
void slotCheckBackupConfig();
void slotNoteJobTerminated();
void slotWriteNextArchiveResource();
void backupConfig();
void convertCollectionIdsToRealPath(KConfigGroup &selectFolderNoteGroup, const QString &selectFolderNoteGroupStr);
void backupTheme();
int mIndexIdentifier = 0;
};
#endif // EXPORTNOTESJOBINTERFACE_H
......@@ -104,9 +104,9 @@ Q_REQUIRED_RESULT QString resourcePath(const Akonadi::AgentInstance &agent, cons
Q_REQUIRED_RESULT QString adaptResourcePath(const KSharedConfigPtr &resourceConfig, const QString &storedData);
Q_REQUIRED_RESULT QString storeResources(KZip *archive, const QString &identifier, const QString &path);
KZip *openZip(const QString &filename, QString &errorMsg);
void storeDataExportInfo(const QString &filename, KZip *archive);
PIMDATAEXPORTER_EXPORT void storeDataExportInfo(const QString &filename, KZip *archive);
void addVersion(KZip *archive);
PIMDATAEXPORTER_EXPORT void addVersion(KZip *archive);
Q_REQUIRED_RESULT int archiveVersion(KZip *archive);
Q_REQUIRED_RESULT int currentArchiveVersion();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment