diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-06-30 12:32:18 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-07-02 16:17:18 +0200 |
commit | a354431ba0d8c057bd360c0b23565b650814ffc3 (patch) | |
tree | 6c590abd41bb79f8d920946e5cab9f2f115e9c9d /tests | |
parent | ce09187a209ec50aa8699e160dfc4f481a0d5e51 (diff) |
Rewrite QLowEnergyCharacteristic unit test
This change incorporates the change from QLECharacteristicInfo to
QLECharacteristic.
Change-Id: I0fc6d31b60975e3b0cccc7666df9c0555350f40f
Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/auto.pro | 2 | ||||
-rw-r--r-- | tests/auto/qlowenergycharacteristic/qlowenergycharacteristic.pro (renamed from tests/auto/qlowenergycharacteristicinfo/qlowenergycharacteristicinfo.pro) | 4 | ||||
-rw-r--r-- | tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp | 299 | ||||
-rw-r--r-- | tests/auto/qlowenergycharacteristicinfo/tst_qlowenergycharacteristicinfo.cpp | 226 | ||||
-rw-r--r-- | tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp | 21 |
5 files changed, 321 insertions, 231 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 99c81f30..8966e5d9 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -17,7 +17,7 @@ qtHaveModule(bluetooth) { qbluetoothtransferrequest \ qbluetoothuuid \ qbluetoothserver \ - qlowenergycharacteristicinfo \ + qlowenergycharacteristic \ qlowenergydescriptor \ qlowenergyserviceinfo \ qlowenergycontroller diff --git a/tests/auto/qlowenergycharacteristicinfo/qlowenergycharacteristicinfo.pro b/tests/auto/qlowenergycharacteristic/qlowenergycharacteristic.pro index e14c18e3..33302d60 100644 --- a/tests/auto/qlowenergycharacteristicinfo/qlowenergycharacteristicinfo.pro +++ b/tests/auto/qlowenergycharacteristic/qlowenergycharacteristic.pro @@ -1,5 +1,5 @@ -SOURCES += tst_qlowenergycharacteristicinfo.cpp -TARGET = tst_qlowenergycharacteristicinfo +SOURCES += tst_qlowenergycharacteristic.cpp +TARGET = tst_qlowenergycharacteristic CONFIG += testcase QT = core bluetooth testlib diff --git a/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp new file mode 100644 index 00000000..0c0cdb31 --- /dev/null +++ b/tests/auto/qlowenergycharacteristic/tst_qlowenergycharacteristic.cpp @@ -0,0 +1,299 @@ +/*************************************************************************** +** +** Copyright (C) 2013 BlackBerry Limited all rights reserved +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtBluetooth module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QUuid> + +#include <QDebug> + +#include <QBluetoothServiceDiscoveryAgent> +#include <QLowEnergyCharacteristic> +#include <QLowEnergyServiceInfo> +#include <QLowEnergyControllerNew> +#include <QBluetoothLocalDevice> + +QT_USE_NAMESPACE + +class tst_QLowEnergyCharacteristic : public QObject +{ + Q_OBJECT + +public: + tst_QLowEnergyCharacteristic(); + ~tst_QLowEnergyCharacteristic(); + +protected slots: + void serviceDiscovered(const QLowEnergyServiceInfo &info); + +private slots: + void initTestCase(); + void cleanupTestCase(); + void tst_constructionDefault(); + void tst_assignCompare(); + +private: + QBluetoothServiceDiscoveryAgent *agent; + QSet<QString> remoteLeDevices; + QLowEnergyControllerNew *globalControl; + QLowEnergyService *globalService; +}; + +tst_QLowEnergyCharacteristic::tst_QLowEnergyCharacteristic() : + globalControl(0), globalService(0) +{ + QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); +} + +tst_QLowEnergyCharacteristic::~tst_QLowEnergyCharacteristic() +{ +} + +void tst_QLowEnergyCharacteristic::initTestCase() +{ + if (QBluetoothLocalDevice::allDevices().isEmpty()) { + qWarning("No remote device discovered."); + return; + } + + // start Bluetooth if not started + QBluetoothLocalDevice device; + device.powerOn(); + + // find an arbitrary low energy device in vincinity + // find an arbitrary service with characteristic + + QBluetoothServiceDiscoveryAgent * agent = new QBluetoothServiceDiscoveryAgent(this); + connect(agent, SIGNAL(serviceDiscovered(QLowEnergyServiceInfo)), + SLOT(serviceDiscovered(QLowEnergyServiceInfo))); + + QSignalSpy spy(agent, SIGNAL(finished())); + // there should be no changes yet + QVERIFY(spy.isValid()); + QVERIFY(spy.isEmpty()); + + agent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery); + QTRY_VERIFY_WITH_TIMEOUT(spy.count() > 0, 50000); + + // find first service with descriptor + QLowEnergyControllerNew *controller = 0; + foreach (const QString &remoteDevice, remoteLeDevices.toList()) { + controller = new QLowEnergyControllerNew(QBluetoothAddress(remoteDevice), this); + qDebug() << "Connecting to" << remoteDevice; + controller->connectToDevice(); + QTRY_IMPL(controller->state() != QLowEnergyControllerNew::ConnectingState, + 10000); + if (controller->state() != QLowEnergyControllerNew::ConnectedState) { + // any error and we skip + delete controller; + qDebug() << "Skipping device"; + continue; + } + + QSignalSpy discoveryFinishedSpy(controller, SIGNAL(discoveryFinished())); + controller->discoverServices(); + QTRY_VERIFY_WITH_TIMEOUT(discoveryFinishedSpy.count() == 1, 10000); + foreach (const QBluetoothUuid &leServiceUuid, controller->services()) { + QLowEnergyService *leService = controller->createServiceObject(leServiceUuid, this); + if (!leService) + continue; + + leService->discoverDetails(); + QTRY_VERIFY_WITH_TIMEOUT( + leService->state() == QLowEnergyService::ServiceDiscovered, 10000); + + QList<QLowEnergyCharacteristic> chars = leService->characteristics(); + foreach (const QLowEnergyCharacteristic &ch, chars) { + if (!ch.descriptors().isEmpty()) { + globalService = leService; + globalControl = controller; + qWarning() << "Found service with descriptor" << remoteDevice + << globalService->serviceName() << globalService->serviceUuid(); + break; + } + } + + if (globalControl) + break; + else + delete leService; + } + + if (globalControl) + break; + + delete controller; + } + + if (!globalControl) { + qWarning() << "Test limited due to missing remote QLowEnergyDescriptor." + << "Please ensure the Bluetooth Low Energy device is advertising its services."; + } +} + +void tst_QLowEnergyCharacteristic::cleanupTestCase() +{ + if (globalControl) + globalControl->disconnectFromDevice(); +} + +void tst_QLowEnergyCharacteristic::serviceDiscovered(const QLowEnergyServiceInfo &info) +{ + remoteLeDevices.insert(info.device().address().toString()); +} + +void tst_QLowEnergyCharacteristic::tst_constructionDefault() +{ + QLowEnergyCharacteristic characteristic; + QVERIFY(!characteristic.isValid()); + QCOMPARE(characteristic.value(), QByteArray()); + QVERIFY(characteristic.uuid().isNull()); + QVERIFY(characteristic.handle() == 0); + QCOMPARE(characteristic.name(), QString()); + QCOMPARE(characteristic.descriptors().count(), 0); + QCOMPARE(characteristic.properties(), QLowEnergyCharacteristic::Unknown); + + QLowEnergyCharacteristic copyConstructed(characteristic); + QVERIFY(!copyConstructed.isValid()); + QCOMPARE(copyConstructed.value(), QByteArray()); + QVERIFY(copyConstructed.uuid().isNull()); + QVERIFY(copyConstructed.handle() == 0); + QCOMPARE(copyConstructed.name(), QString()); + QCOMPARE(copyConstructed.descriptors().count(), 0); + QCOMPARE(copyConstructed.properties(), QLowEnergyCharacteristic::Unknown); + + QLowEnergyCharacteristic assigned; + assigned = characteristic; + QVERIFY(!assigned.isValid()); + QCOMPARE(assigned.value(), QByteArray()); + QVERIFY(assigned.uuid().isNull()); + QVERIFY(assigned.handle() == 0); + QCOMPARE(assigned.name(), QString()); + QCOMPARE(assigned.descriptors().count(), 0); + QCOMPARE(assigned.properties(), QLowEnergyCharacteristic::Unknown); +} + +void tst_QLowEnergyCharacteristic::tst_assignCompare() +{ + if (!globalService) + QSKIP("No characteristic found."); + + QLowEnergyCharacteristic target; + QVERIFY(!target.isValid()); + QCOMPARE(target.value(), QByteArray()); + QVERIFY(target.uuid().isNull()); + QVERIFY(target.handle() == 0); + QCOMPARE(target.name(), QString()); + QCOMPARE(target.descriptors().count(), 0); + QCOMPARE(target.properties(), QLowEnergyCharacteristic::Unknown); + + int indexWithDescriptor = -1; + const QList<QLowEnergyCharacteristic> chars = globalService->characteristics(); + QVERIFY(!chars.isEmpty()); + for (int i = 0; i < chars.count(); i++) { + if (chars[i].descriptors().count() > 0) { + indexWithDescriptor = i; + break; + } + } + + if (chars.isEmpty()) + QSKIP("No suitable characteristic found despite prior indication."); + + bool noDescriptors = (indexWithDescriptor == -1); + if (noDescriptors) + indexWithDescriptor = 0; // just choose one + + // test assignment operator + target = chars[indexWithDescriptor]; + QVERIFY(target.isValid()); + QVERIFY(!target.name().isEmpty()); + QVERIFY(target.handle() > 0); + QVERIFY(!target.uuid().isNull()); + QVERIFY(target.properties() != QLowEnergyCharacteristic::Unknown); + if (target.properties() & QLowEnergyCharacteristic::Read) + QVERIFY(!target.value().isEmpty()); + if (!noDescriptors) + QVERIFY(target.descriptors().count() > 0); + + QCOMPARE(target.isValid(), chars[indexWithDescriptor].isValid()); + QCOMPARE(target.name(), chars[indexWithDescriptor].name()); + QCOMPARE(target.handle(), chars[indexWithDescriptor].handle()); + QCOMPARE(target.uuid(), chars[indexWithDescriptor].uuid()); + QCOMPARE(target.value(), chars[indexWithDescriptor].value()); + QCOMPARE(target.properties(), chars[indexWithDescriptor].properties()); + QCOMPARE(target.descriptors().count(), + chars[indexWithDescriptor].descriptors().count()); + for (int i = 0; i < target.descriptors().count(); i++) { + const QLowEnergyDescriptor ref = chars[indexWithDescriptor].descriptors()[i]; + QCOMPARE(target.descriptors()[i].name(), ref.name()); + QCOMPARE(target.descriptors()[i].isValid(), ref.isValid()); + QCOMPARE(target.descriptors()[i].type(), ref.type()); + QCOMPARE(target.descriptors()[i].handle(), ref.handle()); + QCOMPARE(target.descriptors()[i].uuid(), ref.uuid()); + QCOMPARE(target.descriptors()[i].value(), ref.value()); + } + + // test copy constructor + QLowEnergyCharacteristic copyConstructed(target); + QCOMPARE(copyConstructed.isValid(), chars[indexWithDescriptor].isValid()); + QCOMPARE(copyConstructed.name(), chars[indexWithDescriptor].name()); + QCOMPARE(copyConstructed.handle(), chars[indexWithDescriptor].handle()); + QCOMPARE(copyConstructed.uuid(), chars[indexWithDescriptor].uuid()); + QCOMPARE(copyConstructed.value(), chars[indexWithDescriptor].value()); + QCOMPARE(copyConstructed.properties(), chars[indexWithDescriptor].properties()); + QCOMPARE(copyConstructed.descriptors().count(), + chars[indexWithDescriptor].descriptors().count()); + + // test invalidation + QLowEnergyCharacteristic invalid; + target = invalid; + QVERIFY(!target.isValid()); + QCOMPARE(target.value(), QByteArray()); + QVERIFY(target.uuid().isNull()); + QVERIFY(target.handle() == 0); + QCOMPARE(target.name(), QString()); + QCOMPARE(target.descriptors().count(), 0); + QCOMPARE(target.properties(), QLowEnergyCharacteristic::Unknown); +} + +QTEST_MAIN(tst_QLowEnergyCharacteristic) + +#include "tst_qlowenergycharacteristic.moc" diff --git a/tests/auto/qlowenergycharacteristicinfo/tst_qlowenergycharacteristicinfo.cpp b/tests/auto/qlowenergycharacteristicinfo/tst_qlowenergycharacteristicinfo.cpp deleted file mode 100644 index 580ad0c1..00000000 --- a/tests/auto/qlowenergycharacteristicinfo/tst_qlowenergycharacteristicinfo.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/*************************************************************************** -** -** Copyright (C) 2013 BlackBerry Limited all rights reserved -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtBluetooth module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QUuid> - -#include <QDebug> - -#include <qbluetoothdeviceinfo.h> -#include <qlowenergycharacteristicinfo.h> -#include <qbluetoothaddress.h> -#include <qbluetoothlocaldevice.h> -#include <qbluetoothuuid.h> - -QT_USE_NAMESPACE - -Q_DECLARE_METATYPE(QUuid) -Q_DECLARE_METATYPE(QLowEnergyCharacteristicInfo) -Q_DECLARE_METATYPE(QBluetoothUuid::CharacteristicType) - -class tst_QLowEnergyCharacteristicInfo : public QObject -{ - Q_OBJECT - -public: - tst_QLowEnergyCharacteristicInfo(); - ~tst_QLowEnergyCharacteristicInfo(); - -private slots: - void initTestCase(); - void tst_construction(); - void tst_assignment_data(); - void tst_assignment(); -}; - -tst_QLowEnergyCharacteristicInfo::tst_QLowEnergyCharacteristicInfo() -{ -} - -tst_QLowEnergyCharacteristicInfo::~tst_QLowEnergyCharacteristicInfo() -{ -} - -void tst_QLowEnergyCharacteristicInfo::initTestCase() -{ - // start Bluetooth if not started - QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); - device->powerOn(); - delete device; -} - -void tst_QLowEnergyCharacteristicInfo::tst_construction() -{ - const QBluetoothUuid characteristicUuid(QBluetoothUuid::HIDControlPoint); - const QBluetoothUuid alternateCharacteristicUuid(QBluetoothUuid::TemperatureMeasurement); - - { - QLowEnergyCharacteristicInfo characteristicInfo; - - QVERIFY(!characteristicInfo.isValid()); - QCOMPARE(characteristicInfo.uuid().toString(), QBluetoothUuid().toString()); - QCOMPARE(characteristicInfo.value(), QByteArray()); - QCOMPARE(characteristicInfo.properties(), QLowEnergyCharacteristicInfo::Unknown); - QCOMPARE(characteristicInfo.handle(), 0u); - QCOMPARE(characteristicInfo.name(), QString("")); - QCOMPARE(characteristicInfo.isNotificationCharacteristic(), false); - QCOMPARE(characteristicInfo.descriptors().count(), 0); - } - - { - QLowEnergyCharacteristicInfo characteristicInfo(characteristicUuid); - - QVERIFY(!characteristicInfo.isValid()); - - QCOMPARE(characteristicInfo.uuid().toString(), characteristicUuid.toString()); - QCOMPARE(characteristicInfo.value(), QByteArray()); - QCOMPARE(characteristicInfo.properties(), QLowEnergyCharacteristicInfo::Unknown); - QCOMPARE(characteristicInfo.handle(), 0u); - QCOMPARE(characteristicInfo.name(), - QBluetoothUuid::characteristicToString(QBluetoothUuid::HIDControlPoint)); - QCOMPARE(characteristicInfo.isNotificationCharacteristic(), false); - QCOMPARE(characteristicInfo.descriptors().count(), 0); - - QLowEnergyCharacteristicInfo copyInfo(characteristicInfo); - QVERIFY(!copyInfo.isValid()); - QCOMPARE(copyInfo.uuid().toString(), characteristicUuid.toString()); - QCOMPARE(copyInfo.value(), QByteArray()); - copyInfo.setValue(QByteArray("test")); - QCOMPARE(copyInfo.value(), QByteArray("test")); - - //QLowEnergyCharacteristicInfos share their internal data - //for now enshrine this in the test - //TODO do we really need this behavior as it is unusual for value types - QCOMPARE(characteristicInfo.value(), QByteArray("test")); - - - copyInfo = QLowEnergyCharacteristicInfo(alternateCharacteristicUuid); - QCOMPARE(copyInfo.uuid().toString(), alternateCharacteristicUuid.toString()); - - QCOMPARE(copyInfo.handle(), 0u); - QCOMPARE(copyInfo.value(), QByteArray()); - QCOMPARE(copyInfo.properties(), QLowEnergyCharacteristicInfo::Unknown); - QCOMPARE(copyInfo.handle(), 0u); - QCOMPARE(copyInfo.name(), - QBluetoothUuid::characteristicToString(QBluetoothUuid::TemperatureMeasurement)); - QCOMPARE(copyInfo.isNotificationCharacteristic(), false); - QCOMPARE(copyInfo.descriptors().count(), 0); - QCOMPARE(copyInfo.value(), QByteArray()); - copyInfo.setValue(QByteArray("test")); - QCOMPARE(copyInfo.value(), QByteArray("test")); - } -} - -void tst_QLowEnergyCharacteristicInfo::tst_assignment_data() -{ - QTest::addColumn<QBluetoothUuid>("characteristicClassUuid"); - - QTest::newRow("0x000000 COD") << QBluetoothUuid(QBluetoothUuid::AlertCategoryID); - QTest::newRow("0x001000 COD") << QBluetoothUuid(QBluetoothUuid::AlertCategoryIDBitMask); - QTest::newRow("0x002000 COD") << QBluetoothUuid(QBluetoothUuid::AlertLevel); - QTest::newRow("0x003000 COD") << QBluetoothUuid(QBluetoothUuid::AlertNotificationControlPoint); - QTest::newRow("0x004000 COD") << QBluetoothUuid(QBluetoothUuid::AlertStatus); - QTest::newRow("0x005000 COD") << QBluetoothUuid(QBluetoothUuid::Appearance); - QTest::newRow("0x006000 COD") << QBluetoothUuid(QBluetoothUuid::CSCFeature); - QTest::newRow("0x007000 COD") << QBluetoothUuid(QBluetoothUuid::CSCMeasurement); - QTest::newRow("0x008000 COD") << QBluetoothUuid(QBluetoothUuid::CurrentTime); - QTest::newRow("0x009000 COD") << QBluetoothUuid(QBluetoothUuid::DateTime); - QTest::newRow("0x010000 COD") << QBluetoothUuid(QBluetoothUuid::DayOfWeek); - QTest::newRow("0x011000 COD") << QBluetoothUuid(QBluetoothUuid::DeviceName); - QTest::newRow("0x012000 COD") << QBluetoothUuid(QBluetoothUuid::DSTOffset); - QTest::newRow("0x013000 COD") << QBluetoothUuid(QBluetoothUuid::ExactTime256); - QTest::newRow("0x014000 COD") << QBluetoothUuid(QBluetoothUuid::HeartRateControlPoint); - QTest::newRow("0x015000 COD") << QBluetoothUuid(QBluetoothUuid::IntermediateCuffPressure); - QTest::newRow("0x016000 COD") << QBluetoothUuid(QBluetoothUuid::Navigation); - QTest::newRow("0x017000 COD") << QBluetoothUuid(QBluetoothUuid::NewAlert); - QTest::newRow("0x018000 COD") << QBluetoothUuid(QBluetoothUuid::PeripheralPreferredConnectionParameters); -} - -void tst_QLowEnergyCharacteristicInfo::tst_assignment() -{ - QFETCH(QBluetoothUuid, characteristicClassUuid); - - QLowEnergyCharacteristicInfo characteristicInfo(characteristicClassUuid); - - QVERIFY(!characteristicInfo.isValid()); - - { - QLowEnergyCharacteristicInfo copyInfo = characteristicInfo; - - QVERIFY(!copyInfo.isValid()); - - QCOMPARE(copyInfo.uuid(), characteristicClassUuid); - QCOMPARE(copyInfo.value(), QByteArray()); - } - - { - QLowEnergyCharacteristicInfo copyInfo; - - QVERIFY(!copyInfo.isValid()); - - copyInfo = characteristicInfo; - - QVERIFY(!copyInfo.isValid()); - - QCOMPARE(copyInfo.uuid(), characteristicClassUuid); - } - - { - QLowEnergyCharacteristicInfo copyInfo1; - QLowEnergyCharacteristicInfo copyInfo2; - - QVERIFY(!copyInfo1.isValid()); - QVERIFY(!copyInfo2.isValid()); - - copyInfo1 = copyInfo2 = characteristicInfo; - - QVERIFY(!copyInfo1.isValid()); - QVERIFY(!copyInfo2.isValid()); - //QVERIFY(QLowEnergyCharacteristicInfo() != copyInfo1); - - QCOMPARE(copyInfo1.uuid(), characteristicClassUuid); - QCOMPARE(copyInfo2.uuid(), characteristicClassUuid); - } -} - -QTEST_MAIN(tst_QLowEnergyCharacteristicInfo) - -#include "tst_qlowenergycharacteristicinfo.moc" diff --git a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp index ca3c0ff2..5ab59a60 100644 --- a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp +++ b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp @@ -72,7 +72,6 @@ private slots: private: QBluetoothServiceDiscoveryAgent *agent; QSet<QString> remoteLeDevices; - QList<QLowEnergyServiceInfo> foundServices; QLowEnergyControllerNew *globalControl; QLowEnergyService *globalService; }; @@ -224,7 +223,6 @@ void tst_QLowEnergyDescriptor::tst_assignCompare() QCOMPARE(target.uuid(), QBluetoothUuid()); QCOMPARE(target.value(), QByteArray()); - QLowEnergyCharacteristic targetChar; QList<QLowEnergyDescriptor> targets; const QList<QLowEnergyCharacteristic> chars = globalService->characteristics(); foreach (const QLowEnergyCharacteristic &ch, chars) { @@ -252,6 +250,25 @@ void tst_QLowEnergyDescriptor::tst_assignCompare() QCOMPARE(target.handle(), targets.first().handle()); QCOMPARE(target.uuid(), targets.first().uuid()); QCOMPARE(target.value(), targets.first().value()); + + // test copy constructor + QLowEnergyDescriptor copyConstructed(target); + QCOMPARE(copyConstructed.isValid(), targets.first().isValid()); + QCOMPARE(copyConstructed.type(), targets.first().type()); + QCOMPARE(copyConstructed.name(), targets.first().name()); + QCOMPARE(copyConstructed.handle(), targets.first().handle()); + QCOMPARE(copyConstructed.uuid(), targets.first().uuid()); + QCOMPARE(copyConstructed.value(), targets.first().value()); + + // test invalidation + QLowEnergyDescriptor invalid; + target = invalid; + QVERIFY(!target.isValid()); + QCOMPARE(target.value(), QByteArray()); + QVERIFY(target.uuid().isNull()); + QVERIFY(target.handle() == 0); + QCOMPARE(target.name(), QString()); + QCOMPARE(target.type(), QBluetoothUuid::UnknownDescriptorType); } QTEST_MAIN(tst_QLowEnergyDescriptor) |