From 85f6b441c905fe61c20da0291defe4f6e12095c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 8 Jul 2015 13:39:41 +0200 Subject: [PATCH] fix tests --- tests/auto/jsonrpc/testjsonrpc.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tests/auto/jsonrpc/testjsonrpc.cpp b/tests/auto/jsonrpc/testjsonrpc.cpp index 5c11afc8..c023218c 100644 --- a/tests/auto/jsonrpc/testjsonrpc.cpp +++ b/tests/auto/jsonrpc/testjsonrpc.cpp @@ -211,26 +211,21 @@ void TestJSONRPC::stateChangeEmitsNotifications() QNetworkReply *reply = nam.get(request); reply->deleteLater(); - // Lets wait for the notification - clientSpy.wait(); - QCOMPARE(clientSpy.count(), 3); // statechangeevent, state change, log entry added + clientSpy.wait(500); // Make sure the notification contains all the stuff we expect - QJsonDocument jsonDoc = QJsonDocument::fromJson(clientSpy.at(0).at(1).toByteArray()); - QCOMPARE(jsonDoc.toVariant().toMap().value("notification").toString(), QString("Devices.StateChanged")); - QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("stateTypeId").toUuid(), stateTypeId); - QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("value").toInt(), newVal); + QVariant stateChangedVariant = checkNotification(clientSpy, "Devices.StateChanged"); + QCOMPARE(stateChangedVariant.toMap().value("params").toMap().value("stateTypeId").toUuid(), stateTypeId); + QCOMPARE(stateChangedVariant.toMap().value("params").toMap().value("value").toInt(), newVal); // Make sure the notification contains all the stuff we expect - jsonDoc = QJsonDocument::fromJson(clientSpy.at(1).at(1).toByteArray()); - QCOMPARE(jsonDoc.toVariant().toMap().value("notification").toString(), QString("Logging.LogEntryAdded")); - QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("logEntry").toMap().value("typeId").toUuid(), stateTypeId); + QVariant loggEntryAddedVariant = checkNotification(clientSpy, "Logging.LogEntryAdded"); + QCOMPARE(loggEntryAddedVariant.toMap().value("params").toMap().value("logEntry").toMap().value("typeId").toUuid(), stateTypeId); // Make sure the notification contains all the stuff we expect - jsonDoc = QJsonDocument::fromJson(clientSpy.at(2).at(1).toByteArray()); - QCOMPARE(jsonDoc.toVariant().toMap().value("notification").toString(), QString("Events.EventTriggered")); - QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("event").toMap().value("eventTypeId").toUuid(), stateTypeId); - QCOMPARE(jsonDoc.toVariant().toMap().value("params").toMap().value("event").toMap().value("params").toList().first().toMap().value("value").toInt(), newVal); + QVariant eventTriggeredVariant = checkNotification(clientSpy, "Events.EventTriggered"); + QCOMPARE(eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("eventTypeId").toUuid(), stateTypeId); + QCOMPARE(eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("params").toList().first().toMap().value("value").toInt(), newVal); // Now turn off notifications QCOMPARE(disableNotifications(), true);