Add tests for the scriptengine
This commit is contained in:
parent
dd70129a4d
commit
24cecf9d47
1
debian/control
vendored
1
debian/control
vendored
@ -61,6 +61,7 @@ Depends: libqt5network5,
|
|||||||
tar,
|
tar,
|
||||||
iputils-tracepath,
|
iputils-tracepath,
|
||||||
iputils-ping,
|
iputils-ping,
|
||||||
|
qml-module-qtquick2,
|
||||||
dnsutils,
|
dnsutils,
|
||||||
nymea-translations,
|
nymea-translations,
|
||||||
libnymea1 (= ${binary:Version}),
|
libnymea1 (= ${binary:Version}),
|
||||||
|
|||||||
@ -607,6 +607,12 @@ RuleEngine *NymeaCore::ruleEngine() const
|
|||||||
return m_ruleEngine;
|
return m_ruleEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Returns a pointer to the \l{ScriptEngine} instance owned by NymeaCore.*/
|
||||||
|
ScriptEngine *NymeaCore::scriptEngine() const
|
||||||
|
{
|
||||||
|
return m_scriptEngine;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Returns a pointer to the \l{TimeManager} instance owned by NymeaCore.*/
|
/*! Returns a pointer to the \l{TimeManager} instance owned by NymeaCore.*/
|
||||||
TimeManager *NymeaCore::timeManager() const
|
TimeManager *NymeaCore::timeManager() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -86,6 +86,7 @@ public:
|
|||||||
JsonRPCServerImplementation *jsonRPCServer() const;
|
JsonRPCServerImplementation *jsonRPCServer() const;
|
||||||
DeviceManager *deviceManager() const;
|
DeviceManager *deviceManager() const;
|
||||||
RuleEngine *ruleEngine() const;
|
RuleEngine *ruleEngine() const;
|
||||||
|
ScriptEngine *scriptEngine() const;
|
||||||
TimeManager *timeManager() const;
|
TimeManager *timeManager() const;
|
||||||
ServerManager *serverManager() const;
|
ServerManager *serverManager() const;
|
||||||
BluetoothServer *bluetoothServer() const;
|
BluetoothServer *bluetoothServer() const;
|
||||||
|
|||||||
@ -91,8 +91,10 @@ bool ScriptAlarm::active() const
|
|||||||
void ScriptAlarm::timerEvent(QTimerEvent *event)
|
void ScriptAlarm::timerEvent(QTimerEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
QTime now = QTime::currentTime();
|
QTime now = QTime::currentTime();
|
||||||
|
|
||||||
|
|
||||||
updateActive();
|
updateActive();
|
||||||
|
|
||||||
if (!m_weekDays.testFlag(today())) {
|
if (!m_weekDays.testFlag(today())) {
|
||||||
|
|||||||
@ -371,8 +371,6 @@ bool ScriptEngine::loadScript(Script *script)
|
|||||||
|
|
||||||
QString name = jsonDoc.toVariant().toMap().value("name").toString();
|
QString name = jsonDoc.toVariant().toMap().value("name").toString();
|
||||||
|
|
||||||
qCWarning(dcScriptEngine()) << "Loading script";
|
|
||||||
|
|
||||||
script->errors.clear();
|
script->errors.clear();
|
||||||
|
|
||||||
script->component = new QQmlComponent(m_engine, QUrl::fromLocalFile(fileName), this);
|
script->component = new QQmlComponent(m_engine, QUrl::fromLocalFile(fileName), this);
|
||||||
|
|||||||
@ -20,4 +20,5 @@ SUBDIRS = versioning \
|
|||||||
usermanager \
|
usermanager \
|
||||||
mqttbroker \
|
mqttbroker \
|
||||||
tags \
|
tags \
|
||||||
|
scripts \
|
||||||
|
|
||||||
|
|||||||
26
tests/auto/scripts/testhelper.cpp
Normal file
26
tests/auto/scripts/testhelper.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "testhelper.h"
|
||||||
|
|
||||||
|
TestHelper* TestHelper::s_instance = nullptr;
|
||||||
|
|
||||||
|
TestHelper *TestHelper::instance()
|
||||||
|
{
|
||||||
|
if (!s_instance) {
|
||||||
|
s_instance = new TestHelper();
|
||||||
|
}
|
||||||
|
return s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestHelper::logEvent(const QString &deviceId, const QString &eventId, const QVariantMap ¶ms)
|
||||||
|
{
|
||||||
|
emit eventLogged(DeviceId(deviceId), eventId, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestHelper::logStateChange(const QString &deviceId, const QString &stateId, const QVariant &value)
|
||||||
|
{
|
||||||
|
emit stateChangeLogged(DeviceId(deviceId), stateId, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
TestHelper::TestHelper(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
28
tests/auto/scripts/testhelper.h
Normal file
28
tests/auto/scripts/testhelper.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef TESTHELPER_H
|
||||||
|
#define TESTHELPER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "typeutils.h"
|
||||||
|
|
||||||
|
class TestHelper : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
static TestHelper* instance();
|
||||||
|
|
||||||
|
Q_INVOKABLE void logEvent(const QString &deviceId, const QString &eventId, const QVariantMap ¶ms);
|
||||||
|
Q_INVOKABLE void logStateChange(const QString &deviceId, const QString &stateId, const QVariant &value);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void setState(const QVariant &value);
|
||||||
|
void executeAction(const QVariantMap ¶ms);
|
||||||
|
|
||||||
|
void eventLogged(const DeviceId &deviceId, const QString &eventId, const QVariantMap ¶ms);
|
||||||
|
void stateChangeLogged(const DeviceId &deviceId, const QString stateId, const QVariant &value);
|
||||||
|
private:
|
||||||
|
explicit TestHelper(QObject *parent = nullptr);
|
||||||
|
static TestHelper* s_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TESTHELPER_H
|
||||||
Reference in New Issue
Block a user