From 4fc0ef01fad2bc3a8456efcf378edfe50eab39eb Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Mon, 10 Jul 2017 23:33:36 +0200 Subject: [PATCH] add a test --- libguh/interfaces/colorlight.json | 4 +-- libguh/plugin/deviceplugin.cpp | 32 ++++++++++++++----- plugins/deviceplugins/deviceplugins.pro | 2 +- .../deviceplugins/mock/devicepluginmock.json | 1 + tests/auto/devices/testdevices.cpp | 23 +++++++++++++ 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/libguh/interfaces/colorlight.json b/libguh/interfaces/colorlight.json index 4054ad69..bd5f5770 100644 --- a/libguh/interfaces/colorlight.json +++ b/libguh/interfaces/colorlight.json @@ -4,8 +4,8 @@ { "name": "color temperature", "type": "int", - "minValue": "any", - "maxValue": "any" + "minimumValue": "any", + "maximumValue": "any" }, { "name": "color", diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index a2dac58f..58f18408 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -487,15 +487,31 @@ QList DevicePlugin::supportedDevices() const valid = false; continue; } - if (stateMap.contains("minimumValue") && stateMap.value("minimumValue") != stateType.minValue()) { - qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateMap.value("name").toString() << "has not matching minimum value" << stateMap.value("minimumValue") << "!=" << stateType.minValue(); - valid = false; - continue; + if (stateMap.contains("minimumValue")) { + if (stateMap.value("minimumValue").toString() == "any") { + if (stateType.minValue().isNull()) { + qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateMap.value("name").toString() << "has no minimum value defined."; + valid = false; + continue; + } + } else if (stateMap.value("minimumValue") != stateType.minValue()) { + qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateMap.value("name").toString() << "has not matching minimum value:" << stateMap.value("minimumValue") << "!=" << stateType.minValue(); + valid = false; + continue; + } } - if (stateMap.contains("maximumValue") && stateMap.value("maximumValue") != stateType.maxValue()) { - qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateMap.value("name").toString() << "has not matching allowed value" << stateMap.value("maximumValue") << "!=" << stateType.maxValue(); - valid = false; - continue; + if (stateMap.contains("maximumValue")) { + if (stateMap.value("maximumValue").toString() == "any") { + if (stateType.maxValue().isNull()) { + qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateMap.value("name").toString() << "has no maximum value defined."; + valid = false; + continue; + } + } else if (stateMap.value("maximumValue") != stateType.maxValue()) { + qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateMap.value("name").toString() << "has not matching maximum value:" << stateMap.value("maximumValue") << "!=" << stateType.minValue(); + valid = false; + continue; + } } if (stateMap.contains("allowedValues") && stateMap.value("allowedValues") != stateType.possibleValues()) { qCWarning(dcDeviceManager) << "DeviceClass" << deviceClass.name() << "claims to implement interface" << value.toString() << "but state" << stateMap.value("name").toString() << "has not matching allowed values" << stateMap.value("allowedValues") << "!=" << stateType.possibleValues(); diff --git a/plugins/deviceplugins/deviceplugins.pro b/plugins/deviceplugins/deviceplugins.pro index eb3bee68..36527c4e 100644 --- a/plugins/deviceplugins/deviceplugins.pro +++ b/plugins/deviceplugins/deviceplugins.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs SUBDIRS += \ -# mock \ + mock \ # elro \ # intertechno \ # networkdetector \ diff --git a/plugins/deviceplugins/mock/devicepluginmock.json b/plugins/deviceplugins/mock/devicepluginmock.json index a8f1fa61..b55b7728 100644 --- a/plugins/deviceplugins/mock/devicepluginmock.json +++ b/plugins/deviceplugins/mock/devicepluginmock.json @@ -33,6 +33,7 @@ "idName": "mock", "name": "Mock Device", "deviceIcon": "Tune", + "interfaces": ["gateway", "light", "mediacontroller"], "basicTags": [ "Device", "Actuator", diff --git a/tests/auto/devices/testdevices.cpp b/tests/auto/devices/testdevices.cpp index 24ed521a..ba4a9fa2 100644 --- a/tests/auto/devices/testdevices.cpp +++ b/tests/auto/devices/testdevices.cpp @@ -51,6 +51,8 @@ private slots: void getSupportedDevices_data(); void getSupportedDevices(); + void verifyInterfaces(); + void addConfiguredDevice_data(); void addConfiguredDevice(); @@ -223,6 +225,27 @@ void TestDevices::getSupportedDevices() QCOMPARE(supportedDevices.count() >= resultCount, true); } +void TestDevices::verifyInterfaces() +{ + QVariantMap params; + params.insert("vendorId", guhVendorId); + QVariant result = injectAndWait("Devices.GetSupportedDevices", params); + QVariantList supportedDevices = result.toMap().value("params").toMap().value("deviceClasses").toList(); + + QVariantMap mockDevice; + foreach (const QVariant &deviceClass, supportedDevices) { + if (deviceClass.toMap().value("id") == mockDeviceClassId) { + mockDevice = deviceClass.toMap(); + } + } + QVERIFY(!mockDevice.isEmpty()); + + QVariantList interfaces = mockDevice.value("interfaces").toList(); + // Must contain gateway, but must not contain anything else as device manager should filter it away + QCOMPARE(interfaces.count() == 1, true); + QVERIFY(interfaces.contains("gateway")); +} + void TestDevices::addConfiguredDevice_data() { QTest::addColumn("deviceClassId");