summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp')
-rw-r--r--tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
index bbf0c7f0d7..48fa4f7bcc 100644
--- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
@@ -97,7 +97,10 @@ private slots:
void multiConnect();
void writeOnlySocket();
+
+ void writeToClientAndDisconnect_data();
void writeToClientAndDisconnect();
+
void debug();
void bytesWrittenSignal();
void syncDisconnectNotify();
@@ -600,7 +603,7 @@ void tst_QLocalSocket::readBufferOverflow()
serverSocket->write(buffer, dataBufferSize);
#ifndef Q_OS_WIN
// The data is not immediately sent, but buffered.
- // On Windows, the flushing is done asynchronously by a separate thread.
+ // On Windows, the flushing is done by an asynchronous write operation.
// However, this operation will never complete as long as the data is not
// read by the other end, so the call below always times out.
// On Unix, the flushing is synchronous and thus needs to be done before
@@ -1024,8 +1027,16 @@ void tst_QLocalSocket::writeOnlySocket()
QCOMPARE(client.state(), QLocalSocket::ConnectedState);
}
+void tst_QLocalSocket::writeToClientAndDisconnect_data()
+{
+ QTest::addColumn<int>("chunks");
+ QTest::newRow("one chunk") << 1;
+ QTest::newRow("several chunks") << 20;
+}
+
void tst_QLocalSocket::writeToClientAndDisconnect()
{
+ QFETCH(int, chunks);
QLocalServer server;
QLocalSocket client;
QSignalSpy readChannelFinishedSpy(&client, SIGNAL(readChannelFinished()));
@@ -1039,14 +1050,17 @@ void tst_QLocalSocket::writeToClientAndDisconnect()
char buffer[100];
memset(buffer, 0, sizeof(buffer));
- QCOMPARE(clientSocket->write(buffer, sizeof(buffer)), (qint64)sizeof(buffer));
- clientSocket->waitForBytesWritten();
+ for (int i = 0; i < chunks; ++i)
+ QCOMPARE(clientSocket->write(buffer, sizeof(buffer)), qint64(sizeof(buffer)));
+ while (clientSocket->bytesToWrite())
+ QVERIFY(clientSocket->waitForBytesWritten());
clientSocket->close();
server.close();
client.waitForDisconnected();
QCOMPARE(readChannelFinishedSpy.count(), 1);
- QCOMPARE(client.read(buffer, sizeof(buffer)), (qint64)sizeof(buffer));
+ const QByteArray received = client.readAll();
+ QCOMPARE(received.size(), qint64(sizeof(buffer) * chunks));
QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
}