Exemple #1
0
//! [les-devicediscovery-3]
void Device::addDevice(const QBluetoothDeviceInfo &info)
{
    if (info.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) {
        DeviceInfo *d = new DeviceInfo(info);
        devices.append(d);
        setUpdate("Last device added: " + d->getName());
    }
}
Exemple #2
0
void tst_QBluetoothDeviceInfo::tst_assignment()
{
    QFETCH(QBluetoothAddress, address);
    QFETCH(QString, name);
    QFETCH(quint32, classOfDevice);
    QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses);
    QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass);
    QFETCH(quint8, minorDeviceClass);
    QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration);
    QFETCH(QBluetoothUuid, deviceUuid);

    QBluetoothDeviceInfo deviceInfo(address, name, classOfDevice);

    deviceInfo.setDeviceUuid(deviceUuid);
    deviceInfo.setCoreConfigurations(coreConfiguration);

    QVERIFY(deviceInfo.isValid());

    {
        QBluetoothDeviceInfo copyInfo = deviceInfo;

        QVERIFY(copyInfo.isValid());

        QCOMPARE(copyInfo.address(), address);
        QCOMPARE(copyInfo.name(), name);
        QCOMPARE(copyInfo.serviceClasses(), serviceClasses);
        QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass);
        QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass);
        QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration);
        QCOMPARE(copyInfo.deviceUuid(), deviceUuid);
    }

    {
        QBluetoothDeviceInfo copyInfo;

        QVERIFY(!copyInfo.isValid());

        copyInfo = deviceInfo;

        QVERIFY(copyInfo.isValid());

        QCOMPARE(copyInfo.address(), address);
        QCOMPARE(copyInfo.name(), name);
        QCOMPARE(copyInfo.serviceClasses(), serviceClasses);
        QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass);
        QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass);
        QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration);
        QCOMPARE(copyInfo.deviceUuid(), deviceUuid);
    }

    {
        QBluetoothDeviceInfo copyInfo1;
        QBluetoothDeviceInfo copyInfo2;

        QVERIFY(!copyInfo1.isValid());
        QVERIFY(!copyInfo2.isValid());

        copyInfo1 = copyInfo2 = deviceInfo;

        QVERIFY(copyInfo1.isValid());
        QVERIFY(copyInfo2.isValid());
        QVERIFY(QBluetoothDeviceInfo() != copyInfo1);

        QCOMPARE(copyInfo1.address(), address);
        QCOMPARE(copyInfo2.address(), address);
        QCOMPARE(copyInfo1.name(), name);
        QCOMPARE(copyInfo2.name(), name);
        QCOMPARE(copyInfo1.serviceClasses(), serviceClasses);
        QCOMPARE(copyInfo2.serviceClasses(), serviceClasses);
        QCOMPARE(copyInfo1.majorDeviceClass(), majorDeviceClass);
        QCOMPARE(copyInfo2.majorDeviceClass(), majorDeviceClass);
        QCOMPARE(copyInfo1.minorDeviceClass(), minorDeviceClass);
        QCOMPARE(copyInfo2.minorDeviceClass(), minorDeviceClass);
        QCOMPARE(copyInfo1.coreConfigurations(), coreConfiguration);
        QCOMPARE(copyInfo2.coreConfigurations(), coreConfiguration);
        QCOMPARE(copyInfo1.deviceUuid(), deviceUuid);
        QCOMPARE(copyInfo2.deviceUuid(), deviceUuid);
    }

    {
        QBluetoothDeviceInfo testDeviceInfo;
        QVERIFY(testDeviceInfo == QBluetoothDeviceInfo());
    }
}
Exemple #3
0
void tst_QBluetoothDeviceInfo::tst_construction()
{
    {
        QBluetoothDeviceInfo deviceInfo;

        QVERIFY(!deviceInfo.isValid());
        QVERIFY(deviceInfo.coreConfigurations()
                    == QBluetoothDeviceInfo::UnknownCoreConfiguration);
    }

    {
        QFETCH(QBluetoothAddress, address);
        QFETCH(QString, name);
        QFETCH(quint32, classOfDevice);
        QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses);
        QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass);
        QFETCH(quint8, minorDeviceClass);
        QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration);
        QFETCH(QBluetoothUuid, deviceUuid);

        QBluetoothDeviceInfo deviceInfo(address, name, classOfDevice);
        QVERIFY(deviceInfo.isValid());

        QCOMPARE(deviceInfo.address(), address);
        QCOMPARE(deviceInfo.name(), name);
        QCOMPARE(deviceInfo.serviceClasses(), serviceClasses);
        QCOMPARE(deviceInfo.majorDeviceClass(), majorDeviceClass);
        QCOMPARE(deviceInfo.minorDeviceClass(), minorDeviceClass);
        QCOMPARE(deviceInfo.coreConfigurations(), QBluetoothDeviceInfo::UnknownCoreConfiguration);

        deviceInfo.setCoreConfigurations(coreConfiguration);
        QCOMPARE(deviceInfo.coreConfigurations(), coreConfiguration);

        deviceInfo.setDeviceUuid(deviceUuid);
        QCOMPARE(deviceInfo.deviceUuid(), deviceUuid);

        QBluetoothDeviceInfo copyInfo(deviceInfo);
        QVERIFY(copyInfo.isValid());

        QCOMPARE(copyInfo.address(), address);
        QCOMPARE(copyInfo.name(), name);
        QCOMPARE(copyInfo.serviceClasses(), serviceClasses);
        QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass);
        QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass);
        QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration);
        QCOMPARE(copyInfo.deviceUuid(), deviceUuid);
    }

    {
        // Test construction from the device unique UUID, without an address.
        QFETCH(QString, name);
        QFETCH(quint32, classOfDevice);
        QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses);
        QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass);
        QFETCH(quint8, minorDeviceClass);
        QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration);
        QFETCH(QBluetoothUuid, deviceUuid);

        QBluetoothDeviceInfo deviceInfo(deviceUuid, name, classOfDevice);
        QVERIFY(deviceInfo.isValid());

        QCOMPARE(deviceInfo.name(), name);
        QCOMPARE(deviceInfo.serviceClasses(), serviceClasses);
        QCOMPARE(deviceInfo.majorDeviceClass(), majorDeviceClass);
        QCOMPARE(deviceInfo.minorDeviceClass(), minorDeviceClass);
        QCOMPARE(deviceInfo.coreConfigurations(), QBluetoothDeviceInfo::UnknownCoreConfiguration);

        deviceInfo.setCoreConfigurations(coreConfiguration);
        QCOMPARE(deviceInfo.coreConfigurations(), coreConfiguration);

        QBluetoothDeviceInfo copyInfo(deviceInfo);
        QVERIFY(copyInfo.isValid());

        QCOMPARE(copyInfo.name(), name);
        QCOMPARE(copyInfo.serviceClasses(), serviceClasses);
        QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass);
        QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass);
        QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration);
        QCOMPARE(copyInfo.deviceUuid(), deviceUuid);
    }
}