void ServiceDiscoveryDialog::addService(const QBluetoothServiceInfo &info) { if (info.serviceName().isEmpty()) return; QString line = info.serviceName(); if (!info.serviceDescription().isEmpty()) line.append("\n\t" + info.serviceDescription()); if (!info.serviceProvider().isEmpty()) line.append("\n\t" + info.serviceProvider()); ui->list->addItem(line); }
void tst_QBluetoothServiceInfo::tst_construction() { const QString serviceName("My Service"); const QString alternateServiceName("Another ServiceName"); const QBluetoothDeviceInfo deviceInfo(QBluetoothAddress("001122334455"), "Test Device", 0); const QBluetoothDeviceInfo alternatedeviceInfo(QBluetoothAddress("554433221100"), "Test Device2", 0); QList<QBluetoothUuid::ProtocolUuid> protUuids; //list taken from qbluetoothuuid.h protUuids << QBluetoothUuid::Sdp; protUuids << QBluetoothUuid::Udp; protUuids << QBluetoothUuid::Rfcomm; protUuids << QBluetoothUuid::Tcp; protUuids << QBluetoothUuid::TcsBin; protUuids << QBluetoothUuid::TcsAt; protUuids << QBluetoothUuid::Att; protUuids << QBluetoothUuid::Obex; protUuids << QBluetoothUuid::Ip; protUuids << QBluetoothUuid::Ftp; protUuids << QBluetoothUuid::Http; protUuids << QBluetoothUuid::Wsp; protUuids << QBluetoothUuid::Bnep; protUuids << QBluetoothUuid::Upnp; protUuids << QBluetoothUuid::Hidp; protUuids << QBluetoothUuid::HardcopyControlChannel; protUuids << QBluetoothUuid::HardcopyDataChannel; protUuids << QBluetoothUuid::HardcopyNotification; protUuids << QBluetoothUuid::Avctp; protUuids << QBluetoothUuid::Avdtp; protUuids << QBluetoothUuid::Cmtp; protUuids << QBluetoothUuid::UdiCPlain; protUuids << QBluetoothUuid::McapControlChannel; protUuids << QBluetoothUuid::McapDataChannel; protUuids << QBluetoothUuid::L2cap; { QBluetoothServiceInfo serviceInfo; QVERIFY(!serviceInfo.isValid()); QVERIFY(!serviceInfo.isComplete()); QVERIFY(!serviceInfo.isRegistered()); QCOMPARE(serviceInfo.serviceName(), QString()); QCOMPARE(serviceInfo.serviceDescription(), QString()); QCOMPARE(serviceInfo.serviceProvider(), QString()); QCOMPARE(serviceInfo.serviceUuid(), QBluetoothUuid()); QCOMPARE(serviceInfo.serviceClassUuids().count(), 0); QCOMPARE(serviceInfo.attributes().count(), 0); QCOMPARE(serviceInfo.serverChannel(), -1); QCOMPARE(serviceInfo.protocolServiceMultiplexer(), -1); foreach (QBluetoothUuid::ProtocolUuid u, protUuids) QCOMPARE(serviceInfo.protocolDescriptor(u).count(), 0); } { QBluetoothServiceInfo serviceInfo; serviceInfo.setServiceName(serviceName); serviceInfo.setDevice(deviceInfo); QVERIFY(serviceInfo.isValid()); QVERIFY(!serviceInfo.isComplete()); QVERIFY(!serviceInfo.isRegistered()); QCOMPARE(serviceInfo.serviceName(), serviceName); QCOMPARE(serviceInfo.device().address(), deviceInfo.address()); QBluetoothServiceInfo copyInfo(serviceInfo); QVERIFY(copyInfo.isValid()); QVERIFY(!copyInfo.isComplete()); QVERIFY(!copyInfo.isRegistered()); QCOMPARE(copyInfo.serviceName(), serviceName); QCOMPARE(copyInfo.device().address(), deviceInfo.address()); copyInfo.setAttribute(QBluetoothServiceInfo::ServiceName, alternateServiceName); copyInfo.setDevice(alternatedeviceInfo); QCOMPARE(copyInfo.serviceName(), alternateServiceName); QCOMPARE(copyInfo.attribute(QBluetoothServiceInfo::ServiceName).toString(), alternateServiceName); QCOMPARE(serviceInfo.serviceName(), alternateServiceName); QCOMPARE(copyInfo.device().address(), alternatedeviceInfo.address()); QCOMPARE(serviceInfo.device().address(), alternatedeviceInfo.address()); foreach (QBluetoothUuid::ProtocolUuid u, protUuids) QCOMPARE(serviceInfo.protocolDescriptor(u).count(), 0); foreach (QBluetoothUuid::ProtocolUuid u, protUuids) QCOMPARE(copyInfo.protocolDescriptor(u).count(), 0); } }