tests/auto/qtcpsocket/tst_qtcpsocket.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 14 c0432d11811c
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
    89 #include <stdio.h>
    89 #include <stdio.h>
    90 #include <stdlib.h>
    90 #include <stdlib.h>
    91 #include <sys/stat.h>
    91 #include <sys/stat.h>
    92 #include <unistd.h>
    92 #include <unistd.h>
    93 #endif
    93 #endif
       
    94 
       
    95 #include "private/qhostinfo_p.h"
    94 
    96 
    95 #include "../network-settings.h"
    97 #include "../network-settings.h"
    96 
    98 
    97 Q_DECLARE_METATYPE(QAbstractSocket::SocketError)
    99 Q_DECLARE_METATYPE(QAbstractSocket::SocketError)
    98 Q_DECLARE_METATYPE(QAbstractSocket::SocketState)
   100 Q_DECLARE_METATYPE(QAbstractSocket::SocketState)
   313             proxy = QNetworkProxy(QNetworkProxy::HttpProxy, fluke, 3130);
   315             proxy = QNetworkProxy(QNetworkProxy::HttpProxy, fluke, 3130);
   314             break;
   316             break;
   315         }
   317         }
   316         QNetworkProxy::setApplicationProxy(proxy);
   318         QNetworkProxy::setApplicationProxy(proxy);
   317     }
   319     }
       
   320 
       
   321     qt_qhostinfo_clear_cache();
   318 }
   322 }
   319 
   323 
   320 QTcpSocket *tst_QTcpSocket::newSocket() const
   324 QTcpSocket *tst_QTcpSocket::newSocket() const
   321 {
   325 {
   322     QTcpSocket *socket;
   326     QTcpSocket *socket;
  1057         return;                 // we let the proxies do the lookup now
  1061         return;                 // we let the proxies do the lookup now
  1058 
  1062 
  1059     // just connect and disconnect, then make sure nothing weird happened
  1063     // just connect and disconnect, then make sure nothing weird happened
  1060     QTcpSocket *socket = newSocket();
  1064     QTcpSocket *socket = newSocket();
  1061     socket->connectToHost(QtNetworkSettings::serverName(), 21);
  1065     socket->connectToHost(QtNetworkSettings::serverName(), 21);
  1062     QVERIFY(socket->state() == QAbstractSocket::HostLookupState);
  1066 
       
  1067     // check that connect is in progress
       
  1068     QVERIFY(socket->state() != QAbstractSocket::UnconnectedState);
  1063 
  1069 
  1064     QFETCH(bool, doClose);
  1070     QFETCH(bool, doClose);
  1065     if (doClose) {
  1071     if (doClose) {
  1066         socket->close();
  1072         socket->close();
  1067         QVERIFY(socket->openMode() == QIODevice::NotOpen);
  1073         QVERIFY(socket->openMode() == QIODevice::NotOpen);
  1663     timer.start(15000);
  1669     timer.start(15000);
  1664 
  1670 
  1665     connect(tmpSocket, SIGNAL(hostFound()), this, SLOT(hostLookupSlot()));
  1671     connect(tmpSocket, SIGNAL(hostFound()), this, SLOT(hostLookupSlot()));
  1666     tmpSocket->connectToHost(QtNetworkSettings::serverName(), 143);
  1672     tmpSocket->connectToHost(QtNetworkSettings::serverName(), 143);
  1667 
  1673 
  1668     loop.exec();
  1674     // only execute the loop if not already connected
       
  1675     if (tmpSocket->state() != QAbstractSocket::ConnectedState)
       
  1676         loop.exec();
       
  1677 
  1669     QCOMPARE(timerSpy.count(), 0);
  1678     QCOMPARE(timerSpy.count(), 0);
  1670 
  1679 
  1671     delete tmpSocket;
  1680     delete tmpSocket;
  1672 }
  1681 }
  1673 
  1682