diff options
Diffstat (limited to 'tests/auto/qlocalsocket/tst_qlocalsocket.cpp')
-rw-r--r-- | tests/auto/qlocalsocket/tst_qlocalsocket.cpp | 114 |
1 files changed, 112 insertions, 2 deletions
diff --git a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp index 1180d4d..be39d00 100644 --- a/tests/auto/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/qlocalsocket/tst_qlocalsocket.cpp @@ -87,6 +87,8 @@ private slots: void sendData_data(); void sendData(); + void readBufferOverflow(); + void fullPath(); void hitMaximumConnections_data(); @@ -102,13 +104,15 @@ private slots: void longPath(); void waitForDisconnect(); + void waitForDisconnectByServer(); void removeServer(); void recycleServer(); + void multiConnect(); + void writeOnlySocket(); void writeToClientAndDisconnect(); - void debug(); void bytesWrittenSignal(); @@ -151,7 +155,13 @@ public: LocalServer() : QLocalServer() { connect(this, SIGNAL(newConnection()), this, SLOT(slotNewConnection())); - }; + } + + bool listen(const QString &name) + { + removeServer(name); + return QLocalServer::listen(name); + } QList<int> hits; @@ -553,6 +563,40 @@ void tst_QLocalSocket::sendData() QCOMPARE(spy.count(), (canListen ? 1 : 0)); } +void tst_QLocalSocket::readBufferOverflow() +{ + const int readBufferSize = 128; + const int dataBufferSize = readBufferSize * 2; + const QString serverName = QLatin1String("myPreciousTestServer"); + LocalServer server; + server.listen(serverName); + QVERIFY(server.isListening()); + + LocalSocket client; + client.setReadBufferSize(readBufferSize); + client.connectToServer(serverName); + + bool timedOut = true; + QVERIFY(server.waitForNewConnection(3000, &timedOut)); + QVERIFY(!timedOut); + + QCOMPARE(client.state(), QLocalSocket::ConnectedState); + QVERIFY(server.hasPendingConnections()); + + QLocalSocket* serverSocket = server.nextPendingConnection(); + char buffer[dataBufferSize]; + memset(buffer, 0, dataBufferSize); + serverSocket->write(buffer, dataBufferSize); + serverSocket->flush(); + + QVERIFY(client.waitForReadyRead()); + QCOMPARE(client.read(buffer, readBufferSize), qint64(readBufferSize)); +#if defined(QT_LOCALSOCKET_TCP) || defined(Q_OS_SYMBIAN) + QTest::qWait(250); +#endif + QCOMPARE(client.read(buffer, readBufferSize), qint64(readBufferSize)); +} + // QLocalSocket/Server can take a name or path, check that it works as expected void tst_QLocalSocket::fullPath() { @@ -833,6 +877,25 @@ void tst_QLocalSocket::waitForDisconnect() QVERIFY(timer.elapsed() < 2000); } +void tst_QLocalSocket::waitForDisconnectByServer() +{ + QString name = "tst_localsocket"; + LocalServer server; + QVERIFY(server.listen(name)); + LocalSocket socket; + QSignalSpy spy(&socket, SIGNAL(disconnected())); + QVERIFY(spy.isValid()); + socket.connectToServer(name); + QVERIFY(socket.waitForConnected(3000)); + QVERIFY(server.waitForNewConnection(3000)); + QLocalSocket *serverSocket = server.nextPendingConnection(); + QVERIFY(serverSocket); + serverSocket->close(); + QVERIFY(serverSocket->state() == QLocalSocket::UnconnectedState); + QVERIFY(socket.waitForDisconnected(3000)); + QCOMPARE(spy.count(), 1); +} + void tst_QLocalSocket::removeServer() { // this is a hostile takeover, but recovering from a crash results in the same @@ -874,6 +937,53 @@ void tst_QLocalSocket::recycleServer() QVERIFY(server.nextPendingConnection() != 0); } +void tst_QLocalSocket::multiConnect() +{ + QLocalServer server; + QLocalSocket client1; + QLocalSocket client2; + QLocalSocket client3; + + QVERIFY(server.listen("multiconnect")); + + client1.connectToServer("multiconnect"); + client2.connectToServer("multiconnect"); + client3.connectToServer("multiconnect"); + + QVERIFY(client1.waitForConnected(201)); + QVERIFY(client2.waitForConnected(202)); + QVERIFY(client3.waitForConnected(203)); + + QVERIFY(server.waitForNewConnection(201)); + QVERIFY(server.nextPendingConnection() != 0); + QVERIFY(server.waitForNewConnection(202)); + QVERIFY(server.nextPendingConnection() != 0); + QVERIFY(server.waitForNewConnection(203)); + QVERIFY(server.nextPendingConnection() != 0); +} + +void tst_QLocalSocket::writeOnlySocket() +{ + QLocalServer server; +#ifdef Q_OS_SYMBIAN + unlink("writeOnlySocket"); +#endif + QVERIFY(server.listen("writeOnlySocket")); + + QLocalSocket client; + client.connectToServer("writeOnlySocket", QIODevice::WriteOnly); + QVERIFY(client.waitForConnected()); +#if defined(Q_OS_SYMBIAN) + QTest::qWait(250); +#endif + QVERIFY(server.waitForNewConnection()); + QLocalSocket* serverSocket = server.nextPendingConnection(); + QVERIFY(serverSocket); + + QCOMPARE(client.bytesAvailable(), qint64(0)); + QCOMPARE(client.state(), QLocalSocket::ConnectedState); +} + void tst_QLocalSocket::writeToClientAndDisconnect() { #ifdef Q_OS_SYMBIAN |