From 9b6d7408bc294d7e0b7d4c2791c4c07a889a009c Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 10 Oct 2014 15:33:48 +0200 Subject: Fix QBluetoothSocket unit test failures on Android Change-Id: Ib8800fa30c74678c74df9ed943b143ea4cf49bb2 Reviewed-by: Timur Pocheptsov Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothsocket_android.cpp | 1 + .../auto/qbluetoothsocket/tst_qbluetoothsocket.cpp | 30 ++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index 4faf2f19..e8d7d028 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -441,6 +441,7 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize) env->SetByteArrayRegion(nativeData, 0, (qint32)maxSize, reinterpret_cast(data)); outputStream.callMethod("write", "([BII)V", nativeData, 0, (qint32)maxSize); env->DeleteLocalRef(nativeData); + emit q->bytesWritten(maxSize); if (env->ExceptionCheck()) { qCWarning(QT_BT_ANDROID) << "Error while writing"; diff --git a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp index 100c158a..6290f075 100644 --- a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp +++ b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp @@ -384,10 +384,14 @@ void tst_QBluetoothSocket::tst_clientCommunication() QSignalSpy readyReadSpy(&socket, SIGNAL(readyRead())); QSignalSpy bytesWrittenSpy(&socket, SIGNAL(bytesWritten(qint64))); - socket.write(line.toUtf8()); + qint64 dataWritten = socket.write(line.toUtf8()); -// QEXPECT_FAIL("", "TODO: need to implement write buffering", Continue); - QCOMPARE(socket.bytesToWrite(), qint64(line.length())); + if (socket.openMode() & QIODevice::Unbuffered) + QCOMPARE(socket.bytesToWrite(), qint64(0)); + else + QCOMPARE(socket.bytesToWrite(), qint64(line.length())); + + QCOMPARE(dataWritten, qint64(line.length())); int readWriteTime = MaxReadWriteTime; while ((bytesWrittenSpy.count() == 0 || readyReadSpy.count() == 0) && readWriteTime > 0) { @@ -406,7 +410,10 @@ void tst_QBluetoothSocket::tst_clientCommunication() QCOMPARE(readyReadSpy.count(), 1); - QCOMPARE(socket.bytesAvailable(), qint64(line.length())); + if (socket.openMode() & QIODevice::Unbuffered) + QVERIFY(socket.bytesAvailable() <= qint64(line.length())); + else + QCOMPARE(socket.bytesAvailable(), qint64(line.length())); QVERIFY(socket.canReadLine()); @@ -426,10 +433,14 @@ void tst_QBluetoothSocket::tst_clientCommunication() QSignalSpy bytesWrittenSpy(&socket, SIGNAL(bytesWritten(qint64))); QString joined = data.join(QString()); - socket.write(joined.toUtf8()); + qint64 dataWritten = socket.write(joined.toUtf8()); + + if (socket.openMode() & QIODevice::Unbuffered) + QCOMPARE(socket.bytesToWrite(), qint64(0)); + else + QCOMPARE(socket.bytesToWrite(), qint64(joined.length())); -// QEXPECT_FAIL("", "TODO: need to implement write buffering", Continue); - QCOMPARE(socket.bytesToWrite(), qint64(joined.length())); + QCOMPARE(dataWritten, qint64(joined.length())); int readWriteTime = MaxReadWriteTime; while ((bytesWrittenSpy.count() == 0 || readyReadSpy.count() == 0) && readWriteTime > 0) { @@ -441,7 +452,10 @@ void tst_QBluetoothSocket::tst_clientCommunication() QCOMPARE(bytesWrittenSpy.at(0).at(0).toLongLong(), qint64(joined.length())); QVERIFY(readyReadSpy.count() > 0); - QCOMPARE(socket.bytesAvailable(), qint64(joined.length())); + if (socket.openMode() & QIODevice::Unbuffered) + QVERIFY(socket.bytesAvailable() <= qint64(joined.length())); + else + QCOMPARE(socket.bytesAvailable(), qint64(joined.length())); QVERIFY(socket.canReadLine()); -- cgit v1.2.3