diff options
author | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2015-12-15 12:09:02 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@theqtcompany.com> | 2015-12-16 08:36:41 +0000 |
commit | 3c3df2e6a5d9d7b9421c3421553640502be41e48 (patch) | |
tree | 35fa763ef1404a2361a1d57c1d0f3703d271b13c /tests/auto/qlowenergycontroller-gattserver | |
parent | c4f5a247cccda4bad46aeff530364f7e4da2df57 (diff) |
Bluetooth: Fix endianness issues in GATT server autotest.
Change-Id: Ifac43c3799f87de7ed0ea981ed7e229714f51584
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'tests/auto/qlowenergycontroller-gattserver')
-rw-r--r-- | tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp | 5 | ||||
-rw-r--r-- | tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp | 17 |
2 files changed, 12 insertions, 10 deletions
diff --git a/tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp b/tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp index 97adf9db..e2c930bf 100644 --- a/tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp +++ b/tests/auto/qlowenergycontroller-gattserver/server/qlowenergycontroller-gattserver.cpp @@ -38,6 +38,7 @@ #include <QtBluetooth/qlowenergydescriptordata.h> #include <QtBluetooth/qlowenergyservicedata.h> #include <QtCore/qcoreapplication.h> +#include <QtCore/qendian.h> #include <QtCore/qhash.h> #include <QtCore/qscopedpointer.h> #include <QtCore/qsharedpointer.h> @@ -81,7 +82,7 @@ void addRunningSpeedService() charData.setUuid(QBluetoothUuid::RSCFeature); charData.setProperties(QLowEnergyCharacteristic::Read); value = QByteArray(2, 0); - value[0] = 1 << 2; // "Walking or Running" supported. + qToLittleEndian<quint16>(1 << 2, reinterpret_cast<uchar *>(value.data())); charData.setValue(value); serviceData.addCharacteristic(charData); addService(serviceData); @@ -103,7 +104,7 @@ void addGenericAccessService() charData.setUuid(QBluetoothUuid::Appearance); charData.setProperties(QLowEnergyCharacteristic::Read); QByteArray value(2, 0); - value[0] = 64; // Generic Phone + qToLittleEndian<quint16>(128, reinterpret_cast<uchar *>(value.data())); // Generic computer. charData.setValue(value); serviceData.addCharacteristic(charData); diff --git a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp index c1701217..6c45eed7 100644 --- a/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp +++ b/tests/auto/qlowenergycontroller-gattserver/test/tst_qlowenergycontroller-gattserver.cpp @@ -41,6 +41,7 @@ #include <QtBluetooth/qlowenergycharacteristicdata.h> #include <QtBluetooth/qlowenergydescriptordata.h> #include <QtBluetooth/qlowenergyservicedata.h> +#include <QtCore/qendian.h> #include <QtCore/qscopedpointer.h> #include <QtTest/qsignalspy.h> #include <QtTest/QtTest> @@ -222,9 +223,9 @@ void TestQLowEnergyControllerGattServer::serverCommunication() QVERIFY(appearanceChar.isValid()); QCOMPARE(appearanceChar.descriptors().count(), 0); QCOMPARE(appearanceChar.properties(), QLowEnergyCharacteristic::Read); - QByteArray appearanceValue(2, 0); - appearanceValue[0] = 64; - QCOMPARE(appearanceChar.value(), appearanceValue); + auto value = qFromLittleEndian<quint16>(reinterpret_cast<const uchar *>( + appearanceChar.value().constData())); + QCOMPARE(value, quint16(128)); const QScopedPointer<QLowEnergyService> runningSpeedService( m_leController->createServiceObject(QBluetoothUuid::RunningSpeedAndCadence)); @@ -251,9 +252,9 @@ void TestQLowEnergyControllerGattServer::serverCommunication() QVERIFY(featureChar.isValid()); QCOMPARE(featureChar.descriptors().count(), 0); QCOMPARE(featureChar.properties(), QLowEnergyCharacteristic::Read); - QByteArray featureValue = QByteArray(2, 0); - featureValue[0] = 1 << 2; - QCOMPARE(featureChar.value(), featureValue); + value = qFromLittleEndian<quint16>(reinterpret_cast<const uchar *>( + featureChar.value().constData())); + QCOMPARE(value, quint16(1 << 2)); QScopedPointer<QLowEnergyService> customService( m_leController->createServiceObject(QBluetoothUuid(quint16(0x2000)))); @@ -304,13 +305,13 @@ void TestQLowEnergyControllerGattServer::serverCommunication() QCOMPARE(customService->error(), QLowEnergyService::CharacteristicWriteError); QByteArray indicateValue(2, 0); - indicateValue[0] = 2; + qToLittleEndian<quint16>(2, reinterpret_cast<uchar *>(indicateValue.data())); customService->writeDescriptor(cc3ClientConfig, indicateValue); spy.reset(new QSignalSpy(customService.data(), &QLowEnergyService::descriptorWritten)); QVERIFY(spy->wait(3000)); QByteArray notifyValue(2, 0); - notifyValue[0] = 1; + qToLittleEndian<quint16>(1, reinterpret_cast<uchar *>(notifyValue.data())); customService->writeDescriptor(cc4ClientConfig, notifyValue); spy.reset(new QSignalSpy(customService.data(), &QLowEnergyService::descriptorWritten)); QVERIFY(spy->wait(3000)); |