1 | /* |
2 | * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com> |
3 | * |
4 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #include "autotests.h" |
8 | |
9 | #include <QDBusObjectPath> |
10 | |
11 | #include <QQmlEngine> |
12 | #include <QtQuickTest> // krazy:exclude=includes |
13 | |
14 | #ifdef IMPORT_EXTENSIONS_QML_PLUGIN |
15 | #include <QPluginLoader> |
16 | Q_IMPORT_PLUGIN(BluezQtExtensionPlugin) |
17 | #endif |
18 | |
19 | class FakeBluezObject : public QObject |
20 | { |
21 | Q_OBJECT |
22 | |
23 | public Q_SLOTS: |
24 | void start() |
25 | { |
26 | FakeBluez::start(); |
27 | } |
28 | |
29 | void stop() |
30 | { |
31 | FakeBluez::stop(); |
32 | } |
33 | |
34 | bool isRunning() |
35 | { |
36 | return FakeBluez::isRunning(); |
37 | } |
38 | |
39 | void runTest(const QString &testName) |
40 | { |
41 | FakeBluez::runTest(testName); |
42 | } |
43 | |
44 | static void processProperties(QVariantMap &properties) |
45 | { |
46 | const QStringList &toDBusObjectPath = properties.value(QStringLiteral("_toDBusObjectPath" )).toStringList(); |
47 | for (const QString &name : toDBusObjectPath) { |
48 | const QString &val = properties.value(name).toString(); |
49 | properties[name] = QVariant::fromValue(QDBusObjectPath(val)); |
50 | } |
51 | properties.remove(QStringLiteral("_toDBusObjectPath" )); |
52 | |
53 | QMapIterator<QString, QVariant> it(properties); |
54 | while (it.hasNext()) { |
55 | it.next(); |
56 | if (it.key() == QLatin1String("UUIDs" )) { |
57 | properties[it.key()] = it.value().toStringList(); |
58 | } else if (it.value().userType() == QMetaType::QVariantMap) { |
59 | QVariantMap props = it.value().toMap(); |
60 | processProperties(props); |
61 | properties[it.key()] = props; |
62 | } |
63 | } |
64 | } |
65 | |
66 | void runAction(const QString &object, const QString &actionName, QVariantMap properties = QVariantMap()) |
67 | { |
68 | processProperties(properties); |
69 | FakeBluez::runAction(object, actionName, properties); |
70 | } |
71 | }; |
72 | |
73 | static QObject *fakebluez_singleton(QQmlEngine *engine, QJSEngine *scriptEngine) |
74 | { |
75 | Q_UNUSED(engine) |
76 | Q_UNUSED(scriptEngine) |
77 | |
78 | return new FakeBluezObject; |
79 | } |
80 | |
81 | namespace BluezQt |
82 | { |
83 | extern void bluezqt_initFakeBluezTestRun(); |
84 | } |
85 | |
86 | int main(int argc, char *argv[]) |
87 | { |
88 | qmlRegisterSingletonType<QObject>("org.kde.bluezqt.fakebluez" , 1, 0, "FakeBluez" , fakebluez_singleton); |
89 | |
90 | BluezQt::bluezqt_initFakeBluezTestRun(); |
91 | |
92 | qputenv("QML2_IMPORT_PATH" , QByteArrayLiteral(BLUEZQT_QML_IMPORT_PATH)); |
93 | const QString &testsDir = QFileInfo(QFINDTESTDATA("qml/tst_device.qml" )).absolutePath(); |
94 | |
95 | return quick_test_main(argc, argv, "qmltests" , testsDir.toUtf8().constData()); |
96 | } |
97 | |
98 | #include "qmltests.moc" |
99 | |