From 016126e38c65947c3f9eb4401ff0e7b5d6603a1a Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 4 May 2014 15:00:42 +0200 Subject: [PATCH] added tests for GetStateValue --- tests/auto/auto.pro | 2 +- tests/auto/events/events.pro | 2 - tests/auto/states/states.pro | 6 +++ tests/auto/states/teststates.cpp | 74 ++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 tests/auto/states/states.pro create mode 100644 tests/auto/states/teststates.cpp diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 5c36ce24..dd85f1da 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,2 +1,2 @@ TEMPLATE=subdirs -SUBDIRS=versioning devices jsonrpc events +SUBDIRS=versioning devices jsonrpc events states diff --git a/tests/auto/events/events.pro b/tests/auto/events/events.pro index 6f260434..9d95f0ec 100644 --- a/tests/auto/events/events.pro +++ b/tests/auto/events/events.pro @@ -3,6 +3,4 @@ TARGET = events include(../../../guh.pri) include(../autotests.pri) -DEFINES += TESTS_SOURCE_DIR=\\\"$$top_srcdir/tests/auto/\\\" - SOURCES += testevents.cpp diff --git a/tests/auto/states/states.pro b/tests/auto/states/states.pro new file mode 100644 index 00000000..f5fcf33c --- /dev/null +++ b/tests/auto/states/states.pro @@ -0,0 +1,6 @@ +TARGET = states + +include(../../../guh.pri) +include(../autotests.pri) + +SOURCES += teststates.cpp diff --git a/tests/auto/states/teststates.cpp b/tests/auto/states/teststates.cpp new file mode 100644 index 00000000..c08b576a --- /dev/null +++ b/tests/auto/states/teststates.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + ***************************************************************************/ + +#include "guhtestbase.h" +#include "guhcore.h" +#include "devicemanager.h" +#include "mocktcpserver.h" + +#include +#include +#include +#include +#include +#include +#include + +class TestStates: public GuhTestBase +{ + Q_OBJECT + +private slots: + void getStateValue_data(); + void getStateValue(); +}; + +void TestStates::getStateValue_data() +{ + QList devices = GuhCore::instance()->deviceManager()->findConfiguredDevices(mockDeviceClassId); + QVERIFY2(devices.count() > 0, "There needs to be at least one configured Mock Device for this test"); + Device *device = devices.first(); + + QTest::addColumn("deviceId"); + QTest::addColumn("stateTypeId"); + QTest::addColumn("success"); + + QTest::newRow("existing state") << device->id() << mockIntStateId << true; + QTest::newRow("invalid device") << DeviceId::createDeviceId() << mockIntStateId << false; + QTest::newRow("invalid statetype") << device->id() << StateTypeId::createStateTypeId() << false; +} + +void TestStates::getStateValue() +{ + QFETCH(DeviceId, deviceId); + QFETCH(StateTypeId, stateTypeId); + QFETCH(bool, success); + + QVariantMap params; + params.insert("deviceId", deviceId.toString()); + params.insert("stateTypeId", stateTypeId.toString()); + + QVariant response = injectAndWait("Devices.GetStateValue", params); + + qDebug() << "got response" << response; + + verifySuccess(response, success); +} + +#include "teststates.moc" +QTEST_MAIN(TestStates)