summaryrefslogtreecommitdiffstats
path: root/tests/auto/qbluetoothserviceinfo
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2019-08-05 11:28:30 +0200
committerOliver Wolff <oliver.wolff@qt.io>2019-08-07 10:44:32 +0200
commit99db6526341e6f0f2a4798088c1f954cff013b7b (patch)
treeda49c1c9717a03cdc2e69970ad4848e989e6bb8c /tests/auto/qbluetoothserviceinfo
parent8b7b52d66f2616040ca4aaae3f2732be96e19ab8 (diff)
parentf2f9da656fd77330cce44dfe0721b3f68f1d809d (diff)
Merge remote-tracking branch 'origin/dev' into wip/win
Diffstat (limited to 'tests/auto/qbluetoothserviceinfo')
-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 7833495d..f89802d2 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"