File indexing completed on 2024-12-22 05:05:24

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "importcalendarjobinterfacetest.h"
0008 #include "archivestorage.h"
0009 #include "importcalendarjobinterfacetestimpl.h"
0010 #include "testimportfile.h"
0011 #include <QTest>
0012 QTEST_MAIN(ImportCalendarJobInterfaceTest)
0013 
0014 ImportCalendarJobInterfaceTest::ImportCalendarJobInterfaceTest(QObject *parent)
0015     : QObject(parent)
0016 {
0017 }
0018 
0019 void ImportCalendarJobInterfaceTest::importCalendar_data()
0020 {
0021     QTest::addColumn<QString>("zipFilePath");
0022     QTest::addColumn<QString>("testPath");
0023     QTest::addColumn<Utils::StoredTypes>("options");
0024     Utils::StoredTypes options = {Utils::StoredType::Config};
0025 
0026     const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/");
0027     QTest::newRow("calendaronlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/calendaronlyconfig/") << options;
0028 
0029     options = {Utils::StoredType::Config | Utils::StoredType::Resources};
0030     QTest::newRow("calendarconfigandresource") << QString::fromLatin1(pathConfig) << QStringLiteral("/calendarconfigandresource/") << options;
0031 
0032     options = {Utils::StoredType::Config | Utils::StoredType::Resources};
0033     QTest::newRow("calendarconfigandresourceskalendar") << QString::fromLatin1(pathConfig) << QStringLiteral("/calendarconfigandresourceskalendar/") << options;
0034 }
0035 
0036 void ImportCalendarJobInterfaceTest::importCalendar()
0037 {
0038     QFETCH(QString, zipFilePath);
0039     QFETCH(QString, testPath);
0040     QFETCH(Utils::StoredTypes, options);
0041     const QString fullTestPath = zipFilePath + testPath;
0042 
0043     auto file = new TestImportFile(fullTestPath, this);
0044     file->setPathConfig(fullTestPath);
0045     file->setExtractPath(QDir::tempPath() + testPath);
0046     file->setExcludePath(Utils::calendarPath());
0047     auto impl = new ImportCalendarJobInterfaceTestImpl(this, options, file->archiveStorage(), 1);
0048     impl->setPathConfig(file->pathConfig());
0049     impl->setExtractPath(file->extractPath());
0050     impl->setTempDirName(file->extractPath());
0051     impl->setExistingPathConfig(fullTestPath + QStringLiteral("/existingconfig/"));
0052     file->setAbstractImportExportJob(impl);
0053     file->setLoggingFilePath(impl->loggingFilePath());
0054     file->start();
0055     delete impl;
0056     delete file;
0057 }
0058 
0059 #include "moc_importcalendarjobinterfacetest.cpp"