on xenial help sign in
add a mock InputInfo plugin - not loading yet
commit7b3f46eb1d064e4597a09028c32a21ed1b62ba25 authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 23 Jun 2015, 16:20 (11 years ago) parent95d4294
8 files changed+543
tests/mocks/Unity/InputInfo/CMakeLists.txt+21 tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo.cpp+140 tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo_p.h+86 tests/mocks/Unity/InputInfo/mockqinputinfo.cpp+104 tests/mocks/Unity/InputInfo/mockqinputinfo.h+127 tests/mocks/Unity/InputInfo/plugin.cpp+33 tests/mocks/Unity/InputInfo/plugin.h+30 tests/mocks/Unity/InputInfo/qmldir+2
tests/mocks/Unity/InputInfo/CMakeLists.txtnew file+21
@@ -0,0 +1,21 @@
1+find_package(Qt5Core REQUIRED)
2+find_package(Qt5Quick REQUIRED)
3+
4+include_directories(
5+ ${CMAKE_CURRENT_SOURCE_DIR}
6+ ${CMAKE_CURRENT_BINARY_DIR}
7+)
8+
9+set(MockInputInfo_SOURCES
10+ plugin.cpp
11+ mockqinputinfo.cpp
12+ mockqdeclarativeinputdeviceinfo.cpp
13+)
14+
15+add_library(MockInputInfo SHARED
16+ ${MockInputInfo_SOURCES}
17+)
18+
19+qt5_use_modules(MockInputInfo Core Qml Quick)
20+
21+add_unity8_mock(Unity.InputInfo 0.1 Unity/InputInfo TARGETS MockInputInfo)
tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo.cppnew file+140
@@ -0,0 +1,140 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2015 Jolla.
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+#include "mockqdeclarativeinputdeviceinfo_p.h"
42+
43+QDeclarativeInputDeviceInfo::QDeclarativeInputDeviceInfo(QObject *parent) :
44+ QAbstractListModel(parent),
45+ deviceInfo(new QInputDeviceInfo)
46+{
47+}
48+
49+QDeclarativeInputDeviceInfo::~QDeclarativeInputDeviceInfo()
50+{
51+ delete deviceInfo;
52+}
53+
54+QVariant QDeclarativeInputDeviceInfo::data(const QModelIndex &index, int role) const
55+{
56+ switch (role) {
57+ case ServiceRole:
58+ return QVariant::fromValue(static_cast<QObject *>(inputDevices.value(index.row())));
59+ }
60+
61+ return QVariant();
62+}
63+
64+int QDeclarativeInputDeviceInfo::rowCount(const QModelIndex &parent) const
65+{
66+ Q_UNUSED(parent);
67+
68+ return inputDevices.count();
69+}
70+
71+int QDeclarativeInputDeviceInfo::indexOf(const QString &devicePath) const
72+{
73+ int idx(-1);
74+ Q_FOREACH (QInputDevice *device, inputDevices) {
75+ idx++;
76+ if (device->devicePath() == devicePath) return idx;
77+ }
78+
79+ return -1;
80+}
81+
82+QInputDevice *QDeclarativeInputDeviceInfo::get(int index) const
83+{
84+ if (index < 0 || index > inputDevices.count())
85+ return 0;
86+ return inputDevices.value(index);
87+}
88+
89+void QDeclarativeInputDeviceInfo::updateDeviceList()
90+{
91+ QVector <QInputDevice *> newDevices = deviceInfo->deviceList();
92+
93+ int numNew = newDevices.count();
94+
95+ for (int i = 0; i < numNew; i++) {
96+ int j = inputDevices.indexOf(newDevices.value(i));
97+ if (j == -1) {
98+ // not found -> remove from list
99+ beginInsertRows(QModelIndex(), i, i);
100+ inputDevices.insert(i, newDevices.value(i));
101+ endInsertRows();
102+ } else if (i != j) {
103+ // changed its position -> move it
104+ QInputDevice* device = inputDevices.value(j);
105+ beginMoveRows(QModelIndex(), j, j, QModelIndex(), i);
106+ inputDevices.remove(j);
107+ inputDevices.insert(i, device);
108+ endMoveRows();
109+ } else {
110+ QModelIndex changedIndex(this->index(j, 0, QModelIndex()));
111+ Q_EMIT dataChanged(changedIndex, changedIndex);
112+ }
113+ }
114+
115+ int numOld = inputDevices.count();
116+ if (numOld > numNew) {
117+ beginRemoveRows(QModelIndex(), numNew, numOld - 1);
118+ inputDevices.remove(numNew, numOld - numNew);
119+ endRemoveRows();
120+ }
121+}
122+
123+void QDeclarativeInputDeviceInfo::addedDevice(const QString &devicePath)
124+{
125+ updateDeviceList();
126+ Q_EMIT newDevice(devicePath);
127+}
128+
129+void QDeclarativeInputDeviceInfo::removedDevice(const QString &devicePath)
130+{
131+ updateDeviceList();
132+ Q_EMIT deviceRemoved(devicePath);
133+}
134+
135+QHash<int, QByteArray> QDeclarativeInputDeviceInfo::roleNames() const
136+{
137+ QHash<int, QByteArray> roles;
138+ roles.insert(ServiceRole, "service");
139+ return roles;
140+}
tests/mocks/Unity/InputInfo/mockqdeclarativeinputdeviceinfo_p.hnew file+86
@@ -0,0 +1,86 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2015 Jolla.
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+
42+#ifndef QDECLARATIVEINPUTDEVICEINFO_H
43+#define QDECLARATIVEINPUTDEVICEINFO_H
44+
45+#include <QObject>
46+#include <QAbstractListModel>
47+#include "mockqinputinfo.h"
48+
49+class QDeclarativeInputDeviceInfo : public QAbstractListModel
50+{
51+ Q_OBJECT
52+ Q_DISABLE_COPY(QDeclarativeInputDeviceInfo)
53+
54+public:
55+ enum ItemRoles {
56+ ServiceRole = Qt::UserRole + 1
57+ };
58+
59+ explicit QDeclarativeInputDeviceInfo(QObject *parent = 0);
60+ virtual ~QDeclarativeInputDeviceInfo();
61+
62+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
63+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
64+
65+ QHash<int, QByteArray> roleNames() const;
66+
67+ Q_INVOKABLE int indexOf(const QString &devicePath) const;
68+
69+ Q_INVOKABLE QInputDevice *get(int index) const;
70+
71+Q_SIGNALS:
72+ void newDevice(const QString &devicePath);
73+ void deviceRemoved(const QString &devicePath);
74+
75+public Q_SLOTS:
76+ void updateDeviceList();
77+private:
78+ QInputDeviceInfo *deviceInfo;
79+ QVector<QInputDevice *> inputDevices;
80+private Q_SLOTS:
81+ void addedDevice(const QString &);
82+ void removedDevice(const QString &path);
83+
84+};
85+
86+#endif // QDECLARATIVEINPUTDEVICEINFO_H
tests/mocks/Unity/InputInfo/mockqinputinfo.cppnew file+104
@@ -0,0 +1,104 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+
42+#include "mockqinputinfo.h"
43+
44+
45+QInputDevice::QInputDevice(QObject *parent) :
46+ QObject(parent)
47+{
48+}
49+
50+QString QInputDevice::name() const
51+{
52+ return m_name;
53+}
54+
55+void QInputDevice::setName(const QString &name)
56+{
57+ m_name = name;
58+}
59+
60+QString QInputDevice::devicePath() const
61+{
62+ return "/mock/device/path";
63+}
64+
65+QList <int> QInputDevice::buttons() const
66+{
67+ return {1, 2 ,3};
68+}
69+
70+QList <int> QInputDevice::switches() const
71+{
72+ return {};
73+}
74+
75+QList <int> QInputDevice::relativeAxis() const
76+{
77+ return {};
78+}
79+
80+QList <int> QInputDevice::absoluteAxis() const
81+{
82+ return {};
83+}
84+
85+QInputDeviceInfo::InputTypes QInputDevice::types()
86+{
87+ return m_types;
88+}
89+
90+void QInputDevice::setTypes(QInputDeviceInfo::InputTypes types)
91+{
92+ m_types = types;
93+}
94+
95+
96+QInputDeviceInfo::QInputDeviceInfo(QObject *parent) :
97+ QObject(parent)
98+{
99+}
100+
101+QVector <QInputDevice *> QInputDeviceInfo::deviceList()
102+{
103+ return {};
104+}
tests/mocks/Unity/InputInfo/mockqinputinfo.hnew file+127
@@ -0,0 +1,127 @@
1+/****************************************************************************
2+**
3+** Copyright (C) 2014 Canonical, Ltd. and/or its subsidiary(-ies).
4+** Contact: http://www.qt-project.org/legal
5+**
6+** This file is part of the QtSystems module of the Qt Toolkit.
7+**
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
16+**
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24+**
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28+**
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
36+**
37+**
38+** $QT_END_LICENSE$
39+**
40+****************************************************************************/
41+
42+#ifndef MOCKQINPUTINFO_H
43+#define MOCKQINPUTINFO_H
44+
45+#include <QObject>
46+#include <QVector>
47+#include <QMap>
48+#include <QSocketNotifier>
49+#include <QDebug>
50+
51+class QInputDevicePrivate;
52+class QInputDevice;
53+
54+class QInputDeviceInfoPrivate;
55+class QInputDeviceInfo : public QObject
56+{
57+ Q_OBJECT
58+ Q_PROPERTY(int deviceCount READ deviceCount)
59+public:
60+
61+ enum InputType {
62+ Unknown = 0,
63+ Button = 1,
64+ Mouse = 2,
65+ TouchPad = 4,
66+ TouchScreen = 8,
67+ Keyboard = 16,
68+ Switch = 32
69+ };
70+ Q_ENUMS(InputType)
71+ Q_FLAGS(InputTypes)
72+ Q_DECLARE_FLAGS(InputTypes, InputType)
73+
74+ explicit QInputDeviceInfo(QObject *parent = 0);
75+
76+ Q_INVOKABLE QVector <QInputDevice *> deviceList();
77+
78+ int deviceCount() { return deviceList().count(); }
79+Q_SIGNALS:
80+
81+ void deviceAdded(const QString & devicePath);
82+ void deviceRemoved(const QString & devicePath);
83+
84+};
85+
86+class QInputDevice : public QObject
87+{
88+ friend class QInputDeviceInfoPrivate;
89+ Q_OBJECT
90+ Q_ENUMS(InputType)
91+ Q_FLAGS(InputTypes)
92+ Q_PROPERTY(QString name READ name NOTIFY nameChanged)
93+ Q_PROPERTY(QString devicePath READ devicePath NOTIFY devicePathChanged)
94+ Q_PROPERTY(QList <int> buttons READ buttons NOTIFY buttonsChanged)
95+ Q_PROPERTY(QList <int> switches READ switches NOTIFY switchesChanged)
96+ Q_PROPERTY(QList <int> relativeAxis READ relativeAxis NOTIFY relativeAxisChanged)
97+ Q_PROPERTY(QList <int> absoluteAxis READ absoluteAxis NOTIFY absoluteAxisChanged)
98+ Q_PROPERTY(QInputDeviceInfo::InputTypes types READ types NOTIFY typesChanged)
99+
100+public:
101+ explicit QInputDevice(QObject *parent = 0);
102+
103+ QString name() const;
104+ QString devicePath() const;
105+ QList <int> buttons() const; //keys event code
106+ QList <int> switches() const;
107+ QList <int> relativeAxis() const;
108+ QList <int> absoluteAxis() const;
109+
110+ QInputDeviceInfo::InputTypes types();
111+Q_SIGNALS:
112+ void nameChanged();
113+ void devicePathChanged();
114+ void buttonsChanged();
115+ void switchesChanged();
116+ void relativeAxisChanged();
117+ void absoluteAxisChanged();
118+ void typesChanged();
119+private:
120+ void setName(const QString &name);
121+ void setTypes(QInputDeviceInfo::InputTypes types);
122+
123+ QString m_name;
124+ QInputDeviceInfo::InputTypes m_types;
125+};
126+
127+#endif // MOCKQINPUTINFO_H
tests/mocks/Unity/InputInfo/plugin.cppnew file+33
@@ -0,0 +1,33 @@
1+/*
2+ * Copyright 2015 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+// Qt
18+#include <QtQml/qqml.h>
19+
20+// self
21+#include "plugin.h"
22+
23+// local
24+#include "mockqdeclarativeinputdeviceinfo_p.h"
25+
26+void InputInfoPlugin::registerTypes(const char *uri)
27+{
28+ int major = 0;
29+ int minor = 1;
30+ qDebug() << "****************** creating inputplugin";
31+ qmlRegisterType<QDeclarativeInputDeviceInfo>(uri, major, minor, "InputDeviceInfo");
32+ qmlRegisterType<QInputDevice>(uri, major, minor, "InputInfo");
33+}
tests/mocks/Unity/InputInfo/plugin.hnew file+30
@@ -0,0 +1,30 @@
1+/*
2+ * Copyright 2015 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef INPUTINFO_PLUGIN_H
18+#define INPUTINFO_PLUGIN_H
19+
20+#include <QtQml/QQmlExtensionPlugin>
21+
22+class InputInfoPlugin : public QQmlExtensionPlugin
23+{
24+ Q_OBJECT
25+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
26+public:
27+ void registerTypes(const char *uri);
28+};
29+
30+#endif // INPUTINFO_PLUGIN_H
tests/mocks/Unity/InputInfo/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module Unity.InputInfo
2+plugin MockInputInfo