summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-06-30 09:39:35 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-07-02 16:17:14 +0200
commitce09187a209ec50aa8699e160dfc4f481a0d5e51 (patch)
treef5df3388a209680ff3ad1e9769638dd2c65efd4c /tests
parentc35020419edafae6e7d1f0489942909a611f729f (diff)
Rewrite Descriptor class unit test
- Rename test due to class renaming - Test all class properties - Fix QLowEnergyDescriptor::uuid() when using invalid descriptor - Fixup dead code in QLowEnergyController unit test Change-Id: I5ffed5b67db786e6c2d9752ca51d2ede51e3f176 Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro2
-rw-r--r--tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp13
-rw-r--r--tests/auto/qlowenergydescriptor/qlowenergydescriptor.pro8
-rw-r--r--tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp260
-rw-r--r--tests/auto/qlowenergydescriptorinfo/qlowenergydescriptorinfo.pro9
-rw-r--r--tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp194
6 files changed, 269 insertions, 217 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 62318c88..99c81f30 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -18,7 +18,7 @@ qtHaveModule(bluetooth) {
qbluetoothuuid \
qbluetoothserver \
qlowenergycharacteristicinfo \
- qlowenergydescriptorinfo \
+ qlowenergydescriptor \
qlowenergyserviceinfo \
qlowenergycontroller
}
diff --git a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
index 1710abed..2e88d97f 100644
--- a/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
+++ b/tests/auto/qlowenergycontroller/tst_qlowenergycontroller.cpp
@@ -63,8 +63,6 @@ public:
protected slots:
void discoveryError(QBluetoothServiceDiscoveryAgent::Error error);
void serviceDiscovered(const QLowEnergyServiceInfo &info);
- void serviceConnected(const QLowEnergyServiceInfo &info);
- void serviceDisconnected(const QLowEnergyServiceInfo &info);
private slots:
void initTestCase();
@@ -116,17 +114,6 @@ void tst_QLowEnergyController::serviceDiscovered(const QLowEnergyServiceInfo &in
foundServices.append(info);
}
-void tst_QLowEnergyController::serviceConnected(const QLowEnergyServiceInfo &/*info*/)
-{
-
-}
-
-void tst_QLowEnergyController::serviceDisconnected(const QLowEnergyServiceInfo &/*info*/)
-{
-
-}
-
-
void tst_QLowEnergyController::initTestCase()
{
if (remoteDevice.isNull()
diff --git a/tests/auto/qlowenergydescriptor/qlowenergydescriptor.pro b/tests/auto/qlowenergydescriptor/qlowenergydescriptor.pro
new file mode 100644
index 00000000..60b5a740
--- /dev/null
+++ b/tests/auto/qlowenergydescriptor/qlowenergydescriptor.pro
@@ -0,0 +1,8 @@
+SOURCES += tst_qlowenergydescriptor.cpp
+TARGET = tst_qlowenergydescriptor
+CONFIG += testcase
+
+QT = core bluetooth testlib
+blackberry {
+ LIBS += -lbtapi
+}
diff --git a/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp
new file mode 100644
index 00000000..ca3c0ff2
--- /dev/null
+++ b/tests/auto/qlowenergydescriptor/tst_qlowenergydescriptor.cpp
@@ -0,0 +1,260 @@
+/***************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited all rights reserved
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** 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 <QLowEnergyDescriptor>
+#include <QLowEnergyControllerNew>
+#include <QBluetoothLocalDevice>
+
+QT_USE_NAMESPACE
+
+class tst_QLowEnergyDescriptor : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QLowEnergyDescriptor();
+ ~tst_QLowEnergyDescriptor();
+
+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;
+ QList<QLowEnergyServiceInfo> foundServices;
+ QLowEnergyControllerNew *globalControl;
+ QLowEnergyService *globalService;
+};
+
+tst_QLowEnergyDescriptor::tst_QLowEnergyDescriptor() :
+ globalControl(0), globalService(0)
+{
+ QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));
+}
+
+tst_QLowEnergyDescriptor::~tst_QLowEnergyDescriptor()
+{
+}
+
+void tst_QLowEnergyDescriptor::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 descriptor
+
+ 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_QLowEnergyDescriptor::cleanupTestCase()
+{
+ if (globalControl)
+ globalControl->disconnectFromDevice();
+}
+
+void tst_QLowEnergyDescriptor::serviceDiscovered(const QLowEnergyServiceInfo &info)
+{
+ remoteLeDevices.insert(info.device().address().toString());
+}
+
+void tst_QLowEnergyDescriptor::tst_constructionDefault()
+{
+ QLowEnergyDescriptor descriptor;
+ QVERIFY(!descriptor.isValid());
+ QCOMPARE(descriptor.value(), QByteArray());
+ QVERIFY(descriptor.uuid().isNull());
+ QVERIFY(descriptor.handle() == 0);
+ QCOMPARE(descriptor.name(), QString());
+ QCOMPARE(descriptor.type(), QBluetoothUuid::UnknownDescriptorType);
+
+ QLowEnergyDescriptor copyConstructed(descriptor);
+ QVERIFY(!copyConstructed.isValid());
+ QCOMPARE(copyConstructed.value(), QByteArray());
+ QVERIFY(copyConstructed.uuid().isNull());
+ QVERIFY(copyConstructed.handle() == 0);
+ QCOMPARE(copyConstructed.name(), QString());
+ QCOMPARE(copyConstructed.type(), QBluetoothUuid::UnknownDescriptorType);
+
+ QLowEnergyDescriptor assigned;
+ assigned = descriptor;
+ QVERIFY(!assigned.isValid());
+ QCOMPARE(assigned.value(), QByteArray());
+ QVERIFY(assigned.uuid().isNull());
+ QVERIFY(assigned.handle() == 0);
+ QCOMPARE(assigned.name(), QString());
+ QCOMPARE(assigned.type(), QBluetoothUuid::UnknownDescriptorType);
+}
+
+
+void tst_QLowEnergyDescriptor::tst_assignCompare()
+{
+ //find the descriptor
+ if (!globalService)
+ QSKIP("No descriptor found.");
+
+ QLowEnergyDescriptor target;
+ QVERIFY(!target.isValid());
+ QCOMPARE(target.type(), QBluetoothUuid::UnknownDescriptorType);
+ QCOMPARE(target.name(), QString());
+ QCOMPARE(target.handle(), 0u);
+ QCOMPARE(target.uuid(), QBluetoothUuid());
+ QCOMPARE(target.value(), QByteArray());
+
+ QLowEnergyCharacteristic targetChar;
+ QList<QLowEnergyDescriptor> targets;
+ const QList<QLowEnergyCharacteristic> chars = globalService->characteristics();
+ foreach (const QLowEnergyCharacteristic &ch, chars) {
+ if (!ch.descriptors().isEmpty()) {
+ targets = ch.descriptors();
+ break;
+ }
+ }
+
+ if (targets.isEmpty())
+ QSKIP("No descriptor found despite prior indication.");
+
+ // test assignment operator
+ target = targets.first();
+ QVERIFY(target.isValid());
+ QVERIFY(target.type() != QBluetoothUuid::UnknownDescriptorType);
+ QVERIFY(!target.name().isEmpty());
+ QVERIFY(target.handle() > 0);
+ QVERIFY(!target.uuid().isNull());
+ QVERIFY(!target.value().isEmpty());
+
+ QCOMPARE(target.isValid(), targets.first().isValid());
+ QCOMPARE(target.type(), targets.first().type());
+ QCOMPARE(target.name(), targets.first().name());
+ QCOMPARE(target.handle(), targets.first().handle());
+ QCOMPARE(target.uuid(), targets.first().uuid());
+ QCOMPARE(target.value(), targets.first().value());
+}
+
+QTEST_MAIN(tst_QLowEnergyDescriptor)
+
+#include "tst_qlowenergydescriptor.moc"
+
diff --git a/tests/auto/qlowenergydescriptorinfo/qlowenergydescriptorinfo.pro b/tests/auto/qlowenergydescriptorinfo/qlowenergydescriptorinfo.pro
deleted file mode 100644
index 11d3d843..00000000
--- a/tests/auto/qlowenergydescriptorinfo/qlowenergydescriptorinfo.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-SOURCES += tst_qlowenergydescriptorinfo.cpp
-TARGET = tst_qlowenergydescriptorinfo
-CONFIG += testcase
-
-QT = core bluetooth testlib
-DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
-blackberry {
- LIBS += -lbtapi
-}
diff --git a/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp b/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp
deleted file mode 100644
index 6934417a..00000000
--- a/tests/auto/qlowenergydescriptorinfo/tst_qlowenergydescriptorinfo.cpp
+++ /dev/null
@@ -1,194 +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 <qlowenergydescriptorinfo.h>
-#include <qbluetoothlocaldevice.h>
-#include "qbluetoothuuid.h"
-
-QT_USE_NAMESPACE
-
-Q_DECLARE_METATYPE(QUuid)
-Q_DECLARE_METATYPE(QBluetoothUuid::DescriptorType)
-
-class tst_QLowEnergyDescriptorInfo : public QObject
-{
- Q_OBJECT
-
-public:
- tst_QLowEnergyDescriptorInfo();
- ~tst_QLowEnergyDescriptorInfo();
-
-private slots:
- void initTestCase();
- void tst_construction();
- void tst_assignment_data();
- void tst_assignment();
-};
-
-tst_QLowEnergyDescriptorInfo::tst_QLowEnergyDescriptorInfo()
-{
-}
-
-tst_QLowEnergyDescriptorInfo::~tst_QLowEnergyDescriptorInfo()
-{
-}
-
-void tst_QLowEnergyDescriptorInfo::initTestCase()
-{
- // start Bluetooth if not started
- QBluetoothLocalDevice *device = new QBluetoothLocalDevice();
- device->powerOn();
- delete device;
-}
-
-void tst_QLowEnergyDescriptorInfo::tst_construction()
-{
- const QBluetoothUuid descriptorUuid(0x2902u);
- const QBluetoothUuid alternateDescriptorUuid(0x2906u);
-
- {
- QLowEnergyDescriptorInfo descriptorInfo = QLowEnergyDescriptorInfo(QBluetoothUuid());
-
- QCOMPARE(descriptorInfo.uuid(), QBluetoothUuid());
- QCOMPARE(descriptorInfo.value(), QByteArray());
- QCOMPARE(descriptorInfo.handle(), 0u);
- QCOMPARE(descriptorInfo.name(),
- QBluetoothUuid::descriptorToString(descriptorInfo.type()));
- QCOMPARE(descriptorInfo.type(),
- QBluetoothUuid::ClientCharacteristicConfiguration);
- }
-
- {
- QLowEnergyDescriptorInfo descriptorInfo(descriptorUuid);
-
- QCOMPARE(descriptorInfo.uuid().toString(), descriptorUuid.toString());
-
- QLowEnergyDescriptorInfo copyInfo = descriptorInfo;
- QCOMPARE(copyInfo.uuid().toString(), descriptorUuid.toString());
- QCOMPARE(copyInfo.name(),
- QBluetoothUuid::descriptorToString(copyInfo.type()));
- copyInfo.setValue(QByteArray("test"));
- QCOMPARE(copyInfo.value(), QByteArray("test"));
-
- //QLowEnergyDescriptorInfos 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(descriptorInfo.value(), QByteArray("test"));
-
- copyInfo = QLowEnergyDescriptorInfo(alternateDescriptorUuid);
- QCOMPARE(copyInfo.uuid().toString(), alternateDescriptorUuid.toString());
-
- QCOMPARE(copyInfo.uuid(), alternateDescriptorUuid);
- QCOMPARE(copyInfo.value(), QByteArray());
- QCOMPARE(copyInfo.handle(), 0u);
- QCOMPARE(copyInfo.name(),
- QBluetoothUuid::descriptorToString(copyInfo.type()));
- }
-}
-
-void tst_QLowEnergyDescriptorInfo::tst_assignment_data()
-{
- QTest::addColumn<QBluetoothUuid>("descriptorClassUuid");
-
- QTest::newRow("0x000000 COD")
- << QBluetoothUuid(QBluetoothUuid::CharacteristicUserDescription);
- QTest::newRow("0x001000 COD")
- << QBluetoothUuid(QBluetoothUuid::ClientCharacteristicConfiguration);
- QTest::newRow("0x002000 COD")
- << QBluetoothUuid(QBluetoothUuid::ServerCharacteristicConfiguration);
- QTest::newRow("0x003000 COD")
- << QBluetoothUuid(QBluetoothUuid::CharacteristicPresentationFormat);
- QTest::newRow("0x004000 COD")
- << QBluetoothUuid(QBluetoothUuid::CharacteristicAggregateFormat);
- QTest::newRow("0x005000 COD")
- << QBluetoothUuid(QBluetoothUuid::ValidRange);
- QTest::newRow("0x006000 COD")
- << QBluetoothUuid(QBluetoothUuid::ExternalReportReference);
- QTest::newRow("0x007000 COD")
- << QBluetoothUuid(QBluetoothUuid::ReportReference);
- QTest::newRow("0x008000 COD")
- << QBluetoothUuid(QBluetoothUuid::CharacteristicExtendedProperties);
-}
-
-void tst_QLowEnergyDescriptorInfo::tst_assignment()
-{
- QFETCH(QBluetoothUuid, descriptorClassUuid);
-
- QLowEnergyDescriptorInfo descriptorInfo(descriptorClassUuid);
-
-
- {
- QLowEnergyDescriptorInfo copyInfo = descriptorInfo;
-
- QCOMPARE(copyInfo.uuid(), descriptorClassUuid);
- QCOMPARE(copyInfo.value(), QByteArray());
- }
-
- {
- QLowEnergyDescriptorInfo copyInfo = QLowEnergyDescriptorInfo(QBluetoothUuid());
-
- copyInfo = descriptorInfo;
-
- QCOMPARE(copyInfo.uuid(), descriptorClassUuid);
- }
-
- {
- QLowEnergyDescriptorInfo copyInfo1 = QLowEnergyDescriptorInfo(QBluetoothUuid());
- QLowEnergyDescriptorInfo copyInfo2 = QLowEnergyDescriptorInfo(QBluetoothUuid());
-
- copyInfo1 = copyInfo2 = descriptorInfo;
-
- QCOMPARE(copyInfo1.uuid(), descriptorClassUuid);
- QCOMPARE(copyInfo2.uuid(), descriptorClassUuid);
- }
-
-}
-
-QTEST_MAIN(tst_QLowEnergyDescriptorInfo)
-
-#include "tst_qlowenergydescriptorinfo.moc"
-