importnotesjobinterfacetest.cpp 4.27 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
/*
   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 "importnotesjobinterfacetest.h"
21
#include "archivestorage.h"
Laurent Montel's avatar
Laurent Montel committed
22
#include "notes/importnotesjobinterface.h"
23
#include "resourceconvertertest.h"
Laurent Montel's avatar
Laurent Montel committed
24
#include "testimportfile.h"
25
#include <QSignalSpy>
Laurent Montel's avatar
Laurent Montel committed
26
27
28
29
30
31
32
33
34
35
36
37
#include <QTest>
QTEST_MAIN(ImportNotesJobInterfaceTest)

ImportNotesJobInterfaceTestImpl::ImportNotesJobInterfaceTestImpl(QObject *parent, Utils::StoredTypes typeSelected, ArchiveStorage *archiveStorage, int numberOfStep)
    : ImportNotesJobInterface(parent, typeSelected, archiveStorage, numberOfStep)
{
}

ImportNotesJobInterfaceTestImpl::~ImportNotesJobInterfaceTestImpl()
{
}

Laurent Montel's avatar
Laurent Montel committed
38
39
40
Akonadi::Collection::Id ImportNotesJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path)
{
    ResourceConverterTest resourceConverterTest;
Laurent Montel's avatar
Laurent Montel committed
41
    resourceConverterTest.setTestPath(QLatin1String(PIMDATAEXPORTER_DIR));
Laurent Montel's avatar
Laurent Montel committed
42
43
44
    return resourceConverterTest.convertFolderPathToCollectionId(path);
}

Laurent Montel's avatar
Laurent Montel committed
45
46
QString ImportNotesJobInterfaceTestImpl::createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings, bool synchronizeTree)
{
47
48
    mLogCreateResource->logCreateResource(resources, name, settings, synchronizeTree);
    qDebug() << " QString createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings)" << resources << " name " << name << " settings " << settings;
Laurent Montel's avatar
Laurent Montel committed
49
50
51
52
    //TODO
    return {};
}

53
54
void ImportNotesJobInterfaceTestImpl::synchronizeResource(const QStringList &lst)
{
55
56
    //TODO log it!
    qDebug() << " void ImportNotesJobInterfaceTestImpl::synchronizeResource(const QStringList &lst) TODO IMPLEMENT" << lst;
Laurent Montel's avatar
Laurent Montel committed
57
    mLogCreateResource->appendText(lst.join(QLatin1Char('\n')));
58
    slotNextStep();
59
60
}

Laurent Montel's avatar
Laurent Montel committed
61
62
63
64
ImportNotesJobInterfaceTest::ImportNotesJobInterfaceTest(QObject *parent)
    : QObject(parent)
{
}
65

Laurent Montel's avatar
Laurent Montel committed
66
67
68
void ImportNotesJobInterfaceTest::importNoteConfig_data()
{
    QTest::addColumn<QString>("zipFilePath");
69
    QTest::addColumn<QString>("testPath");
Laurent Montel's avatar
Laurent Montel committed
70
    const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/");
71
    QTest::newRow("test1") << QString::fromLatin1(pathConfig) << QStringLiteral("/test1/");
Laurent Montel's avatar
Laurent Montel committed
72
73
74
}

void ImportNotesJobInterfaceTest::importNoteConfig()
75
{
Laurent Montel's avatar
Laurent Montel committed
76
    QFETCH(QString, zipFilePath);
77
    QFETCH(QString, testPath);
78
    TestImportFile *file = new TestImportFile(zipFilePath + testPath, this);
79
80
    file->setPathConfig(zipFilePath + testPath);
    file->setExtractPath(QDir::tempPath() + testPath);
Laurent Montel's avatar
Laurent Montel committed
81
82
83
84
    ImportNotesJobInterfaceTestImpl *impl = new ImportNotesJobInterfaceTestImpl(this, {Utils::StoredType::Config}, file->archiveStorage(), 1);
    file->setAbstractImportExportJob(impl);
    file->start();
    delete impl;
85
    delete file;
Laurent Montel's avatar
Laurent Montel committed
86
}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

void ImportNotesJobInterfaceTest::importNoteConfigAndResources_data()
{
    QTest::addColumn<QString>("zipFilePath");
    QTest::addColumn<QString>("testPath");
    const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/");
    QTest::newRow("test1") << QString::fromLatin1(pathConfig) << QStringLiteral("/test1/");
}

void ImportNotesJobInterfaceTest::importNoteConfigAndResources()
{
    QFETCH(QString, zipFilePath);
    QFETCH(QString, testPath);
    TestImportFile *file = new TestImportFile(zipFilePath + testPath, this);
    file->setPathConfig(zipFilePath + testPath);
    file->setExtractPath(QDir::tempPath() + testPath);
    ImportNotesJobInterfaceTestImpl *impl = new ImportNotesJobInterfaceTestImpl(this, {Utils::StoredType::Config|Utils::StoredType::Resources}, file->archiveStorage(), 1);
    file->setAbstractImportExportJob(impl);
    file->start();
    delete impl;
    delete file;
}