142 void setSocketDescriptor(); |
142 void setSocketDescriptor(); |
143 void socketDescriptor(); |
143 void socketDescriptor(); |
144 void blockingIMAP(); |
144 void blockingIMAP(); |
145 void nonBlockingIMAP(); |
145 void nonBlockingIMAP(); |
146 void hostNotFound(); |
146 void hostNotFound(); |
|
147 void timeoutConnect_data(); |
147 void timeoutConnect(); |
148 void timeoutConnect(); |
148 void delayedClose(); |
149 void delayedClose(); |
149 void partialRead(); |
150 void partialRead(); |
150 void unget(); |
151 void unget(); |
151 void readAllAfterClose(); |
152 void readAllAfterClose(); |
191 void connectToMultiIP(); |
192 void connectToMultiIP(); |
192 void moveToThread0(); |
193 void moveToThread0(); |
193 void increaseReadBufferSize(); |
194 void increaseReadBufferSize(); |
194 void taskQtBug5799ConnectionErrorWaitForConnected(); |
195 void taskQtBug5799ConnectionErrorWaitForConnected(); |
195 void taskQtBug5799ConnectionErrorEventLoop(); |
196 void taskQtBug5799ConnectionErrorEventLoop(); |
|
197 void taskQtBug7054TimeoutErrorResetting(); |
196 |
198 |
197 void invalidProxy_data(); |
199 void invalidProxy_data(); |
198 void invalidProxy(); |
200 void invalidProxy(); |
199 void proxyFactory_data(); |
201 void proxyFactory_data(); |
200 void proxyFactory(); |
202 void proxyFactory(); |
541 |
543 |
542 delete socket; |
544 delete socket; |
543 } |
545 } |
544 |
546 |
545 //---------------------------------------------------------------------------------- |
547 //---------------------------------------------------------------------------------- |
|
548 void tst_QTcpSocket::timeoutConnect_data() |
|
549 { |
|
550 QTest::addColumn<QString>("address"); |
|
551 QTest::newRow("host") << QtNetworkSettings::serverName(); |
|
552 QTest::newRow("ip") << QtNetworkSettings::serverIP().toString(); |
|
553 } |
546 |
554 |
547 void tst_QTcpSocket::timeoutConnect() |
555 void tst_QTcpSocket::timeoutConnect() |
548 { |
556 { |
549 QTcpSocket *socket = newSocket(); |
557 QFETCH(QString, address); |
550 |
558 QTcpSocket *socket = newSocket(); |
551 // Outgoing port 53 is firewalled in the Oslo office. |
559 |
552 socket->connectToHost("cisco.com", 53); |
560 QElapsedTimer timer; |
|
561 timer.start(); |
|
562 |
|
563 // Port 1357 is configured to drop packets on the test server |
|
564 socket->connectToHost(address, 1357); |
|
565 QVERIFY(timer.elapsed() < 50); |
553 QVERIFY(!socket->waitForConnected(200)); |
566 QVERIFY(!socket->waitForConnected(200)); |
554 QCOMPARE(socket->state(), QTcpSocket::UnconnectedState); |
567 QCOMPARE(socket->state(), QTcpSocket::UnconnectedState); |
555 QCOMPARE(int(socket->error()), int(QTcpSocket::SocketTimeoutError)); |
568 QCOMPARE(int(socket->error()), int(QTcpSocket::SocketTimeoutError)); |
556 |
569 |
557 socket->connectToHost("cisco.com", 53); |
570 timer.start(); |
558 QTest::qSleep(50); |
571 socket->connectToHost(address, 1357); |
|
572 QVERIFY(timer.elapsed() < 50); |
|
573 QTimer::singleShot(50, &QTestEventLoop::instance(), SLOT(exitLoop())); |
|
574 QTestEventLoop::instance().enterLoop(5); |
|
575 QVERIFY(!QTestEventLoop::instance().timeout()); |
|
576 QVERIFY(socket->state() == QTcpSocket::ConnectingState |
|
577 || socket->state() == QTcpSocket::HostLookupState); |
559 socket->abort(); |
578 socket->abort(); |
560 QCOMPARE(socket->state(), QTcpSocket::UnconnectedState); |
579 QCOMPARE(socket->state(), QTcpSocket::UnconnectedState); |
561 QCOMPARE(socket->openMode(), QIODevice::NotOpen); |
580 QCOMPARE(socket->openMode(), QIODevice::NotOpen); |
562 |
581 |
563 delete socket; |
582 delete socket; |
2241 QTestEventLoop::instance().enterLoop(10); |
2260 QTestEventLoop::instance().enterLoop(10); |
2242 QVERIFY2(!QTestEventLoop::instance().timeout(), "Connection to closed port timed out instead of refusing, something is wrong"); |
2261 QVERIFY2(!QTestEventLoop::instance().timeout(), "Connection to closed port timed out instead of refusing, something is wrong"); |
2243 QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!"); |
2262 QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!"); |
2244 QVERIFY2(socket.error() == QAbstractSocket::ConnectionRefusedError, |
2263 QVERIFY2(socket.error() == QAbstractSocket::ConnectionRefusedError, |
2245 QString("Could not reach server: %1").arg(socket.errorString()).toLocal8Bit()); |
2264 QString("Could not reach server: %1").arg(socket.errorString()).toLocal8Bit()); |
|
2265 } |
|
2266 |
|
2267 void tst_QTcpSocket::taskQtBug7054TimeoutErrorResetting() |
|
2268 { |
|
2269 QTcpSocket *socket = newSocket(); |
|
2270 |
|
2271 socket->connectToHost(QtNetworkSettings::serverName(), 443); |
|
2272 QVERIFY(socket->waitForConnected(5*1000)); |
|
2273 QVERIFY(socket->error() == QAbstractSocket::UnknownSocketError); |
|
2274 |
|
2275 // We connected to the HTTPS port. Wait two seconds to receive data. We will receive |
|
2276 // nothing because we would need to start the SSL handshake |
|
2277 QVERIFY(!socket->waitForReadyRead(2*1000)); |
|
2278 QVERIFY(socket->error() == QAbstractSocket::SocketTimeoutError); |
|
2279 |
|
2280 // Now write some crap to make the server disconnect us. 4 lines are enough. |
|
2281 socket->write("a\r\nb\r\nc\r\nd\r\n"); |
|
2282 socket->waitForBytesWritten(2*1000); |
|
2283 |
|
2284 // we try to waitForReadyRead another time, but this time instead of a timeout we |
|
2285 // should get a better error since the server disconnected us |
|
2286 QVERIFY(!socket->waitForReadyRead(2*1000)); |
|
2287 // It must NOT be the SocketTimeoutError that had been set before |
|
2288 QVERIFY(socket->error() == QAbstractSocket::RemoteHostClosedError); |
2246 } |
2289 } |
2247 |
2290 |
2248 void tst_QTcpSocket::invalidProxy_data() |
2291 void tst_QTcpSocket::invalidProxy_data() |
2249 { |
2292 { |
2250 QTest::addColumn<int>("type"); |
2293 QTest::addColumn<int>("type"); |