From 1e626015b647998b3e807390b62afbdfc44af72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20H=C3=B6ltt=C3=A4?= Date: Mon, 26 Feb 2018 10:28:51 +0100 Subject: Add autotest for the ivigenerator's qtro-features Add autoest for ivigenerator's qtro-features. Test program runs the server and client in the same process and tests the default values, initializations and the communication. Change-Id: I57176ad86b6b9f6f0a2ecbabe51430237c6dd124 Reviewed-by: Dominik Holland --- tests/auto/core/ivigenerator/ivigenerator.pro | 3 +- .../core/ivigenerator/org.example.echo.qtro.qface | 63 ++++++ .../backend_qtro/backend_qtro.pro | 18 ++ .../org-example-echo-qtro/frontend/frontend.pro | 13 ++ .../org-example-echo-qtro.pro | 8 + .../server_qtro_test/echoservice.cpp | 34 +++ .../server_qtro_test/echoservice.h | 43 ++++ .../server_qtro_test/main.cpp | 38 ++++ .../server_qtro_test/server.cpp | 35 +++ .../server_qtro_test/server.h | 46 ++++ .../server_qtro_test/server_qtro_test.pro | 28 +++ .../server_qtro_test/tst_echoqtro.cpp | 240 +++++++++++++++++++++ .../server_qtro_test/tst_echoqtro.h | 50 +++++ tests/auto/core/ivigenerator/projects/projects.pro | 3 +- 14 files changed, 620 insertions(+), 2 deletions(-) create mode 100644 tests/auto/core/ivigenerator/org.example.echo.qtro.qface create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/backend_qtro/backend_qtro.pro create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/frontend/frontend.pro create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/org-example-echo-qtro.pro create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.cpp create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.h create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/main.cpp create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server_qtro_test.pro create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp create mode 100644 tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h (limited to 'tests/auto/core') diff --git a/tests/auto/core/ivigenerator/ivigenerator.pro b/tests/auto/core/ivigenerator/ivigenerator.pro index dfc1c66..2254d04 100644 --- a/tests/auto/core/ivigenerator/ivigenerator.pro +++ b/tests/auto/core/ivigenerator/ivigenerator.pro @@ -4,4 +4,5 @@ SUBDIRS = projects OTHER_FILES = org.example.echo.qface \ org.example.echo.yaml \ - org.example.echo.noprivate.qface + org.example.echo.noprivate.qface \ + org.example.echo.qtro.qface diff --git a/tests/auto/core/ivigenerator/org.example.echo.qtro.qface b/tests/auto/core/ivigenerator/org.example.echo.qtro.qface new file mode 100644 index 0000000..af7be12 --- /dev/null +++ b/tests/auto/core/ivigenerator/org.example.echo.qtro.qface @@ -0,0 +1,63 @@ +/** + * module + */ +@config: { interfaceBuilder: "echoInterfaceBuilder" } +module org.example.echo 1.0 + +/** + * @brief the brief + * @description the description + * continues {@link http://qt.io} + * @deprecated + * @see org.example.echo.Echo + * @see org.example + * @see http://qt.io + * @anything hello + */ +@config: {id: "org.foo.id.1.0", qml_class_name: "UiEcho"} +interface Echo { + /** + * @brief brief message + * @details long message + * + * @param msg the message + * @return the echo + */ + readonly string lastMessage; + int intValue; + @config_simulator: {minimum: 10.} + real floatValue1; + @config_simulator: {maximum: 10.} + real floatValue2; + string stringValue; + list contactList; + Contact contact; + WeekDay weekDay; +} + +@config: { type: "DaysOfTheWeek" } +flag WeekDay { + Monday = 1, + Tuesday = 2, + Wednesday = 3, + Thursday = 4, + Friday = 5 +} + +/** + * The contact information + */ +struct Contact { + string name; + int age; + bool isMarried; +} + +struct Combo { + Contact contactInfo; + WeekDay day; +} + +struct AnotherStruct { + int justANumber; +} diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/backend_qtro/backend_qtro.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/backend_qtro/backend_qtro.pro new file mode 100644 index 0000000..445d68b --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/backend_qtro/backend_qtro.pro @@ -0,0 +1,18 @@ +TEMPLATE=lib +TARGET = $$qtLibraryTarget(echo_backend_qtro) +LIBS += -L$$OUT_PWD/.. -l$$qtLibraryTarget(echo_frontend) +DESTDIR = ../qtivi + +CONFIG += warn_off ivigenerator plugin + +INCLUDEPATH += $$OUT_PWD/../frontend +PLUGIN_TYPE = qtivi +PLUGIN_EXTENDS = qtivi +PLUGIN_CLASS_NAME = QIviServiceInterface + +QT += core ivicore remoteobjects + +macos: QMAKE_SONAME_PREFIX = @rpath + +QFACE_FORMAT = backend_qtro +QFACE_SOURCES = ../../../org.example.echo.qtro.qface diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/frontend/frontend.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/frontend/frontend.pro new file mode 100644 index 0000000..f515c5a --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/frontend/frontend.pro @@ -0,0 +1,13 @@ +TEMPLATE=lib +TARGET= $$qtLibraryTarget(echo_frontend) +DESTDIR = ../ + +CONFIG += ivigenerator + +QT += ivicore ivicore-private qml quick + +DEFINES += QT_BUILD_ECHO_LIB + +macos: QMAKE_SONAME_PREFIX = @rpath + +QFACE_SOURCES = ../../../org.example.echo.qtro.qface diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/org-example-echo-qtro.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/org-example-echo-qtro.pro new file mode 100644 index 0000000..0940541 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/org-example-echo-qtro.pro @@ -0,0 +1,8 @@ +TEMPLATE = subdirs + +SUBDIRS = frontend \ + backend_qtro \ + server_qtro_test + +backend_qtro.depends = frontend +server_qtro_test.depends = backend_qtro diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.cpp b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.cpp new file mode 100644 index 0000000..d8bbf82 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.cpp @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AG +** 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 "echoservice.h" + +EchoService::EchoService() +{ + +} diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.h b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.h new file mode 100644 index 0000000..fc2131c --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.h @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AG +** 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 ECHOSERVICE_H +#define ECHOSERVICE_H + +#include "echosource.h" + +class EchoService: public EchoSource +{ + Q_OBJECT + +public: + EchoService(); + +}; + +#endif // ECHOSERVICE_H diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/main.cpp b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/main.cpp new file mode 100644 index 0000000..61880c1 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/main.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AG +** 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 "tst_echoqtro.h" +#include + +int main(int argc, char *argv[]) +{ + EchoQtroTest echoTest; + QCoreApplication app(argc, argv); + + return QTest::qExec(&echoTest, argc, argv); +} 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 new file mode 100644 index 0000000..e18ad2d --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AG +** 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 "server.h" +#include "core.h" + +bool Server::start() +{ + return Core::instance()->host()->enableRemoting(&m_service, "org.example.echo.Echo"); +} 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 new file mode 100644 index 0000000..9168ee6 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AG +** 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 SERVER_H +#define SERVER_H + +#include "echoservice.h" + +class Server : public QObject +{ + Q_OBJECT + +public Q_SLOTS: + bool start(); + +public: + EchoService m_service; + +}; + +#endif // SERVER_H 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 new file mode 100644 index 0000000..3038130 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server_qtro_test.pro @@ -0,0 +1,28 @@ +TARGET = tst_org-example-echo-qtro +QT -= gui +QT += remoteobjects testlib ivicore +LIBS += -L$$OUT_PWD/.. -l$$qtLibraryTarget(echo_frontend) + +DESTDIR = .. + +CONFIG += c++11 console ivigenerator testcase +CONFIG -= app_bundle + +INCLUDEPATH += $$OUT_PWD/../frontend +INCLUDEPATH += $$OUT_PWD/../backend_qtro + +SOURCES += main.cpp \ + server.cpp \ + echoservice.cpp \ + tst_echoqtro.cpp + +QFACE_FORMAT = server_qtro +QFACE_SOURCES = ../../../org.example.echo.qtro.qface + +HEADERS += \ + server.h \ + echoservice.h \ + tst_echoqtro.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 new file mode 100644 index 0000000..091f336 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp @@ -0,0 +1,240 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AG +** 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 "tst_echoqtro.h" +#include "echoplugin.h" +#include "server.h" +#include "echo.h" + +EchoQtroTest::EchoQtroTest() + :QObject() +{ + EchoModule::registerTypes(); + + QCoreApplication::setLibraryPaths({QDir::currentPath()}); +} + +void EchoQtroTest::cleanup() +{ +} + +void EchoQtroTest::testInitServer() +{ + Server server; + QVERIFY(server.start()); + + //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::DaysOfTheWeek()); +} + +void EchoQtroTest::testInitClient() +{ + QTest::ignoreMessage(QtWarningMsg, "QtRO cannot convert the property weekDay to type EchoModule::DaysOfTheWeek"); + Echo client; + QVERIFY(client.startAutoDiscovery()==QIviAbstractFeature::ProductionBackendLoaded); + + QCOMPARE(client.lastMessage(), QString()); + QCOMPARE(client.intValue(), 0); + QCOMPARE(client.floatValue1(), qreal(0.0)); + QCOMPARE(client.floatValue2(), qreal(0.0)); + QCOMPARE(client.stringValue(), QString()); + QCOMPARE(client.contactList(), QVariantList()); + QCOMPARE(client.contact(), Contact()); + QCOMPARE(client.weekDay(), EchoModule::DaysOfTheWeek()); +} + +void EchoQtroTest::testClient2Server() +{ + Server server; + QVERIFY(server.start()); + + QTest::ignoreMessage(QtWarningMsg, "QtRO cannot convert the property weekDay to type EchoModule::DaysOfTheWeek"); + Echo client; + QVERIFY(client.startAutoDiscovery()==QIviAbstractFeature::ProductionBackendLoaded); + + + //hack that makes sure we wait until the client is connected to the server + server.m_service.setFloatValue1(1.0); + QSignalSpy spy(&client, SIGNAL(floatValue1Changed(qreal))); + spy.wait(1000); + // end of hack + + + //test properties + QSignalSpy intValueSpy(&server.m_service, SIGNAL(intValueChanged(int))); + QVERIFY(intValueSpy.isValid()); + int intValueTestValue = 12345; + client.setIntValue(intValueTestValue); + intValueSpy.wait(1000); + QCOMPARE(server.m_service.intValue(), intValueTestValue); + QCOMPARE(intValueSpy[0][0].toInt(), intValueTestValue); + + QSignalSpy floatValue1Spy(&server.m_service, SIGNAL(floatValue1Changed(qreal))); + QVERIFY(floatValue1Spy.isValid()); + qreal floatValue1TestValue = 1234.5678; + client.setFloatValue1(floatValue1TestValue); + floatValue1Spy.wait(1000); + QCOMPARE(server.m_service.floatValue1(), floatValue1TestValue); + QCOMPARE(floatValue1Spy[0][0].toReal(), floatValue1TestValue); + + QSignalSpy floatValue2Spy(&server.m_service, SIGNAL(floatValue2Changed(qreal))); + QVERIFY(floatValue2Spy.isValid()); + qreal floatValue2TestValue = 3.1415; + client.setFloatValue2(floatValue2TestValue); + floatValue2Spy.wait(1000); + QCOMPARE(server.m_service.floatValue2(), floatValue2TestValue); + QCOMPARE(floatValue2Spy[0][0].toReal(), floatValue2TestValue); + + QSignalSpy stringValueSpy(&server.m_service, SIGNAL(stringValueChanged(QString))); + QVERIFY(stringValueSpy.isValid()); + QString stringValueTestValue = "hello test"; + client.setStringValue(stringValueTestValue); + stringValueSpy.wait(1000); + QCOMPARE(server.m_service.stringValue(), stringValueTestValue); + QCOMPARE(stringValueSpy[0][0].toString(), stringValueTestValue); + + QSignalSpy contactListSpy(&server.m_service, SIGNAL(contactListChanged(QVariantList))); + QVERIFY(contactListSpy.isValid()); + QVariantList contactListTestValue( + { QVariant::fromValue(Contact("Mr A.", 20, false)), + QVariant::fromValue(Contact("Mr B.", 40, true)) }); + client.setContactList(contactListTestValue); + contactListSpy.wait(1000); + QCOMPARE(server.m_service.contactList().count(),contactListTestValue.count()); + QCOMPARE(server.m_service.contactList()[0].value(), contactListTestValue[0].value()); + QCOMPARE(server.m_service.contactList()[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))); + QVERIFY(contactSpy.isValid()); + Contact contactTestValue("Nemo", 47, true); + client.setContact(contactTestValue); + contactSpy.wait(1000); + QCOMPARE(server.m_service.contact(), contactTestValue); + QCOMPARE(contactSpy[0][0].value(), contactTestValue); + + QSignalSpy weekDaySpy(&server.m_service, SIGNAL(weekDayChanged(EchoModule::DaysOfTheWeek))); + QVERIFY(weekDaySpy.isValid()); + EchoModule::DaysOfTheWeek weekDayTestValue = EchoModule::Wednesday; + client.setWeekDay(weekDayTestValue); + weekDaySpy.wait(1000); + QCOMPARE(server.m_service.weekDay(), weekDayTestValue); + QCOMPARE(weekDaySpy[0][0].value(), weekDayTestValue); +} + +void EchoQtroTest::testServer2Client() +{ + Server server; + QVERIFY(server.start()); + + QTest::ignoreMessage(QtWarningMsg, "QtRO cannot convert the property weekDay to type EchoModule::DaysOfTheWeek"); + Echo client; + QVERIFY(client.startAutoDiscovery()==QIviAbstractFeature::ProductionBackendLoaded); + + + //hack that makes sure we wait until the client is connected to the server + server.m_service.setFloatValue1(1.0); + QSignalSpy spy(&client, SIGNAL(floatValue1Changed(qreal))); + spy.wait(1000); + // end of hack + + + //test properties + QSignalSpy intValueSpy(&client, SIGNAL(intValueChanged(int))); + QVERIFY(intValueSpy.isValid()); + int intValueTestValue = 12345; + server.m_service.setIntValue(intValueTestValue); + QVERIFY(intValueSpy.wait(1000)); + QCOMPARE(client.intValue(), intValueTestValue); + QCOMPARE(intValueSpy[0][0].toInt(), intValueTestValue); + + QSignalSpy floatValue1Spy(&client, SIGNAL(floatValue1Changed(qreal))); + QVERIFY(floatValue1Spy.isValid()); + qreal floatValue1TestValue = 1234.5678; + server.m_service.setFloatValue1(floatValue1TestValue); + floatValue1Spy.wait(1000); + QCOMPARE(client.floatValue1(), floatValue1TestValue); + QCOMPARE(floatValue1Spy[0][0].toReal(), floatValue1TestValue); + + QSignalSpy floatValue2Spy(&client, SIGNAL(floatValue2Changed(qreal))); + QVERIFY(floatValue2Spy.isValid()); + qreal floatValue2TestValue = 234.678; + server.m_service.setFloatValue2(floatValue2TestValue); + floatValue2Spy.wait(1000); + QCOMPARE(client.floatValue2(), floatValue2TestValue); + QCOMPARE(floatValue2Spy[0][0].toReal(), floatValue2TestValue); + + QSignalSpy stringValueSpy(&client, SIGNAL(stringValueChanged(QString))); + QVERIFY(stringValueSpy.isValid()); + QString stringValueTestValue = QString("hello test"); + server.m_service.setStringValue(stringValueTestValue); + stringValueSpy.wait(1000); + QCOMPARE(client.stringValue(), stringValueTestValue); + QCOMPARE(stringValueSpy[0][0].toString(), stringValueTestValue); + + QSignalSpy contactListSpy(&client, SIGNAL(contactListChanged(QVariantList))); + QVERIFY(contactListSpy.isValid()); + QVariantList contactListTestValue( + { QVariant::fromValue(Contact("Mr A.", 20, false)), + QVariant::fromValue(Contact("Mr B.", 40, true)) }); + server.m_service.setContactList(contactListTestValue); + contactListSpy.wait(1000); + QCOMPARE(client.contactList().count(),contactListTestValue.count()); + QCOMPARE(client.contactList()[0].value(), contactListTestValue[0].value()); + QCOMPARE(client.contactList()[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(&client, SIGNAL(contactChanged(Contact))); + QVERIFY(contactSpy.isValid()); + Contact contactTestValue("Nemo", 47, true); + server.m_service.setContact(contactTestValue); + contactSpy.wait(1000); + QCOMPARE(client.contact(), contactTestValue); + QCOMPARE(contactSpy[0][0].value(), contactTestValue); + + QSignalSpy weekDaySpy(&client, SIGNAL(weekDayChanged(EchoModule::DaysOfTheWeek))); + QVERIFY(weekDaySpy.isValid()); + EchoModule::DaysOfTheWeek weekDayTestValue = EchoModule::Wednesday; + server.m_service.setWeekDay(weekDayTestValue); + weekDaySpy.wait(1000); + QCOMPARE(client.weekDay(), weekDayTestValue); + QCOMPARE(weekDaySpy[0][0].value(), weekDayTestValue); +} + + 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 new file mode 100644 index 0000000..a8b5315 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Pelagicore AG +** 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 ECHOQTROTEST_H +#define ECHOQTROTEST_H + +#include + +QT_FORWARD_DECLARE_CLASS(QIviServiceManager); + +class EchoQtroTest : public QObject +{ + Q_OBJECT +public: + EchoQtroTest(); + +private slots: + void cleanup(); + void testInitServer(); + void testInitClient(); + void testClient2Server(); + void testServer2Client(); +}; + +#endif // ECHOQTROTEST_H diff --git a/tests/auto/core/ivigenerator/projects/projects.pro b/tests/auto/core/ivigenerator/projects/projects.pro index 986a841..134d4c4 100644 --- a/tests/auto/core/ivigenerator/projects/projects.pro +++ b/tests/auto/core/ivigenerator/projects/projects.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs SUBDIRS = org-example-echo \ - org-example-echo-noprivate + org-example-echo-noprivate \ + org-example-echo-qtro -- cgit v1.2.1