diff options
Diffstat (limited to 'tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp')
-rw-r--r-- | tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp | 70 |
1 files changed, 46 insertions, 24 deletions
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index cde453c191..904b26ac73 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -1,31 +1,27 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -94,7 +90,6 @@ class tst_QTcpSocket : public QObject public: tst_QTcpSocket(); - virtual ~tst_QTcpSocket(); static void enterLoop(int secs) { @@ -201,6 +196,7 @@ private slots: void setSocketOption(); void clientSendDataOnDelayedDisconnect(); void serverDisconnectWithBuffered(); + void socketDiscardDataInWriteMode(); void readNotificationsAfterBind(); protected slots: @@ -322,11 +318,6 @@ tst_QTcpSocket::tst_QTcpSocket() firstFailInfo.setAddresses(QList<QHostAddress>() << QHostAddress("224.0.0.0") << QtNetworkSettings::serverIP()); } -tst_QTcpSocket::~tst_QTcpSocket() -{ - -} - void tst_QTcpSocket::initTestCase_data() { QTest::addColumn<bool>("setProxy"); @@ -1776,7 +1767,7 @@ void tst_QTcpSocket::atEnd() // Test server must use some vsFTPd 2.x.x version QVERIFY2(greeting.length() == sizeof("220 (vsFTPd 2.x.x)")-1, qPrintable(greeting)); QVERIFY2(greeting.startsWith("220 (vsFTPd 2."), qPrintable(greeting)); - QVERIFY2(greeting.endsWith(")"), qPrintable(greeting)); + QVERIFY2(greeting.endsWith(QLatin1Char(')')), qPrintable(greeting)); delete socket; } @@ -3029,6 +3020,37 @@ void tst_QTcpSocket::serverDisconnectWithBuffered() delete socket; } +// Test buffered sockets discard input when opened in WriteOnly mode +void tst_QTcpSocket::socketDiscardDataInWriteMode() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; + + QTcpServer tcpServer; + QTcpSocket *socket = newSocket(); + + QVERIFY(tcpServer.listen(QHostAddress::LocalHost)); + socket->connectToHost(tcpServer.serverAddress(), tcpServer.serverPort(), + QIODevice::WriteOnly); + QVERIFY(socket->waitForConnected(5000)); // ready for write + QCOMPARE(socket->state(), QAbstractSocket::ConnectedState); + + // Accept connection on server side + QVERIFY2(tcpServer.waitForNewConnection(5000), "Network timeout"); + QTcpSocket *newConnection = tcpServer.nextPendingConnection(); + // Send one char and drop link + QVERIFY(newConnection != NULL); + QVERIFY(newConnection->putChar(0)); + QVERIFY(newConnection->flush()); + delete newConnection; + + QVERIFY(socket->waitForReadyRead(5000)); // discard input + QVERIFY(socket->atEnd()); + + delete socket; +} + // Test that the socket does not enable the read notifications in bind() void tst_QTcpSocket::readNotificationsAfterBind() { |