summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-10-10 15:33:48 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-10-13 09:31:38 +0200
commit9b6d7408bc294d7e0b7d4c2791c4c07a889a009c (patch)
tree8985809d1b3a13274a8109028e097d6452c08d16
parentfa7615b4e98ec7319e6a264c2a6686949037f6bd (diff)
Fix QBluetoothSocket unit test failures on Android
Change-Id: Ib8800fa30c74678c74df9ed943b143ea4cf49bb2 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r--src/bluetooth/qbluetoothsocket_android.cpp1
-rw-r--r--tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp30
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<const jbyte*>(data));
outputStream.callMethod<void>("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());