Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
PIM Data Exporter
Commits
e984449a
Commit
e984449a
authored
May 02, 2020
by
Laurent Montel
Browse files
Remove duplicate code
parent
7fc00820
Changes
4
Hide whitespace changes
Inline
Side-by-side
core/autotests/CMakeLists.txt
View file @
e984449a
...
...
@@ -12,6 +12,7 @@ add_library(test_resourceconverter STATIC
loadlistfromfile.cpp
compareexportfile.cpp
compareimportfile.cpp
testexportfile.cpp
)
target_link_libraries
(
test_resourceconverter PUBLIC KF5::ConfigCore pimdataexporterprivate KF5::Archive Qt5::Test
)
...
...
core/autotests/notes/exportnotesjobinterfacetest.cpp
View file @
e984449a
...
...
@@ -20,10 +20,9 @@
#include
"exportnotesjobinterfacetest.h"
#include
"archivestorage.h"
#include
"resourceconvertertest.h"
#include
"
compare
exportfile.h"
#include
"
test
exportfile.h"
#include
<QDebug>
#include
<QTest>
#include
<QSignalSpy>
QTEST_MAIN
(
ExportNotesJobInterfaceTest
)
...
...
@@ -61,34 +60,11 @@ ExportNotesJobInterfaceTest::ExportNotesJobInterfaceTest(QObject *parent)
void
ExportNotesJobInterfaceTest
::
exportNoteConfigTest1
()
{
//Don't use setTestModeEnabled otherwise we can set env
//QStandardPaths::setTestModeEnabled(true);
TestExportFile
*
file
=
new
TestExportFile
(
this
);
const
QByteArray
pathConfig
(
"/export/test1/"
);
qputenv
(
"XDG_DATA_HOME"
,
QByteArray
(
PIMDATAEXPORTER_DIR
)
+
pathConfig
+
"/share"
);
qputenv
(
"XDG_CONFIG_HOME"
,
QByteArray
(
PIMDATAEXPORTER_DIR
)
+
pathConfig
+
"/config"
);
//TODO fix file name.
const
QString
temporaryFile
=
QDir
::
tempPath
()
+
QStringLiteral
(
"/archive.zip"
);
ArchiveStorage
*
archiveStorage
=
new
ArchiveStorage
(
temporaryFile
,
this
);
Q_ASSERT
(
archiveStorage
->
openArchive
(
true
));
Utils
::
addVersion
(
archiveStorage
->
archive
());
//qDebug() << " temporaryFile " << temporaryFile;
Utils
::
storeDataExportInfo
(
archiveStorage
->
archive
());
ExportNotesJobInterfaceTestImpl
*
exportNote
=
new
ExportNotesJobInterfaceTestImpl
(
this
,
{
Utils
::
StoredType
::
Config
},
archiveStorage
,
1
);
QSignalSpy
finish
(
exportNote
,
&
ExportNotesJobInterfaceTestImpl
::
jobFinished
);
QSignalSpy
error
(
exportNote
,
&
ExportNotesJobInterfaceTestImpl
::
error
);
exportNote
->
start
();
QVERIFY
(
finish
.
wait
());
QCOMPARE
(
error
.
count
(),
0
);
file
->
setPathConfig
(
QByteArray
(
PIMDATAEXPORTER_DIR
)
+
pathConfig
);
ExportNotesJobInterfaceTestImpl
*
exportNote
=
new
ExportNotesJobInterfaceTestImpl
(
this
,
{
Utils
::
StoredType
::
Config
},
file
->
archiveStorage
(),
1
);
file
->
setAbstractImportExportJob
(
exportNote
);
file
->
start
();
delete
exportNote
;
delete
archiveStorage
;
CompareExportFile
compareExportFile
;
compareExportFile
.
setTempFilePath
(
temporaryFile
);
compareExportFile
.
setListFilePath
(
QLatin1String
(
QByteArray
(
PIMDATAEXPORTER_DIR
+
pathConfig
)));
compareExportFile
.
compareFiles
();
QVERIFY
(
QFile
(
temporaryFile
).
remove
());
}
core/autotests/testexportfile.cpp
0 → 100644
View file @
e984449a
/*
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
"testexportfile.h"
#include
"archivestorage.h"
#include
"compareexportfile.h"
#include
"abstractimportexportjob.h"
#include
"utils.h"
#include
<QDir>
#include
<QSignalSpy>
#include
<QTest>
TestExportFile
::
TestExportFile
(
QObject
*
parent
)
:
QObject
(
parent
)
{
const
QString
temporaryFile
=
QDir
::
tempPath
()
+
QStringLiteral
(
"/archive.zip"
);
mArchiveStorage
=
new
ArchiveStorage
(
temporaryFile
,
this
);
Q_ASSERT
(
mArchiveStorage
->
openArchive
(
true
));
}
TestExportFile
::~
TestExportFile
()
{
}
QByteArray
TestExportFile
::
pathConfig
()
const
{
return
mPathConfig
;
}
void
TestExportFile
::
setPathConfig
(
const
QByteArray
&
pathConfig
)
{
mPathConfig
=
pathConfig
;
}
AbstractImportExportJob
*
TestExportFile
::
abstractImportExportJob
()
const
{
return
mAbstractImportExportJob
;
}
void
TestExportFile
::
setAbstractImportExportJob
(
AbstractImportExportJob
*
abstractImportExportJob
)
{
mAbstractImportExportJob
=
abstractImportExportJob
;
}
void
TestExportFile
::
start
()
{
//Don't use setTestModeEnabled otherwise we can set env
//QStandardPaths::setTestModeEnabled(true);
qputenv
(
"XDG_DATA_HOME"
,
mPathConfig
+
"/share"
);
qputenv
(
"XDG_CONFIG_HOME"
,
mPathConfig
+
"/config"
);
//TODO fix file name.
const
QString
temporaryFile
=
QDir
::
tempPath
()
+
QStringLiteral
(
"/archive.zip"
);
Utils
::
addVersion
(
mArchiveStorage
->
archive
());
//qDebug() << " temporaryFile " << temporaryFile;
Utils
::
storeDataExportInfo
(
mArchiveStorage
->
archive
());
QSignalSpy
finish
(
mAbstractImportExportJob
,
&
AbstractImportExportJob
::
jobFinished
);
QSignalSpy
error
(
mAbstractImportExportJob
,
&
AbstractImportExportJob
::
error
);
mAbstractImportExportJob
->
start
();
QVERIFY
(
finish
.
wait
());
QCOMPARE
(
error
.
count
(),
0
);
delete
mArchiveStorage
;
mArchiveStorage
=
nullptr
;
CompareExportFile
compareExportFile
;
compareExportFile
.
setTempFilePath
(
temporaryFile
);
compareExportFile
.
setListFilePath
(
QLatin1String
(
mPathConfig
));
compareExportFile
.
compareFiles
();
QVERIFY
(
QFile
(
temporaryFile
).
remove
());
}
ArchiveStorage
*
TestExportFile
::
archiveStorage
()
const
{
return
mArchiveStorage
;
}
core/autotests/testexportfile.h
0 → 100644
View file @
e984449a
/*
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.
*/
#ifndef TESTEXPORTFILE_H
#define TESTEXPORTFILE_H
#include
<QObject>
class
AbstractImportExportJob
;
class
ArchiveStorage
;
class
TestExportFile
:
public
QObject
{
Q_OBJECT
public:
explicit
TestExportFile
(
QObject
*
parent
=
nullptr
);
~
TestExportFile
();
Q_REQUIRED_RESULT
QByteArray
pathConfig
()
const
;
void
setPathConfig
(
const
QByteArray
&
pathConfig
);
AbstractImportExportJob
*
abstractImportExportJob
()
const
;
void
setAbstractImportExportJob
(
AbstractImportExportJob
*
abstractImportExportJob
);
void
start
();
Q_REQUIRED_RESULT
ArchiveStorage
*
archiveStorage
()
const
;
private:
QByteArray
mPathConfig
;
AbstractImportExportJob
*
mAbstractImportExportJob
=
nullptr
;
ArchiveStorage
*
mArchiveStorage
=
nullptr
;
};
#endif // TESTEXPORTFILE_H
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment