void tst_QBluetoothLocalDevice::tst_hostModes() { QFETCH(QBluetoothLocalDevice::HostMode, hostModeExpected); QBluetoothLocalDevice localDevice; QSignalSpy hostModeSpy(&localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode))); // there should be no changes yet QVERIFY(hostModeSpy.isEmpty()); QTest::qWait(1000); localDevice.setHostMode(hostModeExpected); // wait for the device to switch bluetooth mode. QTest::qWait(1000); if (hostModeExpected != localDevice.hostMode()) { WAIT_FOR_CONDITION(hostModeSpy.count(),1); QVERIFY(hostModeSpy.count() > 0); } // test the actual signal values. QList<QVariant> arguments = hostModeSpy.takeFirst(); QBluetoothLocalDevice::HostMode hostMode = qvariant_cast<QBluetoothLocalDevice::HostMode>(arguments.at(0)); QCOMPARE(hostModeExpected, hostMode); // test actual QCOMPARE(hostModeExpected, localDevice.hostMode()); }
void tst_QBluetoothLocalDevice::tst_powerOff() { if (!QBluetoothLocalDevice::allDevices().count()) QSKIP("Skipping test due to missing Bluetooth device"); { QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); device->powerOn(); delete device; // wait for the device to switch bluetooth mode. QTest::qWait(1000); } QBluetoothLocalDevice localDevice; QSignalSpy hostModeSpy(&localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode))); // there should be no changes yet QVERIFY(hostModeSpy.isValid()); QVERIFY(hostModeSpy.isEmpty()); localDevice.setHostMode(QBluetoothLocalDevice::HostPoweredOff); // async, wait for it QTRY_VERIFY(hostModeSpy.count() > 0); // we should not be powered off QVERIFY(localDevice.hostMode() == QBluetoothLocalDevice::HostPoweredOff); }
void tst_QBluetoothDeviceDiscoveryAgent::initTestCase() { qRegisterMetaType<QBluetoothDeviceInfo>("QBluetoothDeviceInfo"); qRegisterMetaType<QBluetoothDeviceDiscoveryAgent::InquiryType>("QBluetoothDeviceDiscoveryAgent::InquiryType"); // turn on BT in case it is not on QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); if (device->hostMode() == QBluetoothLocalDevice::HostPoweredOff) { QSignalSpy hostModeSpy(device, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode))); QVERIFY(hostModeSpy.isEmpty()); device->powerOn(); int connectTime = 5000; // ms while (hostModeSpy.count() < 1 && connectTime > 0) { QTest::qWait(500); connectTime -= 500; } QVERIFY(hostModeSpy.count() > 0); } QBluetoothLocalDevice::HostMode hostMode= device->hostMode(); QVERIFY(hostMode == QBluetoothLocalDevice::HostConnectable || hostMode == QBluetoothLocalDevice::HostDiscoverable || hostMode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry); delete device; }
void tst_QBluetoothLocalDevice::tst_powerOn() { { QBluetoothLocalDevice localDevice; QSignalSpy hostModeSpy(&localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode))); // there should be no changes yet QVERIFY(hostModeSpy.isEmpty()); localDevice.powerOn(); // async, wait for it WAIT_FOR_CONDITION(hostModeSpy.count(),1); QVERIFY(hostModeSpy.count() > 0); QBluetoothLocalDevice::HostMode hostMode= localDevice.hostMode(); // we should not be powered off QVERIFY(hostMode == QBluetoothLocalDevice::HostConnectable || hostMode == QBluetoothLocalDevice::HostDiscoverable); } }
void tst_QBluetoothLocalDevice::tst_powerOn() { QBluetoothLocalDevice localDevice; QSignalSpy hostModeSpy(&localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode))); // there should be no changes yet QVERIFY(hostModeSpy.isValid()); QVERIFY(hostModeSpy.isEmpty()); if (!QBluetoothLocalDevice::allDevices().count()) QSKIP("Skipping test due to missing Bluetooth device"); localDevice.powerOn(); // async, wait for it QTRY_VERIFY(hostModeSpy.count() > 0); QBluetoothLocalDevice::HostMode hostMode= localDevice.hostMode(); // we should not be powered off QVERIFY(hostMode == QBluetoothLocalDevice::HostConnectable || hostMode == QBluetoothLocalDevice::HostDiscoverable); }
void tst_QBluetoothLocalDevice::tst_powerOff() { { QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); device->powerOn(); delete device; // wait for the device to switch bluetooth mode. QTest::qWait(1000); } QBluetoothLocalDevice localDevice; QSignalSpy hostModeSpy(&localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode))); // there should be no changes yet QVERIFY(hostModeSpy.isEmpty()); localDevice.setHostMode(QBluetoothLocalDevice::HostPoweredOff); // async, wait for it WAIT_FOR_CONDITION(hostModeSpy.count(),1); QVERIFY(hostModeSpy.count() > 0); // we should not be powered off QVERIFY(localDevice.hostMode() == QBluetoothLocalDevice::HostPoweredOff); }