Warning, file /frameworks/bluez-qt/autotests/qmltests.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "autotests.h" 0008 0009 #include <QDBusObjectPath> 0010 0011 #include <QtQml> // krazy:exclude=includes 0012 #include <QtQuickTest> // krazy:exclude=includes 0013 0014 #ifdef IMPORT_EXTENSIONS_QML_PLUGIN 0015 #include <QPluginLoader> 0016 Q_IMPORT_PLUGIN(BluezQtExtensionPlugin) 0017 #endif 0018 0019 class FakeBluezObject : public QObject 0020 { 0021 Q_OBJECT 0022 0023 public Q_SLOTS: 0024 void start() 0025 { 0026 FakeBluez::start(); 0027 } 0028 0029 void stop() 0030 { 0031 FakeBluez::stop(); 0032 } 0033 0034 bool isRunning() 0035 { 0036 return FakeBluez::isRunning(); 0037 } 0038 0039 void runTest(const QString &testName) 0040 { 0041 FakeBluez::runTest(testName); 0042 } 0043 0044 static void processProperties(QVariantMap &properties) 0045 { 0046 const QStringList &toDBusObjectPath = properties.value(QStringLiteral("_toDBusObjectPath")).toStringList(); 0047 for (const QString &name : toDBusObjectPath) { 0048 const QString &val = properties.value(name).toString(); 0049 properties[name] = QVariant::fromValue(QDBusObjectPath(val)); 0050 } 0051 properties.remove(QStringLiteral("_toDBusObjectPath")); 0052 0053 QMapIterator<QString, QVariant> it(properties); 0054 while (it.hasNext()) { 0055 it.next(); 0056 if (it.key() == QLatin1String("UUIDs")) { 0057 properties[it.key()] = it.value().toStringList(); 0058 } else if (it.value().type() == QVariant::Map) { 0059 QVariantMap props = it.value().toMap(); 0060 processProperties(props); 0061 properties[it.key()] = props; 0062 } 0063 } 0064 } 0065 0066 void runAction(const QString &object, const QString &actionName, QVariantMap properties = QVariantMap()) 0067 { 0068 processProperties(properties); 0069 FakeBluez::runAction(object, actionName, properties); 0070 } 0071 }; 0072 0073 static QObject *fakebluez_singleton(QQmlEngine *engine, QJSEngine *scriptEngine) 0074 { 0075 Q_UNUSED(engine) 0076 Q_UNUSED(scriptEngine) 0077 0078 return new FakeBluezObject; 0079 } 0080 0081 namespace BluezQt 0082 { 0083 extern void bluezqt_initFakeBluezTestRun(); 0084 } 0085 0086 int main(int argc, char *argv[]) 0087 { 0088 qmlRegisterSingletonType<QObject>("org.kde.bluezqt.fakebluez", 1, 0, "FakeBluez", fakebluez_singleton); 0089 0090 BluezQt::bluezqt_initFakeBluezTestRun(); 0091 0092 qputenv("QML2_IMPORT_PATH", QByteArrayLiteral(BLUEZQT_QML_IMPORT_PATH)); 0093 const QString &testsDir = QFileInfo(QFINDTESTDATA("qml/tst_device.qml")).absolutePath(); 0094 0095 return quick_test_main(argc, argv, "qmltests", testsDir.toUtf8().constData()); 0096 } 0097 0098 #include "qmltests.moc"