summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2017-06-28 22:08:19 +0200
committerMontel Laurent <[email protected]>2017-06-28 22:08:19 +0200
commit89ff343373e8345bc79625563a9144ea51318cb1 (patch)
tree8d0278dfd391cd1c63119b1504c238e2ba3cac4d
parente567b79d2b7ae3697958c1ee5a158e4610fe7c2c (diff)
load plugin + add test apps
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/kmailtransport/CMakeLists.txt1
-rw-r--r--src/kmailtransport/kmailtransport_private_export.h34
-rw-r--r--src/kmailtransport/plugins/tests/CMakeLists.txt6
-rw-r--r--src/kmailtransport/plugins/tests/transportmanagertest.cpp45
-rw-r--r--src/kmailtransport/plugins/tests/transportmanagertest.h32
-rw-r--r--src/kmailtransport/plugins/transportpluginmanager.cpp38
-rw-r--r--src/kmailtransport/plugins/transportpluginmanager.h3
8 files changed, 136 insertions, 27 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 25d0145..b1df276 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -54,6 +54,10 @@ set_package_properties(Sasl2 PROPERTIES
TYPE OPTIONAL
)
+if(BUILD_TESTING)
+ add_definitions(-DBUILD_TESTING)
+endif(BUILD_TESTING)
+
########### Targets ###########
add_subdirectory(cmake)
add_subdirectory(src)
diff --git a/src/kmailtransport/CMakeLists.txt b/src/kmailtransport/CMakeLists.txt
index afce02d..7ac2e2c 100644
--- a/src/kmailtransport/CMakeLists.txt
+++ b/src/kmailtransport/CMakeLists.txt
@@ -171,6 +171,7 @@ install(FILES
if(BUILD_TESTING)
add_subdirectory(tests)
+ add_subdirectory(plugins/tests)
endif()
add_subdirectory(plugins/smtp)
diff --git a/src/kmailtransport/kmailtransport_private_export.h b/src/kmailtransport/kmailtransport_private_export.h
new file mode 100644
index 0000000..83ea3ab
--- /dev/null
+++ b/src/kmailtransport/kmailtransport_private_export.h
@@ -0,0 +1,34 @@
+/* This file is part of the KDE project
+ Copyright (C) 2007 David Faure <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KMAILTRANSPORTPRIVATE_EXPORT_H
+#define KMAILTRANSPORTPRIVATE_EXPORT_H
+
+#include "mailtransport_export.h"
+
+/* Classes which are exported only for unit tests */
+#ifdef BUILD_TESTING
+# ifndef KMAILTRANSPORT_TESTS_EXPORT
+# define KMAILTRANSPORT_TESTS_EXPORT MAILTRANSPORT_EXPORT
+# endif
+#else /* not compiling tests */
+# define KMAILTRANSPORT_TESTS_EXPORT
+#endif
+
+#endif
diff --git a/src/kmailtransport/plugins/tests/CMakeLists.txt b/src/kmailtransport/plugins/tests/CMakeLists.txt
new file mode 100644
index 0000000..5e05a9f
--- /dev/null
+++ b/src/kmailtransport/plugins/tests/CMakeLists.txt
@@ -0,0 +1,6 @@
+include(ECMMarkAsTest)
+find_package(Qt5Test CONFIG REQUIRED)
+
+add_executable(transportmanagertest transportmanagertest.cpp)
+ecm_mark_as_test(transportmanagertest)
+target_link_libraries(transportmanagertest KF5MailTransport)
diff --git a/src/kmailtransport/plugins/tests/transportmanagertest.cpp b/src/kmailtransport/plugins/tests/transportmanagertest.cpp
new file mode 100644
index 0000000..e82f825
--- /dev/null
+++ b/src/kmailtransport/plugins/tests/transportmanagertest.cpp
@@ -0,0 +1,45 @@
+/*
+ Copyright (c) 2017 Laurent Montel <[email protected]>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ This library 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 Library General Public
+ License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#include "transportmanagertest.h"
+#include "kmailtransport/plugins/transportpluginmanager.h"
+#include <QCoreApplication>
+#include <MailTransport/TransportAbstractPlugin>
+#include <QDebug>
+
+TransportManagerTest::TransportManagerTest(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ const QVector<MailTransport::TransportAbstractPlugin *> lst = MailTransport::TransportPluginManager::self()->pluginsList();
+ for (MailTransport::TransportAbstractPlugin *plugin : lst) {
+ const QVector<MailTransport::TransportAbstractPluginInfo> lstPluginInfo = plugin->names();
+ for (const MailTransport::TransportAbstractPluginInfo &info : lstPluginInfo) {
+ qDebug() << "Plugin name " << info.name;
+ }
+ }
+ return 0;
+}
+
diff --git a/src/kmailtransport/plugins/tests/transportmanagertest.h b/src/kmailtransport/plugins/tests/transportmanagertest.h
new file mode 100644
index 0000000..9a75c10
--- /dev/null
+++ b/src/kmailtransport/plugins/tests/transportmanagertest.h
@@ -0,0 +1,32 @@
+/*
+ Copyright (c) 2017 Laurent Montel <[email protected]>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ This library 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 Library General Public
+ License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+*/
+
+#ifndef TRANSPORTMANAGERTEST_H
+#define TRANSPORTMANAGERTEST_H
+
+#include <QObject>
+
+class TransportManagerTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit TransportManagerTest(QObject *parent = nullptr);
+};
+
+#endif // TRANSPORTMANAGERTEST_H
diff --git a/src/kmailtransport/plugins/transportpluginmanager.cpp b/src/kmailtransport/plugins/transportpluginmanager.cpp
index fc5574b..8035780 100644
--- a/src/kmailtransport/plugins/transportpluginmanager.cpp
+++ b/src/kmailtransport/plugins/transportpluginmanager.cpp
@@ -18,12 +18,15 @@
*/
#include "transportpluginmanager.h"
+#include "mailtransport_debug.h"
#include <kpluginmetadata.h>
#include <KPluginLoader>
#include <KPluginFactory>
#include <MailTransport/TransportAbstractPlugin>
+#include <QFileInfo>
+
using namespace MailTransport;
class TransportPluginManagerInstancePrivate
@@ -48,8 +51,7 @@ class MailTransportPluginInfo
{
public:
MailTransportPluginInfo()
- : plugin(nullptr),
- isEnabled(true)
+ : plugin(nullptr)
{
}
@@ -57,7 +59,6 @@ public:
QString metaDataFileNameBaseName;
QString metaDataFileName;
MailTransport::TransportAbstractPlugin *plugin;
- bool isEnabled;
};
namespace
@@ -89,28 +90,19 @@ bool TransportPluginManagerPrivate::initializePlugins()
if (!mPluginList.isEmpty()) {
return true;
}
-/*
- static const QString s_serviceTypeName = serviceTypeName;
- const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(pluginName, [](const KPluginMetaData & md) {
- return md.serviceTypes().contains(s_serviceTypeName);
+ const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("mailtransport"), [](const KPluginMetaData &md) {
+ return md.serviceTypes().contains(QStringLiteral("MailTransport/Plugin"));
});
- const QPair<QStringList, QStringList> pair = PimCommon::PluginUtil::loadPluginSetting(configGroupName(), configPrefixSettingKey());
QVectorIterator<KPluginMetaData> i(plugins);
i.toBack();
QSet<QString> unique;
while (i.hasPrevious()) {
- GenericPluginInfo info;
+ MailTransportPluginInfo info;
const KPluginMetaData data = i.previous();
- //1) get plugin data => name/description etc.
- info.pluginData = PimCommon::PluginUtil::createPluginMetaData(data);
- //2) look at if plugin is activated
- const bool isPluginActivated = PimCommon::PluginUtil::isPluginActivated(pair.first, pair.second, info.pluginData.mEnableByDefault, info.pluginData.mIdentifier);
- info.isEnabled = isPluginActivated;
info.metaDataFileNameBaseName = QFileInfo(data.fileName()).baseName();
info.metaDataFileName = data.fileName();
-
if (pluginVersion() == data.version()) {
// only load plugins once, even if found multiple times!
if (unique.contains(info.metaDataFileNameBaseName)) {
@@ -120,35 +112,29 @@ bool TransportPluginManagerPrivate::initializePlugins()
mPluginList.push_back(info);
unique.insert(info.metaDataFileNameBaseName);
} else {
- qCWarning(PIMCOMMON_LOG) << "Plugin " << data.name() << " doesn't have correction plugin version. It will not be loaded.";
+ qCWarning(MAILTRANSPORT_LOG) << "Plugin " << data.name() << " doesn't have correction plugin version. It will not be loaded.";
}
}
- QVector<GenericPluginInfo>::iterator end(mPluginList.end());
- for (QVector<GenericPluginInfo>::iterator it = mPluginList.begin(); it != end; ++it) {
+ const QVector<MailTransportPluginInfo>::iterator end(mPluginList.end());
+ for (QVector<MailTransportPluginInfo>::iterator it = mPluginList.begin(); it != end; ++it) {
loadPlugin(&(*it));
}
- */
return true;
}
void TransportPluginManagerPrivate::loadPlugin(MailTransportPluginInfo *item)
{
- /*
KPluginLoader pluginLoader(item->metaDataFileName);
if (pluginLoader.factory()) {
- item->plugin = pluginLoader.factory()->create<PluginEditorInit>(q, QVariantList() << item->metaDataFileNameBaseName);
- item->plugin->setIsEnabled(item->isEnabled);
- item->pluginData.mHasConfigureDialog = item->plugin->hasConfigureDialog();
- mPluginDataList.append(item->pluginData);
+ item->plugin = pluginLoader.factory()->create<MailTransport::TransportAbstractPlugin>(q, QVariantList() << item->metaDataFileNameBaseName);
}
- */
}
QVector<MailTransport::TransportAbstractPlugin *> TransportPluginManagerPrivate::pluginsList() const
{
QVector<MailTransport::TransportAbstractPlugin *> lst;
- QVector<MailTransportPluginInfo>::ConstIterator end(mPluginList.constEnd());
+ const QVector<MailTransportPluginInfo>::ConstIterator end(mPluginList.constEnd());
for (QVector<MailTransportPluginInfo>::ConstIterator it = mPluginList.constBegin(); it != end; ++it) {
if (auto plugin = (*it).plugin) {
lst << plugin;
diff --git a/src/kmailtransport/plugins/transportpluginmanager.h b/src/kmailtransport/plugins/transportpluginmanager.h
index 594decf..5064459 100644
--- a/src/kmailtransport/plugins/transportpluginmanager.h
+++ b/src/kmailtransport/plugins/transportpluginmanager.h
@@ -21,10 +21,11 @@
#define TRANSPORTPLUGINMANAGER_H
#include <QObject>
+#include "kmailtransport_private_export.h"
namespace MailTransport {
class TransportAbstractPlugin;
class TransportPluginManagerPrivate;
-class TransportPluginManager : public QObject
+class KMAILTRANSPORT_TESTS_EXPORT TransportPluginManager : public QObject
{
Q_OBJECT
public: