saveresourceconfigtest.cpp 2.51 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
   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 "saveresourceconfigtest.h"
#include "resourceconvertertest.h"
#include <QTest>
#include <AkonadiCore/ServerManager>

Laurent Montel's avatar
Laurent Montel committed
25
SaveResourceConfigTest::SaveResourceConfigTest()
Laurent Montel's avatar
Laurent Montel committed
26
27
28
{
}

Laurent Montel's avatar
Laurent Montel committed
29
KZip *SaveResourceConfigTest::archive() const
Laurent Montel's avatar
Laurent Montel committed
30
31
32
33
{
    return mArchive;
}

Laurent Montel's avatar
Laurent Montel committed
34
void SaveResourceConfigTest::setArchive(KZip *archive)
Laurent Montel's avatar
Laurent Montel committed
35
36
37
38
{
    mArchive = archive;
}

Laurent Montel's avatar
Laurent Montel committed
39
void SaveResourceConfigTest::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier, const QString &resourceArchiveName, const QStringList &resourceIdentifierTypes)
Laurent Montel's avatar
Laurent Montel committed
40
41
42
{
    QVERIFY(mArchive);
    bool typeIdentifierFound = false;
Laurent Montel's avatar
Laurent Montel committed
43
    for (const QString &resourceType: resourceIdentifierTypes) {
Laurent Montel's avatar
Laurent Montel committed
44
45
46
47
48
        typeIdentifierFound = identifier.startsWith(resourceType);
        if (typeIdentifierFound) {
            break;
        }
    }
Laurent Montel's avatar
Laurent Montel committed
49

Laurent Montel's avatar
Laurent Montel committed
50
    QVERIFY(typeIdentifierFound);
Laurent Montel's avatar
Laurent Montel committed
51
52
53
    if (QFileInfo(url).isFile()) {
        QVERIFY(mArchive->addLocalFile(url, archivePath + resourceArchiveName));
    } else {
Laurent Montel's avatar
Laurent Montel committed
54
55
56
57
58
59
        const QString zipFile = url + identifier + QLatin1String(".zip");
        const bool success = mArchive->addLocalFile(zipFile, archivePath + resourceArchiveName);
        if (!success) {
            qDebug() << " zip file " << zipFile;
        }
        QVERIFY(success);
Laurent Montel's avatar
Laurent Montel committed
60
    }
Laurent Montel's avatar
Laurent Montel committed
61
62
63
64
65
66
67
    ResourceConverterTest converter;
    const QString errorStr = converter.storeResources(mArchive, identifier, archivePath);
    QVERIFY(errorStr.isEmpty());
    const QString urlAgentConfig = Akonadi::ServerManager::agentConfigFilePath(identifier);
    QVERIFY(!urlAgentConfig.isEmpty());
    const QFileInfo fi(urlAgentConfig);
    const QString filename = fi.fileName();
Laurent Montel's avatar
Laurent Montel committed
68
    //qDebug() << "urlAgentConfig  " << urlAgentConfig;
Laurent Montel's avatar
Laurent Montel committed
69
70
    QVERIFY(mArchive->addLocalFile(urlAgentConfig, archivePath + filename));
}