Commit 4b769657 authored by Laurent Montel's avatar Laurent Montel 😁

Move this code here. I will create a plugins

parent 80899619
......@@ -2,5 +2,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kmail_plugins\")
add_subdirectory(antispamplugin)
add_subdirectory(antivirusplugin)
add_subdirectory(common/avscripts)
#Laurent disable for the moment
#add_subdirectory(mailmergeplugin)
install(FILES common/kmail.antispamrc common/kmail.antivirusrc DESTINATION ${KDE_INSTALL_CONFDIR})
install(FILES common/pics/kmwizard.png common/pics/kmwizard.svg DESTINATION ${KDE_INSTALL_DATADIR}/kmail2/pics)
# convenience macro to add qtest unit tests
macro(add_kmail_unittest _source _additionalsource)
set(_test ${_source} ${_additionalsource})
get_filename_component(_name ${_source} NAME_WE)
add_executable( ${_name} ${_test} )
add_test( ${_name} ${_name} )
ecm_mark_as_test(kmail-${_name})
target_link_libraries( ${_name}
KF5::PimCommon
Qt5::Test
KF5::KIOCore
KF5::KIOWidgets
KF5::I18n
)
endmacro ()
add_kmail_unittest( mailmergewidgettest.cpp "../widgets/csvwidget.cpp;../widgets/addressbookwidget.cpp;../widgets/mailmergewidget.cpp;../widgets/attachmentlistwidget.cpp;../widgets/selectattachmentdialog.cpp")
add_kmail_unittest(addressbookwidgettest.cpp "../widgets/csvwidget.cpp")
add_kmail_unittest(csvwidgettest.cpp "../widgets/csvwidget.cpp")
add_kmail_unittest(mailmergedialogtest.cpp "../mailmergedialog.cpp;../widgets/attachmentlistwidget.cpp;../widgets/selectattachmentdialog.cpp;../widgets/mailmergewidget.cpp;../widgets/csvwidget.cpp;../widgets/addressbookwidget.cpp;../widgets/selectattachmentdialog.cpp" "KF5::PimCommon")
add_kmail_unittest(mailmergejobtest.cpp "../job/mailmergejob.cpp" "")
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "addressbookwidgettest.h"
#include <qtest.h>
AddressBookWidgetTest::AddressBookWidgetTest(QObject *parent)
: QObject(parent)
{
}
AddressBookWidgetTest::~AddressBookWidgetTest()
{
}
QTEST_MAIN(AddressBookWidgetTest)
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ADDRESSBOOKWIDGETTEST_H
#define ADDRESSBOOKWIDGETTEST_H
#include <QObject>
class AddressBookWidgetTest : public QObject
{
Q_OBJECT
public:
explicit AddressBookWidgetTest(QObject *parent = Q_NULLPTR);
~AddressBookWidgetTest();
};
#endif // ADDRESSBOOKWIDGETTEST_H
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "csvwidgettest.h"
#include "../widgets/csvwidget.h"
#include <KUrlRequester>
#include <QLabel>
#include <qtest.h>
CsvWidgetTest::CsvWidgetTest(QObject *parent)
: QObject(parent)
{
}
CsvWidgetTest::~CsvWidgetTest()
{
}
void CsvWidgetTest::shouldHaveDefaultValue()
{
MailMerge::CsvWidget w;
QLabel *lab = w.findChild<QLabel *>(QStringLiteral("label"));
QVERIFY(lab);
KUrlRequester *urlrequester = w.findChild<KUrlRequester *>(QStringLiteral("cvsurlrequester"));
QVERIFY(urlrequester);
QVERIFY(urlrequester->url().isEmpty());
}
void CsvWidgetTest::shouldChangePath()
{
MailMerge::CsvWidget w;
KUrlRequester *urlrequester = w.findChild<KUrlRequester *>(QStringLiteral("cvsurlrequester"));
QVERIFY(urlrequester->url().isEmpty());
QUrl url(QStringLiteral("file:///tmp/foo.txt"));
urlrequester->setUrl(url);
QCOMPARE(urlrequester->url(), url);
}
QTEST_MAIN(CsvWidgetTest)
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CSVWIDGETTEST_H
#define CSVWIDGETTEST_H
#include <QObject>
class CsvWidgetTest : public QObject
{
Q_OBJECT
public:
explicit CsvWidgetTest(QObject *parent = Q_NULLPTR);
~CsvWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldChangePath();
};
#endif // CSVWIDGETTEST_H
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mailmergedialogtest.h"
#include "../mailmergedialog.h"
#include "../widgets/mailmergewidget.h"
#include <QDialogButtonBox>
#include <qtest.h>
MailMergeDialogTest::MailMergeDialogTest(QObject *parent) : QObject(parent)
{
}
MailMergeDialogTest::~MailMergeDialogTest()
{
}
void MailMergeDialogTest::shouldHaveDefaultValue()
{
MailMerge::MailMergeDialog dlg;
QDialogButtonBox *buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
QVERIFY(buttonBox);
MailMerge::MailMergeWidget *mailMergeWidget = dlg.findChild<MailMerge::MailMergeWidget *>(QStringLiteral("mailmergewidget"));
QVERIFY(mailMergeWidget);
}
QTEST_MAIN(MailMergeDialogTest)
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MAILMERGEDIALOGTEST_H
#define MAILMERGEDIALOGTEST_H
#include <QObject>
class MailMergeDialogTest : public QObject
{
Q_OBJECT
public:
explicit MailMergeDialogTest(QObject *parent = Q_NULLPTR);
~MailMergeDialogTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // MAILMERGEDIALOGTEST_H
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mailmergejobtest.h"
#include <qtest.h>
MailMergeJobTest::MailMergeJobTest(QObject *parent)
: QObject(parent)
{
}
MailMergeJobTest::~MailMergeJobTest()
{
}
QTEST_MAIN(MailMergeJobTest)
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MAILMERGEJOBTEST_H
#define MAILMERGEJOBTEST_H
#include <QObject>
class MailMergeJobTest : public QObject
{
Q_OBJECT
public:
explicit MailMergeJobTest(QObject *parent = Q_NULLPTR);
~MailMergeJobTest();
};
#endif // MAILMERGEJOBTEST_H
/*
Copyright (c) 2014-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mailmergewidgettest.h"
#include "../widgets/mailmergewidget.h"
#include "PimCommon/SimpleStringlistEditor"
#include <qtest.h>
#include <KComboBox>
#include <QStackedWidget>
#include <QSignalSpy>
using namespace MailMerge;
Q_DECLARE_METATYPE(MailMerge::MailMergeWidget::SourceType)
MailMergeWidgetTest::MailMergeWidgetTest()
{
qRegisterMetaType<MailMergeWidget::SourceType>();
}
void MailMergeWidgetTest::shouldHaveDefaultValueOnCreation()
{
MailMergeWidget mailmerge;
KComboBox *source = mailmerge.findChild<KComboBox *>(QStringLiteral("source"));
QVERIFY(source);
QCOMPARE(source->currentIndex(), 0);
QStackedWidget *stackedwidget = mailmerge.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
QVERIFY(stackedwidget);
QCOMPARE(stackedwidget->count(), 2);
QCOMPARE(stackedwidget->currentIndex(), 0);
for (int i = 0; i < stackedwidget->count(); ++i) {
const QString objectName = stackedwidget->widget(i)->objectName();
bool hasName = (objectName == QLatin1String("addressbookwidget") ||
objectName == QLatin1String("csvwidget"));
QVERIFY(hasName);
}
PimCommon::SimpleStringListEditor *listEditor = mailmerge.findChild<PimCommon::SimpleStringListEditor *>(QStringLiteral("attachment-list"));
QVERIFY(listEditor);
QCOMPARE(listEditor->stringList().count(), 0);
}
void MailMergeWidgetTest::shouldEmitSourceModeChanged()
{
MailMergeWidget mailmerge;
KComboBox *source = mailmerge.findChild<KComboBox *>(QStringLiteral("source"));
QCOMPARE(source->currentIndex(), 0);
QSignalSpy spy(&mailmerge, SIGNAL(sourceModeChanged(MailMerge::MailMergeWidget::SourceType)));
source->setCurrentIndex(1);
QCOMPARE(spy.count(), 1);
}
void MailMergeWidgetTest::shouldDontEmitSourceModeChangedWhenIndexIsInvalid()
{
MailMergeWidget mailmerge;
KComboBox *source = mailmerge.findChild<KComboBox *>(QStringLiteral("source"));
QCOMPARE(source->currentIndex(), 0);
QSignalSpy spy(&mailmerge, SIGNAL(sourceModeChanged(MailMerge::MailMergeWidget::SourceType)));
source->setCurrentIndex(-1);
QCOMPARE(spy.count(), 0);
}
void MailMergeWidgetTest::shouldChangeStackedWidgetIndexWhenChangeComboboxIndex()
{
MailMergeWidget mailmerge;
KComboBox *source = mailmerge.findChild<KComboBox *>(QStringLiteral("source"));
QCOMPARE(source->currentIndex(), 0);
QStackedWidget *stackedwidget = mailmerge.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
QCOMPARE(stackedwidget->currentIndex(), 0);
source->setCurrentIndex(0);
QCOMPARE(stackedwidget->currentIndex(), 0);
source->setCurrentIndex(1);
QCOMPARE(stackedwidget->currentIndex(), 1);
}
QTEST_MAIN(MailMergeWidgetTest)
/*
Copyright (c) 2014-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MAILMERGEWIDGETTEST_H
#define MAILMERGEWIDGETTEST_H
#include <QObject>
class MailMergeWidgetTest : public QObject
{
Q_OBJECT
public:
MailMergeWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValueOnCreation();
void shouldEmitSourceModeChanged();
void shouldDontEmitSourceModeChangedWhenIndexIsInvalid();
void shouldChangeStackedWidgetIndexWhenChangeComboboxIndex();
};
#endif // MAILMERGEWIDGETTEST_H
/*
Copyright (c) 2015 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "selectattachmentdialogtest.h"
#include "../widgets/selectattachmentdialog.h"
#include <KUrlRequester>
#include <QLabel>
#include <qtest.h>
SelectAttachmentDialogTest::SelectAttachmentDialogTest(QObject *parent)
: QObject(parent)
{
}
SelectAttachmentDialogTest::~SelectAttachmentDialogTest()
{
}
void SelectAttachmentDialogTest::shouldHaveDefaultValue()
{
MailMerge::SelectAttachmentDialog dlg;
QLabel *lab = dlg.findChild<QLabel *>(QStringLiteral("selectattachment_label"));
QVERIFY(lab);
KUrlRequester *urlRequester = dlg.findChild<KUrlRequester *>(QStringLiteral("urlrequester"));
QVERIFY(urlRequester);
}
QTEST_MAIN(SelectAttachmentDialogTest)
/*
Copyright (c) 2015 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef SELECTATTACHMENTDIALOGTEST_H
#define SELECTATTACHMENTDIALOGTEST_H
#include <QObject>
class SelectAttachmentDialogTest : public QObject
{
Q_OBJECT
public:
explicit SelectAttachmentDialogTest(QObject *parent = Q_NULLPTR);
~SelectAttachmentDialogTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // SELECTATTACHMENTDIALOGTEST_H
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mailmergejob.h"
using namespace MailMerge;
MailMergeJob::MailMergeJob(QObject *parent)
: QObject(parent)
{
}
MailMergeJob::~MailMergeJob()
{
}
void MailMergeJob::start()
{
}
/*
Copyright (c) 2015-2016 Montel Laurent <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, version 2, as
published by the Free Software Foundation.
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