summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-10-10 14:41:59 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-10-13 09:31:28 +0200
commitfa7615b4e98ec7319e6a264c2a6686949037f6bd (patch)
tree54931c510fd78cea5a40d5db6e2eb4197b4f02b3 /tests
parent0a3b0177116fd0033c315968e7a3d559ad043c5d (diff)
downloadqtconnectivity-fa7615b4e98ec7319e6a264c2a6686949037f6bd.tar.gz
Fix QBluetoothSocket::isReadable()/isOpen()/isWritable()
Change-Id: Ifd6b5ed8176aa7959ed8da0edc762266aa2bd6fa Task-number: QTBUG-32704 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp47
1 files changed, 35 insertions, 12 deletions
diff --git a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp
index 3a577db1..100c158a 100644
--- a/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp
+++ b/tests/auto/qbluetoothsocket/tst_qbluetoothsocket.cpp
@@ -213,24 +213,17 @@ void tst_QBluetoothSocket::tst_construction()
QCOMPARE(socket.atEnd(), true);
QCOMPARE(socket.pos(), 0);
QCOMPARE(socket.size(), 0);
-
- QSignalSpy spy(&socket, SIGNAL(error(QBluetoothSocket::SocketError)));
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(socket.isOpen(), false);
+ QCOMPARE(socket.isReadable(), false);
+ QCOMPARE(socket.isWritable(), false);
+ QCOMPARE(socket.openMode(), QIODevice::NotOpen);
QByteArray array = socket.readAll();
QVERIFY(array.isEmpty());
- QCOMPARE(socket.error(), QBluetoothSocket::OperationError);
- QCOMPARE(spy.count(), 1);
char buffer[10];
int returnValue = socket.read((char*)&buffer, 10);
QCOMPARE(returnValue, -1);
- QCOMPARE(socket.error(), QBluetoothSocket::OperationError);
- QVERIFY(spy.count() >= 2);
- while (spy.count()) {
- QBluetoothSocket::SocketError er = spy.takeFirst().at(0).value<QBluetoothSocket::SocketError>();
- QVERIFY(er == QBluetoothSocket::OperationError);
- }
}
{
@@ -256,6 +249,11 @@ void tst_QBluetoothSocket::tst_serviceConnection()
QSignalSpy connectedSpy(&socket, SIGNAL(connected()));
QSignalSpy errorSpy(&socket, SIGNAL(error(QBluetoothSocket::SocketError)));
+ QCOMPARE(socket.openMode(), QIODevice::NotOpen);
+ QCOMPARE(socket.isWritable(), false);
+ QCOMPARE(socket.isReadable(), false);
+ QCOMPARE(socket.isOpen(), false);
+
socket.connectToService(remoteServiceInfo);
QCOMPARE(stateSpy.count(), 1);
@@ -279,6 +277,10 @@ void tst_QBluetoothSocket::tst_serviceConnection()
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::ConnectedState);
QCOMPARE(socket.state(), QBluetoothSocket::ConnectedState);
+ QCOMPARE(socket.isWritable(), true);
+ QCOMPARE(socket.isReadable(), true);
+ QCOMPARE(socket.isOpen(), true);
+
stateSpy.clear();
//check the peer & local info
@@ -290,7 +292,11 @@ void tst_QBluetoothSocket::tst_serviceConnection()
/* Disconnection */
QSignalSpy disconnectedSpy(&socket, SIGNAL(disconnected()));
- socket.disconnectFromService();
+ socket.abort(); // close() tested by other functions
+ QCOMPARE(socket.isWritable(), false);
+ QCOMPARE(socket.isReadable(), false);
+ QCOMPARE(socket.isOpen(), false);
+ QCOMPARE(socket.openMode(), QIODevice::NotOpen);
QVERIFY(stateSpy.count() >= 1);
QCOMPARE(stateSpy.takeFirst().at(0).value<QBluetoothSocket::SocketState>(), QBluetoothSocket::ClosingState);
@@ -339,6 +345,10 @@ void tst_QBluetoothSocket::tst_clientCommunication()
/* Connection */
QSignalSpy connectedSpy(&socket, SIGNAL(connected()));
+ QCOMPARE(socket.isWritable(), false);
+ QCOMPARE(socket.isReadable(), false);
+ QCOMPARE(socket.isOpen(), false);
+ QCOMPARE(socket.openMode(), QIODevice::NotOpen);
socket.connectToService(remoteServiceInfo);
QCOMPARE(stateSpy.count(), 1);
@@ -353,6 +363,10 @@ void tst_QBluetoothSocket::tst_clientCommunication()
connectTime -= 1000;
}
+ QCOMPARE(socket.isWritable(), true);
+ QCOMPARE(socket.isReadable(), true);
+ QCOMPARE(socket.isOpen(), true);
+
QCOMPARE(connectedSpy.count(), 1);
QCOMPARE(stateSpy.count(), 1);
QCOMPARE(qvariant_cast<QBluetoothSocket::SocketState>(stateSpy.takeFirst().at(0)), QBluetoothSocket::ConnectedState);
@@ -402,6 +416,10 @@ void tst_QBluetoothSocket::tst_clientCommunication()
}
}
+ QCOMPARE(socket.isWritable(), true);
+ QCOMPARE(socket.isReadable(), true);
+ QCOMPARE(socket.isOpen(), true);
+
{
/* Send all at once */
QSignalSpy readyReadSpy(&socket, SIGNAL(readyRead()));
@@ -437,6 +455,11 @@ void tst_QBluetoothSocket::tst_clientCommunication()
socket.disconnectFromService();
+ QCOMPARE(socket.isWritable(), false);
+ QCOMPARE(socket.isReadable(), false);
+ QCOMPARE(socket.isOpen(), false);
+ QCOMPARE(socket.openMode(), QIODevice::NotOpen);
+
int disconnectTime = MaxConnectTime;
while (disconnectedSpy.count() == 0 && disconnectTime > 0) {
QTest::qWait(1000);