File indexing completed on 2024-12-22 05:05:25
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 "saveresourceconfigtest.h" 0008 #include "resourceconvertertest.h" 0009 #include <Akonadi/ServerManager> 0010 #include <QTest> 0011 0012 SaveResourceConfigTest::SaveResourceConfigTest() = default; 0013 0014 KZip *SaveResourceConfigTest::archive() const 0015 { 0016 return mArchive; 0017 } 0018 0019 void SaveResourceConfigTest::setArchive(KZip *archive) 0020 { 0021 mArchive = archive; 0022 } 0023 0024 void SaveResourceConfigTest::exportResourceToArchive(const QString &archivePath, 0025 const QString &url, 0026 const QString &identifier, 0027 const QString &resourceArchiveName, 0028 const QStringList &resourceIdentifierTypes) 0029 { 0030 QVERIFY(mArchive); 0031 bool typeIdentifierFound = false; 0032 for (const QString &resourceType : resourceIdentifierTypes) { 0033 typeIdentifierFound = identifier.startsWith(resourceType); 0034 if (typeIdentifierFound) { 0035 break; 0036 } 0037 } 0038 0039 QVERIFY(typeIdentifierFound); 0040 if (QFileInfo(url).isFile()) { 0041 QVERIFY(mArchive->addLocalFile(url, archivePath + resourceArchiveName)); 0042 } else { 0043 const QString zipFile = url + identifier + QLatin1StringView(".zip"); 0044 const bool success = mArchive->addLocalFile(zipFile, archivePath + resourceArchiveName); 0045 if (!success) { 0046 qDebug() << " zip file " << zipFile; 0047 } 0048 QVERIFY(success); 0049 } 0050 ResourceConverterTest converter; 0051 const QString errorStr = converter.storeResources(mArchive, identifier, archivePath); 0052 QVERIFY(errorStr.isEmpty()); 0053 const QString urlAgentConfig = Akonadi::ServerManager::agentConfigFilePath(identifier); 0054 QVERIFY(!urlAgentConfig.isEmpty()); 0055 const QFileInfo fi(urlAgentConfig); 0056 const QString filename = fi.fileName(); 0057 // qDebug() << "urlAgentConfig " << urlAgentConfig; 0058 QVERIFY(mArchive->addLocalFile(urlAgentConfig, archivePath + filename)); 0059 }