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 "importmailjobinterfacetest.h"
0008 #include "archivestorage.h"
0009 #include "importmailjobinterfacetestimpl.h"
0010 #include "testimportfile.h"
0011 #include "utils.h"
0012 #include <QTest>
0013 QTEST_MAIN(ImportMailJobInterfaceTest)
0014 
0015 ImportMailJobInterfaceTest::ImportMailJobInterfaceTest(QObject *parent)
0016     : QObject(parent)
0017 {
0018 }
0019 
0020 void ImportMailJobInterfaceTest::importMail_data()
0021 {
0022     QTest::addColumn<QString>("zipFilePath");
0023     QTest::addColumn<QString>("testPath");
0024     QTest::addColumn<Utils::StoredTypes>("options");
0025     Utils::StoredTypes options = {Utils::StoredType::Config};
0026     const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/");
0027 
0028     QTest::newRow("mailonlyconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("/mailonlyconfig/") << options;
0029 
0030     options = {Utils::StoredType::Config | Utils::StoredType::Resources};
0031     QTest::newRow("mailconfigandresource") << QString::fromLatin1(pathConfig) << QStringLiteral("mailconfigandresource/") << options;
0032 
0033     options = {Utils::StoredType::MailTransport};
0034     QTest::newRow("mailtransport") << QString::fromLatin1(pathConfig) << QStringLiteral("mailtransport/") << options;
0035 
0036     options = {Utils::StoredType::MailTransport};
0037     QTest::newRow("mailtransport2") << QString::fromLatin1(pathConfig) << QStringLiteral("mailtransport2/") << options;
0038 
0039     options = {Utils::StoredType::Identity};
0040     QTest::newRow("identities") << QString::fromLatin1(pathConfig) << QStringLiteral("identities/") << options;
0041 
0042     options = {Utils::StoredType::Config | Utils::StoredType::Identity};
0043     QTest::newRow("identitiesandconfig") << QString::fromLatin1(pathConfig) << QStringLiteral("identitiesandconfig/") << options;
0044 
0045     options = {Utils::StoredType::Config | Utils::StoredType::Identity | Utils::StoredType::MailTransport};
0046     QTest::newRow("identitiesandconfigandmailtransport")
0047         << QString::fromLatin1(pathConfig) << QStringLiteral("identitiesandconfigandmailtransport/") << options;
0048 
0049     options = {Utils::StoredType::Config | Utils::StoredType::Identity | Utils::StoredType::MailTransport | Utils::StoredType::Resources | Utils::Mails};
0050     QTest::newRow("identitiesandconfigandmailtransportandresources")
0051         << QString::fromLatin1(pathConfig) << QStringLiteral("identitiesandconfigandmailtransportandresources/") << options;
0052 }
0053 
0054 void ImportMailJobInterfaceTest::importMail()
0055 {
0056     QFETCH(QString, zipFilePath);
0057     QFETCH(QString, testPath);
0058     QFETCH(Utils::StoredTypes, options);
0059     const QString fullTestPath = zipFilePath + testPath;
0060     auto file = new TestImportFile(fullTestPath, this);
0061     file->setPathConfig(fullTestPath);
0062     file->setExtractPath(QDir::tempPath() + QLatin1Char('/') + testPath);
0063     file->setExcludePath(Utils::mailsPath()); // ???
0064     auto impl = new ImportMailJobInterfaceTestImpl(this, options, file->archiveStorage(), 1);
0065     impl->setPathConfig(file->pathConfig());
0066     impl->setExtractPath(file->extractPath());
0067     impl->setTempDirName(file->extractPath());
0068     impl->setExistingPathConfig(fullTestPath + QStringLiteral("/existingconfig/"));
0069     file->setAbstractImportExportJob(impl);
0070     file->setLoggingFilePath(impl->loggingFilePath());
0071     file->start();
0072     delete impl;
0073     delete file;
0074 }
0075 
0076 #include "moc_importmailjobinterfacetest.cpp"