diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-10-16 14:24:13 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-10-21 09:58:55 +0200 |
commit | ec2cc1b88b0ba2ef20b1969d0a6a897f7f312d4c (patch) | |
tree | 60a2e9ba0d5706de351c7a11845407ab2cf1b5e8 /tests/auto/qlowenergycontroller | |
parent | c3e68510068d3ce3ce4cc65e0352e346b3722bd2 (diff) |
Ensure behavior of QLEController ctor when handling invld remote device
Change-Id: I467c57d7466d0cbf57fe6550eb03e23212db3fea
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'tests/auto/qlowenergycontroller')
-rw-r--r-- | tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp index 4af96f3c..10fceb00 100644 --- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp +++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp @@ -32,6 +32,7 @@ ****************************************************************************/ #include <QtTest/QtTest> +#include <QBluetoothAddress> #include <QBluetoothLocalDevice> #include <QBluetoothDeviceDiscoveryAgent> #include <QBluetoothUuid> @@ -63,6 +64,7 @@ public: private slots: void initTestCase(); void cleanupTestCase(); + void tst_emptyCtor(); void tst_connect(); void tst_concurrentDiscovery(); void tst_defaultBehavior(); @@ -82,12 +84,14 @@ Q_DECLARE_METATYPE(QLowEnergyCharacteristic) Q_DECLARE_METATYPE(QLowEnergyDescriptor) Q_DECLARE_METATYPE(QLowEnergyService::ServiceError) Q_DECLARE_METATYPE(QLowEnergyController::ControllerState) +Q_DECLARE_METATYPE(QLowEnergyController::Error) tst_QLowEnergyController::tst_QLowEnergyController() { qRegisterMetaType<QLowEnergyCharacteristic>(); qRegisterMetaType<QLowEnergyDescriptor>(); qRegisterMetaType<QLowEnergyController::ControllerState>(); + qRegisterMetaType<QLowEnergyController::Error>(); //QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); const QString remote = qgetenv("BT_TEST_DEVICE"); @@ -153,6 +157,48 @@ void tst_QLowEnergyController::cleanupTestCase() } +void tst_QLowEnergyController::tst_emptyCtor() +{ + { + QBluetoothAddress remoteAddress; + QLowEnergyController control(remoteAddress); + QSignalSpy connectedSpy(&control, SIGNAL(connected())); + QSignalSpy stateSpy(&control, SIGNAL(stateChanged(QLowEnergyController::ControllerState))); + QSignalSpy errorSpy(&control, SIGNAL(error(QLowEnergyController::Error))); + QCOMPARE(control.error(), QLowEnergyController::NoError); + control.connectToDevice(); + + QTRY_VERIFY_WITH_TIMEOUT(!errorSpy.isEmpty(), 10000); + + QVERIFY(connectedSpy.isEmpty()); + QVERIFY(stateSpy.isEmpty()); + + QLowEnergyController::Error lastError = errorSpy[0].at(0).value<QLowEnergyController::Error>(); + QVERIFY(lastError == QLowEnergyController::UnknownRemoteDeviceError + || lastError == QLowEnergyController::InvalidBluetoothAdapterError); + } + + { + QBluetoothDeviceInfo deviceInfo; + QLowEnergyController control(deviceInfo); + QSignalSpy connectedSpy(&control, SIGNAL(connected())); + QSignalSpy stateSpy(&control, SIGNAL(stateChanged(QLowEnergyController::ControllerState))); + QSignalSpy errorSpy(&control, SIGNAL(error(QLowEnergyController::Error))); + QCOMPARE(control.error(), QLowEnergyController::NoError); + control.connectToDevice(); + + QTRY_VERIFY_WITH_TIMEOUT(!errorSpy.isEmpty(), 10000); + + QVERIFY(connectedSpy.isEmpty()); + QVERIFY(stateSpy.isEmpty()); + + QLowEnergyController::Error lastError = errorSpy[0].at(0).value<QLowEnergyController::Error>(); + QVERIFY(lastError == QLowEnergyController::UnknownRemoteDeviceError // if local device on platform found + || lastError == QLowEnergyController::InvalidBluetoothAdapterError); // otherwise, e.g. fallback backend + } + +} + void tst_QLowEnergyController::tst_connect() { QList<QBluetoothHostInfo> localAdapters = QBluetoothLocalDevice::allDevices(); |