add checkNotifications
This commit is contained in:
parent
1c46a99412
commit
e060d27a57
@ -177,6 +177,27 @@ QVariant GuhTestBase::checkNotification(const QSignalSpy &spy, const QString &no
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariantList GuhTestBase::checkNotifications(const QSignalSpy &spy, const QString ¬ification)
|
||||||
|
{
|
||||||
|
qDebug() << "Got" << spy.count() << "notifications while waiting for" << notification;
|
||||||
|
QVariantList notificationList;
|
||||||
|
for (int i = 0; i < spy.count(); i++) {
|
||||||
|
// Make sure the response it a valid JSON string
|
||||||
|
QJsonParseError error;
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(spy.at(i).last().toByteArray(), &error);
|
||||||
|
if (error.error != QJsonParseError::NoError) {
|
||||||
|
qWarning() << "JSON parser error" << error.errorString();
|
||||||
|
return notificationList;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap response = jsonDoc.toVariant().toMap();
|
||||||
|
if (response.value("notification").toString() == notification) {
|
||||||
|
notificationList.append(jsonDoc.toVariant());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return notificationList;
|
||||||
|
}
|
||||||
|
|
||||||
QVariant GuhTestBase::getAndWait(const QNetworkRequest &request, const int &expectedStatus)
|
QVariant GuhTestBase::getAndWait(const QNetworkRequest &request, const int &expectedStatus)
|
||||||
{
|
{
|
||||||
QNetworkAccessManager nam;
|
QNetworkAccessManager nam;
|
||||||
@ -323,6 +344,7 @@ bool GuhTestBase::enableNotifications()
|
|||||||
if (response.toMap().value("params").toMap().value("enabled").toBool() != true) {
|
if (response.toMap().value("params").toMap().value("enabled").toBool() != true) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
qDebug() << "Notifications enabled.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,6 +356,7 @@ bool GuhTestBase::disableNotifications()
|
|||||||
if (response.toMap().value("params").toMap().value("enabled").toBool() != false) {
|
if (response.toMap().value("params").toMap().value("enabled").toBool() != false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
qDebug() << "Notifications disabled.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -72,6 +72,7 @@ protected slots:
|
|||||||
protected:
|
protected:
|
||||||
QVariant injectAndWait(const QString &method, const QVariantMap ¶ms = QVariantMap());
|
QVariant injectAndWait(const QString &method, const QVariantMap ¶ms = QVariantMap());
|
||||||
QVariant checkNotification(const QSignalSpy &spy, const QString ¬ification);
|
QVariant checkNotification(const QSignalSpy &spy, const QString ¬ification);
|
||||||
|
QVariantList checkNotifications(const QSignalSpy &spy, const QString ¬ification);
|
||||||
|
|
||||||
QVariant getAndWait(const QNetworkRequest &request, const int &expectedStatus = 200);
|
QVariant getAndWait(const QNetworkRequest &request, const int &expectedStatus = 200);
|
||||||
QVariant deleteAndWait(const QNetworkRequest &request, const int &expectedStatus = 200);
|
QVariant deleteAndWait(const QNetworkRequest &request, const int &expectedStatus = 200);
|
||||||
|
|||||||
@ -215,15 +215,25 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
|||||||
clientSpy.wait();
|
clientSpy.wait();
|
||||||
|
|
||||||
// Make sure the notification contains all the stuff we expect
|
// Make sure the notification contains all the stuff we expect
|
||||||
QVariant stateChangedVariant = checkNotification(clientSpy, "Devices.StateChanged");
|
QVariantList stateChangedVariants = checkNotifications(clientSpy, "Devices.StateChanged");
|
||||||
QVERIFY2(!stateChangedVariant.isNull(), "Did not get Devices.StateChanged notification.");
|
QVERIFY2(!stateChangedVariants.isEmpty(), "Did not get Devices.StateChanged notification.");
|
||||||
QCOMPARE(stateChangedVariant.toMap().value("params").toMap().value("stateTypeId").toUuid(), stateTypeId);
|
|
||||||
QCOMPARE(stateChangedVariant.toMap().value("params").toMap().value("value").toInt(), newVal);
|
qDebug() << "got" << stateChangedVariants.count() << "Devices.StateChanged notifications";
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
foreach (const QVariant &stateChangedVariant, stateChangedVariants) {
|
||||||
|
if (stateChangedVariant.toMap().value("params").toMap().value("stateTypeId").toUuid() == stateTypeId)
|
||||||
|
{
|
||||||
|
QCOMPARE(stateChangedVariant.toMap().value("params").toMap().value("value").toInt(), newVal);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QCOMPARE(found, true);
|
||||||
|
|
||||||
// Make sure the notification contains all the stuff we expect
|
// Make sure the notification contains all the stuff we expect
|
||||||
QVariant loggEntryAddedVariant = checkNotification(clientSpy, "Logging.LogEntryAdded");
|
QVariant loggEntryAddedVariant = checkNotification(clientSpy, "Logging.LogEntryAdded");
|
||||||
QVERIFY2(!loggEntryAddedVariant.isNull(), "Did not get Logging.LogEntryAdded notification.");
|
QVERIFY2(!loggEntryAddedVariant.isNull(), "Did not get Logging.LogEntryAdded notification.");
|
||||||
QCOMPARE(loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("typeId").toUuid(), stateTypeId);
|
|
||||||
|
|
||||||
// Make sure the notification contains all the stuff we expect
|
// Make sure the notification contains all the stuff we expect
|
||||||
QVariant eventTriggeredVariant = checkNotification(clientSpy, "Events.EventTriggered");
|
QVariant eventTriggeredVariant = checkNotification(clientSpy, "Events.EventTriggered");
|
||||||
|
|||||||
Reference in New Issue
Block a user