summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-09-29 16:56:41 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-09-30 15:27:39 +0200
commit7d1de5c312ccf0a85ba0a6a047240cc5777ea18d (patch)
treea57069ca95b4f92434d71500172e37be1bd1f1c2 /tests
parent0564f806ee4eaeb10743ab21e30c783436e36d49 (diff)
Fix QBluetoothServiceInfo uni test on platforms using fake server ports
Those platforms require a running QBluetoothServer to satisfy the prerequisites of calling QBluetoothServiceInfo::registerService(). This requirement is imposed by the public API contract anyway. Change-Id: I2498030fa2787df9745580cd744886693945fe4f Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qbluetoothserviceinfo/qbluetoothserviceinfo.pro4
-rw-r--r--tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp58
2 files changed, 56 insertions, 6 deletions
diff --git a/tests/auto/qbluetoothserviceinfo/qbluetoothserviceinfo.pro b/tests/auto/qbluetoothserviceinfo/qbluetoothserviceinfo.pro
index 90703bd1..563df1a9 100644
--- a/tests/auto/qbluetoothserviceinfo/qbluetoothserviceinfo.pro
+++ b/tests/auto/qbluetoothserviceinfo/qbluetoothserviceinfo.pro
@@ -4,3 +4,7 @@ CONFIG += testcase
QT = core concurrent bluetooth testlib
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+
+android:!android-no-sdk {
+ DEFINES += QT_ANDROID_BLUETOOTH
+}
diff --git a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp
index cc51b007..61bad7c5 100644
--- a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp
+++ b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp
@@ -41,6 +41,7 @@
#include <qbluetoothaddress.h>
#include <qbluetoothlocaldevice.h>
#include <qbluetoothuuid.h>
+#include <QtBluetooth/QBluetoothServer>
QT_USE_NAMESPACE
@@ -182,10 +183,20 @@ void tst_QBluetoothServiceInfo::tst_assignment_data()
QTest::addColumn<QUuid>("uuid");
QTest::addColumn<QBluetoothUuid::ProtocolUuid>("protocolUuid");
QTest::addColumn<QBluetoothServiceInfo::Protocol>("serviceInfoProtocol");
-
- QTest::newRow("assignment_data")
+ QTest::addColumn<bool>("protocolSupported");
+
+ bool l2cpSupported = true;
+ //some platforms don't support L2CP
+#ifdef QT_ANDROID_BLUETOOTH
+ l2cpSupported = false;
+#endif
+ QTest::newRow("assignment_data_l2cp")
+ << QUuid(0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee)
+ << QBluetoothUuid::L2cap << QBluetoothServiceInfo::L2capProtocol << l2cpSupported;
+ QTest::newRow("assignment_data_rfcomm")
<< QUuid(0x67c8770b, 0x44f1, 0x410a, 0xab, 0x9a, 0xf9, 0xb5, 0x44, 0x6f, 0x13, 0xee)
- << QBluetoothUuid::L2cap << QBluetoothServiceInfo::L2capProtocol;
+ << QBluetoothUuid::Rfcomm << QBluetoothServiceInfo::RfcommProtocol << true;
+
}
void tst_QBluetoothServiceInfo::tst_assignment()
@@ -193,6 +204,7 @@ void tst_QBluetoothServiceInfo::tst_assignment()
QFETCH(QUuid, uuid);
QFETCH(QBluetoothUuid::ProtocolUuid, protocolUuid);
QFETCH(QBluetoothServiceInfo::Protocol, serviceInfoProtocol);
+ QFETCH(bool, protocolSupported);
const QString serviceName("My Service");
const QBluetoothDeviceInfo deviceInfo(QBluetoothAddress("001122334455"), "Test Device", 0);
@@ -294,20 +306,51 @@ void tst_QBluetoothServiceInfo::tst_assignment()
protocolDescriptorList.append(QVariant::fromValue(protocol));
copyInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
protocolDescriptorList);
- QVERIFY(copyInfo.serverChannel() == -1);
- QVERIFY(copyInfo.protocolServiceMultiplexer() != -1);
+ if (serviceInfoProtocol == QBluetoothServiceInfo::L2capProtocol) {
+ QVERIFY(copyInfo.serverChannel() == -1);
+ QVERIFY(copyInfo.protocolServiceMultiplexer() != -1);
+ } else if (serviceInfoProtocol == QBluetoothServiceInfo::RfcommProtocol) {
+ QVERIFY(copyInfo.serverChannel() != -1);
+ QVERIFY(copyInfo.protocolServiceMultiplexer() == -1);
+ }
+
QVERIFY(copyInfo.socketProtocol() == serviceInfoProtocol);
}
{
QBluetoothServiceInfo copyInfo;
+
QVERIFY(!copyInfo.isValid());
copyInfo = serviceInfo;
+ copyInfo.setServiceUuid(QBluetoothUuid::SerialPort);
QVERIFY(!copyInfo.isRegistered());
if (!QBluetoothLocalDevice::allDevices().count()) {
QSKIP("Skipping test due to missing Bluetooth device");
- } else {
+ } else if (protocolSupported) {
+ QBluetoothServer server(serviceInfoProtocol);
+ QVERIFY(server.listen());
+ QTRY_VERIFY_WITH_TIMEOUT(server.isListening(), 5000);
+ QVERIFY(server.serverPort() > 0);
+
+ QBluetoothServiceInfo::Sequence protocolDescriptorList;
+ QBluetoothServiceInfo::Sequence protocol;
+ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
+
+ if (serviceInfoProtocol == QBluetoothServiceInfo::L2capProtocol) {
+ protocol << QVariant::fromValue(server.serverPort());
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+ } else if (serviceInfoProtocol == QBluetoothServiceInfo::RfcommProtocol) {
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+ protocol.clear();
+ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
+ << QVariant::fromValue(quint8(server.serverPort()));
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+ }
+
+ serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
+ protocolDescriptorList);
+
QVERIFY(copyInfo.registerService());
QVERIFY(copyInfo.isRegistered());
QVERIFY(serviceInfo.isRegistered());
@@ -319,6 +362,9 @@ void tst_QBluetoothServiceInfo::tst_assignment()
QVERIFY(!copyInfo.isRegistered());
QVERIFY(!secondCopy.isRegistered());
QVERIFY(!serviceInfo.isRegistered());
+ QVERIFY(server.isListening());
+ server.close();
+ QVERIFY(!server.isListening());
}
}
}