From 2275db4b397d66114e05f434d5a90dadc2ec14fb Mon Sep 17 00:00:00 2001 From: Anthony Fieroni Date: Thu, 19 May 2016 22:45:29 +0300 Subject: [PATCH] [dataengine]If the DataEngine constructor is called with an invalid KPluginInfo object, make sure valid is set to false. + test case REVIEW: 127795 Signed-off-by: Anthony Fieroni --- autotests/pluginloadertest.cpp | 33 ++++++++++++++++++++++++++++----- autotests/pluginloadertest.h | 11 +++++++++++ src/plasma/dataengine.cpp | 5 +++-- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/autotests/pluginloadertest.cpp b/autotests/pluginloadertest.cpp index 4f967805b..5b5c76cc0 100644 --- a/autotests/pluginloadertest.cpp +++ b/autotests/pluginloadertest.cpp @@ -22,12 +22,13 @@ #include #include //#include +#include #include //#include -#include #include +#include QTEST_MAIN(PluginTest) @@ -67,12 +68,34 @@ void PluginTest::listContainmentsOfType() } +static const auto source = QStringLiteral("Europe/Sofia"); + +void EngineTest::dataUpdated(const QString &s, const Plasma::DataEngine::Data &data) { + QVERIFY(source == s); + QVERIFY(data["Timezone"] == source); +} + void PluginTest::loadDataEngine() { - Plasma::DataEngine *engine = Plasma::PluginLoader::self()->loadDataEngine(QStringLiteral("time")); - //qDebug() << "Engine loaded successfully" << engine->pluginInfo().name(); - QVERIFY(engine != 0 || buildonly); - + QPointer engine, nullEngine; + { + Plasma::DataEngineConsumer consumer; + engine = consumer.dataEngine(QStringLiteral("time")); + nullEngine = consumer.dataEngine(QStringLiteral("noop")); + QVERIFY(nullEngine && engine); + QVERIFY(!nullEngine->isValid() && engine->isValid()); + { + EngineTest test; + engine->connectSource(source, &test); + QSignalSpy spy(engine, SIGNAL(sourceAdded(QString))); + spy.wait(); + QVERIFY(!engine->isEmpty()); + } + QSignalSpy spy(engine, SIGNAL(sourceRemoved(QString))); + spy.wait(); + QVERIFY(engine->isEmpty()); + } + QVERIFY(!nullEngine.isNull() && engine.isNull()); } #include "moc_pluginloadertest.cpp" diff --git a/autotests/pluginloadertest.h b/autotests/pluginloadertest.h index 61fc96305..02011cdb0 100644 --- a/autotests/pluginloadertest.h +++ b/autotests/pluginloadertest.h @@ -21,6 +21,7 @@ #define PLUGINTEST_H #include +#include class PluginTest : public QObject { @@ -39,4 +40,14 @@ private Q_SLOTS: private: }; +class EngineTest : public QObject +{ + Q_OBJECT +public: + EngineTest() {} + +public Q_SLOTS: + void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data); +}; + #endif diff --git a/src/plasma/dataengine.cpp b/src/plasma/dataengine.cpp index f942926bf..1c3efb656 100644 --- a/src/plasma/dataengine.cpp +++ b/src/plasma/dataengine.cpp @@ -299,9 +299,9 @@ void DataEngine::removeSource(const QString &source) if (it != d->sources.end()) { DataContainer *s = it.value(); s->d->store(); + d->sources.erase(it); s->disconnect(this); s->deleteLater(); - d->sources.erase(it); emit sourceRemoved(source); } } @@ -416,13 +416,14 @@ DataEnginePrivate::DataEnginePrivate(DataEngine *e, const KPluginInfo &info, con checkSourcesTimerId(0), updateTimerId(0), minPollingInterval(-1), - valid(true), + valid(false), script(0), package(0) { updateTimer.start(); if (dataEngineDescription.isValid()) { + valid = true; e->setObjectName(dataEngineDescription.name()); } else { e->setObjectName(QStringLiteral("NullEngine"));