diff options
author | Jaroslaw Kubik <jarek@froglogic.com> | 2019-02-05 22:34:30 +0100 |
---|---|---|
committer | Bramastyo Harimukti Santoso <bramastyo.harimukti.santoso@pelagicore.com> | 2019-02-13 14:14:27 +0000 |
commit | b7f0326b87aa682fcd7c2ae92bf1f858d7c97c5e (patch) | |
tree | ffcee548d3fbca29d1151fa042467f53b2313542 | |
parent | 7bbaca145724afbede057381d8c8176aa543fd02 (diff) |
[squish] Added a froglogic Squish hook plugin
A small plugin that simplifies hooking of the applications managed
by the Qt Application Manager with froglogic Squish GUI Tester.
It requires each application to have a unique TCP port assigned in
the manifest file. Started applications will use that port to listen
for incoming connections.
Change-Id: I44f35d3ea3d49c817d1aec5052f984b798c98e37
Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
Reviewed-by: Bramastyo Harimukti Santoso <bramastyo.harimukti.santoso@pelagicore.com>
-rw-r--r-- | plugins/plugins.pro | 4 | ||||
-rw-r--r-- | plugins/squishhook/README | 31 | ||||
-rw-r--r-- | plugins/squishhook/appmanhook_global.h | 43 | ||||
-rw-r--r-- | plugins/squishhook/appmansquishhook.cpp | 118 | ||||
-rw-r--r-- | plugins/squishhook/appmansquishhook.h | 63 | ||||
-rw-r--r-- | plugins/squishhook/squish-appman-hook.yaml | 15 | ||||
-rw-r--r-- | plugins/squishhook/squishhook.pro | 25 |
7 files changed, 299 insertions, 0 deletions
diff --git a/plugins/plugins.pro b/plugins/plugins.pro index 7f0534f0..c8ebc14a 100644 --- a/plugins/plugins.pro +++ b/plugins/plugins.pro @@ -8,3 +8,7 @@ SUBDIRS = \ style \ systeminfo \ com.pelagicore.map + +!isEmpty(SQUISH_PREFIX) { + SUBDIRS += squishhook +} diff --git a/plugins/squishhook/README b/plugins/squishhook/README new file mode 100644 index 00000000..ea1440f7 --- /dev/null +++ b/plugins/squishhook/README @@ -0,0 +1,31 @@ + +1. What is Appman Squish Hook plugin? +================================ + +It is a plugin for the Qt Application Manager (appman) and +applications using the appman qml runtime. It simplifies usage of +Squish with applications managed by appman. +The Qt Application Manager keeps the sub-applications under tight +control, which makes hooking it with Squish difficult. The Squish Hook +Plugin turns the applicatons using appman runtime into attachable +applications, using the TCP port specified in the appliation mainfest +file. + +2. Usage +================================ + +Once the Appman Squish Plugin is installed, it can be used by passing +the path to the squish-appman-hook.yaml configuration file: + +appman [...] -c squish-appman-hook.yaml + +Alternatively, the contents of the file can be manually merged with +the main configuration file. +The TCP port for each of the tested applications must be specified in +the application manifest file by adding a squishPort parameter: + +applicationProperties: { private: { squishPort: 45678 } } + +The application needs to be registered with the squishserver under the +specified port. Once the application is started using base appman GUI, +it can be attached to with the attachToApplication() Squish test API. diff --git a/plugins/squishhook/appmanhook_global.h b/plugins/squishhook/appmanhook_global.h new file mode 100644 index 00000000..448726d4 --- /dev/null +++ b/plugins/squishhook/appmanhook_global.h @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2019 froglogic GmbH +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Neptune IVI UI. +** +** $QT_BEGIN_LICENSE:GPL-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 or (at your option) 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.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-3.0.html. +** +** $QT_END_LICENSE$ +** +** SPDX-License-Identifier: GPL-3.0 +** +****************************************************************************/ + +#ifndef APPMANHOOK_GLOBAL_H +#define APPMANHOOK_GLOBAL_H + +#include <QtCore/qglobal.h> + +#if defined(APPMANHOOK_LIBRARY) +# define APPMANHOOKSHARED_EXPORT Q_DECL_EXPORT +#else +# define APPMANHOOKSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // APPMANHOOK_GLOBAL_H diff --git a/plugins/squishhook/appmansquishhook.cpp b/plugins/squishhook/appmansquishhook.cpp new file mode 100644 index 00000000..20600072 --- /dev/null +++ b/plugins/squishhook/appmansquishhook.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2019 froglogic GmbH +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Neptune IVI UI. +** +** $QT_BEGIN_LICENSE:GPL-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 or (at your option) 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.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-3.0.html. +** +** $QT_END_LICENSE$ +** +** SPDX-License-Identifier: GPL-3.0 +** +****************************************************************************/ + +#include "appmansquishhook.h" + +#include "qtbuiltinhook.h" + +#include <qdebug.h> +#include <qqmlengine.h> +#include <qqmlcontext.h> + +AppmanSquishhook::AppmanSquishhook() + : port( -1 ), + listening( false ) +{} + +void AppmanSquishhook::initialize(const QVariantMap &systemProperties) Q_DECL_NOEXCEPT_EXPR(false) +{ + QVariantMap::const_iterator portIt = systemProperties.find( "squishPort" ); + if ( portIt != systemProperties.end() ) { + bool ok = false; + int p = portIt->toInt( &ok ); + if ( ok ) { + port = p; + } else { + qDebug() << "squishPort system property is invalid"; + } + } +} + +void AppmanSquishhook::afterRuntimeRegistration() Q_DECL_NOEXCEPT_EXPR(false) +{} + +void AppmanSquishhook::beforeQmlEngineLoad(QQmlEngine *engine) Q_DECL_NOEXCEPT_EXPR(false) +{ + if ( listening ) { + return; + } + + listening = true; + int p = getApplicationPort( engine ); + if ( p > 0 ) { + port = p; + } + qDebug() << "squishPort is set to " << port; + if ( port > 0 ) { + Squish::allowAttaching( port ); + } +} + +void AppmanSquishhook::afterQmlEngineLoad(QQmlEngine *) Q_DECL_NOEXCEPT_EXPR(false) +{} + +void AppmanSquishhook::beforeWindowShow(QWindow *) Q_DECL_NOEXCEPT_EXPR(false) +{} + +void AppmanSquishhook::afterWindowShow(QWindow *) Q_DECL_NOEXCEPT_EXPR(false) +{} + +int AppmanSquishhook::getApplicationPort(QQmlEngine* engine) +{ + QVariant ai = engine->rootContext()->contextProperty( "ApplicationInterface" ); + if ( !ai.isValid() ) { + qDebug() << "ApplicationInterface is not present"; + return -1; + } + QObject* aio = ai.value<QObject*>(); + if ( !aio ) { + qDebug() << "ApplicationInterface is not a QObject"; + return -1; + } + QVariant appProps = aio->property( "applicationProperties" ); + if ( appProps.type() != QVariant::Map ) { + qDebug() << "ApplicationInterface has no applicationProperties map"; + return -1; + } + QVariantMap appPropsMap = appProps.toMap(); + QVariantMap::const_iterator it = appPropsMap.find( "squishPort" ); + if ( it == appPropsMap.end() ) { + qDebug() << "applicationProperties do not specify squish port"; + return -1; + } + bool ok = false; + int port = it->toInt( &ok ); + if ( !ok ) { + qDebug() << "squishPort is not a valid string"; + return -1; + } + return port; +} diff --git a/plugins/squishhook/appmansquishhook.h b/plugins/squishhook/appmansquishhook.h new file mode 100644 index 00000000..edd2f117 --- /dev/null +++ b/plugins/squishhook/appmansquishhook.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2019 froglogic GmbH +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Neptune IVI UI. +** +** $QT_BEGIN_LICENSE:GPL-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 or (at your option) 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.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-3.0.html. +** +** $QT_END_LICENSE$ +** +** SPDX-License-Identifier: GPL-3.0 +** +****************************************************************************/ + +#ifndef APPMANSQUISHHOOK_H +#define APPMANSQUISHHOOK_H + +#include "appmanhook_global.h" + +#include <qvariant.h> +#include <startupinterface.h> + +class APPMANHOOKSHARED_EXPORT AppmanSquishhook : public QObject, public StartupInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "com.froglogic.squish.appman.hookplug") + Q_INTERFACES(StartupInterface) +public: + AppmanSquishhook(); + + virtual void initialize(const QVariantMap &systemProperties) Q_DECL_NOEXCEPT_EXPR(false); + + virtual void afterRuntimeRegistration() Q_DECL_NOEXCEPT_EXPR(false); + virtual void beforeQmlEngineLoad(QQmlEngine *engine) Q_DECL_NOEXCEPT_EXPR(false); + virtual void afterQmlEngineLoad(QQmlEngine *engine) Q_DECL_NOEXCEPT_EXPR(false); + + virtual void beforeWindowShow(QWindow *window) Q_DECL_NOEXCEPT_EXPR(false); + virtual void afterWindowShow(QWindow *window) Q_DECL_NOEXCEPT_EXPR(false); +private: + static int getApplicationPort(QQmlEngine* engine); + + int port; + bool listening; +}; + +#endif // APPMANSQUISHHOOK_H diff --git a/plugins/squishhook/squish-appman-hook.yaml b/plugins/squishhook/squish-appman-hook.yaml new file mode 100644 index 00000000..53c24316 --- /dev/null +++ b/plugins/squishhook/squish-appman-hook.yaml @@ -0,0 +1,15 @@ +formatVersion: 1 +formatType: am-configuration +--- + +plugins: + startup: [ "PATH_TO_THE_HOOK_LIBRARY" ] +systemProperties: + public: + squishPort: 7777 + +runtimes: + qml: + plugins: + startup: [ "PATH_TO_THE_HOOK_LIBRARY" ] + diff --git a/plugins/squishhook/squishhook.pro b/plugins/squishhook/squishhook.pro new file mode 100644 index 00000000..2e4dee58 --- /dev/null +++ b/plugins/squishhook/squishhook.pro @@ -0,0 +1,25 @@ +QT -= gui +QT += qml appman_plugininterfaces_private + +TARGET = AppmanSquishHook +TEMPLATE = lib + +isEmpty(SQUISH_PREFIX) { + error( Please specify the path to the Squish installation under $${SQUISH_PREFIX} ) +} + +include( $${SQUISH_PREFIX}/qtbuiltinhook.pri ) + +DEFINES += APPMANHOOK_LIBRARY + +SOURCES += \ + appmansquishhook.cpp + +HEADERS += \ + appmansquishhook.h \ + appmanhook_global.h + +target.path = $${INSTALL_PREFIX}/neptune3/lib +config.path = $${INSTALL_PREFIX}/neptune3 +config.extra = sed "\'s\\PATH_TO_THE_HOOK_LIBRARY\\$${INSTALL_PREFIX}/neptune3/lib/libAppmanSquishHook.so\\;w $${INSTALL_PREFIX}/neptune3/squish-appman-hook.yaml\'" $${PWD}/squish-appman-hook.yaml +INSTALLS += target config |