diff options
author | Andre Hartmann <aha_1980@gmx.de> | 2017-03-10 06:55:00 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2017-03-30 05:51:39 +0000 |
commit | 4c9c77784a0acc86696a1c890f0026c741f81220 (patch) | |
tree | 6b0bbcf53972be4d397a4a305ea0bb22078c80bc | |
parent | d09ec5d8f496b7e3b5bdfef52f48e2d301be99f1 (diff) |
Add plugin to test CanBusFactory compatibility
Add a plugin that implements the now deprecated
QCanBusFactory to assure this still works.
Change-Id: Idd0e121ebdd324bacc01c1805ab43749a85c7a84
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r-- | tests/auto/plugins/genericcanbusv1/dummybackendv1.cpp | 80 | ||||
-rw-r--r-- | tests/auto/plugins/genericcanbusv1/dummybackendv1.h | 65 | ||||
-rw-r--r-- | tests/auto/plugins/genericcanbusv1/genericcanbusv1.pro | 17 | ||||
-rw-r--r-- | tests/auto/plugins/genericcanbusv1/main.cpp | 66 | ||||
-rw-r--r-- | tests/auto/plugins/genericcanbusv1/plugin.json | 3 | ||||
-rw-r--r-- | tests/auto/plugins/plugins.pro | 2 | ||||
-rw-r--r-- | tests/auto/qcanbus/tst_qcanbus.cpp | 11 |
7 files changed, 242 insertions, 2 deletions
diff --git a/tests/auto/plugins/genericcanbusv1/dummybackendv1.cpp b/tests/auto/plugins/genericcanbusv1/dummybackendv1.cpp new file mode 100644 index 0000000..117aeec --- /dev/null +++ b/tests/auto/plugins/genericcanbusv1/dummybackendv1.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Andre Hartmann <aha_1980@gmx.de> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSerialBus module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "dummybackendv1.h" + +#include <QtCore/qdatetime.h> +#include <QtCore/qdebug.h> +#include <QtCore/qtimer.h> + +QT_BEGIN_NAMESPACE + +DummyBackendV1::DummyBackendV1() : + sendTimer(new QTimer(this)) +{ + connect(sendTimer, &QTimer::timeout, [this]() { + const quint64 timeStamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); + QCanBusFrame dummyFrame(11, "abc"); + dummyFrame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(timeStamp * 1000)); + + enqueueReceivedFrames({dummyFrame}); + }); + sendTimer->start(1000); +} + +bool DummyBackendV1::open() +{ + setState(QCanBusDevice::ConnectedState); + return true; +} + +void DummyBackendV1::close() +{ + setState(QCanBusDevice::UnconnectedState); +} + +bool DummyBackendV1::writeFrame(const QCanBusFrame &data) +{ + qDebug("DummyBackendV1::writeFrame: %ls", qUtf16Printable(data.toString())); + return true; +} + +QString DummyBackendV1::interpretErrorFrame(const QCanBusFrame &/*errorFrame*/) +{ + return QString(); +} + +QT_END_NAMESPACE diff --git a/tests/auto/plugins/genericcanbusv1/dummybackendv1.h b/tests/auto/plugins/genericcanbusv1/dummybackendv1.h new file mode 100644 index 0000000..4c3fc64 --- /dev/null +++ b/tests/auto/plugins/genericcanbusv1/dummybackendv1.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Andre Hartmann <aha_1980@gmx.de> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSerialBus module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DUMMYBACKENDV1_H +#define DUMMYBACKENDV1_H + +#include <QtSerialBus/qcanbusdevice.h> + +QT_BEGIN_NAMESPACE + +class QTimer; + +class DummyBackendV1 : public QCanBusDevice +{ + Q_OBJECT +public: + explicit DummyBackendV1(); + + bool open() override; + void close() override; + + bool writeFrame(const QCanBusFrame &data) override; + + QString interpretErrorFrame(const QCanBusFrame &) override; + +private: + QTimer *sendTimer; +}; + +QT_END_NAMESPACE + +#endif // DUMMYBACKENDV1_H diff --git a/tests/auto/plugins/genericcanbusv1/genericcanbusv1.pro b/tests/auto/plugins/genericcanbusv1/genericcanbusv1.pro new file mode 100644 index 0000000..57c4aa1 --- /dev/null +++ b/tests/auto/plugins/genericcanbusv1/genericcanbusv1.pro @@ -0,0 +1,17 @@ +TARGET = qtcanbustestgenericv1 + +QT = core serialbus + +HEADERS += \ + dummybackendv1.h + +SOURCES += \ + main.cpp \ + dummybackendv1.cpp + +DISTFILES = plugin.json + +PLUGIN_TYPE = canbus +PLUGIN_EXTENDS = - +PLUGIN_CLASS_NAME = GenericBusPluginV1 +load(qt_plugin) diff --git a/tests/auto/plugins/genericcanbusv1/main.cpp b/tests/auto/plugins/genericcanbusv1/main.cpp new file mode 100644 index 0000000..3ed41f9 --- /dev/null +++ b/tests/auto/plugins/genericcanbusv1/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Andre Hartmann <aha_1980@gmx.de> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtSerialBus module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "dummybackendv1.h" + +#include <QtSerialBus/qcanbus.h> +#include <QtSerialBus/qcanbusfactory.h> + +QT_BEGIN_NAMESPACE + +class GenericBusPluginV1 : public QObject, public QCanBusFactory +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory" FILE "plugin.json") + Q_INTERFACES(QCanBusFactory) + +public: + QCanBusDevice *createDevice(const QString &interfaceName, QString *errorMessage) const override + { + if (interfaceName == QStringLiteral("invalid")) { + if (errorMessage) + *errorMessage = tr("No such interface: '%1'").arg(interfaceName); + + return nullptr; + } + auto device = new DummyBackendV1(); + return device; + } +}; + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/tests/auto/plugins/genericcanbusv1/plugin.json b/tests/auto/plugins/genericcanbusv1/plugin.json new file mode 100644 index 0000000..e9f0f4c --- /dev/null +++ b/tests/auto/plugins/genericcanbusv1/plugin.json @@ -0,0 +1,3 @@ +{ + "Key": "genericv1" +} diff --git a/tests/auto/plugins/plugins.pro b/tests/auto/plugins/plugins.pro index 58d4100..f4f4623 100644 --- a/tests/auto/plugins/plugins.pro +++ b/tests/auto/plugins/plugins.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += genericcanbus +SUBDIRS += genericcanbus genericcanbusv1 diff --git a/tests/auto/qcanbus/tst_qcanbus.cpp b/tests/auto/qcanbus/tst_qcanbus.cpp index fbab78a..7389b1e 100644 --- a/tests/auto/qcanbus/tst_qcanbus.cpp +++ b/tests/auto/qcanbus/tst_qcanbus.cpp @@ -81,11 +81,15 @@ void tst_QCanBus::plugins() const QStringList pluginList = bus->plugins(); QVERIFY(!pluginList.isEmpty()); QVERIFY(pluginList.contains("generic")); - + QVERIFY(pluginList.contains("genericv1")); } void tst_QCanBus::interfaces() { + // Plugins derived from QCanBusFactory(V1) don't have availableDevices() + const QList<QCanBusDeviceInfo> pluginListV1 = bus->availableDevices("genericV1"); + QVERIFY(pluginListV1.isEmpty()); + const QList<QCanBusDeviceInfo> pluginList = bus->availableDevices("generic"); QCOMPARE(1, pluginList.size()); QCOMPARE(QString("can0"), pluginList.at(0).name()); @@ -95,6 +99,11 @@ void tst_QCanBus::interfaces() void tst_QCanBus::createDevice() { + // Assure we can still create plugins derived from QCanBusFactory(V1) + QCanBusDevice *dummyV1 = bus->createDevice("genericv1", "unused"); + QVERIFY(dummyV1); + delete dummyV1; + QString error, error2; QCanBusDevice *dummy = bus->createDevice("generic", "unused"); QCanBusDevice *dummy2 = bus->createDevice("generic", "unused"); |