diff options
author | Dominik Holland <dominik.holland@pelagicore.com> | 2017-11-27 08:53:21 +0100 |
---|---|---|
committer | Antti Hölttä <ahoelttae@luxoft.com> | 2018-02-07 09:23:50 +0000 |
commit | 0448ec8f0cb3fb52d41e156c2ec15fcff225d2f9 (patch) | |
tree | 82dffc0ddb4638f19eab79199543561ab6442732 | |
parent | 2cfdc03e5e4e8b5674dd13d8d179fde973976d27 (diff) | |
download | qtivi-0448ec8f0cb3fb52d41e156c2ec15fcff225d2f9.tar.gz |
Add an autotest generator template
The template generates a basic autotest for the generated
API and the backend interfaces.
It tests the following:
- default behavior when no or an invalid backend is connected.
- Changes from the backend are populated to the frontend API
- Changes in the frontend are populated to the backend API
The test are generated and executed for the autogenerator
test as well as for the ivivehiclefunctions module
Task-number: QTAUTO-365
Change-Id: Ie7ac78db821d930dca99c3e7db95c1d373460f85
Reviewed-by: Antti Hölttä <ahoelttae@luxoft.com>
18 files changed, 756 insertions, 5 deletions
@@ -18,6 +18,10 @@ ui_* # Test generated files tst_* +!tst_*.cpp +!tst_*.h +!tst_*.tpl +!tst_*.qface *Makefile.tst_* # Directories to ignore diff --git a/src/tools/ivigenerator/generate.py b/src/tools/ivigenerator/generate.py index fbe8805..6eaff84 100755 --- a/src/tools/ivigenerator/generate.py +++ b/src/tools/ivigenerator/generate.py @@ -58,7 +58,7 @@ log = logging.getLogger(__file__) Filters.classPrefix = '' builtin_config = {} -IVI_DEFAULT_TEMPLATES = ['frontend', 'backend_simulator', 'generation_validator', 'control_panel'] +IVI_DEFAULT_TEMPLATES = ['frontend', 'backend_simulator', 'generation_validator', 'control_panel', 'test'] def tag_by_path(symbol, path, default_value=False): """ @@ -131,6 +131,41 @@ def default_type_value(symbol): return 'nullptr' return 'XXX' +def test_type_value(symbol): + """ + Find a value different than the default value for the type. Models are initialized as nullptr + """ + prefix = Filters.classPrefix + t = symbol.type # type: qface.domain.TypeSymbol + if t.is_primitive: + if t.is_int: + return '111' + if t.is_bool: + return 'true' + if t.is_string: + return '"TEST STRING"' + if t.is_real: + return '1234.5678' + if t.is_variant: + return 'QVariant("TEST VARIANT")' + elif t.is_void: + return '' + elif t.is_enum: + module_name = t.reference.module.module_name + value = list(iter(t.reference.members))[-1] + return '{0}{1}Module::{2}'.format(prefix, module_name, value) + elif t.is_flag: + module_name = t.reference.module.module_name + value = next(iter(t.reference.members)) + return '{0}{1}Module::{2}'.format(prefix, module_name, value) + elif symbol.type.is_list: + return 'QVariantList({})' + elif symbol.type.is_struct: + values_string = ', '.join(test_type_value(e) for e in symbol.type.reference.fields) + return '{0}{1}({2})'.format(prefix, symbol.type, values_string) + elif symbol.type.is_model: + return 'new {0}{1}Model()'.format(prefix, symbol.type.nested) + return 'XXX' def default_value(symbol, zone='='): """ @@ -529,6 +564,7 @@ def generate(tplconfig, moduleConfig, src, dst): generator.register_filter('parameter_type', parameter_type) generator.register_filter('getter_name', getter_name) generator.register_filter('setter_name', setter_name) + generator.register_filter('test_type_value', test_type_value) generator.register_filter('default_type_value', default_type_value) generator.register_filter('default_value', default_value) generator.register_filter('model_type', model_type) diff --git a/src/tools/ivigenerator/ivigenerator.pro b/src/tools/ivigenerator/ivigenerator.pro index e56bc41..0ca927f 100644 --- a/src/tools/ivigenerator/ivigenerator.pro +++ b/src/tools/ivigenerator/ivigenerator.pro @@ -71,12 +71,21 @@ templates_control_panel.files += \ templates_control_panel/utils.tpl templates_control_panel.path = $$[QT_HOST_BINS]/ivigenerator/templates_control_panel +templates_test.files += \ + templates_test/generated_comment.cpp.tpl \ + templates_test/tst_test.h.tpl \ + templates_test/tst_test.cpp.tpl \ + templates_test/module.pri.tpl \ + templates_test/main.cpp.tpl +templates_test.path = $$[QT_HOST_BINS]/ivigenerator/templates_test + generator.files += \ generate.py \ $$OUT_PWD/.config \ templates_frontend.yaml \ templates_backend_simulator.yaml \ templates_generation_validator.yaml \ + templates_test.yaml \ generator.path = $$[QT_HOST_BINS]/ivigenerator @@ -85,7 +94,11 @@ qtConfig(simulator) { INSTALLS += templates_control_panel } -INSTALLS += templates_frontend templates_backend_simulator templates_generation_validator generator +INSTALLS += generator \ + templates_frontend \ + templates_backend_simulator \ + templates_generation_validator \ + templates_test \ # Ensure files are installed to qtbase for non-prefixed builds !force_independent:if(!debug_and_release|!build_all|CONFIG(release, debug|release)) { diff --git a/src/tools/ivigenerator/templates_test.yaml b/src/tools/ivigenerator/templates_test.yaml new file mode 100644 index 0000000..f7b6b64 --- /dev/null +++ b/src/tools/ivigenerator/templates_test.yaml @@ -0,0 +1,12 @@ +generate_rules: + module_rules: + - dest_file: "{{srcBase|lower}}.pri" + template_file: "module.pri.tpl" + - dest_file: 'main.cpp' + template_file: 'main.cpp.tpl' + interface_rules: + - dest_file: 'tst_{{interface|lower}}.cpp' + template_file: 'tst_test.cpp.tpl' + - dest_file: 'tst_{{interface|lower}}.h' + template_file: 'tst_test.h.tpl' + struct_rules: diff --git a/src/tools/ivigenerator/templates_test/generated_comment.cpp.tpl b/src/tools/ivigenerator/templates_test/generated_comment.cpp.tpl new file mode 100644 index 0000000..1ec9404 --- /dev/null +++ b/src/tools/ivigenerator/templates_test/generated_comment.cpp.tpl @@ -0,0 +1,46 @@ +{# +# Copyright (C) 2017 Pelagicore AG +# Contact: https://www.qt.io/licensing/ +# +# This file is part of the QtIvi module of the Qt Toolkit. +# +# $QT_BEGIN_LICENSE:LGPL-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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +/**************************************************************************** +** Generated from '{{module}}.qface' +** +** Created by: The QFace generator (QtAS {{qtASVersion}}) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + diff --git a/src/tools/ivigenerator/templates_test/main.cpp.tpl b/src/tools/ivigenerator/templates_test/main.cpp.tpl new file mode 100644 index 0000000..f5bc66a --- /dev/null +++ b/src/tools/ivigenerator/templates_test/main.cpp.tpl @@ -0,0 +1,54 @@ +{# +# 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:LGPL-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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +{% include "generated_comment.cpp.tpl" %} +#include <QtTest> +{% for interface in module.interfaces %} +#include "tst_{{interface|lower}}.h" +{% endfor %} + +int main(int argc, char *argv[]) +{ + int returnCode = 0; + {% for interface in module.interfaces %} + {{interface}}Test {{interface|lower}}; + returnCode += QTest::qExec(&{{interface|lower}}, argc, argv); + {% endfor %} + + return returnCode; +} diff --git a/src/tools/ivigenerator/templates_test/module.pri.tpl b/src/tools/ivigenerator/templates_test/module.pri.tpl new file mode 100644 index 0000000..f470991 --- /dev/null +++ b/src/tools/ivigenerator/templates_test/module.pri.tpl @@ -0,0 +1,53 @@ +{# +# 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:LGPL-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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +############################################################################# +## This is an auto-generated file. +## Do not edit! All changes made to it will be lost. +############################################################################# + +HEADERS += \ +{% for interface in module.interfaces %} + $$PWD/tst_{{interface|lower}}.h \ +{% endfor %} + +SOURCES += \ +{% for interface in module.interfaces %} + $$PWD/tst_{{interface|lower}}.cpp \ +{% endfor %} + $$PWD/main.cpp \ diff --git a/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl b/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl new file mode 100644 index 0000000..09e59e2 --- /dev/null +++ b/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl @@ -0,0 +1,426 @@ +{# +# 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:LGPL-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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +{% include "generated_comment.cpp.tpl" %} +{% set interface_zoned = interface.tags.config and interface.tags.config.zoned %} +#include "tst_{{interface|lower}}.h" + +#include <QtIviCore/QIviServiceManager> +#include <QtIviCore/QIviServiceObject> + +#include <{{interface|lower}}.h> +#include <{{interface|lower}}backendinterface.h> + +{% for property in interface.properties %} +{% if property.is_model and property.type.nested.is_complex %} +#include <{{property.type.nested.type|lower}}model.h> +{% endif %} +{% endfor %} + +class {{interface}}TestBackend : public {{interface}}BackendInterface +{ + Q_OBJECT + +public: + {{interface}}TestBackend() + : {{interface}}BackendInterface() +{% for property in interface.properties %} + , m_{{property}}({{property|default_type_value}}) +{% endfor %} + { +{% if interface.tags.config.zoned %} + m_zones << "TestZone1" << "TestZone2"; + for (const QString &z : qAsConst(m_zones)) { +{% for property in interface.properties %} + m_zone{{property|upperfirst}}[z] = {{property|default_type_value}}; +{% endfor %} + } +{% endif %} + } + +{% if interface.tags.config.zoned %} + QStringList availableZones() const override + { + return m_zones; + } +{% endif %} + + void initialize() override + { +{% for property in interface.properties %} + emit {{property}}Changed(m_{{property}}{% if interface.tags.config.zoned %}, QString(){% endif %}); +{% endfor%} + +{% if interface.tags.config.zoned %} + QStringList zones = availableZones(); + for (const QString &zone : qAsConst(zones)) { +{% for property in interface.properties %} + emit {{property}}Changed(m_zone{{property|upperfirst}}[zone], zone); +{% endfor %} + } +{% endif %} + emit initializationDone(); + } + +{% if interface.tags.config.zoned %} +{% for property in interface.properties %} + void set{{property|upperfirst}}({{property|parameter_type}}{% if interface_zoned %}, const QString &z{% endif %}) {% if not property.readonly and not property.const %}override{%endif%} + + { + if (!m_zone{{property|upperfirst}}.contains(z)) { + if (m_{{property}} != {{property}}) { + m_{{property}} = {{property}}; + emit {{property}}Changed(m_{{property}}, z); + } + return; + } + + if (m_zone{{property|upperfirst}}[z] != {{property}}){ + m_zone{{property|upperfirst}}[z] = {{property}}; + emit {{property}}Changed(m_zone{{property|upperfirst}}[z], z); + } + } +{% endfor %} +{% else %} +{% for property in interface.properties %} + void set{{property|upperfirst}}({{property|parameter_type}}{% if interface_zoned %}, const QString &z{% endif %}) {% if not property.readonly and not property.const %}override{%endif%} + + { + if (m_{{property}} != {{property}}) { + m_{{property}} = {{property}}; + emit {{property}}Changed(m_{{property}}); + } + } +{% endfor%} +{% endif %} + +{% for signal in interface.signals %} + virtual void trigger{{signal|upperfirst}}({{signal.parameters|map('parameter_type')|join(', ')}}{% if interface_zoned %}{% + if signal.parameters|length %}, {%endif%}const QString &zone{% endif %}) + { + emit {{signal}}({% if signal.parameters|length %}{{signal.parameters|join(', ')}}{% endif %}{% + if interface_zoned %}{%if signal.parameters|length %}, {%endif%} zone{% endif %}); + } +{% endfor %} + +{% for operation in interface.operations %} + virtual {{operation|return_type}} {{operation}}({{operation.parameters|map('parameter_type')|join(', ')}}{% if interface_zoned %}{% + if operation.parameters|length %}, {%endif%}const QString &zone{% endif %}) override + { + emit {{operation}}Called({% if operation.parameters|length %}{{operation.parameters|join(', ')}}{% endif %}{% + if interface_zoned %}{%if operation.parameters|length %}, {%endif%} zone{% endif %}); + return {{operation|return_type}}(); + } + + Q_SIGNAL void {{operation}}Called({{operation.parameters|map('parameter_type')|join(', ')}}{% if interface_zoned %}{% + if operation.parameters|length %}, {%endif%}const QString &zone{% endif %}); + +{% endfor %} + +private: +{% for property in interface.properties %} + {{property|return_type}} m_{{property}}; +{% endfor %} + +{% if interface.tags.config.zoned %} +{% for property in interface.properties %} + QMap<QString, {{property|return_type}}> m_zone{{property|upperfirst}}; +{% endfor %} +{% endif %} + + QStringList m_zones; +}; + +class {{interface}}TestServiceObject : public QIviServiceObject { + +public: + explicit {{interface}}TestServiceObject(QObject *parent=nullptr) : + QIviServiceObject(parent), m_name(QLatin1String("")) + { + m_backend = new {{interface}}TestBackend; + m_interfaces << {{module.module_name}}_{{interface}}_iid; + } + + QString name() const { return m_name; } + QStringList interfaces() const { return m_interfaces; } + QIviFeatureInterface *interfaceInstance(const QString& interface) const + { + if (interface == {{module.module_name}}_{{interface}}_iid) + return testBackend(); + else + return nullptr; + } + + {{interface}}TestBackend *testBackend() const + { + return m_backend; + } + +private: + QString m_name; + QStringList m_interfaces; + {{interface}}TestBackend *m_backend; +}; + +class {{interface}}InvalidInterface : public QIviFeatureInterface +{ + Q_OBJECT +public: + {{interface}}InvalidInterface(QObject *parent) + : QIviFeatureInterface(parent) + {} + + void initialize() override + { + emit initializationDone(); + } +}; + +class {{interface}}InvalidServiceObject : public QIviServiceObject { + +public: + explicit {{interface}}InvalidServiceObject(QObject *parent=nullptr) : + QIviServiceObject(parent), m_name(QLatin1String("")), m_dummyBackend(new {{interface}}InvalidInterface(this)) + { + m_interfaces << {{module.module_name}}_{{interface}}_iid; + } + + QString name() const { return m_name; } + QStringList interfaces() const { return m_interfaces; } + QIviFeatureInterface *interfaceInstance(const QString& ) const { return m_dummyBackend; } + +private: + QString m_name; + QStringList m_interfaces; + QIviFeatureInterface *m_dummyBackend; +}; + +{{interface}}Test::{{interface}}Test() + : QObject() +{ + {{module.module_name}}Module::registerTypes(); + manager = QIviServiceManager::instance(); +} + +void {{interface}}Test::cleanup() +{ + manager->unloadAllBackends(); +} + +void {{interface}}Test::testWithoutBackend() +{ + {{interface}} cc; + + // Running without a backend means that changes do not propagate +{% for property in interface.properties %} + //Test {{property}} + {{property|parameter_type}}DefaultValue = {{property|default_type_value}}; + {{property|parameter_type}}Value = cc.{{property|getter_name}}(); + //Test that the current value of a property is the type default value; + QCOMPARE({{property}}Value, {{property}}DefaultValue); + +{% if not property.readonly and not property.const %} + //Test that this is still the case if we try to change it, as we don't + //have a connected backend + QSignalSpy {{property}}Spy(&cc, SIGNAL({{property}}Changed({{property|return_type}}))); + cc.{{property|setter_name}}({{property|test_type_value}}); + QCOMPARE({{property}}Spy.count(), 1); + QCOMPARE({{property}}Spy.at(0).at(0).value<{{property|return_type}}>(), {{property}}DefaultValue); + QCOMPARE(cc.{{property|getter_name}}(), {{property}}DefaultValue); +{% endif %} + +{% endfor %} +{% if interface.tags.config.zoned %} + QCOMPARE(cc.zones().count(), 0); +{% endif %} +} + +void {{interface}}Test::testInvalidBackend() +{ + {{interface}}InvalidServiceObject *service = new {{interface}}InvalidServiceObject(); + manager->registerService(service, service->interfaces()); + {{interface}} cc; + cc.startAutoDiscovery(); + + // Running without a backend means that changes do not propagate +{% for property in interface.properties %} + //Test {{property}} + {{property|parameter_type}}DefaultValue = {{property|default_type_value}}; + {{property|parameter_type}}Value = cc.{{property|getter_name}}(); + //Test that the current value of a property is the type default value; + QCOMPARE({{property}}Value, {{property}}DefaultValue); + +{% if not property.readonly and not property.const %} + //Test that this is still the case if we try to change it, as we don't + //have a connected backend + QSignalSpy {{property}}Spy(&cc, SIGNAL({{property}}Changed({{property|return_type}}))); + cc.{{property|setter_name}}({{property|test_type_value}}); + QCOMPARE({{property}}Spy.count(), 1); + QCOMPARE({{property}}Spy.at(0).at(0).value<{{property|return_type}}>(), {{property}}DefaultValue); + QCOMPARE(cc.{{property|getter_name}}(), {{property}}DefaultValue); +{% endif %} + +{% endfor %} + +{% if interface.tags.config.zoned %} + QCOMPARE(cc.zones().count(), 0); +{% endif %} +} + +void {{interface}}Test::testClearServiceObject() +{ + {{interface}}TestServiceObject *service = new {{interface}}TestServiceObject(); + manager->registerService(service, service->interfaces()); + +{% for property in interface.properties %} + {{property|parameter_type}}TestValue = {{property|test_type_value}}; +{% if interface_zoned %} + service->testBackend()->set{{property|upperfirst}}({{property}}TestValue, QString()); +{% else %} + service->testBackend()->set{{property|upperfirst}}({{property}}TestValue); +{% endif %} +{% endfor %} + + {{interface}} cc; + cc.startAutoDiscovery(); + +{% if interface.tags.config.zoned %} + QVERIFY(!cc.zones().isEmpty()); +{% endif %} + +{% for property in interface.properties %} + QCOMPARE(cc.{{property|getter_name}}(), {{property}}TestValue); +{% endfor %} + + cc.setServiceObject(nullptr); + +{% for property in interface.properties %} + QCOMPARE(cc.{{property|getter_name}}(), {{property|default_type_value}}); +{% endfor %} + +{% if interface.tags.config.zoned %} + QCOMPARE(cc.zones().count(), 0); +{% endif %} +} + +void {{interface}}Test::testChangeFromBackend() +{ + {{interface}}TestServiceObject *service = new {{interface}}TestServiceObject(); + manager->registerService(service, service->interfaces()); + + {{interface}} cc; + cc.startAutoDiscovery(); + +{% for property in interface.properties %} + //Test {{property}} + QSignalSpy {{property}}Spy(&cc, SIGNAL({{property}}Changed({{property|return_type}}))); + QCOMPARE({{property}}Spy.count(), 0); + {{property|parameter_type}}TestValue = {{property|test_type_value}}; + QCOMPARE(cc.{{property|getter_name}}(), {{property|default_type_value}}); +{% if interface_zoned %} + service->testBackend()->set{{property|upperfirst}}({{property}}TestValue, QString()); +{% else %} + service->testBackend()->set{{property|upperfirst}}({{property}}TestValue); +{% endif %} + QCOMPARE({{property}}Spy.count(), 1); + QCOMPARE(cc.{{property|getter_name}}(), {{property}}TestValue); + +{% endfor %} +} + +void {{interface}}Test::testChangeFromFrontend() +{ + {{interface}}TestServiceObject *service = new {{interface}}TestServiceObject(); + manager->registerService(service, service->interfaces()); + + {{interface}} cc; + cc.startAutoDiscovery(); + +{% for property in interface.properties %} +{% if not property.readonly and not property.const %} + //Test {{property}} + QSignalSpy {{property}}Spy(&cc, SIGNAL({{property}}Changed({{property|return_type}}))); + QCOMPARE({{property}}Spy.count(), 0); + QCOMPARE(cc.{{property|getter_name}}(), {{property|default_type_value}}); + {{property|parameter_type}}TestValue = {{property|test_type_value}}; + cc.{{property|setter_name}}({{property}}TestValue); + QCOMPARE({{property}}Spy.count(), 1); + QCOMPARE(cc.{{property|getter_name}}(), {{property}}TestValue); + +{% endif %} +{% endfor %} +} + +void {{interface}}Test::testMethods() +{ + {{interface}}TestServiceObject *service = new {{interface}}TestServiceObject(); + manager->registerService(service, service->interfaces()); + + {{interface}} cc; + cc.startAutoDiscovery(); + +{% for operation in interface.operations %} + //Test {{operation}} + QSignalSpy {{operation}}Spy(service->testBackend(), SIGNAL({{operation}}Called({{operation.parameters|map('return_type')|join(', ')}}{%if interface_zoned %}{% + if operation.parameters|length %}, {%endif%}QString{% endif %}))); + + cc.{{operation}}({% if operation.parameters|length %}{{operation.parameters|map('test_type_value')|join(' ')}}{% endif %}); + QCOMPARE({{operation}}Spy.count(), 1); + +{% endfor %} +} + +void {{interface}}Test::testSignals() +{ + {{interface}}TestServiceObject *service = new {{interface}}TestServiceObject(); + manager->registerService(service, service->interfaces()); + + {{interface}} cc; + cc.startAutoDiscovery(); + +{% for signal in interface.signals %} + //Test {{signal}} + QSignalSpy {{signal}}Spy(&cc, SIGNAL({{signal}}({{signal.parameters|map('return_type')|join(', ')}}))); + service->testBackend()->trigger{{signal|upperfirst}}({{signal.parameters|map('test_type_value')|join(' ')}}{%if interface_zoned %}{% + if signal.parameters|length %}, {%endif%}QString(){% endif %}); + QCOMPARE({{signal}}Spy.count(), 1); + +{% endfor %} +} + +#include "tst_{{interface|lower}}.moc" diff --git a/src/tools/ivigenerator/templates_test/tst_test.h.tpl b/src/tools/ivigenerator/templates_test/tst_test.h.tpl new file mode 100644 index 0000000..d97b126 --- /dev/null +++ b/src/tools/ivigenerator/templates_test/tst_test.h.tpl @@ -0,0 +1,65 @@ +{# +# 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:LGPL-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 Lesser General Public License Usage +# Alternatively, this file may be used under the terms of the GNU Lesser +# General Public License version 3 as published by the Free Software +# Foundation and appearing in the file LICENSE.LGPL3 included in the +# packaging of this file. Please review the following information to +# ensure the GNU Lesser General Public License version 3 requirements +# will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +# +# GNU General Public License Usage +# Alternatively, this file may be used under the terms of the GNU +# General Public License version 2.0 or (at your option) the GNU General +# Public license version 3 or any later version approved by the KDE Free +# Qt Foundation. The licenses are as published by the Free Software +# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +# 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-2.0.html and +# https://www.gnu.org/licenses/gpl-3.0.html. +# +# $QT_END_LICENSE$ +# +# SPDX-License-Identifier: LGPL-3.0 +#} +{% include "generated_comment.cpp.tpl" %} +{% set interface_zoned = interface.tags.config and interface.tags.config.zoned %} +#include <QtTest> + +QT_FORWARD_DECLARE_CLASS(QIviServiceManager); + +class {{interface}}Test : public QObject +{ + Q_OBJECT + +public: + {{interface}}Test(); + +private slots: + void cleanup(); + + void testWithoutBackend(); + void testInvalidBackend(); + void testClearServiceObject(); + void testChangeFromBackend(); + void testChangeFromFrontend(); + void testMethods(); + void testSignals(); + +private: + QIviServiceManager *manager; +}; diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index bf3f50d..561f32b 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs qtHaveModule(ivicore): SUBDIRS += core -#qtHaveModule(ivivehiclefunctions): SUBDIRS += vehiclefunctions +qtHaveModule(ivivehiclefunctions): SUBDIRS += vehiclefunctions qtHaveModule(geniviextras): SUBDIRS += dlt diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro index 0902433..13144fc 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/frontend/frontend.pro @@ -8,5 +8,7 @@ QT += ivicore ivicore-private qml quick DEFINES += QT_BUILD_NOPRIVATE_LIB +macos: QMAKE_SONAME_PREFIX = @rpath + QFACE_SOURCES = ../../../org.example.echo.noprivate.qface diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/org-example-echo-noprivate.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/org-example-echo-noprivate.pro index 8922ad6..40feb20 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/org-example-echo-noprivate.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/org-example-echo-noprivate.pro @@ -4,7 +4,8 @@ QT_FOR_CONFIG += ivicore SUBDIRS = frontend \ backend_simulator \ - validator + validator \ + test qtConfig(simulator) { SUBDIRS += control_panel @@ -12,3 +13,4 @@ qtConfig(simulator) { backend_simulator.depends = frontend validator.depends = frontend +test.depends = frontend diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/test/test.pro b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/test/test.pro new file mode 100644 index 0000000..f30a1c4 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo-noprivate/test/test.pro @@ -0,0 +1,13 @@ +TARGET = tst_org-example-echo-noprivate +DESTDIR = ../ + +QT += testlib core ivicore +CONFIG += c++11 ivigenerator testcase + +INCLUDEPATH += $$OUT_PWD/../frontend +LIBS += -L$$OUT_PWD/.. -l$$qtLibraryTarget(echo_noprivate_frontend) + +QMAKE_RPATHDIR += $$OUT_PWD/.. + +QFACE_FORMAT = test +QFACE_SOURCES = ../../../org.example.echo.noprivate.qface diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo/frontend/frontend.pro b/tests/auto/core/ivigenerator/projects/org-example-echo/frontend/frontend.pro index fdecab8..af958af 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo/frontend/frontend.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo/frontend/frontend.pro @@ -8,5 +8,7 @@ QT += ivicore ivicore-private qml quick DEFINES += QT_BUILD_ECHO_LIB +macos: QMAKE_SONAME_PREFIX = @rpath + QFACE_SOURCES = ../../../org.example.echo.qface diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo/org-example-echo.pro b/tests/auto/core/ivigenerator/projects/org-example-echo/org-example-echo.pro index 7083d85..2446d17 100644 --- a/tests/auto/core/ivigenerator/projects/org-example-echo/org-example-echo.pro +++ b/tests/auto/core/ivigenerator/projects/org-example-echo/org-example-echo.pro @@ -3,6 +3,8 @@ TEMPLATE = subdirs SUBDIRS = frontend \ backend_simulator \ validator \ + test \ backend_simulator.depends = frontend validator.depends = frontend +test.depends = frontend diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo/test/test.pro b/tests/auto/core/ivigenerator/projects/org-example-echo/test/test.pro new file mode 100644 index 0000000..17cfdd7 --- /dev/null +++ b/tests/auto/core/ivigenerator/projects/org-example-echo/test/test.pro @@ -0,0 +1,13 @@ +TARGET = tst_org-example-echo +DESTDIR = ../ + +QT += testlib core ivicore +CONFIG += c++11 ivigenerator testcase + +INCLUDEPATH += $$OUT_PWD/../frontend +LIBS += -L$$OUT_PWD/.. -l$$qtLibraryTarget(echo_frontend) + +QMAKE_RPATHDIR += $$OUT_PWD/.. + +QFACE_FORMAT = test +QFACE_SOURCES = ../../../org.example.echo.qface diff --git a/tests/auto/vehiclefunctions/basic/basic.pro b/tests/auto/vehiclefunctions/basic/basic.pro new file mode 100644 index 0000000..f67bb18 --- /dev/null +++ b/tests/auto/vehiclefunctions/basic/basic.pro @@ -0,0 +1,7 @@ +TARGET = tst_basic + +QT += testlib core ivicore ivivehiclefunctions +CONFIG += c++11 ivigenerator testcase + +QFACE_FORMAT = test +QFACE_SOURCES += ../../../../src/ivivehiclefunctions/ivivehiclefunctions.qface diff --git a/tests/auto/vehiclefunctions/vehiclefunctions.pro b/tests/auto/vehiclefunctions/vehiclefunctions.pro index cea792f..f8e6ba3 100644 --- a/tests/auto/vehiclefunctions/vehiclefunctions.pro +++ b/tests/auto/vehiclefunctions/vehiclefunctions.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs -SUBDIRS = climatecontroltest \ +SUBDIRS = basic +#SUBDIRS = climatecontroltest \ windowcontroltest |