From 399f406d103af3dc03476466cc2e1521d6e00b86 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Mon, 27 Jul 2020 14:36:44 +0200 Subject: [PATCH] fixes --- .../integrations/thingmanagerimplementation.cpp | 6 +++--- libnymea/types/statedescriptor.cpp | 6 +++--- plugins/mock/integrationpluginmock.json | 2 +- tests/auto/integrations/testintegrations.cpp | 4 ++-- tests/auto/rules/testrules.cpp | 13 +++++++------ tests/testlib/nymeatestbase.h | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libnymea-core/integrations/thingmanagerimplementation.cpp b/libnymea-core/integrations/thingmanagerimplementation.cpp index 2de8e413..3c5ca71d 100644 --- a/libnymea-core/integrations/thingmanagerimplementation.cpp +++ b/libnymea-core/integrations/thingmanagerimplementation.cpp @@ -1697,19 +1697,19 @@ void ThingManagerImplementation::onAutoThingDisappeared(const ThingId &thingId) Thing *thing = m_configuredThings.value(thingId); if (!thing) { - qWarning(dcThingManager) << "Received an autoThingDisappeared signal but this thing is unknown:" << thingId; + qCWarning(dcThingManager) << "Received an autoThingDisappeared signal but this thing is unknown:" << thingId; return; } ThingClass thingClass = m_supportedThings.value(thing->thingClassId()); if (thingClass.pluginId() != plugin->pluginId()) { - qWarning(dcThingManager) << "Received a autoThingDisappeared signal but emitting plugin does not own the thing"; + qCWarning(dcThingManager) << "Received a autoThingDisappeared signal but emitting plugin does not own the thing"; return; } if (!thing->autoCreated()) { - qWarning(dcThingManager) << "Received an autoThingDisappeared signal but thing creationMethod is not CreateMothodAuto"; + qCWarning(dcThingManager) << "Received an autoThingDisappeared signal but thing creationMethod is not CreateMothodAuto"; return; } diff --git a/libnymea/types/statedescriptor.cpp b/libnymea/types/statedescriptor.cpp index 22e0de29..2dc1e84b 100644 --- a/libnymea/types/statedescriptor.cpp +++ b/libnymea/types/statedescriptor.cpp @@ -171,11 +171,11 @@ bool StateDescriptor::operator ==(const State &state) const if ((m_stateTypeId != state.stateTypeId()) || (m_thingId != state.thingId())) { return false; } - if (!m_stateValue.canConvert(state.value().type())) { + QVariant convertedValue = m_stateValue; + bool res = convertedValue.convert(state.value().type()); + if (!res) { return false; } - QVariant convertedValue = m_stateValue; - convertedValue.convert(state.value().type()); switch (m_operatorType) { case Types::ValueOperatorEquals: return convertedValue == state.value(); diff --git a/plugins/mock/integrationpluginmock.json b/plugins/mock/integrationpluginmock.json index 35d4fdd6..14953bec 100644 --- a/plugins/mock/integrationpluginmock.json +++ b/plugins/mock/integrationpluginmock.json @@ -98,7 +98,7 @@ "name": "double", "displayName": "Dummy double state", "displayNameEvent": "Dummy double state changed", - "type": "int", + "type": "double", "minValue": 0, "maxValue": 100, "defaultValue": 2.7 diff --git a/tests/auto/integrations/testintegrations.cpp b/tests/auto/integrations/testintegrations.cpp index 1eced86d..b3c6e373 100644 --- a/tests/auto/integrations/testintegrations.cpp +++ b/tests/auto/integrations/testintegrations.cpp @@ -382,10 +382,10 @@ void TestIntegrations::addThing_data() QTest::newRow("User, JustAdd, wrong param") << mockThingClassId << invalidThingParams << true << Thing::ThingErrorInvalidParameter; thingParams.clear(); thingParams << httpportParam << fakeparam; - QTest::newRow("USer, JustAdd, additional invalid param") << mockThingClassId << thingParams << false << Thing::ThingErrorNoError; + QTest::newRow("USer, JustAdd, additional invalid param") << mockThingClassId << thingParams << false << Thing::ThingErrorInvalidParameter; thingParams.clear(); thingParams << httpportParam << fakeparam2; - QTest::newRow("USer, JustAdd, additional param, valid but unused") << mockThingClassId << thingParams << true << Thing::ThingErrorNoError; + QTest::newRow("USer, JustAdd, duplicate param") << mockThingClassId << thingParams << true << Thing::ThingErrorInvalidParameter; } diff --git a/tests/auto/rules/testrules.cpp b/tests/auto/rules/testrules.cpp index 0f5c986a..df196e67 100644 --- a/tests/auto/rules/testrules.cpp +++ b/tests/auto/rules/testrules.cpp @@ -265,13 +265,14 @@ void TestRules::setWritableStateValue(const ThingId &thingId, const StateTypeId QVariantList stateChangedVariants = checkNotifications(stateSpy, "Integrations.StateChanged"); QVERIFY2(stateChangedVariants.count() == 1, "Did not get Integrations.StateChanged notification."); + qCDebug(dcTests()) << "Notification content:" << qUtf8Printable(QJsonDocument::fromVariant(stateChangedVariants).toJson()); QVariantMap notification = stateChangedVariants.first().toMap().value("params").toMap(); QVERIFY2(notification.contains("thingId"), "Integrations.StateChanged notification does not contain thingId"); QVERIFY2(ThingId(notification.value("thingId").toString()) == thingId, "Integrations.StateChanged notification does not contain the correct thingId"); QVERIFY2(notification.contains("stateTypeId"), "Integrations.StateChanged notification does not contain stateTypeId"); QVERIFY2(StateTypeId(notification.value("stateTypeId").toString()) == stateTypeId, "Integrations.StateChanged notification does not contain the correct stateTypeId"); QVERIFY2(notification.contains("value"), "Integrations.StateChanged notification does not contain new state value"); - QVERIFY2(notification.value("value") == QVariant(value), "Integrations.StateChanged notification does not contain the new value"); + QVERIFY2(notification.value("value") == QVariant(value), QString("Integrations.StateChanged notification does not contain the new value. Got: %1, Expected: %2").arg(notification.value("value").toString()).arg(QVariant(value).toString()).toUtf8()); } } @@ -1990,11 +1991,11 @@ void TestRules::testChildEvaluator_data() QTest::addColumn("trigger"); QTest::addColumn("active"); - QTest::newRow("Unchanged | 2 | 2.5 | String value 1 | #FF0000") << testThingId << ruleMap << 2 << 2.5 << "String value 1" << "#FF0000" << false << false; - QTest::newRow("Unchanged | 60 | 2.5 | String value 2 | #FF0000") << testThingId << ruleMap << 60 << 2.5 << "String value 2" << "#FF0000" << false << false; - QTest::newRow("Unchanged | 60 | 20.5 | String value 2 | #FF0000") << testThingId << ruleMap << 60 << 20.5 << "String value 2" << "#FF0000" << false << false; - QTest::newRow("Active | 60 | 20.5 | String value 2 | #00FF00") << testThingId << ruleMap << 60 << 20.5 << "String value 2" << "#00FF00" << true << true; - QTest::newRow("Active | 60 | 20.5 | String value 2 | #00FF00") << testThingId << ruleMap << 60 << 20.5 << "String value 2" << "#00FF00" << true << true; + QTest::newRow("Unchanged | 2 | 2.5 | String value 1 | #FF0000") << testThingId << ruleMap << 2 << 2.5 << "String value 1" << "#ff0000" << false << false; + QTest::newRow("Unchanged | 60 | 2.5 | String value 2 | #FF0000") << testThingId << ruleMap << 60 << 2.5 << "String value 2" << "#ff0000" << false << false; + QTest::newRow("Unchanged | 60 | 20.5 | String value 2 | #FF0000") << testThingId << ruleMap << 60 << 20.5 << "String value 2" << "#ff0000" << false << false; + QTest::newRow("Active | 60 | 20.5 | String value 2 | #00FF00") << testThingId << ruleMap << 60 << 20.5 << "String value 2" << "#00ff00" << true << true; + QTest::newRow("Active | 60 | 20.5 | String value 2 | #00FF00") << testThingId << ruleMap << 60 << 20.5 << "String value 2" << "#00ff00" << true << true; } void TestRules::testChildEvaluator() diff --git a/tests/testlib/nymeatestbase.h b/tests/testlib/nymeatestbase.h index ef98d6d1..dc84f738 100644 --- a/tests/testlib/nymeatestbase.h +++ b/tests/testlib/nymeatestbase.h @@ -118,7 +118,7 @@ protected: // just for debugging inline void printJson(const QVariant &response) { QJsonDocument jsonDoc = QJsonDocument::fromVariant(response); - qDebug() << jsonDoc.toJson(); + qCDebug(dcTests()) << jsonDoc.toJson(); } void waitForDBSync();