From 4b8c70c194869c4108fe8c3fc279a2ce6c0506ec Mon Sep 17 00:00:00 2001 From: Dominik Holland Date: Fri, 22 Feb 2019 13:18:19 +0100 Subject: ivigenerator: Support zoned interfaces in the 'backend_qtro' template Fixes: AUTOSUITE-585 Change-Id: I0d8fba5766963cd54e78a455b6476eed58afb96c Reviewed-by: Robert Griebl --- .../core/ivigenerator/org.example.echo.qtro.qface | 59 +++ .../server_qtro_test/echozonedservice.cpp | 232 ++++++++++ .../server_qtro_test/echozonedservice.h | 132 ++++++ .../server_qtro_test/server.cpp | 8 +- .../server_qtro_test/server.h | 4 +- .../server_qtro_test/server_qtro_test.pro | 6 +- .../server_qtro_test/tst_echoqtro.cpp | 495 ++++++++++++++++++--- .../server_qtro_test/tst_echoqtro.h | 4 + 8 files changed, 885 insertions(+), 55 deletions(-) create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echozonedservice.cpp create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echozonedservice.h (limited to 'tests') diff --git a/tests/auto/core/ivigenerator/org.example.echo.qtro.qface b/tests/auto/core/ivigenerator/org.example.echo.qtro.qface index 3c09f1c..340fabb 100644 --- a/tests/auto/core/ivigenerator/org.example.echo.qtro.qface +++ b/tests/auto/core/ivigenerator/org.example.echo.qtro.qface @@ -66,3 +66,62 @@ struct Combo { struct AnotherStruct { int justANumber; } + + + +@config: {id: "org.foo.idz.1.0", zoned: true} +interface EchoZoned { + + /** + * \brief brief message + * + * Some more documentation + */ + readonly string lastMessage; + int intValue; + var varValue; + @config_simulator: {domain: ["one", "two", "three"]} + string stringValue; + string unsupportedValue; + bool zonedValue; + bool valueWithDefault; + @config: { getter_name: "isEchoEnabled" } + bool echoEnabled; + AirflowDirection airflowDirection; + @config_simulator: {minimum: 10., maximum: 15.} + int rangedValue; + int rangedValueWithDefault; + Contact contact; + Combo combo; + list intList; + list comboList; + real UPPERCASEPROPERTY; + + string echo(string msg); + string id(); + var varMethod(); + Combo getCombo(); + + signal anotherChanged(AnotherStruct another); + signal foobar(string foo); + signal somethingHappened(); + signal newValueAvailable(var newValue); +} + +/** + * \brief Control where the airflow goes + */ +flag AirflowDirection { + /** + * \brief Airflow to the windshield + */ + Windshield = 1, + /** + * \brief Airflow to the dashboard + */ + Dashboard = 2, + /** + * \brief Airflow to the floor + */ + Floor = 4 +} diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echozonedservice.cpp b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echozonedservice.cpp new file mode 100644 index 0000000..f7c5862 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echozonedservice.cpp @@ -0,0 +1,232 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtIvi module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite licenses may use +** this file in accordance with the commercial license agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and The Qt Company. For +** licensing terms and conditions see https://www.qt.io/terms-conditions. +** For further information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "echozonedservice.h" + +#define SET_VALUE(m_VALUE, VALUE, CHANGED_SIGNAL) \ + if (m_zoneHash.value(zone).m_VALUE == VALUE) \ + return; \ + \ + m_zoneHash[zone].m_VALUE = VALUE; \ + emit CHANGED_SIGNAL(VALUE, zone); \ + + +EchoZonedService::EchoZonedService(QObject *parent) + : EchoZonedSimpleSource(parent) + , m_testCombo(Contact(QStringLiteral("Antti"), 34, true, QVariant()), EchoModule::Friday) + , m_testId(QStringLiteral("id123")) +{ + m_zoneHash.insert(QString(), ZoneObject()); + m_zoneHash.insert(QStringLiteral("FrontLeft"), ZoneObject()); +} + +QString EchoZonedService::lastMessage(const QString &zone) +{ + return m_zoneHash.value(zone).m_lastMessage; +} + +int EchoZonedService::intValue(const QString &zone) +{ + return m_zoneHash.value(zone).m_intValue; +} + +void EchoZonedService::setIntValue(int intValue, const QString &zone) +{ + SET_VALUE(m_intValue, intValue, intValueChanged); +} + +QVariant EchoZonedService::varValue(const QString &zone) +{ + return m_zoneHash.value(zone).m_varValue; +} + +void EchoZonedService::setVarValue(const QVariant &varValue, const QString &zone) +{ + SET_VALUE(m_varValue, varValue, varValueChanged); +} + +QString EchoZonedService::stringValue(const QString &zone) +{ + return m_zoneHash.value(zone).m_stringValue; +} + +void EchoZonedService::setStringValue(const QString &stringValue, const QString &zone) +{ + SET_VALUE(m_stringValue, stringValue, stringValueChanged); +} + +QString EchoZonedService::unsupportedValue(const QString &zone) +{ + return m_zoneHash.value(zone).m_unsupportedValue; +} + +void EchoZonedService::setUnsupportedValue(const QString &unsupportedValue, const QString &zone) +{ + SET_VALUE(m_unsupportedValue, unsupportedValue, unsupportedValueChanged); +} + +bool EchoZonedService::zonedValue(const QString &zone) +{ + return m_zoneHash.value(zone).m_zonedValue; +} + +void EchoZonedService::setZonedValue(bool zonedValue, const QString &zone) +{ + SET_VALUE(m_zonedValue, zonedValue, zonedValueChanged); +} + +bool EchoZonedService::valueWithDefault(const QString &zone) +{ + return m_zoneHash.value(zone).m_valueWithDefault; +} + +void EchoZonedService::setValueWithDefault(bool valueWithDefault, const QString &zone) +{ + SET_VALUE(m_valueWithDefault, valueWithDefault, valueWithDefaultChanged); +} + +bool EchoZonedService::isEchoEnabled(const QString &zone) +{ + return m_zoneHash.value(zone).m_echoEnabled; +} + +void EchoZonedService::setEchoEnabled(bool echoEnabled, const QString &zone) +{ + SET_VALUE(m_echoEnabled, echoEnabled, echoEnabledChanged); +} + +EchoModule::AirflowDirections EchoZonedService::airflowDirection(const QString &zone) +{ + return m_zoneHash.value(zone).m_airflowDirection; +} + +void EchoZonedService::setAirflowDirection(EchoModule::AirflowDirections airflowDirection, const QString &zone) +{ + SET_VALUE(m_airflowDirection, airflowDirection, airflowDirectionChanged); +} + +int EchoZonedService::rangedValue(const QString &zone) +{ + return m_zoneHash.value(zone).m_rangedValue; +} + +void EchoZonedService::setRangedValue(int rangedValue, const QString &zone) +{ + SET_VALUE(m_rangedValue, rangedValue, rangedValueChanged); +} + +int EchoZonedService::rangedValueWithDefault(const QString &zone) +{ + return m_zoneHash.value(zone).m_rangedValueWithDefault; +} + +void EchoZonedService::setRangedValueWithDefault(int rangedValueWithDefault, const QString &zone) +{ + SET_VALUE(m_rangedValueWithDefault, rangedValueWithDefault, rangedValueWithDefaultChanged); +} + +Contact EchoZonedService::contact(const QString &zone) +{ + return m_zoneHash.value(zone).m_contact; +} + +void EchoZonedService::setContact(const Contact &contact, const QString &zone) +{ + SET_VALUE(m_contact, contact, contactChanged); +} + +Combo EchoZonedService::combo(const QString &zone) +{ + return m_zoneHash.value(zone).m_combo; +} + +void EchoZonedService::setCombo(const Combo &combo, const QString &zone) +{ + SET_VALUE(m_combo, combo, comboChanged); +} + +QVariantList EchoZonedService::intList(const QString &zone) +{ + return m_zoneHash.value(zone).m_intList; +} + +void EchoZonedService::setIntList(const QVariantList &intList, const QString &zone) +{ + SET_VALUE(m_intList, intList, intListChanged); +} + +QVariantList EchoZonedService::comboList(const QString &zone) +{ + return m_zoneHash.value(zone).m_comboList; +} + +void EchoZonedService::setComboList(const QVariantList &comboList, const QString &zone) +{ + SET_VALUE(m_comboList, comboList, comboListChanged); +} + +qreal EchoZonedService::UPPERCASEPROPERTY(const QString &zone) +{ + return m_zoneHash.value(zone).m_UPPERCASEPROPERTY; +} + +void EchoZonedService::setUPPERCASEPROPERTY(qreal UPPERCASEPROPERTY, const QString &zone) +{ + SET_VALUE(m_UPPERCASEPROPERTY, UPPERCASEPROPERTY, UPPERCASEPROPERTYChanged); +} + +QStringList EchoZonedService::availableZones() +{ + auto keys = m_zoneHash.keys(); + keys.removeAll(QString()); + return keys; +} + +QString EchoZonedService::echo(const QString &msg, const QString &zone) +{ + emit echoSlotCalled(msg, zone); + return msg; +} + +QString EchoZonedService::id(const QString &zone) +{ + emit idSlotCalled(zone); + return m_testId; +} + +QVariant EchoZonedService::varMethod(const QString &zone) +{ + emit varMethodSlotCalled(zone); + return QVariant("FOOOO"); +} + +Combo EchoZonedService::getCombo(const QString &zone) +{ + emit getComboSlotCalled(zone); + return m_testCombo; +} diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echozonedservice.h b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echozonedservice.h new file mode 100644 index 0000000..acdb5f5 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echozonedservice.h @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtIvi module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT-QTAS$ +** Commercial License Usage +** Licensees holding valid commercial Qt Automotive Suite licenses may use +** this file in accordance with the commercial license agreement provided +** with the Software or, alternatively, in accordance with the terms +** contained in a written agreement between you and The Qt Company. For +** licensing terms and conditions see https://www.qt.io/terms-conditions. +** For further information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ECHOZONEDSERVICE_H +#define ECHOZONEDSERVICE_H + +#include "rep_echozoned_source.h" + +class EchoZonedService : public EchoZonedSimpleSource +{ + Q_OBJECT +public: + explicit EchoZonedService(QObject *parent = nullptr); + +public slots: + QString lastMessage(const QString &zone) override; + int intValue(const QString &zone) override; + void setIntValue(int intValue, const QString &zone) override; + QVariant varValue(const QString &zone) override; + void setVarValue(const QVariant &varValue, const QString &zone) override; + QString stringValue(const QString &zone) override; + void setStringValue(const QString &stringValue, const QString &zone) override; + QString unsupportedValue(const QString &zone) override; + void setUnsupportedValue(const QString &unsupportedValue, const QString &zone) override; + bool zonedValue(const QString &zone) override; + void setZonedValue(bool zonedValue, const QString &zone) override; + bool valueWithDefault(const QString &zone) override; + void setValueWithDefault(bool valueWithDefault, const QString &zone) override; + bool isEchoEnabled(const QString &zone) override; + void setEchoEnabled(bool echoEnabled, const QString &zone) override; + EchoModule::AirflowDirections airflowDirection(const QString &zone) override; + void setAirflowDirection(EchoModule::AirflowDirections airflowDirection, const QString &zone) override; + int rangedValue(const QString &zone) override; + void setRangedValue(int rangedValue, const QString &zone) override; + int rangedValueWithDefault(const QString &zone) override; + void setRangedValueWithDefault(int rangedValueWithDefault, const QString &zone) override; + Contact contact(const QString &zone) override; + void setContact(const Contact &contact, const QString &zone) override; + Combo combo(const QString &zone) override; + void setCombo(const Combo &combo, const QString &zone) override; + QVariantList intList(const QString &zone) override; + void setIntList(const QVariantList &intList, const QString &zone) override; + QVariantList comboList(const QString &zone) override; + void setComboList(const QVariantList &comboList, const QString &zone) override; + qreal UPPERCASEPROPERTY(const QString &zone) override; + void setUPPERCASEPROPERTY(qreal UPPERCASEPROPERTY, const QString &zone) override; + QStringList availableZones() override; + QString echo(const QString &msg, const QString &zone) override; + QString id(const QString &zone) override; + QVariant varMethod(const QString &zone) override; + Combo getCombo(const QString &zone) override; + +Q_SIGNALS: + void echoSlotCalled(const QString &msg, const QString& zone); + void idSlotCalled(const QString& zone); + void varMethodSlotCalled(const QString& zone); + void getComboSlotCalled(const QString& zone); + void voidSlotCalled(const QString& zone); + void voidSlot2Called(int param, const QString& zone); + +private: + struct ZoneObject { + ZoneObject() + : m_lastMessage(QString()) + , m_intValue(int(0)) + , m_varValue(QVariant()) + , m_stringValue(QString()) + , m_unsupportedValue(QString()) + , m_zonedValue(bool(false)) + , m_valueWithDefault(bool(false)) + , m_echoEnabled(bool(false)) + , m_airflowDirection(EchoModule::AirflowDirections()) + , m_rangedValue(int(0)) + , m_rangedValueWithDefault(int(0)) + , m_contact(Contact()) + , m_combo(Combo()) + , m_intList(QVariantList()) + , m_comboList(QVariantList()) + , m_UPPERCASEPROPERTY(qreal(0.0)) + {} + + QString m_zone; + QString m_lastMessage; + int m_intValue; + QVariant m_varValue; + QString m_stringValue; + QString m_unsupportedValue; + bool m_zonedValue; + bool m_valueWithDefault; + bool m_echoEnabled; + EchoModule::AirflowDirections m_airflowDirection; + int m_rangedValue; + int m_rangedValueWithDefault; + Contact m_contact; + Combo m_combo; + QVariantList m_intList; + QVariantList m_comboList; + qreal m_UPPERCASEPROPERTY; + QStringList m_propertiesToSync; + }; + + QHash m_zoneHash; + Combo m_testCombo; + QString m_testId; +}; + +#endif // ECHOZONEDSERVICE_H diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp index ce9d7c7..192ebca 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp @@ -33,7 +33,9 @@ bool Server::start() { - bool val = Core::instance()->host()->enableRemoting(&m_service, QStringLiteral("org.example.echo.Echo")); + bool val = true; + val = val && Core::instance()->host()->enableRemoting(&m_echoService, QStringLiteral("org.example.echo.Echo")); + val = val && Core::instance()->host()->enableRemoting(&m_echoZonedService, QStringLiteral("org.example.echo.EchoZoned")); //Give QtRO time to announce the service QTest::qWait(200); return val; @@ -41,7 +43,9 @@ bool Server::start() bool Server::stop() { - bool val = Core::instance()->host()->disableRemoting(&m_service); + bool val = true; + val = val && Core::instance()->host()->disableRemoting(&m_echoService); + val = val && Core::instance()->host()->disableRemoting(&m_echoZonedService); //Give QtRO time to send the disconnect message to the Replica QTest::qWait(200); return val; diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h index 03e4696..7c1397b 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h @@ -31,6 +31,7 @@ #define SERVER_H #include "echoservice.h" +#include "echozonedservice.h" class Server : public QObject { @@ -41,7 +42,8 @@ public Q_SLOTS: bool stop(); public: - EchoService m_service; + EchoService m_echoService; + EchoZonedService m_echoZonedService; ~Server(); diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server_qtro_test.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server_qtro_test.pro index 8a8ee55..92f8402 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server_qtro_test.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server_qtro_test.pro @@ -15,7 +15,8 @@ INCLUDEPATH += $$OUT_PWD/../backend_qtro SOURCES += main.cpp \ server.cpp \ echoservice.cpp \ - tst_echoqtro.cpp + tst_echoqtro.cpp \ + echozonedservice.cpp QFACE_FORMAT = server_qtro QFACE_SOURCES = ../../../org.example.echo.qtro.qface @@ -23,7 +24,8 @@ QFACE_SOURCES = ../../../org.example.echo.qtro.qface HEADERS += \ server.h \ echoservice.h \ - tst_echoqtro.h + tst_echoqtro.h \ + echozonedservice.h QMAKE_RPATHDIR += $$OUT_PWD/.. QMAKE_RPATHDIR += $$OUT_PWD/../qtivi diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp index ac948c1..58cd8c6 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp @@ -31,6 +31,7 @@ #include "echoplugin.h" #include "server.h" #include "echo.h" +#include "echozoned.h" #define WAIT_AND_COMPARE(spy, value) \ if (spy.count() == !value) \ @@ -38,6 +39,8 @@ if (spy.count() == !value) \ QCOMPARE(spy.count(), value); \ +static QString frontLeftZone = QStringLiteral("FrontLeft"); + EchoQtroTest::EchoQtroTest() :QObject() { @@ -65,14 +68,14 @@ void EchoQtroTest::testInit() Server server; //test initial values - QCOMPARE(server.m_service.lastMessage(), QString()); - QCOMPARE(server.m_service.intValue(), 0); - QCOMPARE(server.m_service.floatValue1(), qreal(0.0)); - QCOMPARE(server.m_service.floatValue2(), qreal(0.0)); - QCOMPARE(server.m_service.stringValue(), QString()); - QCOMPARE(server.m_service.contactList(), QVariantList()); - QCOMPARE(server.m_service.contact(), Contact()); - QCOMPARE(server.m_service.weekDay(), EchoModule::WeekDay()); + QCOMPARE(server.m_echoService.lastMessage(), QString()); + QCOMPARE(server.m_echoService.intValue(), 0); + QCOMPARE(server.m_echoService.floatValue1(), qreal(0.0)); + QCOMPARE(server.m_echoService.floatValue2(), qreal(0.0)); + QCOMPARE(server.m_echoService.stringValue(), QString()); + QCOMPARE(server.m_echoService.contactList(), QVariantList()); + QCOMPARE(server.m_echoService.contact(), Contact()); + QCOMPARE(server.m_echoService.weekDay(), EchoModule::WeekDay()); QLatin1String lastMessageTestValue("this is the last message"); int intValueTestValue(789); @@ -86,14 +89,14 @@ void EchoQtroTest::testInit() EchoModule::WeekDay weekDayTestValue = EchoModule::Wednesday; - server.m_service.setLastMessage(lastMessageTestValue); - server.m_service.setIntValue(intValueTestValue); - server.m_service.setFloatValue1(floatValue1TestValue); - server.m_service.setFloatValue2(floatValue2TestValue); - server.m_service.setStringValue(stringValueTestValue); - server.m_service.setContactList(contactListTestValue); - server.m_service.setContact(contactTestValue); - server.m_service.setWeekDay(weekDayTestValue); + server.m_echoService.setLastMessage(lastMessageTestValue); + server.m_echoService.setIntValue(intValueTestValue); + server.m_echoService.setFloatValue1(floatValue1TestValue); + server.m_echoService.setFloatValue2(floatValue2TestValue); + server.m_echoService.setStringValue(stringValueTestValue); + server.m_echoService.setContactList(contactListTestValue); + server.m_echoService.setContact(contactTestValue); + server.m_echoService.setWeekDay(weekDayTestValue); QVERIFY(!client.isInitialized()); QCOMPARE(client.error(), QIviAbstractFeature::NoError); @@ -146,6 +149,107 @@ void EchoQtroTest::testInit() QCOMPARE(lastMessageChangedSpy.count(), 0); } +void EchoQtroTest::testZonedInit() +{ + EchoZoned client; + QVERIFY(client.startAutoDiscovery() == QIviAbstractFeature::ProductionBackendLoaded); + + //Just compare a few of them + QCOMPARE(client.intValue(), 0); + QCOMPARE(client.varValue(), QVariant()); + QCOMPARE(client.stringValue(), QString()); + QCOMPARE(client.airflowDirection(), EchoModule::AirflowDirections()); + QCOMPARE(client.contact(), Contact()); + QCOMPARE(client.combo(), Combo()); + QCOMPARE(client.UPPERCASEPROPERTY(), qreal(0.0)); + QCOMPARE(client.availableZones(), QStringList()); + + Server server; + + //test initial values + QCOMPARE(server.m_echoZonedService.intValue(QString()), 0); + QCOMPARE(server.m_echoZonedService.varValue(QString()), QVariant()); + QCOMPARE(server.m_echoZonedService.stringValue(QString()), QString()); + QCOMPARE(server.m_echoZonedService.airflowDirection(QString()), EchoModule::AirflowDirections()); + QCOMPARE(server.m_echoZonedService.contact(QString()), Contact()); + QCOMPARE(server.m_echoZonedService.combo(QString()), Combo()); + QCOMPARE(server.m_echoZonedService.UPPERCASEPROPERTY(QString()), qreal(0.0)); + + int intValueTestValue(789); + QVariant varValueTestValue(789); + qreal floatValueTestValue(3.14); + QLatin1String stringValueTestValue("test string"); + QVariantList comboListTestValue( + { QVariant::fromValue(Contact("Mr A.", 20, false, "foo")), + QVariant::fromValue(Contact("Mr B.", 40, true, "bar")) }); + Contact contactTestValue(QStringLiteral("Nemo"), 47, true, 1); + Combo comboTestValue(Contact(QStringLiteral("Nemo"), 47, true, 1), EchoModule::Wednesday); + EchoModule::AirflowDirections airflowTestValue = EchoModule::Windshield; + + + server.m_echoZonedService.setIntValue(intValueTestValue, QString()); + server.m_echoZonedService.setVarValue(varValueTestValue, QString()); + server.m_echoZonedService.setStringValue(stringValueTestValue, QString()); + + server.m_echoZonedService.setAirflowDirection(airflowTestValue, frontLeftZone); + server.m_echoZonedService.setContact(contactTestValue, frontLeftZone); + server.m_echoZonedService.setCombo(comboTestValue, frontLeftZone); + server.m_echoZonedService.setUPPERCASEPROPERTY(floatValueTestValue, frontLeftZone); + + + QVERIFY(!client.isInitialized()); + QCOMPARE(client.error(), QIviAbstractFeature::NoError); + + //wait until the client has connected and initial values are set + QSignalSpy stringValueChangedSpy(&client, SIGNAL(stringValueChanged(QString))); + QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); + QSignalSpy availableZonesSpy(&client, SIGNAL(availableZonesChanged(QStringList))); + + QVERIFY(server.start()); + + QVERIFY(initSpy.isValid()); + WAIT_AND_COMPARE(initSpy, 1); + QVERIFY(client.isInitialized()); + QVERIFY(availableZonesSpy.count()); + QCOMPARE(client.availableZones(), QStringList({"FrontLeft"})); + + //make sure the change signal is only emitted once with the correct value + QCOMPARE(stringValueChangedSpy.count(), 1); + QCOMPARE(stringValueChangedSpy.at(0).at(0).toString(), stringValueTestValue); + + //test that client gets the same values that were set at the server before connection was established + QCOMPARE(client.intValue(), intValueTestValue); + QCOMPARE(client.varValue(), varValueTestValue); + QCOMPARE(client.stringValue(), stringValueTestValue); + + EchoZoned *zone = qobject_cast(client.zoneAt(frontLeftZone)); + QVERIFY(zone); + QCOMPARE(zone->airflowDirection(), airflowTestValue); + QCOMPARE(zone->contact(), contactTestValue); + QCOMPARE(zone->combo(), comboTestValue); + QCOMPARE(zone->UPPERCASEPROPERTY(), floatValueTestValue); + + stringValueChangedSpy.clear(); + //test that a second instance is also initialized with the correct values + EchoZoned client2; + + QSignalSpy stringValueChangedSpy2(&client2, SIGNAL(stringValueChanged(QString))); + QSignalSpy initSpy2(&client2, SIGNAL(isInitializedChanged(bool))); + + QVERIFY(client2.startAutoDiscovery() == QIviAbstractFeature::ProductionBackendLoaded); + + QVERIFY(initSpy2.isValid()); + WAIT_AND_COMPARE(initSpy2, 1); + QVERIFY(client2.isInitialized()); + + //make sure the change signal is only emitted once with the correct value + QCOMPARE(stringValueChangedSpy2.count(), 1); + QCOMPARE(stringValueChangedSpy2.at(0).at(0).toString(), stringValueTestValue); + + //make sure the first instance doesn't emit the change signal again + QCOMPARE(stringValueChangedSpy.count(), 0); +} + void EchoQtroTest::testReconnect() { Server server; @@ -160,28 +264,49 @@ void EchoQtroTest::testReconnect() WAIT_AND_COMPARE(initSpy, 1); QVERIFY(client.isInitialized()); + EchoZoned zonedClient; + QSignalSpy zonedInitSpy(&zonedClient, SIGNAL(isInitializedChanged(bool))); + QVERIFY(zonedInitSpy.isValid()); + QVERIFY(zonedClient.startAutoDiscovery() == QIviAbstractFeature::ProductionBackendLoaded); + + //wait until the client has connected and initial values are set + WAIT_AND_COMPARE(zonedInitSpy, 1); + QVERIFY(zonedClient.isInitialized()); + //test disconnection QCOMPARE(client.error(), QIviAbstractFeature::NoError); + QCOMPARE(zonedClient.error(), QIviAbstractFeature::NoError); QSignalSpy disconnectSpy(&client, SIGNAL(errorChanged(QIviAbstractFeature::Error, QString))); + QSignalSpy zonedDisconnectSpy(&zonedClient, SIGNAL(errorChanged(QIviAbstractFeature::Error, QString))); QVERIFY(disconnectSpy.isValid()); + QVERIFY(zonedDisconnectSpy.isValid()); server.stop(); WAIT_AND_COMPARE(disconnectSpy, 1); QCOMPARE(client.error(), QIviAbstractFeature::Unknown); + WAIT_AND_COMPARE(zonedDisconnectSpy, 1); + QCOMPARE(zonedClient.error(), QIviAbstractFeature::Unknown); //test that a remote call fails on a disconnected replica QIviPendingReply idReply = client.id(); QVERIFY(idReply.isResultAvailable() && !idReply.watcher()->isSuccessful()); + QIviPendingReply zonedIdReply = zonedClient.id(); + QVERIFY(zonedIdReply.isResultAvailable() && !zonedIdReply.watcher()->isSuccessful()); + //test reconnection QSignalSpy reconnectSpy(&client, SIGNAL(errorChanged(QIviAbstractFeature::Error, QString))); QVERIFY(reconnectSpy.isValid()); + QSignalSpy zonedReconnectSpy(&zonedClient, SIGNAL(errorChanged(QIviAbstractFeature::Error, QString))); + QVERIFY(zonedReconnectSpy.isValid()); server.start(); WAIT_AND_COMPARE(reconnectSpy, 1); QCOMPARE(client.error(), QIviAbstractFeature::NoError); + WAIT_AND_COMPARE(zonedReconnectSpy, 1); + QCOMPARE(zonedClient.error(), QIviAbstractFeature::NoError); } void EchoQtroTest::testClient2Server() @@ -199,69 +324,149 @@ void EchoQtroTest::testClient2Server() QVERIFY(client.isInitialized()); //test properties - QSignalSpy intValueSpy(&server.m_service, SIGNAL(intValueChanged(int))); + QSignalSpy intValueSpy(&server.m_echoService, SIGNAL(intValueChanged(int))); QVERIFY(intValueSpy.isValid()); int intValueTestValue = 12345; client.setIntValue(intValueTestValue); WAIT_AND_COMPARE(intValueSpy, 1); - QCOMPARE(server.m_service.intValue(), intValueTestValue); + QCOMPARE(server.m_echoService.intValue(), intValueTestValue); QCOMPARE(intValueSpy[0][0].toInt(), intValueTestValue); - QSignalSpy floatValue1Spy(&server.m_service, SIGNAL(floatValue1Changed(qreal))); + QSignalSpy floatValue1Spy(&server.m_echoService, SIGNAL(floatValue1Changed(qreal))); QVERIFY(floatValue1Spy.isValid()); qreal floatValue1TestValue = 1234.5678; client.setFloatValue1(floatValue1TestValue); WAIT_AND_COMPARE(floatValue1Spy, 1); - QCOMPARE(server.m_service.floatValue1(), floatValue1TestValue); + QCOMPARE(server.m_echoService.floatValue1(), floatValue1TestValue); QCOMPARE(floatValue1Spy[0][0].toReal(), floatValue1TestValue); - QSignalSpy floatValue2Spy(&server.m_service, SIGNAL(floatValue2Changed(qreal))); + QSignalSpy floatValue2Spy(&server.m_echoService, SIGNAL(floatValue2Changed(qreal))); QVERIFY(floatValue2Spy.isValid()); qreal floatValue2TestValue = 3.1415; client.setFloatValue2(floatValue2TestValue); WAIT_AND_COMPARE(floatValue2Spy, 1); - QCOMPARE(server.m_service.floatValue2(), floatValue2TestValue); + QCOMPARE(server.m_echoService.floatValue2(), floatValue2TestValue); QCOMPARE(floatValue2Spy[0][0].toReal(), floatValue2TestValue); - QSignalSpy stringValueSpy(&server.m_service, SIGNAL(stringValueChanged(QString))); + QSignalSpy stringValueSpy(&server.m_echoService, SIGNAL(stringValueChanged(QString))); QVERIFY(stringValueSpy.isValid()); QString stringValueTestValue = QStringLiteral("hello test"); client.setStringValue(stringValueTestValue); WAIT_AND_COMPARE(stringValueSpy, 1); - QCOMPARE(server.m_service.stringValue(), stringValueTestValue); + QCOMPARE(server.m_echoService.stringValue(), stringValueTestValue); QCOMPARE(stringValueSpy[0][0].toString(), stringValueTestValue); - QSignalSpy contactListSpy(&server.m_service, SIGNAL(contactListChanged(QVariantList))); + QSignalSpy contactListSpy(&server.m_echoService, SIGNAL(contactListChanged(QVariantList))); QVERIFY(contactListSpy.isValid()); QVariantList contactListTestValue( { QVariant::fromValue(Contact("Mr A.", 20, false, "foo")), QVariant::fromValue(Contact("Mr B.", 40, true, "bar")) }); client.setContactList(contactListTestValue); WAIT_AND_COMPARE(contactListSpy, 1); - QCOMPARE(server.m_service.contactList().count(),contactListTestValue.count()); - QCOMPARE(server.m_service.contactList().at(0).value(), contactListTestValue[0].value()); - QCOMPARE(server.m_service.contactList().at(1).value(), contactListTestValue[1].value()); + QCOMPARE(server.m_echoService.contactList().count(),contactListTestValue.count()); + QCOMPARE(server.m_echoService.contactList().at(0).value(), contactListTestValue[0].value()); + QCOMPARE(server.m_echoService.contactList().at(1).value(), contactListTestValue[1].value()); QVariantList signalArgs = contactListSpy[0][0].toList(); QCOMPARE(signalArgs[0].value(), contactListTestValue[0].value()); QCOMPARE(signalArgs[1].value(), contactListTestValue[1].value()); - QSignalSpy contactSpy(&server.m_service, SIGNAL(contactChanged(Contact))); + QSignalSpy contactSpy(&server.m_echoService, SIGNAL(contactChanged(Contact))); QVERIFY(contactSpy.isValid()); Contact contactTestValue(QStringLiteral("Nemo"), 47, true, 1); client.setContact(contactTestValue); WAIT_AND_COMPARE(contactSpy, 1); - QCOMPARE(server.m_service.contact(), contactTestValue); + QCOMPARE(server.m_echoService.contact(), contactTestValue); QCOMPARE(contactSpy[0][0].value(), contactTestValue); - QSignalSpy weekDaySpy(&server.m_service, SIGNAL(weekDayChanged(EchoModule::WeekDay))); + QSignalSpy weekDaySpy(&server.m_echoService, SIGNAL(weekDayChanged(EchoModule::WeekDay))); QVERIFY(weekDaySpy.isValid()); EchoModule::WeekDay weekDayTestValue = EchoModule::Thursday; client.setWeekDay(weekDayTestValue); WAIT_AND_COMPARE(weekDaySpy, 1); - QCOMPARE(server.m_service.weekDay(), weekDayTestValue); + QCOMPARE(server.m_echoService.weekDay(), weekDayTestValue); QCOMPARE(weekDaySpy[0][0].value(), weekDayTestValue); } +void EchoQtroTest::testZonedClient2Server() +{ + Server server; + QVERIFY(server.start()); + + EchoZoned client; + QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); + QVERIFY(initSpy.isValid()); + QVERIFY(client.startAutoDiscovery() == QIviAbstractFeature::ProductionBackendLoaded); + + //wait until the client has connected and initial values are set + WAIT_AND_COMPARE(initSpy, 1); + QVERIFY(client.isInitialized()); + + //test properties + QSignalSpy intValueSpy(&server.m_echoZonedService, SIGNAL(intValueChanged(int, QString))); + QVERIFY(intValueSpy.isValid()); + int intValueTestValue = 12345; + client.setIntValue(intValueTestValue); + WAIT_AND_COMPARE(intValueSpy, 1); + QCOMPARE(server.m_echoZonedService.intValue(QString()), intValueTestValue); + QCOMPARE(intValueSpy[0][0].toInt(), intValueTestValue); + QCOMPARE(intValueSpy[0][1].toString(), QString()); + + QSignalSpy UPPERCASEPROPERTYSpy(&server.m_echoZonedService, SIGNAL(UPPERCASEPROPERTYChanged(qreal, QString))); + QVERIFY(UPPERCASEPROPERTYSpy.isValid()); + qreal floatValueTestValue = 1234.5678; + client.setUPPERCASEPROPERTY(floatValueTestValue); + WAIT_AND_COMPARE(UPPERCASEPROPERTYSpy, 1); + QCOMPARE(server.m_echoZonedService.UPPERCASEPROPERTY(QString()), floatValueTestValue); + QCOMPARE(UPPERCASEPROPERTYSpy[0][0].toReal(), floatValueTestValue); + QCOMPARE(UPPERCASEPROPERTYSpy[0][1].toString(), QString()); + + EchoZoned *zone = qobject_cast(client.zoneAt(frontLeftZone)); + QVERIFY(zone); + + QSignalSpy stringValueSpy(&server.m_echoZonedService, SIGNAL(stringValueChanged(QString, QString))); + QVERIFY(stringValueSpy.isValid()); + QString stringValueTestValue = QStringLiteral("hello test"); + zone->setStringValue(stringValueTestValue); + WAIT_AND_COMPARE(stringValueSpy, 1); + QCOMPARE(server.m_echoZonedService.stringValue(frontLeftZone), stringValueTestValue); + QCOMPARE(stringValueSpy[0][0].toString(), stringValueTestValue); + QCOMPARE(stringValueSpy[0][1].toString(), frontLeftZone); + + QSignalSpy comboListSpy(&server.m_echoZonedService, SIGNAL(comboListChanged(QVariantList, QString))); + QVERIFY(comboListSpy.isValid()); + QVariantList comboListTestValue( + { QVariant::fromValue(Combo(Contact("Mr A.", 20, false, "foo"), EchoModule::Thursday)), + QVariant::fromValue(Combo(Contact("Mr B.", 40, true, "bar"), EchoModule::Tuesday)) }); + zone->setComboList(comboListTestValue); + WAIT_AND_COMPARE(comboListSpy, 1); + QVariantList comboList = server.m_echoZonedService.comboList(frontLeftZone); + QCOMPARE(comboList.count(),comboListTestValue.count()); + QCOMPARE(comboList.at(0).value(), comboListTestValue[0].value()); + QCOMPARE(comboList.at(1).value(), comboListTestValue[1].value()); + QVariantList signalArgs = comboListSpy[0][0].toList(); + QCOMPARE(signalArgs[0].value(), comboListTestValue[0].value()); + QCOMPARE(signalArgs[1].value(), comboListTestValue[1].value()); + QCOMPARE(comboListSpy[0][1].toString(), frontLeftZone); + + QSignalSpy contactSpy(&server.m_echoZonedService, SIGNAL(contactChanged(Contact, QString))); + QVERIFY(contactSpy.isValid()); + Contact contactTestValue(QStringLiteral("Nemo"), 47, true, 1); + zone->setContact(contactTestValue); + WAIT_AND_COMPARE(contactSpy, 1); + QCOMPARE(server.m_echoZonedService.contact(frontLeftZone), contactTestValue); + QCOMPARE(contactSpy[0][0].value(), contactTestValue); + QCOMPARE(contactSpy[0][1].toString(), frontLeftZone); + + QSignalSpy airflowSpy(&server.m_echoZonedService, SIGNAL(airflowDirectionChanged(EchoModule::AirflowDirections, QString))); + QVERIFY(airflowSpy.isValid()); + EchoModule::AirflowDirections airflowTestValue = EchoModule::Windshield; + zone->setAirflowDirection(airflowTestValue); + WAIT_AND_COMPARE(airflowSpy, 1); + QCOMPARE(server.m_echoZonedService.airflowDirection(frontLeftZone), airflowTestValue); + QCOMPARE(airflowSpy[0][0].value(), airflowTestValue); + QCOMPARE(airflowSpy[0][1].toString(), frontLeftZone); +} + void EchoQtroTest::testServer2Client() { Server server; @@ -281,7 +486,7 @@ void EchoQtroTest::testServer2Client() QSignalSpy intValueSpy(&client, SIGNAL(intValueChanged(int))); QVERIFY(intValueSpy.isValid()); int intValueTestValue = 12345; - server.m_service.setIntValue(intValueTestValue); + server.m_echoService.setIntValue(intValueTestValue); WAIT_AND_COMPARE(intValueSpy, 1); QCOMPARE(client.intValue(), intValueTestValue); QCOMPARE(intValueSpy[0][0].toInt(), intValueTestValue); @@ -289,7 +494,7 @@ void EchoQtroTest::testServer2Client() QSignalSpy floatValue1Spy(&client, SIGNAL(floatValue1Changed(qreal))); QVERIFY(floatValue1Spy.isValid()); qreal floatValue1TestValue = 1234.5678; - server.m_service.setFloatValue1(floatValue1TestValue); + server.m_echoService.setFloatValue1(floatValue1TestValue); WAIT_AND_COMPARE(floatValue1Spy, 1); QCOMPARE(client.floatValue1(), floatValue1TestValue); QCOMPARE(floatValue1Spy[0][0].toReal(), floatValue1TestValue); @@ -297,7 +502,7 @@ void EchoQtroTest::testServer2Client() QSignalSpy floatValue2Spy(&client, SIGNAL(floatValue2Changed(qreal))); QVERIFY(floatValue2Spy.isValid()); qreal floatValue2TestValue = 234.678; - server.m_service.setFloatValue2(floatValue2TestValue); + server.m_echoService.setFloatValue2(floatValue2TestValue); WAIT_AND_COMPARE(floatValue2Spy, 1); QCOMPARE(client.floatValue2(), floatValue2TestValue); QCOMPARE(floatValue2Spy[0][0].toReal(), floatValue2TestValue); @@ -305,7 +510,7 @@ void EchoQtroTest::testServer2Client() QSignalSpy stringValueSpy(&client, SIGNAL(stringValueChanged(QString))); QVERIFY(stringValueSpy.isValid()); QLatin1String stringValueTestValue("hello test"); - server.m_service.setStringValue(stringValueTestValue); + server.m_echoService.setStringValue(stringValueTestValue); WAIT_AND_COMPARE(stringValueSpy, 1); QCOMPARE(client.stringValue(), stringValueTestValue); QCOMPARE(stringValueSpy[0][0].toString(), stringValueTestValue); @@ -315,7 +520,7 @@ void EchoQtroTest::testServer2Client() QVariantList contactListTestValue( { QVariant::fromValue(Contact("Mr A.", 20, false, "foo")), QVariant::fromValue(Contact("Mr B.", 40, true, "bar")) }); - server.m_service.setContactList(contactListTestValue); + server.m_echoService.setContactList(contactListTestValue); WAIT_AND_COMPARE(contactListSpy, 1); QCOMPARE(client.contactList().count(),contactListTestValue.count()); QCOMPARE(client.contactList().at(0).value(), contactListTestValue[0].value()); @@ -327,7 +532,7 @@ void EchoQtroTest::testServer2Client() QSignalSpy contactSpy(&client, SIGNAL(contactChanged(Contact))); QVERIFY(contactSpy.isValid()); Contact contactTestValue(QStringLiteral("Nemo"), 47, true, 1); - server.m_service.setContact(contactTestValue); + server.m_echoService.setContact(contactTestValue); WAIT_AND_COMPARE(contactSpy, 1); QCOMPARE(client.contact(), contactTestValue); QCOMPARE(contactSpy[0][0].value(), contactTestValue); @@ -335,12 +540,86 @@ void EchoQtroTest::testServer2Client() QSignalSpy weekDaySpy(&client, SIGNAL(weekDayChanged(EchoModule::WeekDay))); QVERIFY(weekDaySpy.isValid()); EchoModule::WeekDay weekDayTestValue = EchoModule::Friday; - server.m_service.setWeekDay(weekDayTestValue); + server.m_echoService.setWeekDay(weekDayTestValue); WAIT_AND_COMPARE(weekDaySpy, 1); QCOMPARE(client.weekDay(), weekDayTestValue); QCOMPARE(weekDaySpy[0][0].value(), weekDayTestValue); } +void EchoQtroTest::testZonedServer2Client() +{ + Server server; + QVERIFY(server.start()); + + EchoZoned client; + QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); + QVERIFY(initSpy.isValid()); + QVERIFY(client.startAutoDiscovery() == QIviAbstractFeature::ProductionBackendLoaded); + + //wait until the client has connected and initial values are set + WAIT_AND_COMPARE(initSpy, 1); + QVERIFY(client.isInitialized()); + + //test properties + QSignalSpy intValueSpy(&client, SIGNAL(intValueChanged(int))); + QVERIFY(intValueSpy.isValid()); + int intValueTestValue = 12345; + server.m_echoZonedService.setIntValue(intValueTestValue, QString()); + WAIT_AND_COMPARE(intValueSpy, 1); + QCOMPARE(client.intValue(), intValueTestValue); + QCOMPARE(intValueSpy[0][0].toInt(), intValueTestValue); + + QSignalSpy UPPERCASEPROPERTYSpy(&client, SIGNAL(UPPERCASEPROPERTYChanged(qreal))); + QVERIFY(UPPERCASEPROPERTYSpy.isValid()); + qreal floatValueTestValue = 1234.5678; + server.m_echoZonedService.setUPPERCASEPROPERTY(floatValueTestValue, QString()); + WAIT_AND_COMPARE(UPPERCASEPROPERTYSpy, 1); + QCOMPARE(client.UPPERCASEPROPERTY(), floatValueTestValue); + QCOMPARE(UPPERCASEPROPERTYSpy[0][0].toReal(), floatValueTestValue); + + EchoZoned *zone = qobject_cast(client.zoneAt(frontLeftZone)); + QVERIFY(zone); + + QSignalSpy stringValueSpy(zone, SIGNAL(stringValueChanged(QString))); + QVERIFY(stringValueSpy.isValid()); + QString stringValueTestValue = QStringLiteral("hello test"); + server.m_echoZonedService.setStringValue(stringValueTestValue, frontLeftZone); + WAIT_AND_COMPARE(stringValueSpy, 1); + QCOMPARE(zone->stringValue(), stringValueTestValue); + QCOMPARE(stringValueSpy[0][0].toString(), stringValueTestValue); + + QSignalSpy comboListSpy(zone, SIGNAL(comboListChanged(QVariantList))); + QVERIFY(comboListSpy.isValid()); + QVariantList comboListTestValue( + { QVariant::fromValue(Combo(Contact("Mr A.", 20, false, "foo"), EchoModule::Thursday)), + QVariant::fromValue(Combo(Contact("Mr B.", 40, true, "bar"), EchoModule::Tuesday)) }); + server.m_echoZonedService.setComboList(comboListTestValue, frontLeftZone); + WAIT_AND_COMPARE(comboListSpy, 1); + QVariantList comboList = zone->comboList(); + QCOMPARE(comboList.count(), comboListTestValue.count()); + QCOMPARE(comboList.at(0).value(), comboListTestValue[0].value()); + QCOMPARE(comboList.at(1).value(), comboListTestValue[1].value()); + QVariantList signalArgs = comboListSpy[0][0].toList(); + QCOMPARE(signalArgs[0].value(), comboListTestValue[0].value()); + QCOMPARE(signalArgs[1].value(), comboListTestValue[1].value()); + + QSignalSpy contactSpy(zone, SIGNAL(contactChanged(Contact))); + QVERIFY(contactSpy.isValid()); + Contact contactTestValue(QStringLiteral("Nemo"), 47, true, 1); + server.m_echoZonedService.setContact(contactTestValue, frontLeftZone); + WAIT_AND_COMPARE(contactSpy, 1); + QCOMPARE(zone->contact(), contactTestValue); + QCOMPARE(contactSpy[0][0].value(), contactTestValue); + + QSignalSpy airflowSpy(zone, SIGNAL(airflowDirectionChanged(EchoModule::AirflowDirections))); + QVERIFY(airflowSpy.isValid()); + EchoModule::AirflowDirections airflowTestValue = EchoModule::Windshield; + server.m_echoZonedService.setAirflowDirection(airflowTestValue, frontLeftZone); + WAIT_AND_COMPARE(airflowSpy, 1); + QCOMPARE(zone->airflowDirection(), airflowTestValue); + QCOMPARE(airflowSpy[0][0].value(), airflowTestValue); +} + void EchoQtroTest::testSlots() { Server server; @@ -357,7 +636,7 @@ void EchoQtroTest::testSlots() QVERIFY(client.isInitialized()); //test slots by calling them on the client - QSignalSpy echoSpy(&server.m_service, SIGNAL(echoSlotCalled(const QString&))); + QSignalSpy echoSpy(&server.m_echoService, SIGNAL(echoSlotCalled(const QString&))); QVERIFY(echoSpy.isValid()); QLatin1String echoTestValue("this will be echoed"); QIviPendingReply echoReply = client.echo(echoTestValue); @@ -367,28 +646,28 @@ void EchoQtroTest::testSlots() QCOMPARE(echoSpy.count(), 1); QCOMPARE(echoSpy[0][0].toString(), echoTestValue); - QSignalSpy idSpy(&server.m_service, SIGNAL(idSlotCalled())); + QSignalSpy idSpy(&server.m_echoService, SIGNAL(idSlotCalled())); QVERIFY(idSpy.isValid()); QIviPendingReply idReply = client.id(); QSignalSpy idReplySpy(idReply.watcher(), SIGNAL(replySuccess())); WAIT_AND_COMPARE(idReplySpy, 1); - QCOMPARE(idReply.reply(), server.m_service.m_testId); + QCOMPARE(idReply.reply(), server.m_echoService.m_testId); QCOMPARE(idSpy.count(), 1); - QSignalSpy getComboSpy(&server.m_service, SIGNAL(getComboSlotCalled())); + QSignalSpy getComboSpy(&server.m_echoService, SIGNAL(getComboSlotCalled())); QVERIFY(getComboSpy.isValid()); QIviPendingReply comboReply = client.getCombo(); QSignalSpy comboReplySpy(comboReply.watcher(), SIGNAL(replySuccess())); WAIT_AND_COMPARE(comboReplySpy, 1); - QCOMPARE(comboReply.reply(), server.m_service.m_testCombo); + QCOMPARE(comboReply.reply(), server.m_echoService.m_testCombo); QCOMPARE(getComboSpy.count(), 1); - QSignalSpy voidSlotSpy(&server.m_service, SIGNAL(voidSlotCalled())); + QSignalSpy voidSlotSpy(&server.m_echoService, SIGNAL(voidSlotCalled())); QVERIFY(voidSlotSpy.isValid()); client.voidSlot(); WAIT_AND_COMPARE(voidSlotSpy, 1); - QSignalSpy voidSlot2Spy(&server.m_service, SIGNAL(voidSlot2Called(int))); + QSignalSpy voidSlot2Spy(&server.m_echoService, SIGNAL(voidSlot2Called(int))); int voidSlot2TestValue = 776; QVERIFY(voidSlot2Spy.isValid()); client.voidSlot2(voidSlot2TestValue); @@ -397,6 +676,54 @@ void EchoQtroTest::testSlots() QCOMPARE(voidSlot2Spy[0][0].toInt(), voidSlot2TestValue); } +void EchoQtroTest::testZonedSlots() +{ + Server server; + server.start(); + + EchoZoned client; + QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); + QVERIFY(initSpy.isValid()); + QVERIFY(client.startAutoDiscovery() == QIviAbstractFeature::ProductionBackendLoaded); + + + //wait until the client has connected and initial values are set + WAIT_AND_COMPARE(initSpy, 1); + QVERIFY(client.isInitialized()); + + //test slots by calling them on the client + QSignalSpy echoSpy(&server.m_echoZonedService, SIGNAL(echoSlotCalled(QString, QString))); + QVERIFY(echoSpy.isValid()); + QLatin1String echoTestValue("this will be echoed"); + QIviPendingReply echoReply = client.echo(echoTestValue); + QSignalSpy echoReplySpy(echoReply.watcher(), SIGNAL(replySuccess())); + WAIT_AND_COMPARE(echoReplySpy, 1); + QCOMPARE(echoReply.reply(), echoTestValue); + QCOMPARE(echoSpy.count(), 1); + QCOMPARE(echoSpy[0][0].toString(), echoTestValue); + QCOMPARE(echoSpy[0][1].toString(), QString()); + + QSignalSpy idSpy(&server.m_echoZonedService, SIGNAL(idSlotCalled(QString))); + QVERIFY(idSpy.isValid()); + QIviPendingReply idReply = client.id(); + QSignalSpy idReplySpy(idReply.watcher(), SIGNAL(replySuccess())); + WAIT_AND_COMPARE(idReplySpy, 1); + QCOMPARE(idReply.reply(), server.m_echoService.m_testId); + QCOMPARE(idSpy.count(), 1); + QCOMPARE(idSpy[0][0].toString(), QString()); + + EchoZoned *zone = qobject_cast(client.zoneAt(frontLeftZone)); + QVERIFY(zone); + + QSignalSpy getComboSpy(&server.m_echoZonedService, SIGNAL(getComboSlotCalled(QString))); + QVERIFY(getComboSpy.isValid()); + QIviPendingReply comboReply = zone->getCombo(); + QSignalSpy comboReplySpy(comboReply.watcher(), SIGNAL(replySuccess())); + WAIT_AND_COMPARE(comboReplySpy, 1); + QCOMPARE(comboReply.reply(), server.m_echoService.m_testCombo); + QCOMPARE(getComboSpy.count(), 1); +} + void EchoQtroTest::testMultipleSlotCalls() { Server server; @@ -414,7 +741,7 @@ void EchoQtroTest::testMultipleSlotCalls() QVERIFY(client.isInitialized()); //test the pending replies by calling the same slot with 3 different values - QSignalSpy echoSpy(&server.m_service, SIGNAL(echoSlotCalled(const QString&))); + QSignalSpy echoSpy(&server.m_echoService, SIGNAL(echoSlotCalled(const QString&))); QVERIFY(echoSpy.isValid()); QLatin1String echoTestValue("first"); QLatin1String echoTestValue2("second"); @@ -436,6 +763,42 @@ void EchoQtroTest::testMultipleSlotCalls() QCOMPARE(echoSpy[0][0].toString(), echoTestValue); QCOMPARE(echoSpy[1][0].toString(), echoTestValue2); QCOMPARE(echoSpy[2][0].toString(), echoTestValue3); + + EchoZoned zonedClient; + QSignalSpy zonedInitSpy(&zonedClient, SIGNAL(isInitializedChanged(bool))); + QVERIFY(zonedInitSpy.isValid()); + QVERIFY(zonedClient.startAutoDiscovery() == QIviAbstractFeature::ProductionBackendLoaded); + + //wait until the client has connected and initial values are set + zonedInitSpy.wait(1000); + QCOMPARE(zonedInitSpy.count(), 1); + QVERIFY(zonedClient.isInitialized()); + + EchoZoned *zone = qobject_cast(zonedClient.zoneAt(frontLeftZone)); + QVERIFY(zone); + + QSignalSpy echoZonedSpy(&server.m_echoZonedService, SIGNAL(echoSlotCalled(QString, QString))); + QVERIFY(echoSpy.isValid()); + QIviPendingReply echoZonedReply = zone->echo(echoTestValue); + QIviPendingReply echoZonedReply2 = zone->echo(echoTestValue2); + QIviPendingReply echoZonedReply3 = zone->echo(echoTestValue3); + QSignalSpy echoZonedReplySpy(echoZonedReply.watcher(), SIGNAL(replySuccess())); + QSignalSpy echoZonedReplySpy2(echoZonedReply2.watcher(), SIGNAL(replySuccess())); + QSignalSpy echoZonedReplySpy3(echoZonedReply3.watcher(), SIGNAL(replySuccess())); + echoZonedReplySpy3.wait(); + QCOMPARE(echoZonedReplySpy.count(), 1); + QCOMPARE(echoZonedReplySpy2.count(), 1); + QCOMPARE(echoZonedReplySpy3.count(), 1); + QCOMPARE(echoZonedReply.reply(), echoTestValue); + QCOMPARE(echoZonedReply2.reply(), echoTestValue2); + QCOMPARE(echoZonedReply3.reply(), echoTestValue3); + QCOMPARE(echoZonedSpy.count(),3); + QCOMPARE(echoZonedSpy[0][0].toString(), echoTestValue); + QCOMPARE(echoZonedSpy[0][1].toString(), frontLeftZone); + QCOMPARE(echoZonedSpy[1][0].toString(), echoTestValue2); + QCOMPARE(echoZonedSpy[0][1].toString(), frontLeftZone); + QCOMPARE(echoZonedSpy[2][0].toString(), echoTestValue3); + QCOMPARE(echoZonedSpy[0][1].toString(), frontLeftZone); } void EchoQtroTest::testSignals() @@ -456,19 +819,51 @@ void EchoQtroTest::testSignals() QSignalSpy anotherChangedSpy(&client, SIGNAL(anotherChanged(AnotherStruct))); QVERIFY(anotherChangedSpy.isValid()); AnotherStruct anotherTestValue(7); - server.m_service.anotherChanged(anotherTestValue); + server.m_echoService.anotherChanged(anotherTestValue); WAIT_AND_COMPARE(anotherChangedSpy, 1); QCOMPARE(anotherChangedSpy[0][0].value(), anotherTestValue); QSignalSpy foobarSpy(&client, SIGNAL(foobar(QString))); QVERIFY(foobarSpy.isValid()); QLatin1String foobarTestValue("foo and bar"); - server.m_service.foobar(foobarTestValue); + server.m_echoService.foobar(foobarTestValue); WAIT_AND_COMPARE(foobarSpy, 1); QCOMPARE(foobarSpy[0][0].toString(), foobarTestValue); QSignalSpy somethingSpy(&client, SIGNAL(somethingHappened())); QVERIFY(somethingSpy.isValid());; - server.m_service.somethingHappened(); + server.m_echoService.somethingHappened(); WAIT_AND_COMPARE(somethingSpy, 1); + + + EchoZoned zonedClient; + QSignalSpy zonedInitSpy(&zonedClient, SIGNAL(isInitializedChanged(bool))); + QVERIFY(zonedInitSpy.isValid()); + QVERIFY(zonedClient.startAutoDiscovery() == QIviAbstractFeature::ProductionBackendLoaded); + + //wait until the client has connected and initial values are set + zonedInitSpy.wait(1000); + QCOMPARE(zonedInitSpy.count(), 1); + QVERIFY(zonedClient.isInitialized()); + + //test custom signals (other than property notifiers) from server to client + QSignalSpy zonedAnotherChangedSpy(&zonedClient, SIGNAL(anotherChanged(AnotherStruct))); + QVERIFY(zonedAnotherChangedSpy.isValid()); + server.m_echoZonedService.anotherChanged(anotherTestValue, QString()); + WAIT_AND_COMPARE(zonedAnotherChangedSpy, 1); + QCOMPARE(zonedAnotherChangedSpy[0][0].value(), anotherTestValue); + + EchoZoned *zone = qobject_cast(zonedClient.zoneAt(frontLeftZone)); + QVERIFY(zone); + + QSignalSpy zonedFoobarSpy(zone, SIGNAL(foobar(QString))); + QVERIFY(zonedFoobarSpy.isValid()); + server.m_echoZonedService.foobar(foobarTestValue, frontLeftZone); + WAIT_AND_COMPARE(zonedFoobarSpy, 1); + QCOMPARE(zonedFoobarSpy[0][0].toString(), foobarTestValue); + + QSignalSpy zonedSomethingSpy(zone, SIGNAL(somethingHappened())); + QVERIFY(zonedSomethingSpy.isValid());; + server.m_echoZonedService.somethingHappened(frontLeftZone); + WAIT_AND_COMPARE(zonedSomethingSpy, 1); } diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h index f573ab0..9c42b3b 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h @@ -43,10 +43,14 @@ public: private slots: void cleanup(); void testInit(); + void testZonedInit(); void testReconnect(); void testClient2Server(); + void testZonedClient2Server(); void testServer2Client(); + void testZonedServer2Client(); void testSlots(); + void testZonedSlots(); void testMultipleSlotCalls(); void testSignals(); }; -- cgit v1.2.1