[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 <bvbfan@abv.bg>
This commit is contained in:
Anthony Fieroni 2016-05-19 22:45:29 +03:00
parent 92bad819e7
commit 2275db4b39
3 changed files with 42 additions and 7 deletions

View File

@ -22,12 +22,13 @@
#include <qtest.h>
#include <QDebug>
//#include <QJsonObject>
#include <QtTest/QSignalSpy>
#include <kplugininfo.h>
//#include <kplugintrader.h>
#include <plasma/dataengine.h>
#include <plasma/pluginloader.h>
#include <plasma/dataengineconsumer.h>
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<Plasma::DataEngine> 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"

View File

@ -21,6 +21,7 @@
#define PLUGINTEST_H
#include <QCoreApplication>
#include <plasma/dataengine.h>
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

View File

@ -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"));