summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2019-02-11 16:28:05 +0100
committerAlex Blasche <alexander.blasche@qt.io>2019-02-15 11:31:29 +0000
commit68982ef782d7e7c23ce25619f8be2bee1bca355d (patch)
treeaed50b0efa6f7f3e61b19dd476536ee7acb3672a /tests
parent1606ccb76ba72990df652fbd7f01d709ae20b63c (diff)
Ensure SDP records can be byte arrays/hex encoded
This addresses the issue on Bluez only. macOS ignore such attribute values and WinRT implicitly converts them to hex strings. The macOS debug stream operator produced slightly different output compared to the other platforms. The output between the platforms must match though. Therefore, the general version was copied over to macOS. Task-number: QTBUG-73328 Change-Id: Ieea2a3a559b5686f7f7d16d5c75dd9ef2782cdf5 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp
index ae8cf5d0..10c4bd3b 100644
--- a/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp
+++ b/tests/auto/qbluetoothserviceinfo/tst_qbluetoothserviceinfo.cpp
@@ -61,6 +61,8 @@ private slots:
void tst_assignment();
void tst_serviceClassUuids();
+
+ void tst_writeByteArray();
};
tst_QBluetoothServiceInfo::tst_QBluetoothServiceInfo()
@@ -385,6 +387,49 @@ void tst_QBluetoothServiceInfo::tst_serviceClassUuids()
QCOMPARE(svclids.at(1), QBluetoothUuid(QBluetoothUuid::SerialPort));
}
+static QByteArray debugOutput;
+
+void debugHandler(QtMsgType type, const QMessageLogContext &, const QString &msg)
+{
+ switch (type) {
+ case QtDebugMsg :
+ debugOutput = msg.toLocal8Bit();
+ break;
+ default:
+ break;
+ }
+}
+
+void tst_QBluetoothServiceInfo::tst_writeByteArray()
+{
+ // We cannot directly test the produced XML output for Bluez
+ // as there no public API to retrieve it and it would be Bluez specific.
+ // However we can check the debug output.
+ // It should contain a qbyteArray rather than a string. In the XML the QByteArray
+ // is converted to a text tag with hex encoding.
+
+ const QByteArray expected("\n (518)\tSequence\n (518)\t\tSequence\n (518)\t\t\tuchar 34\n (518)\t\t\tbytearray 05010906a101850105079508750119e029e7150025018102950175088103050795067508150026ff00190029ff8100050895057501190129059102950175039103c005010902a10185020901a1000509190129031500250175019503810275059501810105010930093109381581257f750895038106c0c0\n");
+
+ const QByteArray hidDescriptor =
+ QByteArray::fromHex("05010906a101850105079508750119e029e7150025018102950175088103050795067508150026FF00190029FF8100050895057501190129059102950175039103c005010902a10185020901a1000509190129031500250175019503810275059501810105010930093109381581257f750895038106c0c0");
+ const QBluetoothServiceInfo::Sequence hidDescriptorList({
+ QVariant::fromValue(quint8(0x22)), // Report type
+ QByteArray(hidDescriptor) // Descriptor array
+ });
+ const QBluetoothServiceInfo::Sequence hidDescriptorListSeq({
+ QVariant::fromValue(hidDescriptorList)
+ });
+ QBluetoothServiceInfo srvInfo;
+ srvInfo.setAttribute(0x0206, QVariant::fromValue(hidDescriptorListSeq));
+
+ const QVariant attribute = srvInfo.attribute(0x0206);
+ debugOutput.clear();
+ qInstallMessageHandler(debugHandler);
+ qDebug() << srvInfo;
+ qInstallMessageHandler(nullptr);
+ QCOMPARE(debugOutput, expected);
+}
+
QTEST_MAIN(tst_QBluetoothServiceInfo)
#include "tst_qbluetoothserviceinfo.moc"