From 22bc250391bd90873d8389b9bb99c26b24676ce7 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 4 May 2014 15:10:54 +0200 Subject: [PATCH] add discoverdevices tests with invalid parameters --- tests/auto/devices/testdevices.cpp | 46 +++++++++++++++++++++--------- tests/auto/states/teststates.cpp | 2 -- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/tests/auto/devices/testdevices.cpp b/tests/auto/devices/testdevices.cpp index 828ce187..9947313b 100644 --- a/tests/auto/devices/testdevices.cpp +++ b/tests/auto/devices/testdevices.cpp @@ -46,6 +46,7 @@ private slots: void storedDevices(); + void discoverDevices_data(); void discoverDevices(); }; @@ -230,28 +231,47 @@ void TestDevices::storedDevices() verifySuccess(response); } +void TestDevices::discoverDevices_data() +{ + QTest::addColumn("deviceClassId"); + QTest::addColumn("resultCount"); + QTest::addColumn("success"); + + QTest::newRow("valid deviceClassId") << mockDeviceDiscoveryClassId << 2 << true; + QTest::newRow("invalid deviceClassId") << DeviceClassId::createDeviceClassId() << 0 << false; + QTest::newRow("CreateMethodUser deviceClassId") << mockDeviceClassId << 0 << false; +} + void TestDevices::discoverDevices() { + QFETCH(DeviceClassId, deviceClassId); + QFETCH(int, resultCount); + QFETCH(bool, success); + QVariantMap params; - params.insert("deviceClassId", mockDeviceDiscoveryClassId); + params.insert("deviceClassId", deviceClassId); QVariant response = injectAndWait("Devices.GetDiscoveredDevices", params); - qDebug() << "response" << response; + verifySuccess(response, success); + if (success) { + QCOMPARE(response.toMap().value("params").toMap().value("deviceDescriptors").toList().count(), resultCount); + } - QCOMPARE(response.toMap().value("params").toMap().value("deviceDescriptors").toList().count(), 2); + // If we found something, lets try to add it + if (success) { + DeviceDescriptorId descriptorId = DeviceDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString()); - DeviceDescriptorId descriptorId = DeviceDescriptorId(response.toMap().value("params").toMap().value("deviceDescriptors").toList().first().toMap().value("id").toString()); + params.insert("deviceDescriptorId", descriptorId.toString()); + response = injectAndWait("Devices.AddConfiguredDevice", params); - params.insert("deviceDescriptorId", descriptorId.toString()); - response = injectAndWait("Devices.AddConfiguredDevice", params); + verifySuccess(response); - verifySuccess(response); - - DeviceId deviceId(response.toMap().value("params").toMap().value("deviceId").toString()); - params.clear(); - params.insert("deviceId", deviceId.toString()); - response = injectAndWait("Devices.RemoveConfiguredDevice", params); - verifySuccess(response); + DeviceId deviceId(response.toMap().value("params").toMap().value("deviceId").toString()); + params.clear(); + params.insert("deviceId", deviceId.toString()); + response = injectAndWait("Devices.RemoveConfiguredDevice", params); + verifySuccess(response); + } } #include "testdevices.moc" diff --git a/tests/auto/states/teststates.cpp b/tests/auto/states/teststates.cpp index c08b576a..c1a36442 100644 --- a/tests/auto/states/teststates.cpp +++ b/tests/auto/states/teststates.cpp @@ -65,8 +65,6 @@ void TestStates::getStateValue() QVariant response = injectAndWait("Devices.GetStateValue", params); - qDebug() << "got response" << response; - verifySuccess(response, success); }