diff options
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_bluez.cpp | 27 | ||||
-rw-r--r-- | tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp | 21 |
2 files changed, 32 insertions, 16 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index 6a520158..f7beb672 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -197,13 +197,15 @@ static inline OrgBluezDeviceInterface *getDevice(const QBluetoothAddress &addres void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing) { if (address.isNull()) { - emit error(PairingError); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); return; } const Pairing current_pairing = pairingStatus(address); if (current_pairing == pairing) { - emit pairingFinished(address, pairing); + QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address), + Q_ARG(QBluetoothLocalDevice::Pairing, pairing)); return; } @@ -216,7 +218,8 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai d_ptr->agent = new OrgBluezAgentAdaptor(d_ptr); bool res = QDBusConnection::systemBus().registerObject(d_ptr->agent_path, d_ptr); if(!res){ - emit error(PairingError); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); qDebug() << "Failed to register agent"; return; } @@ -225,14 +228,16 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai if(current_pairing == Paired && pairing == AuthorizedPaired){ OrgBluezDeviceInterface *device = getDevice(address, d_ptr); if (!device) { - emit error(PairingError); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); return; } QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(true)); deviceReply.waitForFinished(); if(deviceReply.isError()){ qDebug() << Q_FUNC_INFO << "reply failed" << deviceReply.error(); - emit error(PairingError); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); return; } delete device; @@ -242,14 +247,16 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai else if(current_pairing == AuthorizedPaired && pairing == Paired){ OrgBluezDeviceInterface *device = getDevice(address, d_ptr); if (!device) { - emit error(PairingError); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); return; } QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(false)); deviceReply.waitForFinished(); if(deviceReply.isError()){ qDebug() << Q_FUNC_INFO << "reply failed" << deviceReply.error(); - emit error(PairingError); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); return; } delete device; @@ -274,14 +281,16 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai reply.waitForFinished(); if(reply.isError()) { qDebug() << Q_FUNC_INFO << "failed to find device" << reply.error(); - emit error(QBluetoothLocalDevice::PairingError); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); return; } QDBusPendingReply<> removeReply = this->d_ptr->adapter->RemoveDevice(reply.value()); removeReply.waitForFinished(); if(removeReply.isError()){ qDebug() << Q_FUNC_INFO << "failed to remove device" << removeReply.error(); - emit error(QBluetoothLocalDevice::PairingError); + QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, + Q_ARG(QBluetoothLocalDevice::Error, QBluetoothLocalDevice::PairingError)); } else { QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address), Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::Unpaired)); diff --git a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp index bd2272f1..bc4e269e 100644 --- a/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp +++ b/tests/auto/qbluetoothlocaldevice/tst_qbluetoothlocaldevice.cpp @@ -53,10 +53,8 @@ QT_USE_NAMESPACE_BLUETOOTH * Running the manual tests requires another Bluetooth device in the vincinity. * The remote device's address must be passed via the BT_TEST_DEVICE env variable. * Every pairing request must be accepted within a 10s interval of appearing. + * If BT_TEST_DEVICE is not set manual tests will be skipped. **/ -#define BT_TEST_DEVICE "98:D6:F7:D9:A5:3D" - - class tst_QBluetoothLocalDevice : public QObject { @@ -67,6 +65,7 @@ public: ~tst_QBluetoothLocalDevice(); private slots: + void initTestCase(); void tst_powerOn(); void tst_powerOff(); void tst_hostModes(); @@ -83,16 +82,16 @@ private slots: private: QBluetoothAddress remoteDevice; + bool expectRemoteDevice; }; tst_QBluetoothLocalDevice::tst_QBluetoothLocalDevice() + : expectRemoteDevice(false) { const QString remote = qgetenv("BT_TEST_DEVICE"); - if (remote == QStringLiteral("default")) { - remoteDevice = QBluetoothAddress(BT_TEST_DEVICE); - qWarning() << "Using default remote device for testing"; - } else if (!remote.isEmpty()) { + if (!remote.isEmpty()) { remoteDevice = QBluetoothAddress(remote); + expectRemoteDevice = true; qWarning() << "Using remote device " << remote << " for testing. Ensure that the device is discoverable for pairing requests"; } else { qWarning() << "Not using any remote device for testing. Set BT_TEST_DEVICE env to run manual tests involving a remote device"; @@ -110,6 +109,14 @@ tst_QBluetoothLocalDevice::~tst_QBluetoothLocalDevice() { } +void tst_QBluetoothLocalDevice::initTestCase() +{ + if (expectRemoteDevice) { + //test passed Bt address here since we cannot do that in the ctor + QVERIFY2(!remoteDevice.isNull(), "BT_TEST_DEVICE is not a valid Bluetooth address" ); + } +} + void tst_QBluetoothLocalDevice::tst_powerOn() { QBluetoothLocalDevice localDevice; |