| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2014-2015 David Rosca <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "fakebluez.h" |
| 8 |
#include "agentmanager.h" |
| 9 |
#include "devicemanager.h" |
| 10 |
#include "obexagentmanager.h" |
| 11 |
#include "obexclient.h" |
| 12 |
#include "objectmanager.h" |
| 13 |
#include "profilemanager.h" |
| 14 |
#include "testinterface.h" |
| 15 |
|
| 16 |
#include <QDBusConnection> |
| 17 |
#include <QDebug> |
| 18 |
#include <QTimer> |
| 19 |
|
| 20 |
// ObexObject |
| 21 |
class ObexObject : public QObject |
| 22 |
{ |
| 23 |
public: |
| 24 |
explicit ObexObject(QObject *parent = nullptr) |
| 25 |
: QObject(parent) |
| 26 |
{ |
| 27 |
QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/bluez/obex"), this); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
// FakeBluez |
| 32 |
FakeBluez::FakeBluez(QObject *parent) |
| 33 |
: QObject(parent) |
| 34 |
, m_testInterface(new TestInterface(this)) |
| 35 |
, m_objectManager(nullptr) |
| 36 |
, m_agentManager(nullptr) |
| 37 |
, m_profileManager(nullptr) |
| 38 |
, m_deviceManager(nullptr) |
| 39 |
, m_obexObject(nullptr) |
| 40 |
, m_obexAgentManager(nullptr) |
| 41 |
, m_obexClient(nullptr) |
| 42 |
{ |
| 43 |
QDBusConnection::sessionBus().registerObject(QStringLiteral("/"), this); |
| 44 |
} |
| 45 |
|
| 46 |
void FakeBluez::runTest(const QString &testName) |
| 47 |
{ |
| 48 |
if (testName == QLatin1String("bluez-not-exporting-interfaces")) { |
| 49 |
runBluezNotExportingInterfacesTest(); |
| 50 |
} else if (testName == QLatin1String("bluez-empty-managed-objects")) { |
| 51 |
runBluezEmptyManagedObjectsTest(); |
| 52 |
} else if (testName == QLatin1String("bluez-no-adapters")) { |
| 53 |
runBluezNoAdaptersTest(); |
| 54 |
} else if (testName == QLatin1String("bluez-standard")) { |
| 55 |
runBluezStandardTest(); |
| 56 |
} |
| 57 |
|
| 58 |
if (testName == QLatin1String("obex-not-exporting-interfaces")) { |
| 59 |
runObexNotExportingInterfacesTest(); |
| 60 |
} else if (testName == QLatin1String("obex-empty-managed-objects")) { |
| 61 |
runObexEmptyManagedObjectsTest(); |
| 62 |
} else if (testName == QLatin1String("obex-no-client")) { |
| 63 |
runObexNoClientTest(); |
| 64 |
} else if (testName == QLatin1String("obex-no-agentmanager")) { |
| 65 |
runObexNoAgentManagerTest(); |
| 66 |
} else if (testName == QLatin1String("obex-standard")) { |
| 67 |
runObexStandardTest(); |
| 68 |
} |
| 69 |
|
| 70 |
if (!QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.bluezqt.fakebluez"))) { |
| 71 |
qWarning() << "Cannot register org.kde.bluezqt.fakebluez service!"; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
void FakeBluez::runAction(const QString &object, const QString &actionName, const QVariantMap &properties) |
| 76 |
{ |
| 77 |
m_actionObject = object; |
| 78 |
m_actionName = actionName; |
| 79 |
m_actionProperties = properties; |
| 80 |
|
| 81 |
QTimer::singleShot(0, this, SLOT(doRunAction())); |
| 82 |
} |
| 83 |
|
| 84 |
void FakeBluez::doRunAction() |
| 85 |
{ |
| 86 |
if (m_actionObject == QLatin1String("agentmanager")) { |
| 87 |
m_agentManager->runAction(m_actionName, m_actionProperties); |
| 88 |
} else if (m_actionObject == QLatin1String("devicemanager")) { |
| 89 |
m_deviceManager->runAction(m_actionName, m_actionProperties); |
| 90 |
} |
| 91 |
|
| 92 |
QTimer::singleShot(0, m_testInterface, SLOT(emitActionFinished())); |
| 93 |
} |
| 94 |
|
| 95 |
void FakeBluez::clear() |
| 96 |
{ |
| 97 |
// Everything is parented to ObjectManager |
| 98 |
delete m_objectManager; |
| 99 |
m_objectManager = nullptr; |
| 100 |
} |
| 101 |
|
| 102 |
void FakeBluez::createObjectManager() |
| 103 |
{ |
| 104 |
m_objectManager = new ObjectManager(this); |
| 105 |
} |
| 106 |
|
| 107 |
void FakeBluez::createAgentManager() |
| 108 |
{ |
| 109 |
m_agentManager = new AgentManager(m_objectManager); |
| 110 |
m_objectManager->addObject(m_agentManager); |
| 111 |
} |
| 112 |
|
| 113 |
void FakeBluez::createProfileManager() |
| 114 |
{ |
| 115 |
m_profileManager = new ProfileManager(m_objectManager); |
| 116 |
m_objectManager->addObject(m_profileManager); |
| 117 |
} |
| 118 |
|
| 119 |
void FakeBluez::createDeviceManager() |
| 120 |
{ |
| 121 |
m_deviceManager = new DeviceManager(m_objectManager); |
| 122 |
} |
| 123 |
|
| 124 |
void FakeBluez::createObexObjectManager() |
| 125 |
{ |
| 126 |
createObjectManager(); |
| 127 |
m_obexObject = new ObexObject(this); |
| 128 |
m_objectManager->addAutoDeleteObject(m_obexObject); |
| 129 |
} |
| 130 |
|
| 131 |
void FakeBluez::createObexAgentManager() |
| 132 |
{ |
| 133 |
m_obexAgentManager = new ObexAgentManager(m_obexObject); |
| 134 |
m_objectManager->addObject(m_obexAgentManager); |
| 135 |
} |
| 136 |
|
| 137 |
void FakeBluez::createObexClient() |
| 138 |
{ |
| 139 |
m_obexClient = new ObexClient(m_obexObject); |
| 140 |
m_objectManager->addObject(m_obexClient); |
| 141 |
} |
| 142 |
|
| 143 |
void FakeBluez::runBluezNotExportingInterfacesTest() |
| 144 |
{ |
| 145 |
clear(); |
| 146 |
} |
| 147 |
|
| 148 |
void FakeBluez::runBluezEmptyManagedObjectsTest() |
| 149 |
{ |
| 150 |
clear(); |
| 151 |
createObjectManager(); |
| 152 |
} |
| 153 |
|
| 154 |
void FakeBluez::runBluezNoAdaptersTest() |
| 155 |
{ |
| 156 |
clear(); |
| 157 |
createObjectManager(); |
| 158 |
createAgentManager(); |
| 159 |
createProfileManager(); |
| 160 |
} |
| 161 |
|
| 162 |
void FakeBluez::runBluezStandardTest() |
| 163 |
{ |
| 164 |
clear(); |
| 165 |
createObjectManager(); |
| 166 |
createDeviceManager(); |
| 167 |
createAgentManager(); |
| 168 |
createProfileManager(); |
| 169 |
} |
| 170 |
|
| 171 |
void FakeBluez::runObexNotExportingInterfacesTest() |
| 172 |
{ |
| 173 |
clear(); |
| 174 |
} |
| 175 |
|
| 176 |
void FakeBluez::runObexEmptyManagedObjectsTest() |
| 177 |
{ |
| 178 |
clear(); |
| 179 |
createObexObjectManager(); |
| 180 |
} |
| 181 |
|
| 182 |
void FakeBluez::runObexNoClientTest() |
| 183 |
{ |
| 184 |
clear(); |
| 185 |
createObexObjectManager(); |
| 186 |
createObexAgentManager(); |
| 187 |
} |
| 188 |
|
| 189 |
void FakeBluez::runObexNoAgentManagerTest() |
| 190 |
{ |
| 191 |
clear(); |
| 192 |
createObexObjectManager(); |
| 193 |
createObexClient(); |
| 194 |
} |
| 195 |
|
| 196 |
void FakeBluez::runObexStandardTest() |
| 197 |
{ |
| 198 |
clear(); |
| 199 |
createObexObjectManager(); |
| 200 |
createObexClient(); |
| 201 |
createObexAgentManager(); |
| 202 |
} |
| 203 |
|
| 204 |
#include "moc_fakebluez.cpp" |