diff options
author | Dominik Holland <dominik.holland@qt.io> | 2024-05-28 14:44:09 +0200 |
---|---|---|
committer | Dominik Holland <dominik.holland@qt.io> | 2024-05-29 12:59:23 +0200 |
commit | 009509bfca28fb96d87db3a6bec2786348a6de27 (patch) | |
tree | 70e1548c53a136c82f888bc9a8b5f2af95904800 | |
parent | b03155e567a3040d5325d80f472dd173f5f7d26f (diff) |
Add better support for static backend plugins
Correctly initialize the resources in the simulation plugin when build
statically.
Also make sure the QIfServiceManager always uses the id from static
plugins to dissambiguate plugins.
The main part of this commit is the refactoring of the backends autotest
into several test binaries using a common base class.
This is needed as static simulator plugin and dynamic simulator plugin
can't be loaded into the same process.
This should also make it easier to add backend specific tests in the
future.
Pick-to: 6.7
Change-Id: I326b6e1a11b80b7992893cf3955f86e07f5236f8
Reviewed-by: Robert Griebl <robert.griebl@qt.io>
13 files changed, 273 insertions, 133 deletions
diff --git a/src/interfaceframework/qifservicemanager.cpp b/src/interfaceframework/qifservicemanager.cpp index 8d53c617..ac66e23e 100644 --- a/src/interfaceframework/qifservicemanager.cpp +++ b/src/interfaceframework/qifservicemanager.cpp @@ -151,9 +151,9 @@ QList<QIfServiceObject *> QIfServiceManagerPrivate::findServiceByInterface(const QIfServiceObject *serviceObject = nullptr; QString identifier = fileInfo.fileName(); - if (identifier.isEmpty() && backend->proxyServiceObject) { + if (identifier.isEmpty() && backend->interface) { //static plugin - identifier = backend->proxyServiceObject->id(); + identifier = backend->interface->id(); } if (regexp.match(identifier).hasMatch()) diff --git a/src/tools/ifcodegen/templates/backend_simulator/plugin.cpp.tpl b/src/tools/ifcodegen/templates/backend_simulator/plugin.cpp.tpl index 73875d96..6c8c17ad 100644 --- a/src/tools/ifcodegen/templates/backend_simulator/plugin.cpp.tpl +++ b/src/tools/ifcodegen/templates/backend_simulator/plugin.cpp.tpl @@ -31,6 +31,9 @@ extern {{class}}::InterfaceBuilder {{module.tags.config.interfaceBuilder}}; : QObject(parent) , m_simulationEngine(new QIfSimulationEngine(u"{{module.name|lower}}"_s, this)) { +#ifdef QT_STATICPLUGIN + Q_INIT_RESOURCE({{module.module_name|lower}}_simulation); +#endif {% if module.tags.config.interfaceBuilder %} QVector<QIfFeatureInterface *> interfacesList = {{module.tags.config.interfaceBuilder}}(this); Q_ASSERT(interfacesList.size() == interfaces().size()); diff --git a/tests/auto/core/ifcodegen/backends/CMakeLists.txt b/tests/auto/core/ifcodegen/backends/CMakeLists.txt index 526896fd..c7272d08 100644 --- a/tests/auto/core/ifcodegen/backends/CMakeLists.txt +++ b/tests/auto/core/ifcodegen/backends/CMakeLists.txt @@ -1,9 +1,11 @@ add_subdirectory(frontend) add_subdirectory(backend_simulator) +add_subdirectory(backend_simulator_static) add_subdirectory(cmdlistener) add_subdirectory(test) if (QT_FEATURE_remoteobjects) add_subdirectory(backend_qtro) + add_subdirectory(backend_qtro_static) add_subdirectory(simulation_server_qtro) add_subdirectory(server_qtro) endif() diff --git a/tests/auto/core/ifcodegen/backends/backend_qtro_static/CMakeLists.txt b/tests/auto/core/ifcodegen/backends/backend_qtro_static/CMakeLists.txt new file mode 100644 index 00000000..cd1da475 --- /dev/null +++ b/tests/auto/core/ifcodegen/backends/backend_qtro_static/CMakeLists.txt @@ -0,0 +1,23 @@ +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +qt_add_plugin(echo_backend_qtro_static + STATIC + CLASS_NAME echomoduleRoPlugin + OUTPUT_NAME echo_backend_qtro + PLUGIN_TYPE interfaceframework +) + +# Interface Framework Generator: +qt6_ifcodegen_extend_target(echo_backend_qtro_static + IDL_FILES ../../org.example.echo.qface + TEMPLATE backend_qtro + ANNOTATION_FILES annotation.yaml +) + +target_link_libraries(echo_backend_qtro_static PUBLIC + echo_qtro_frontend +) diff --git a/tests/auto/core/ifcodegen/backends/backend_qtro_static/annotation.yaml b/tests/auto/core/ifcodegen/backends/backend_qtro_static/annotation.yaml new file mode 100644 index 00000000..ad2a60c6 --- /dev/null +++ b/tests/auto/core/ifcodegen/backends/backend_qtro_static/annotation.yaml @@ -0,0 +1,3 @@ +org.example.echomodule: + config_qtro: + serviceObjectId: "org.example.echomodule_qtro_static" diff --git a/tests/auto/core/ifcodegen/backends/backend_simulator_static/CMakeLists.txt b/tests/auto/core/ifcodegen/backends/backend_simulator_static/CMakeLists.txt new file mode 100644 index 00000000..6c81b037 --- /dev/null +++ b/tests/auto/core/ifcodegen/backends/backend_simulator_static/CMakeLists.txt @@ -0,0 +1,22 @@ +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +qt_add_plugin(echo_backend_simulator_static + STATIC + CLASS_NAME EchomoduleSimulatorPlugin + PLUGIN_TYPE interfaceframework +) + +# Interface Framework Generator: +qt6_ifcodegen_extend_target(echo_backend_simulator_static + IDL_FILES ../../org.example.echo.qface + TEMPLATE backend_simulator + ANNOTATION_FILES annotation.yaml +) + +target_link_libraries(echo_backend_simulator_static PUBLIC + echo_qtro_frontend +) diff --git a/tests/auto/core/ifcodegen/backends/backend_simulator_static/annotation.yaml b/tests/auto/core/ifcodegen/backends/backend_simulator_static/annotation.yaml new file mode 100644 index 00000000..2069ed6a --- /dev/null +++ b/tests/auto/core/ifcodegen/backends/backend_simulator_static/annotation.yaml @@ -0,0 +1,3 @@ +org.example.echomodule: + config_simulator: + serviceObjectId: "org.example.echomodule_simulator_static" diff --git a/tests/auto/core/ifcodegen/backends/test/CMakeLists.txt b/tests/auto/core/ifcodegen/backends/test/CMakeLists.txt index 0c6218e5..424e9f51 100644 --- a/tests/auto/core/ifcodegen/backends/test/CMakeLists.txt +++ b/tests/auto/core/ifcodegen/backends/test/CMakeLists.txt @@ -4,22 +4,38 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) -qt_internal_add_test(tst_backends - SOURCES - tst_backends.cpp tst_backends.h - LIBRARIES - echo_qtro_frontend - WORKING_DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR}/../ - TESTDATA simulation.qml minimal_simulation_data.json server.conf - NO_BATCH +function(internal_add_backend_test target sources) + qt_internal_add_test(${target} + SOURCES + ${sources} backendstestbase.cpp backendstestbase.h + LIBRARIES + echo_qtro_frontend + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/../ + TESTDATA simulation.qml minimal_simulation_data.json server.conf + NO_BATCH + ) + set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../) +endfunction() + +internal_add_backend_test(tst_simulation_backend_static + tst_simulation_backend_static.cpp +) +target_link_libraries(tst_simulation_backend_static PRIVATE echo_backend_simulator_static) + +internal_add_backend_test(tst_simulation_backend + tst_simulation_backend.cpp ) +if (QT_FEATURE_remoteobjects) + internal_add_backend_test(tst_qtro_backend + tst_qtro_backend.cpp + ) + target_link_libraries(tst_qtro_backend PRIVATE echo_backend_qtro_static) +endif() + add_custom_target(tst_backends_extra_files SOURCES simulation.qml minimal_simulation_data.json ) - -set_target_properties(tst_backends PROPERTIES RUNTIME_OUTPUT_DIRECTORY ../) - diff --git a/tests/auto/core/ifcodegen/backends/test/tst_backends.cpp b/tests/auto/core/ifcodegen/backends/test/backendstestbase.cpp index 2222910b..eb748d62 100644 --- a/tests/auto/core/ifcodegen/backends/test/tst_backends.cpp +++ b/tests/auto/core/ifcodegen/backends/test/backendstestbase.cpp @@ -3,30 +3,18 @@ // Copyright (C) 2018 Pelagicore AG // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include "tst_backends.h" +#include "backendstestbase.h" #include "echo.h" #include "echozoned.h" #include <QIfServiceManager> #include <QIfConfiguration> -#define WAIT_AND_COMPARE(spy, value) \ -if (spy.count() != value) \ - spy.wait(); \ -QCOMPARE(spy.count(), value); \ - \ - static QString frontLeftZone = QStringLiteral("FrontLeft"); using namespace Qt::StringLiterals; -#ifdef Q_OS_WIN -static QString exeSuffix = u".exe"_s; -#else -static QString exeSuffix; -#endif - -BackendsTest::BackendsTest() +BackendsTestBase::BackendsTestBase() : QObject() #if QT_CONFIG(process) , m_serverProcess(new QProcess(this)) @@ -54,7 +42,7 @@ BackendsTest::BackendsTest() Echomodule::registerTypes(); } -void BackendsTest::sendCmd(const QByteArray &input) +void BackendsTestBase::sendCmd(const QByteArray &input) { if (!m_localSocket) return; @@ -64,7 +52,7 @@ void BackendsTest::sendCmd(const QByteArray &input) qApp->processEvents(); } -void BackendsTest::startServer(QStringList arguments) +void BackendsTestBase::startServer(QStringList arguments) { #if QT_CONFIG(process) if (!m_serverExecutable.isEmpty()) { @@ -82,7 +70,7 @@ void BackendsTest::startServer(QStringList arguments) sendCmd(QTest::currentTestFunction()); } -void BackendsTest::ignoreMessage(QtMsgType type, const char *message) +void BackendsTestBase::ignoreMessage(QtMsgType type, const char *message) { QRegularExpression expression(u".*"_s + message); if (m_isSimulationBackend) @@ -91,21 +79,35 @@ void BackendsTest::ignoreMessage(QtMsgType type, const char *message) QTest::ignoreMessage(QtInfoMsg, expression); } -void BackendsTest::initTestCase_data() +void BackendsTestBase::cleanupTestData() +{ +#if QT_CONFIG(process) + if (m_serverProcess->state() == QProcess::Running) { + qInfo() << "Stopping Server Process"; + + sendCmd("quit"); + m_serverProcess->waitForFinished(500); + + if (m_serverProcess->state() == QProcess::Running) { + m_serverProcess->kill(); + QVERIFY(m_serverProcess->waitForFinished()); + } + } +#endif + delete m_localSocket; + m_localSocket = nullptr; + + QIfServiceManager::instance()->unloadAllBackends(); +} + +void BackendsTestBase::initTestCase_data() { - QDir currentDir = QDir::current(); QTest::addColumn<QString>("backend"); QTest::addColumn<bool>("isSimulation"); QTest::addColumn<QString>("serverExecutable"); - QTest::newRow("simulation-backend") << "*echo_qtro_simulator*" << true << ""; - -#if defined(QT_FEATURE_remoteobjects) - QTest::newRow("qtro-server") << "echo_backend_qtro" << false << currentDir.absoluteFilePath(u"org-example-echo-qtro-server"_s + exeSuffix); - QTest::newRow("qtro-simulation-server") << "echo_backend_qtro" << true << currentDir.absoluteFilePath(u"org-example-echo-qtro-simulation-server"_s + exeSuffix); -#endif } -void BackendsTest::initTestCase() +void BackendsTestBase::initTestCase() { if (!m_localServer->listen("qifcmdsocket")) { QLocalServer::removeServer("qifcmdsocket"); @@ -113,7 +115,7 @@ void BackendsTest::initTestCase() } } -void BackendsTest::init() +void BackendsTestBase::init() { QFETCH_GLOBAL(QString, backend); QFETCH_GLOBAL(bool, isSimulation); @@ -129,28 +131,12 @@ void BackendsTest::init() QVERIFY(QIfConfiguration::setPreferredBackends(u"org.example.echomodule"_s, {backend})); } -void BackendsTest::cleanup() +void BackendsTestBase::cleanup() { -#if QT_CONFIG(process) - if (m_serverProcess->state() == QProcess::Running) { - qInfo() << "Stopping Server Process"; - - sendCmd("quit"); - m_serverProcess->waitForFinished(500); - - if (m_serverProcess->state() == QProcess::Running) { - m_serverProcess->kill(); - QVERIFY(m_serverProcess->waitForFinished()); - } - } -#endif - delete m_localSocket; - m_localSocket = nullptr; - - QIfServiceManager::instance()->unloadAllBackends(); + cleanupTestData(); } -void BackendsTest::testInit() +void BackendsTestBase::testInit() { QTest::failOnWarning(QRegularExpression(u".*Couldn't retrieve MetaObject for enum parsing:.*"_s)); Echo client; @@ -237,7 +223,7 @@ void BackendsTest::testInit() QCOMPARE(lastMessageChangedSpy.count(), 0); } -void BackendsTest::testZonedInit() +void BackendsTestBase::testZonedInit() { EchoZoned client; QVERIFY(client.startAutoDiscovery() > QIfAbstractFeature::ErrorWhileLoading); @@ -327,7 +313,7 @@ void BackendsTest::testZonedInit() QCOMPARE(stringValueChangedSpy.count(), 0); } -void BackendsTest::testReconnect() +void BackendsTestBase::testReconnect() { if (m_serverExecutable.isEmpty()) QSKIP("The reconnection test only makes sense with a server process"); @@ -392,7 +378,7 @@ void BackendsTest::testReconnect() QCOMPARE(zonedClient.error(), QIfAbstractFeature::NoError); } -void BackendsTest::testClient2Server() +void BackendsTestBase::testClient2Server() { Echo client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -477,7 +463,7 @@ void BackendsTest::testClient2Server() QCOMPARE(testEnumSpy[0][0].value<Echomodule::TestEnum>(), testEnumTestValue); } -void BackendsTest::testZonedClient2Server() +void BackendsTestBase::testZonedClient2Server() { EchoZoned client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -560,7 +546,7 @@ void BackendsTest::testZonedClient2Server() QCOMPARE(testEnumSpy[0][0].value<Echomodule::TestEnum>(), testEnumTestValue); } -void BackendsTest::testServer2Client() +void BackendsTestBase::testServer2Client() { Echo client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -642,7 +628,7 @@ void BackendsTest::testServer2Client() QCOMPARE(testEnumSpy[0][0].value<Echomodule::TestEnum>(), testEnumTestValue); } -void BackendsTest::testZonedServer2Client() +void BackendsTestBase::testZonedServer2Client() { EchoZoned client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -721,7 +707,7 @@ void BackendsTest::testZonedServer2Client() QCOMPARE(testEnumSpy[0][0].value<Echomodule::TestEnum>(), testEnumTestValue); } -void BackendsTest::testSlots() +void BackendsTestBase::testSlots() { Echo client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -789,7 +775,7 @@ void BackendsTest::testSlots() QCOMPARE(enumMethodReply.reply(), enumTestValue); } -void BackendsTest::testZonedSlots() +void BackendsTestBase::testZonedSlots() { EchoZoned client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -847,7 +833,7 @@ void BackendsTest::testZonedSlots() QCOMPARE(enumMethodReply.reply(), enumTestValue); } -void BackendsTest::testMultipleSlotCalls() +void BackendsTestBase::testMultipleSlotCalls() { Echo client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -910,7 +896,7 @@ void BackendsTest::testMultipleSlotCalls() QCOMPARE(echoZonedReply3.reply(), echoTestValue3); } -void BackendsTest::testAsyncSlotResults() +void BackendsTestBase::testAsyncSlotResults() { Echo client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -972,7 +958,7 @@ void BackendsTest::testAsyncSlotResults() QCOMPARE(zonedReply.value(), QString()); } -void BackendsTest::testSignals() +void BackendsTestBase::testSignals() { Echo client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -1037,7 +1023,7 @@ void BackendsTest::testSignals() WAIT_AND_COMPARE(zonedSomethingSpy, 1); } -void BackendsTest::testModel() +void BackendsTestBase::testModel() { Echo client; QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); @@ -1084,7 +1070,7 @@ void BackendsTest::testModel() QCOMPARE(model->rowCount(), 0); } -void BackendsTest::testSimulationData() +void BackendsTestBase::testSimulationData() { if (!m_isSimulation) QSKIP("This test is only for simulation backend and simulation servers"); @@ -1180,55 +1166,3 @@ void BackendsTest::testSimulationData() QCOMPARE(unsupportedValueSpy.count(), 0); QCOMPARE(zone->stringValue(), QString()); } - -void BackendsTest::testRemoteObjectsConfig() -{ - if (m_isSimulationBackend) - QSKIP("This test is only for remoteobject"); - - Echo client; - QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); - QVERIFY(initSpy.isValid()); - QVERIFY(client.startAutoDiscovery() > QIfAbstractFeature::ErrorWhileLoading); - - EchoZoned zonedClient; - QSignalSpy zonedInitSpy(&zonedClient, SIGNAL(isInitializedChanged(bool))); - QVERIFY(zonedInitSpy.isValid()); - zonedClient.setServiceObject(client.serviceObject()); - - // Test with same URL for all services - startServer({"--serverUrl", "local:myTestUrl"}); - client.serviceObject()->updateServiceSettings(QVariantMap({{QString("connectionUrl"), QVariant("local:myTestUrl")}})); - - //wait until the client has connected and initial values are set - WAIT_AND_COMPARE(initSpy, 1); - QVERIFY(client.isInitialized()); - - WAIT_AND_COMPARE(zonedInitSpy, 1); - QVERIFY(zonedClient.isInitialized()); - - cleanup(); - QVERIFY(!client.isInitialized()); - QVERIFY(!zonedClient.isInitialized()); - initSpy.clear(); - zonedInitSpy.clear(); - QVERIFY(client.startAutoDiscovery() > QIfAbstractFeature::ErrorWhileLoading); - zonedClient.setServiceObject(client.serviceObject()); - - // Test with conf file, which uses different URLs for different services - startServer({"--serverConf", QFINDTESTDATA("server.conf")}); - client.serviceObject()->updateServiceSettings(QVariantMap({ - {QString("org.example.echomodule.EchoZoned"), QVariantMap({{QString("connectionUrl"), QVariant("local:echozoned")}})}, - {QString("org.example.echomodule"), QVariantMap({{QString("connectionUrl"), QVariant("local:echomoduleconf")}})} - })); - - - //wait until the client has connected and initial values are set - WAIT_AND_COMPARE(initSpy, 1); - QVERIFY(client.isInitialized()); - - WAIT_AND_COMPARE(zonedInitSpy, 1); - QVERIFY(zonedClient.isInitialized()); -} - -QTEST_MAIN(BackendsTest) diff --git a/tests/auto/core/ifcodegen/backends/test/tst_backends.h b/tests/auto/core/ifcodegen/backends/test/backendstestbase.h index a2d745f4..9302e06a 100644 --- a/tests/auto/core/ifcodegen/backends/test/tst_backends.h +++ b/tests/auto/core/ifcodegen/backends/test/backendstestbase.h @@ -3,8 +3,8 @@ // Copyright (C) 2018 Pelagicore AG // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#ifndef BACKENDSTEST_H -#define BACKENDSTEST_H +#ifndef BACKENDSTESTBASE_H +#define BACKENDSTESTBASE_H #include <QtTest> #include <QLocalServer> @@ -12,18 +12,33 @@ QT_FORWARD_DECLARE_CLASS(QIfServiceManager); -class BackendsTest : public QObject +#ifdef Q_OS_WIN +static QString exeSuffix = QStringLiteral(".exe"); +#else +static QString exeSuffix; +#endif + +#define WAIT_AND_COMPARE(spy, value) \ +if (spy.count() != value) \ + spy.wait(); \ + QCOMPARE(spy.count(), value); \ + \ + +class BackendsTestBase : public QObject { Q_OBJECT public: - BackendsTest(); + BackendsTestBase(); void sendCmd(const QByteArray &input); void startServer(QStringList arguments = QStringList()); void ignoreMessage(QtMsgType type, const char *message); + void cleanupTestData(); + + virtual void initTestCase_data(); + private slots: void initTestCase(); - void initTestCase_data(); void init(); void cleanup(); void testInit(); @@ -40,9 +55,8 @@ private slots: void testSignals(); void testModel(); void testSimulationData(); - void testRemoteObjectsConfig(); -private: +protected: #if QT_CONFIG(process) QProcess *m_serverProcess; #endif @@ -53,4 +67,4 @@ private: QString m_serverExecutable; }; -#endif // BACKENDSTEST_H +#endif // BACKENDSTESTBASE_H diff --git a/tests/auto/core/ifcodegen/backends/test/tst_qtro_backend.cpp b/tests/auto/core/ifcodegen/backends/test/tst_qtro_backend.cpp new file mode 100644 index 00000000..2428c930 --- /dev/null +++ b/tests/auto/core/ifcodegen/backends/test/tst_qtro_backend.cpp @@ -0,0 +1,78 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "backendstestbase.h" +#include "echo.h" +#include "echozoned.h" + +using namespace Qt::StringLiterals; + +class QtRoBackendTest : public BackendsTestBase +{ + Q_OBJECT + +private slots: + void initTestCase_data() override + { + BackendsTestBase::initTestCase_data(); + QDir currentDir = QDir::current(); + + QTest::newRow("qtro-static-backend") << "org.example.echomodule_qtro_static" << false << currentDir.absoluteFilePath(u"org-example-echo-qtro-server"_s + exeSuffix); + QTest::newRow("qtro-server") << "echo_backend_qtro" << false << currentDir.absoluteFilePath(u"org-example-echo-qtro-server"_s + exeSuffix); + QTest::newRow("qtro-simulation-server") << "echo_backend_qtro" << true << currentDir.absoluteFilePath(u"org-example-echo-qtro-simulation-server"_s + exeSuffix); + } + + void testRemoteObjectsConfig() + { + if (m_isSimulationBackend) + QSKIP("This test is only for remoteobject"); + + Echo client; + QSignalSpy initSpy(&client, SIGNAL(isInitializedChanged(bool))); + QVERIFY(initSpy.isValid()); + QVERIFY(client.startAutoDiscovery() > QIfAbstractFeature::ErrorWhileLoading); + + EchoZoned zonedClient; + QSignalSpy zonedInitSpy(&zonedClient, SIGNAL(isInitializedChanged(bool))); + QVERIFY(zonedInitSpy.isValid()); + zonedClient.setServiceObject(client.serviceObject()); + + // Test with same URL for all services + startServer({"--serverUrl", "local:myTestUrl"}); + client.serviceObject()->updateServiceSettings(QVariantMap({{QString("connectionUrl"), QVariant("local:myTestUrl")}})); + + //wait until the client has connected and initial values are set + WAIT_AND_COMPARE(initSpy, 1); + QVERIFY(client.isInitialized()); + + WAIT_AND_COMPARE(zonedInitSpy, 1); + QVERIFY(zonedClient.isInitialized()); + + cleanupTestData(); + QVERIFY(!client.isInitialized()); + QVERIFY(!zonedClient.isInitialized()); + initSpy.clear(); + zonedInitSpy.clear(); + QVERIFY(client.startAutoDiscovery() > QIfAbstractFeature::ErrorWhileLoading); + zonedClient.setServiceObject(client.serviceObject()); + + // Test with conf file, which uses different URLs for different services + startServer({"--serverConf", QFINDTESTDATA("server.conf")}); + client.serviceObject()->updateServiceSettings(QVariantMap({ + {QString("org.example.echomodule.EchoZoned"), QVariantMap({{QString("connectionUrl"), QVariant("local:echozoned")}})}, + {QString("org.example.echomodule"), QVariantMap({{QString("connectionUrl"), QVariant("local:echomoduleconf")}})} + })); + + + //wait until the client has connected and initial values are set + WAIT_AND_COMPARE(initSpy, 1); + QVERIFY(client.isInitialized()); + + WAIT_AND_COMPARE(zonedInitSpy, 1); + QVERIFY(zonedClient.isInitialized()); + } +}; + +QTEST_MAIN(QtRoBackendTest) + +#include "tst_qtro_backend.moc" diff --git a/tests/auto/core/ifcodegen/backends/test/tst_simulation_backend.cpp b/tests/auto/core/ifcodegen/backends/test/tst_simulation_backend.cpp new file mode 100644 index 00000000..24c21ab5 --- /dev/null +++ b/tests/auto/core/ifcodegen/backends/test/tst_simulation_backend.cpp @@ -0,0 +1,21 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "backendstestbase.h" + +class SimulationBackendTest : public BackendsTestBase +{ + Q_OBJECT + +private slots: + void initTestCase_data() override + { + BackendsTestBase::initTestCase_data(); + + QTest::newRow("simulation-backend") << "*echo_qtro_simulator*" << true << ""; + } +}; + +QTEST_MAIN(SimulationBackendTest) + +#include "tst_simulation_backend.moc" diff --git a/tests/auto/core/ifcodegen/backends/test/tst_simulation_backend_static.cpp b/tests/auto/core/ifcodegen/backends/test/tst_simulation_backend_static.cpp new file mode 100644 index 00000000..0ee1d791 --- /dev/null +++ b/tests/auto/core/ifcodegen/backends/test/tst_simulation_backend_static.cpp @@ -0,0 +1,21 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "backendstestbase.h" + +class SimulationBackendStaticTest : public BackendsTestBase +{ + Q_OBJECT + +private slots: + void initTestCase_data() override + { + BackendsTestBase::initTestCase_data(); + + QTest::newRow("simulation-static-backend") << "org.example.echomodule_simulator_static" << true << ""; + } +}; + +QTEST_MAIN(SimulationBackendStaticTest) + +#include "tst_simulation_backend_static.moc" |