1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtBluetooth module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QtTest>
30
31#include <QScopedPointer>
32#include <QDebug>
33
34#include <qbluetoothaddress.h>
35#include <qbluetoothdeviceinfo.h>
36#include <qbluetoothlocaldevice.h>
37#include <qbluetoothuuid.h>
38
39QT_USE_NAMESPACE
40
41Q_DECLARE_METATYPE(QBluetoothDeviceInfo::ServiceClasses)
42Q_DECLARE_METATYPE(QBluetoothDeviceInfo::MajorDeviceClass)
43Q_DECLARE_METATYPE(QBluetoothDeviceInfo::CoreConfiguration)
44
45class tst_QBluetoothDeviceInfo : public QObject
46{
47 Q_OBJECT
48
49public:
50 tst_QBluetoothDeviceInfo();
51 ~tst_QBluetoothDeviceInfo();
52
53private slots:
54 void initTestCase();
55
56 void tst_construction_data();
57 void tst_construction();
58
59 void tst_assignment_data();
60 void tst_assignment();
61
62 void tst_serviceUuids();
63
64 void tst_cached();
65
66 void tst_flags();
67
68 void tst_manufacturerData();
69};
70
71tst_QBluetoothDeviceInfo::tst_QBluetoothDeviceInfo()
72{
73}
74
75tst_QBluetoothDeviceInfo::~tst_QBluetoothDeviceInfo()
76{
77}
78
79void tst_QBluetoothDeviceInfo::initTestCase()
80{
81 qRegisterMetaType<QBluetoothDeviceInfo::ServiceClasses>();
82 qRegisterMetaType<QBluetoothDeviceInfo::MajorDeviceClass>();
83 // start Bluetooth if not started
84 QBluetoothLocalDevice *device = new QBluetoothLocalDevice();
85 device->powerOn();
86 delete device;
87}
88
89void tst_QBluetoothDeviceInfo::tst_construction_data()
90{
91 QTest::addColumn<QBluetoothAddress>(name: "address");
92 QTest::addColumn<QString>(name: "name");
93 QTest::addColumn<quint32>(name: "classOfDevice");
94 QTest::addColumn<QBluetoothDeviceInfo::ServiceClasses>(name: "serviceClasses");
95 QTest::addColumn<QBluetoothDeviceInfo::MajorDeviceClass>(name: "majorDeviceClass");
96 QTest::addColumn<quint8>(name: "minorDeviceClass");
97 QTest::addColumn<QBluetoothDeviceInfo::CoreConfiguration>(name: "coreConfiguration");
98 // On OS X and iOS there are no real addresses
99 // with Core Bluetooth, only 'uuids' (128-bit) generated by Apple instead.
100 QTest::addColumn<QBluetoothUuid>(name: "deviceUuid");
101 const QBluetoothUuid leDeviceUuid(QString("6C903349-31E2-40EF-826B-1E62C0D884E2"));
102
103 // bits 12-8 Major
104 // bits 7-2 Minor
105 // bits 1-0 0
106
107 QTest::newRow(dataTag: "0x000000 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
108 << quint32(0x000000)
109 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
110 << QBluetoothDeviceInfo::MiscellaneousDevice
111 << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous)
112 << QBluetoothDeviceInfo::BaseRateCoreConfiguration
113 << leDeviceUuid;
114 QTest::newRow(dataTag: "0x000100 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
115 << quint32(0x000100)
116 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
117 << QBluetoothDeviceInfo::ComputerDevice
118 << quint8(QBluetoothDeviceInfo::UncategorizedComputer)
119 << QBluetoothDeviceInfo::BaseRateCoreConfiguration
120 << leDeviceUuid;
121 QTest::newRow(dataTag: "0x000104 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
122 << quint32(0x000104)
123 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
124 << QBluetoothDeviceInfo::ComputerDevice
125 << quint8(QBluetoothDeviceInfo::DesktopComputer)
126 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
127 << leDeviceUuid;
128 QTest::newRow(dataTag: "0x000118 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
129 << quint32(0x000118)
130 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
131 << QBluetoothDeviceInfo::ComputerDevice
132 << quint8(QBluetoothDeviceInfo::WearableComputer)
133 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
134 << leDeviceUuid;
135 QTest::newRow(dataTag: "0x000200 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000200)
136 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
137 << QBluetoothDeviceInfo::PhoneDevice
138 << quint8(QBluetoothDeviceInfo::UncategorizedPhone)
139 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
140 << leDeviceUuid;
141 QTest::newRow(dataTag: "0x000204 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
142 << quint32(0x000204)
143 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
144 << QBluetoothDeviceInfo::PhoneDevice
145 << quint8(QBluetoothDeviceInfo::CellularPhone)
146 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
147 << leDeviceUuid;
148 QTest::newRow(dataTag: "0x000214 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device" << quint32(0x000214)
149 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
150 << QBluetoothDeviceInfo::PhoneDevice
151 << quint8(QBluetoothDeviceInfo::CommonIsdnAccessPhone)
152 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
153 << leDeviceUuid;
154 QTest::newRow(dataTag: "0x000300 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
155 << quint32(0x000300)
156 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
157 << QBluetoothDeviceInfo::LANAccessDevice
158 << quint8(QBluetoothDeviceInfo::NetworkFullService)
159 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
160 << leDeviceUuid;
161 QTest::newRow(dataTag: "0x000320 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
162 << quint32(0x000320)
163 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
164 << QBluetoothDeviceInfo::LANAccessDevice
165 << quint8(QBluetoothDeviceInfo::NetworkLoadFactorOne)
166 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
167 << leDeviceUuid;
168 QTest::newRow(dataTag: "0x0003E0 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
169 << quint32(0x0003E0)
170 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
171 << QBluetoothDeviceInfo::LANAccessDevice
172 << quint8(QBluetoothDeviceInfo::NetworkNoService)
173 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
174 << leDeviceUuid;
175 QTest::newRow(dataTag: "0x000400 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
176 << quint32(0x000400)
177 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
178 << QBluetoothDeviceInfo::AudioVideoDevice
179 << quint8(QBluetoothDeviceInfo::UncategorizedAudioVideoDevice)
180 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
181 << leDeviceUuid;
182 QTest::newRow(dataTag: "0x000448 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
183 << quint32(0x000448)
184 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
185 << QBluetoothDeviceInfo::AudioVideoDevice
186 << quint8(QBluetoothDeviceInfo::GamingDevice)
187 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
188 << leDeviceUuid;
189 QTest::newRow(dataTag: "0x000500 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
190 << quint32(0x000500)
191 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
192 << QBluetoothDeviceInfo::PeripheralDevice
193 << quint8(QBluetoothDeviceInfo::UncategorizedPeripheral)
194 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
195 << leDeviceUuid;
196 QTest::newRow(dataTag: "0x0005D8 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
197 << quint32(0x0005D8)
198 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
199 << QBluetoothDeviceInfo::PeripheralDevice
200 << quint8(QBluetoothDeviceInfo::KeyboardWithPointingDevicePeripheral | QBluetoothDeviceInfo::CardReaderPeripheral)
201 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
202 << leDeviceUuid;
203 QTest::newRow(dataTag: "0x000600 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
204 << quint32(0x000600)
205 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
206 << QBluetoothDeviceInfo::ImagingDevice
207 << quint8(QBluetoothDeviceInfo::UncategorizedImagingDevice)
208 << QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration
209 << leDeviceUuid;
210 QTest::newRow(dataTag: "0x000680 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
211 << quint32(0x000680)
212 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
213 << QBluetoothDeviceInfo::ImagingDevice
214 << quint8(QBluetoothDeviceInfo::ImagePrinter)
215 << QBluetoothDeviceInfo::LowEnergyCoreConfiguration
216 << leDeviceUuid;
217 QTest::newRow(dataTag: "0x000700 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
218 << quint32(0x000700)
219 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
220 << QBluetoothDeviceInfo::WearableDevice
221 << quint8(QBluetoothDeviceInfo::UncategorizedWearableDevice)
222 << QBluetoothDeviceInfo::LowEnergyCoreConfiguration
223 << leDeviceUuid;
224 QTest::newRow(dataTag: "0x000714 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
225 << quint32(0x000714)
226 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
227 << QBluetoothDeviceInfo::WearableDevice
228 << quint8(QBluetoothDeviceInfo::WearableGlasses)
229 << QBluetoothDeviceInfo::LowEnergyCoreConfiguration
230 << leDeviceUuid;
231 QTest::newRow(dataTag: "0x000800 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
232 << quint32(0x000800)
233 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
234 << QBluetoothDeviceInfo::ToyDevice
235 << quint8(QBluetoothDeviceInfo::UncategorizedToy)
236 << QBluetoothDeviceInfo::LowEnergyCoreConfiguration
237 << leDeviceUuid;
238 QTest::newRow(dataTag: "0x000814 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
239 << quint32(0x000814)
240 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
241 << QBluetoothDeviceInfo::ToyDevice
242 << quint8(QBluetoothDeviceInfo::ToyGame)
243 << QBluetoothDeviceInfo::LowEnergyCoreConfiguration
244 << leDeviceUuid;
245 QTest::newRow(dataTag: "0x001f00 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
246 << quint32(0x001f00)
247 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::NoService)
248 << QBluetoothDeviceInfo::UncategorizedDevice
249 << quint8(0)
250 << QBluetoothDeviceInfo::LowEnergyCoreConfiguration
251 << leDeviceUuid;
252 QTest::newRow(dataTag: "0x002000 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
253 << quint32(0x002000)
254 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::PositioningService)
255 << QBluetoothDeviceInfo::MiscellaneousDevice
256 << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous)
257 << QBluetoothDeviceInfo::LowEnergyCoreConfiguration
258 << leDeviceUuid;
259 QTest::newRow(dataTag: "0x100000 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
260 << quint32(0x100000)
261 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::InformationService)
262 << QBluetoothDeviceInfo::MiscellaneousDevice
263 << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous)
264 << QBluetoothDeviceInfo::LowEnergyCoreConfiguration
265 << leDeviceUuid;
266 QTest::newRow(dataTag: "0xFFE000 COD") << QBluetoothAddress("000000000000") << "My Bluetooth Device"
267 << quint32(0xFFE000)
268 << QBluetoothDeviceInfo::ServiceClasses(QBluetoothDeviceInfo::AllServices)
269 << QBluetoothDeviceInfo::MiscellaneousDevice
270 << quint8(QBluetoothDeviceInfo::UncategorizedMiscellaneous)
271 << QBluetoothDeviceInfo::LowEnergyCoreConfiguration
272 << leDeviceUuid;
273}
274
275void tst_QBluetoothDeviceInfo::tst_construction()
276{
277 {
278 QBluetoothDeviceInfo deviceInfo;
279
280 QVERIFY(!deviceInfo.isValid());
281 QVERIFY(deviceInfo.coreConfigurations()
282 == QBluetoothDeviceInfo::UnknownCoreConfiguration);
283 }
284
285 {
286 QFETCH(QBluetoothAddress, address);
287 QFETCH(QString, name);
288 QFETCH(quint32, classOfDevice);
289 QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses);
290 QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass);
291 QFETCH(quint8, minorDeviceClass);
292 QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration);
293 QFETCH(QBluetoothUuid, deviceUuid);
294
295 QBluetoothDeviceInfo deviceInfo(address, name, classOfDevice);
296 QVERIFY(deviceInfo.isValid());
297
298 QCOMPARE(deviceInfo.address(), address);
299 QCOMPARE(deviceInfo.name(), name);
300 QCOMPARE(deviceInfo.serviceClasses(), serviceClasses);
301 QCOMPARE(deviceInfo.majorDeviceClass(), majorDeviceClass);
302 QCOMPARE(deviceInfo.minorDeviceClass(), minorDeviceClass);
303 QCOMPARE(deviceInfo.coreConfigurations(), QBluetoothDeviceInfo::UnknownCoreConfiguration);
304
305 deviceInfo.setCoreConfigurations(coreConfiguration);
306 QCOMPARE(deviceInfo.coreConfigurations(), coreConfiguration);
307
308 deviceInfo.setDeviceUuid(deviceUuid);
309 QCOMPARE(deviceInfo.deviceUuid(), deviceUuid);
310
311 QBluetoothDeviceInfo copyInfo(deviceInfo);
312 QVERIFY(copyInfo.isValid());
313
314 QCOMPARE(copyInfo.address(), address);
315 QCOMPARE(copyInfo.name(), name);
316 QCOMPARE(copyInfo.serviceClasses(), serviceClasses);
317 QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass);
318 QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass);
319 QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration);
320 QCOMPARE(copyInfo.deviceUuid(), deviceUuid);
321 }
322
323 {
324 // Test construction from the device unique UUID, without an address.
325 QFETCH(QString, name);
326 QFETCH(quint32, classOfDevice);
327 QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses);
328 QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass);
329 QFETCH(quint8, minorDeviceClass);
330 QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration);
331 QFETCH(QBluetoothUuid, deviceUuid);
332
333 QBluetoothDeviceInfo deviceInfo(deviceUuid, name, classOfDevice);
334 QVERIFY(deviceInfo.isValid());
335
336 QCOMPARE(deviceInfo.name(), name);
337 QCOMPARE(deviceInfo.serviceClasses(), serviceClasses);
338 QCOMPARE(deviceInfo.majorDeviceClass(), majorDeviceClass);
339 QCOMPARE(deviceInfo.minorDeviceClass(), minorDeviceClass);
340 QCOMPARE(deviceInfo.coreConfigurations(), QBluetoothDeviceInfo::UnknownCoreConfiguration);
341
342 deviceInfo.setCoreConfigurations(coreConfiguration);
343 QCOMPARE(deviceInfo.coreConfigurations(), coreConfiguration);
344
345 QBluetoothDeviceInfo copyInfo(deviceInfo);
346 QVERIFY(copyInfo.isValid());
347
348 QCOMPARE(copyInfo.name(), name);
349 QCOMPARE(copyInfo.serviceClasses(), serviceClasses);
350 QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass);
351 QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass);
352 QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration);
353 QCOMPARE(copyInfo.deviceUuid(), deviceUuid);
354 }
355}
356
357void tst_QBluetoothDeviceInfo::tst_assignment_data()
358{
359 tst_construction_data();
360}
361
362void tst_QBluetoothDeviceInfo::tst_assignment()
363{
364 QFETCH(QBluetoothAddress, address);
365 QFETCH(QString, name);
366 QFETCH(quint32, classOfDevice);
367 QFETCH(QBluetoothDeviceInfo::ServiceClasses, serviceClasses);
368 QFETCH(QBluetoothDeviceInfo::MajorDeviceClass, majorDeviceClass);
369 QFETCH(quint8, minorDeviceClass);
370 QFETCH(QBluetoothDeviceInfo::CoreConfiguration, coreConfiguration);
371 QFETCH(QBluetoothUuid, deviceUuid);
372
373 QBluetoothDeviceInfo deviceInfo(address, name, classOfDevice);
374
375 deviceInfo.setDeviceUuid(deviceUuid);
376 deviceInfo.setCoreConfigurations(coreConfiguration);
377
378 QVERIFY(deviceInfo.isValid());
379
380 {
381 QBluetoothDeviceInfo copyInfo = deviceInfo;
382
383 QVERIFY(copyInfo.isValid());
384
385 QCOMPARE(copyInfo.address(), address);
386 QCOMPARE(copyInfo.name(), name);
387 QCOMPARE(copyInfo.serviceClasses(), serviceClasses);
388 QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass);
389 QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass);
390 QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration);
391 QCOMPARE(copyInfo.deviceUuid(), deviceUuid);
392 }
393
394 {
395 QBluetoothDeviceInfo copyInfo;
396
397 QVERIFY(!copyInfo.isValid());
398
399 copyInfo = deviceInfo;
400
401 QVERIFY(copyInfo.isValid());
402
403 QCOMPARE(copyInfo.address(), address);
404 QCOMPARE(copyInfo.name(), name);
405 QCOMPARE(copyInfo.serviceClasses(), serviceClasses);
406 QCOMPARE(copyInfo.majorDeviceClass(), majorDeviceClass);
407 QCOMPARE(copyInfo.minorDeviceClass(), minorDeviceClass);
408 QCOMPARE(copyInfo.coreConfigurations(), coreConfiguration);
409 QCOMPARE(copyInfo.deviceUuid(), deviceUuid);
410 }
411
412 {
413 QBluetoothDeviceInfo copyInfo1;
414 QBluetoothDeviceInfo copyInfo2;
415
416 QVERIFY(!copyInfo1.isValid());
417 QVERIFY(!copyInfo2.isValid());
418
419 copyInfo1 = copyInfo2 = deviceInfo;
420
421 QVERIFY(copyInfo1.isValid());
422 QVERIFY(copyInfo2.isValid());
423 QVERIFY(QBluetoothDeviceInfo() != copyInfo1);
424
425 QCOMPARE(copyInfo1.address(), address);
426 QCOMPARE(copyInfo2.address(), address);
427 QCOMPARE(copyInfo1.name(), name);
428 QCOMPARE(copyInfo2.name(), name);
429 QCOMPARE(copyInfo1.serviceClasses(), serviceClasses);
430 QCOMPARE(copyInfo2.serviceClasses(), serviceClasses);
431 QCOMPARE(copyInfo1.majorDeviceClass(), majorDeviceClass);
432 QCOMPARE(copyInfo2.majorDeviceClass(), majorDeviceClass);
433 QCOMPARE(copyInfo1.minorDeviceClass(), minorDeviceClass);
434 QCOMPARE(copyInfo2.minorDeviceClass(), minorDeviceClass);
435 QCOMPARE(copyInfo1.coreConfigurations(), coreConfiguration);
436 QCOMPARE(copyInfo2.coreConfigurations(), coreConfiguration);
437 QCOMPARE(copyInfo1.deviceUuid(), deviceUuid);
438 QCOMPARE(copyInfo2.deviceUuid(), deviceUuid);
439 }
440
441 {
442 QBluetoothDeviceInfo testDeviceInfo;
443 QVERIFY(testDeviceInfo == QBluetoothDeviceInfo());
444 }
445}
446
447void tst_QBluetoothDeviceInfo::tst_serviceUuids()
448{
449 QBluetoothDeviceInfo deviceInfo;
450 QBluetoothDeviceInfo copyInfo = deviceInfo;
451
452 QVector<QBluetoothUuid> servicesList;
453 servicesList.append(t: QBluetoothUuid::L2cap);
454 servicesList.append(t: QBluetoothUuid::Rfcomm);
455 QVERIFY(servicesList.count() > 0);
456
457 deviceInfo.setServiceUuids(servicesList);
458 QVERIFY(deviceInfo.serviceUuids().count() > 0);
459 deviceInfo.setServiceUuids(QVector<QBluetoothUuid>());
460 QCOMPARE(deviceInfo.serviceUuids().count(), 0);
461}
462
463void tst_QBluetoothDeviceInfo::tst_cached()
464{
465 QBluetoothDeviceInfo deviceInfo(QBluetoothAddress("AABBCCDDEEFF"),
466 QString("My Bluetooth Device"), quint32(0x002000));
467 QBluetoothDeviceInfo copyInfo = deviceInfo;
468
469 QVERIFY(!deviceInfo.isCached());
470 deviceInfo.setCached(true);
471 QVERIFY(deviceInfo.isCached());
472 QVERIFY(deviceInfo != copyInfo);
473
474 deviceInfo.setCached(false);
475 QVERIFY(!(deviceInfo.isCached()));
476}
477
478void tst_QBluetoothDeviceInfo::tst_flags()
479{
480 QBluetoothDeviceInfo::CoreConfigurations flags1(QBluetoothDeviceInfo::LowEnergyCoreConfiguration);
481 QBluetoothDeviceInfo::CoreConfigurations flags2(QBluetoothDeviceInfo::BaseRateCoreConfiguration);
482 QBluetoothDeviceInfo::CoreConfigurations result;
483
484 // test QFlags &operator|=(QFlags f)
485 result = flags1 | flags2;
486 QVERIFY(result.testFlag(QBluetoothDeviceInfo::LowEnergyCoreConfiguration));
487 QVERIFY(result.testFlag(QBluetoothDeviceInfo::BaseRateCoreConfiguration));
488
489 // test QFlags &operator|=(Enum f)
490 result = flags1 | QBluetoothDeviceInfo::BaseRateCoreConfiguration;
491 QVERIFY(result.testFlag(QBluetoothDeviceInfo::LowEnergyCoreConfiguration));
492 QVERIFY(result.testFlag(QBluetoothDeviceInfo::BaseRateCoreConfiguration));
493
494 // test Q_DECLARE_OPERATORS_FOR_FLAGS(QBluetoothDeviceInfo::CoreConfigurations)
495 result = QBluetoothDeviceInfo::BaseRateCoreConfiguration | flags1;
496 QVERIFY(result.testFlag(QBluetoothDeviceInfo::LowEnergyCoreConfiguration));
497 QVERIFY(result.testFlag(QBluetoothDeviceInfo::BaseRateCoreConfiguration));
498
499 QBluetoothDeviceInfo::ServiceClasses serviceFlag1(QBluetoothDeviceInfo::AudioService);
500 QBluetoothDeviceInfo::ServiceClasses serviceFlag2(QBluetoothDeviceInfo::CapturingService);
501 QBluetoothDeviceInfo::ServiceClasses serviceResult;
502
503 // test QFlags &operator|=(QFlags f)
504 serviceResult = serviceFlag1 | serviceFlag2;
505 QVERIFY(serviceResult.testFlag(QBluetoothDeviceInfo::AudioService));
506 QVERIFY(serviceResult.testFlag(QBluetoothDeviceInfo::CapturingService));
507
508 // test QFlags &operator|=(Enum f)
509 serviceResult = serviceFlag1 | QBluetoothDeviceInfo::CapturingService;
510 QVERIFY(serviceResult.testFlag(QBluetoothDeviceInfo::AudioService));
511 QVERIFY(serviceResult.testFlag(QBluetoothDeviceInfo::CapturingService));
512
513 // test Q_DECLARE_OPERATORS_FOR_FLAGS(QBluetoothDeviceInfo::ServiceClasses)
514 serviceResult = QBluetoothDeviceInfo::CapturingService | serviceFlag1;
515 QVERIFY(serviceResult.testFlag(QBluetoothDeviceInfo::AudioService));
516 QVERIFY(serviceResult.testFlag(QBluetoothDeviceInfo::CapturingService));
517}
518
519void tst_QBluetoothDeviceInfo::tst_manufacturerData()
520{
521 const int manufacturerAVM = 0x1F;
522
523 QBluetoothDeviceInfo info;
524 QVERIFY(info.manufacturerIds().isEmpty());
525 QVERIFY(info.manufacturerData(manufacturerAVM).isNull());
526
527 QVERIFY(info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("ABCD")));
528 QVERIFY(!info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("ABCD")));
529 QCOMPARE(info.manufacturerData(manufacturerAVM), QByteArray::fromHex("ABCD"));
530 auto temp = info.manufacturerData();
531 QCOMPARE(temp.keys().count(), 1);
532 QCOMPARE(temp.values().count(), 1);
533 QCOMPARE(temp.values(), QList<QByteArray>() << QByteArray::fromHex("ABCD"));
534
535 QVERIFY(info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("CDEF")));
536 QVERIFY(!info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("ABCD")));
537 QVERIFY(!info.setManufacturerData(manufacturerAVM, QByteArray::fromHex("CDEF")));
538
539 temp = info.manufacturerData();
540 QCOMPARE(temp.keys().count(), 2);
541 QCOMPARE(temp.values().count(), 2);
542 auto list = temp.values();
543
544 QCOMPARE(QSet<QByteArray> (list.begin(), list.end()),
545 QSet<QByteArray>() << QByteArray::fromHex("ABCD") << QByteArray::fromHex("CDEF"));
546
547 // return latest entry
548 QCOMPARE(info.manufacturerData(manufacturerAVM), QByteArray::fromHex("CDEF"));
549}
550
551QTEST_MAIN(tst_QBluetoothDeviceInfo)
552
553#include "tst_qbluetoothdeviceinfo.moc"
554

source code of qtconnectivity/tests/auto/qbluetoothdeviceinfo/tst_qbluetoothdeviceinfo.cpp