more tests for events
This commit is contained in:
parent
55b6962ebc
commit
a5b0ceeee4
@ -35,6 +35,7 @@ class TestEvents: public GuhTestBase
|
||||
|
||||
private slots:
|
||||
void triggerEvent();
|
||||
void triggerStateChangeEvent();
|
||||
};
|
||||
|
||||
void TestEvents::triggerEvent()
|
||||
@ -64,5 +65,33 @@ void TestEvents::triggerEvent()
|
||||
QCOMPARE(event.deviceId(), device->id());
|
||||
}
|
||||
|
||||
void TestEvents::triggerStateChangeEvent()
|
||||
{
|
||||
QList<Device*> devices = GuhCore::instance()->deviceManager()->findConfiguredDevices(mockDeviceClassId);
|
||||
QVERIFY2(devices.count() > 0, "There needs to be at least one configured Mock Device for this test");
|
||||
Device *device = devices.first();
|
||||
|
||||
QSignalSpy spy(GuhCore::instance()->deviceManager(), SIGNAL(eventTriggered(const Event&)));
|
||||
|
||||
// Setup connection to mock client
|
||||
QNetworkAccessManager nam;
|
||||
|
||||
// trigger state changed event in mock device
|
||||
int port = device->paramValue("httpport").toInt();
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(port).arg(mockIntStateId.toString()).arg(11)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
reply->deleteLater();
|
||||
|
||||
// Lets wait for the notification
|
||||
spy.wait();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
// Make sure the event contains all the stuff we expect
|
||||
Event event = spy.at(0).at(0).value<Event>();
|
||||
QCOMPARE(event.eventTypeId().toString(), mockIntStateId.toString());
|
||||
QCOMPARE(event.deviceId(), device->id());
|
||||
QCOMPARE(event.param("value").value().toInt(), 11);
|
||||
}
|
||||
|
||||
#include "testevents.moc"
|
||||
QTEST_MAIN(TestEvents)
|
||||
|
||||
@ -34,8 +34,10 @@ class TestRules: public GuhTestBase
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void addRules_data();
|
||||
void addRules();
|
||||
void addRemoveRules_data();
|
||||
void addRemoveRules();
|
||||
|
||||
void removeInvalidRule();
|
||||
|
||||
void loadStoreConfig();
|
||||
|
||||
@ -48,7 +50,7 @@ private slots:
|
||||
void testStateEvaluator2();
|
||||
};
|
||||
|
||||
void TestRules::addRules_data()
|
||||
void TestRules::addRemoveRules_data()
|
||||
{
|
||||
QVariantMap validActionNoParams;
|
||||
validActionNoParams.insert("actionTypeId", mockActionIdNoParams);
|
||||
@ -114,7 +116,7 @@ void TestRules::addRules_data()
|
||||
|
||||
}
|
||||
|
||||
void TestRules::addRules()
|
||||
void TestRules::addRemoveRules()
|
||||
{
|
||||
QFETCH(QVariantMap, action1);
|
||||
QFETCH(QVariantMap, eventDescriptor);
|
||||
@ -184,6 +186,14 @@ void TestRules::addRules()
|
||||
QVERIFY2(rules.count() == 0, "There should be no rules.");
|
||||
}
|
||||
|
||||
void TestRules::removeInvalidRule()
|
||||
{
|
||||
QVariantMap params;
|
||||
params.insert("ruleId", RuleId::createRuleId());
|
||||
QVariant response = injectAndWait("Rules.RemoveRule", params);
|
||||
verifySuccess(response, false);
|
||||
}
|
||||
|
||||
void TestRules::loadStoreConfig()
|
||||
{
|
||||
QVariantMap eventDescriptor1;
|
||||
|
||||
Reference in New Issue
Block a user