summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2013-06-27 21:24:53 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-13 10:57:59 +0200
commitf6b6fb24f642fe7900405861303fb14458514f03 (patch)
tree3d9435bd49fa3c7c6d46a514664547e1dfa405d9
parentde33fa0c04d1853c4e11ec7bc80c8be3111551b9 (diff)
QBluetoothServiceDiscovery auto test fix
Change-Id: I4e20a50549f69367652bd6881a3c541aa283c128 Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
-rw-r--r--tests/auto/auto.pro2
-rw-r--r--tests/auto/qbluetoothservicediscoveryagent/qbluetoothservicediscoveryagent.pro1
-rw-r--r--tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp67
3 files changed, 37 insertions, 33 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 06e92bd8..10798a1b 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -29,5 +29,3 @@ qtHaveModule(nfc) {
qnearfieldtagtype2 \
qndefnfcsmartposterrecord
}
-
-qbluetoothservicediscoveryagent.CONFIG += no_check_target # QTBUG-22017
diff --git a/tests/auto/qbluetoothservicediscoveryagent/qbluetoothservicediscoveryagent.pro b/tests/auto/qbluetoothservicediscoveryagent/qbluetoothservicediscoveryagent.pro
index 88ba38ec..7b8ee74a 100644
--- a/tests/auto/qbluetoothservicediscoveryagent/qbluetoothservicediscoveryagent.pro
+++ b/tests/auto/qbluetoothservicediscoveryagent/qbluetoothservicediscoveryagent.pro
@@ -4,5 +4,4 @@ CONFIG += testcase
QT = core concurrent bluetooth testlib
-CONFIG += insignificant_test # QTBUG-22017
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
index 4970cbde..2ab0326c 100644
--- a/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
+++ b/tests/auto/qbluetoothservicediscoveryagent/tst_qbluetoothservicediscoveryagent.cpp
@@ -79,16 +79,21 @@ private slots:
private:
QList<QBluetoothDeviceInfo> devices;
+ bool localDeviceAvailable;
};
tst_QBluetoothServiceDiscoveryAgent::tst_QBluetoothServiceDiscoveryAgent()
{
// start Bluetooth if not started
QBluetoothLocalDevice *device = new QBluetoothLocalDevice();
- device->powerOn();
+ localDeviceAvailable = device->isValid();
+ if (localDeviceAvailable) {
+ device->powerOn();
+ // wait for the device to switch bluetooth mode.
+ QTest::qWait(1000);
+ }
delete device;
- // wait for the device to switch bluetooth mode.
- QTest::qWait(1000);
+
qRegisterMetaType<QBluetoothDeviceInfo>("QBluetoothDeviceInfo");
qRegisterMetaType<QBluetoothServiceInfo>("QBluetoothServiceInfo");
qRegisterMetaType<QList<QBluetoothUuid> >("QList<QBluetoothUuid>");
@@ -114,33 +119,31 @@ void tst_QBluetoothServiceDiscoveryAgent::serviceError(const QBluetoothServiceDi
void tst_QBluetoothServiceDiscoveryAgent::initTestCase()
{
-#if 1
- QBluetoothDeviceDiscoveryAgent discoveryAgent;
-
- QSignalSpy finishedSpy(&discoveryAgent, SIGNAL(finished()));
- QSignalSpy errorSpy(&discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)));
- QSignalSpy discoveredSpy(&discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)));
-// connect(&discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)),
-// this, SLOT(deviceDiscoveryDebug(const QBluetoothDeviceInfo&)));
+ if (localDeviceAvailable) {
+ QBluetoothDeviceDiscoveryAgent discoveryAgent;
+
+ QSignalSpy finishedSpy(&discoveryAgent, SIGNAL(finished()));
+ QSignalSpy errorSpy(&discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)));
+ QSignalSpy discoveredSpy(&discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)));
+ // connect(&discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)),
+ // this, SLOT(deviceDiscoveryDebug(const QBluetoothDeviceInfo&)));
+
+ discoveryAgent.start();
+
+ // Wait for up to MaxScanTime for the scan to finish
+ int scanTime = MaxScanTime;
+ while (finishedSpy.count() == 0 && scanTime > 0) {
+ QTest::qWait(1000);
+ scanTime -= 1000;
+ }
+ // qDebug() << "Scan time left:" << scanTime;
- discoveryAgent.start();
+ // Expect finished signal with no error
+ QVERIFY(finishedSpy.count() == 1);
+ QVERIFY(errorSpy.isEmpty());
- // Wait for up to MaxScanTime for the scan to finish
- int scanTime = MaxScanTime;
- while (finishedSpy.count() == 0 && scanTime > 0) {
- QTest::qWait(1000);
- scanTime -= 1000;
+ devices = discoveryAgent.discoveredDevices();
}
-// qDebug() << "Scan time left:" << scanTime;
-
- // Expect finished signal with no error
- QVERIFY(finishedSpy.count() == 1);
- QVERIFY(errorSpy.isEmpty());
-
- devices = discoveryAgent.discoveredDevices();
-#else
- devices.append(QBluetoothDeviceInfo(QBluetoothAddress(Q_UINT64_C(0x001e3a81ba69)), "Yuna", 0));
-#endif
}
void tst_QBluetoothServiceDiscoveryAgent::serviceDiscoveryDebug(const QBluetoothServiceInfo &info)
@@ -260,7 +263,7 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery()
QFETCH(QList<QBluetoothUuid>, uuidFilter);
QFETCH(QBluetoothServiceDiscoveryAgent::Error, serviceDiscoveryError);
- qDebug() << "Doing address" << deviceInfo.address().toString();
+ qDebug() << "Scanning address" << deviceInfo.address().toString();
QBluetoothServiceDiscoveryAgent discoveryAgent(deviceInfo.address());
QVERIFY(!discoveryAgent.isActive());
@@ -313,15 +316,16 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery()
// All returned QBluetoothServiceInfo should be valid.
while (!discoveredSpy.isEmpty()) {
const QVariant v = discoveredSpy.takeFirst().at(0);
-
// Work around limitation in QMetaType and moc.
// QBluetoothServiceInfo is registered with metatype as QBluetoothServiceInfo
// moc sees it as the unqualified QBluetoothServiceInfo.
- if (qstrcmp(v.typeName(), "QBluetoothServiceInfo") == 0) {
+ if (v.userType() == qMetaTypeId<QBluetoothServiceInfo>())
+ {
const QBluetoothServiceInfo info =
*reinterpret_cast<const QBluetoothServiceInfo*>(v.constData());
QVERIFY(info.isValid());
+ QVERIFY(!info.isRegistered());
#if 0
qDebug() << info.device().name() << info.device().address().toString();
@@ -332,7 +336,10 @@ void tst_QBluetoothServiceDiscoveryAgent::tst_serviceDiscovery()
qDebug() << "\tRFCOMM server channel:" << info.serverChannel();
//dumpServiceInfoAttributes(info);
#endif
+ } else {
+ QFAIL("Unknown type returned by service discovery");
}
+
}
QVERIFY(discoveryAgent.discoveredServices().count() != 0);