Commit ca3e3af3 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Implement compareimportfile

parent d16a9ee3
......@@ -18,6 +18,8 @@
*/
#include "compareimportfile.h"
#include "generatelistfilefromarchive.h"
#include "loadlistfromfile.h"
#include <QProcess>
#include <QTest>
......@@ -32,33 +34,35 @@ CompareImportFile::~CompareImportFile()
void CompareImportFile::compareFile()
{
QProcess proc;
const QStringList args = QStringList()
<< QStringLiteral("-u")
<< mReferenceFilePath
<< mTempFilePath;
proc.setProcessChannelMode(QProcess::ForwardedChannels);
proc.start(QStringLiteral("diff"), args);
QVERIFY(proc.waitForFinished());
QCOMPARE(proc.exitCode(), 0);
GenerateListFileFromArchive archive(mArchiveFilePath);
//qDebug() << " archive " << archive.listFile();
LoadListFromFile f(mListFilePath + QStringLiteral("/list.txt"));
const QStringList archiveList = archive.listFile();
const bool equal = (f.fileList() == archiveList);
if (!equal) {
qDebug() << "Requested : " << f.fileList();
qDebug() << "List File : " << archiveList;
}
QVERIFY(equal);
}
QString CompareImportFile::tempFilePath() const
QString CompareImportFile::archiveFilePath() const
{
return mTempFilePath;
return mArchiveFilePath;
}
void CompareImportFile::setTempFilePath(const QString &tempFilePath)
void CompareImportFile::setArchiveFilePath(const QString &archiveFilePath)
{
mTempFilePath = tempFilePath;
mArchiveFilePath = archiveFilePath;
}
QString CompareImportFile::referenceFilePath() const
QString CompareImportFile::listFilePath() const
{
return mReferenceFilePath;
return mListFilePath;
}
void CompareImportFile::setReferenceFilePath(const QString &referenceFilePath)
void CompareImportFile::setListFilePath(const QString &listFilePath)
{
mReferenceFilePath = referenceFilePath;
mListFilePath = listFilePath;
}
......@@ -30,15 +30,16 @@ public:
void compareFile();
Q_REQUIRED_RESULT QString tempFilePath() const;
void setTempFilePath(const QString &tempFilePath);
Q_REQUIRED_RESULT QString referenceFilePath() const;
void setReferenceFilePath(const QString &referenceFilePath);
Q_REQUIRED_RESULT QString archiveFilePath() const;
void setArchiveFilePath(const QString &archiveFilePath);
Q_REQUIRED_RESULT QString listFilePath() const;
void setListFilePath(const QString &listFilePath);
private:
QString mTempFilePath;
QString mReferenceFilePath;
QString mArchiveFilePath;
QString mListFilePath;
};
#endif // COMPAREIMPORTFILE_H
......@@ -39,21 +39,35 @@ void ImportNotesJobInterfaceTestImpl::restoreResources()
qDebug() << " not implement yet";
}
Akonadi::Collection::Id ImportNotesJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path)
{
ResourceConverterTest resourceConverterTest;
return resourceConverterTest.convertFolderPathToCollectionId(path);
}
ImportNotesJobInterfaceTest::ImportNotesJobInterfaceTest(QObject *parent)
: QObject(parent)
{
}
void ImportNotesJobInterfaceTest::importNoteConfigTest1()
void ImportNotesJobInterfaceTest::importNoteConfig_data()
{
QTest::addColumn<QString>("zipFilePath");
const QByteArray pathConfig(QByteArray(PIMDATAEXPORTER_DIR) + "/import/");
QTest::newRow("test1") << QLatin1String(pathConfig) + QStringLiteral("test1/test1.zip");
}
void ImportNotesJobInterfaceTest::importNoteConfig()
{
QFETCH(QString, zipFilePath);
//Don't use setTestModeEnabled otherwise we can set env
//QStandardPaths::setTestModeEnabled(true);
qputenv("XDG_DATA_HOME", PIMDATAEXPORTER_DIR "/test1/share");
qputenv("XDG_CONFIG_HOME", PIMDATAEXPORTER_DIR "/test1/config");
//FIXME Extract in tmp !
qputenv("XDG_DATA_HOME", PIMDATAEXPORTER_DIR "/import/test1/share");
qputenv("XDG_CONFIG_HOME", PIMDATAEXPORTER_DIR "/import/test1/config");
//TODO fix file name.
const QString temporaryFile = QStringLiteral("/tmp/foo.zip");
const QString temporaryFile = zipFilePath;
const QString storeArchivePath(temporaryFile);
ArchiveStorage *archiveStorage = new ArchiveStorage(storeArchivePath, this);
Q_ASSERT(archiveStorage->openArchive(false));
......@@ -66,11 +80,5 @@ void ImportNotesJobInterfaceTest::importNoteConfigTest1()
QCOMPARE(error.count(), 0);
delete importNote;
delete archiveStorage;
}
Akonadi::Collection::Id ImportNotesJobInterfaceTestImpl::convertFolderPathToCollectionId(const QString &path)
{
ResourceConverterTest resourceConverterTest;
return resourceConverterTest.convertFolderPathToCollectionId(path);
//TODO compare this number of file extracted.
}
......@@ -45,7 +45,8 @@ public:
explicit ImportNotesJobInterfaceTest(QObject *parent = nullptr);
~ImportNotesJobInterfaceTest() = default;
private Q_SLOTS:
void importNoteConfigTest1();
void importNoteConfig();
void importNoteConfig_data();
};
#endif // IMPORTNOTESJOBINTERFACETEST_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment