diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro | 2 | ||||
-rw-r--r-- | tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp | 144 | ||||
-rw-r--r-- | tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 21 | ||||
-rw-r--r-- | tests/auto/qsocketnotifier/qsocketnotifier.pro | 2 | ||||
-rw-r--r-- | tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp | 109 | ||||
-rw-r--r-- | tests/auto/qtcpserver/tst_qtcpserver.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qtcpsocket/test/test.pro | 2 | ||||
-rw-r--r-- | tests/auto/qtcpsocket/tst_qtcpsocket.cpp | 3 |
8 files changed, 280 insertions, 6 deletions
diff --git a/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro b/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro index f05c423..17ad403 100644 --- a/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro +++ b/tests/auto/qnetworkproxyfactory/qnetworkproxyfactory.pro @@ -7,5 +7,5 @@ QT = core network SOURCES += tst_qnetworkproxyfactory.cpp -symbian: TARGET.CAPABILITY = NetworkServices +symbian: TARGET.CAPABILITY = NetworkServices ReadUserData diff --git a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp index 2baee27..82a4193 100644 --- a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp +++ b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp @@ -41,20 +41,60 @@ #include <QtTest/QTest> +#include <QtTest/QTestEventLoop> #include <qcoreapplication.h> #include <qdebug.h> #include <qnetworkproxy.h> +#include <QNetworkConfiguration> +#include <QNetworkConfigurationManager> +#include <QNetworkSession> +#include <QNetworkAccessManager> +#include <QNetworkReply> +#include <QNetworkRequest> +#include <QList> + +Q_DECLARE_METATYPE(QNetworkConfiguration); +Q_DECLARE_METATYPE(QList<QNetworkProxy>); class tst_QNetworkProxyFactory : public QObject { Q_OBJECT + +public: + tst_QNetworkProxyFactory(); + + class QDebugProxyFactory : public QNetworkProxyFactory + { + public: + virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()) + { + returnedList = QNetworkProxyFactory::systemProxyForQuery(query); + requestCounter++; + return returnedList; + } + QList<QNetworkProxy> returnedList; + int requestCounter; + }; + private slots: void systemProxyForQuery() const; +#ifndef QT_NO_BEARERMANAGEMENT + void fromConfigurations(); + void inNetworkAccessManager_data(); + void inNetworkAccessManager(); +#endif private: QString formatProxyName(const QNetworkProxy & proxy) const; + QDebugProxyFactory *factory; }; +tst_QNetworkProxyFactory::tst_QNetworkProxyFactory() +{ + factory = new QDebugProxyFactory; + QNetworkProxyFactory::setApplicationProxyFactory(factory); +} + QString tst_QNetworkProxyFactory::formatProxyName(const QNetworkProxy & proxy) const { QString proxyName; @@ -96,5 +136,109 @@ void tst_QNetworkProxyFactory::systemProxyForQuery() const QFAIL("One or more system proxy lookup failures occurred."); } +#ifndef QT_NO_BEARERMANAGEMENT + +//Purpose of this test is just to check systemProxyForQuery doesn't hang or crash +//with any given configuration including no configuration. +//We can't test it returns the right proxies without implementing the native proxy code +//again here, which would be testing our implementation against itself. +//Therefore it's just testing that something valid is returned (at least a NoProxy entry) +void tst_QNetworkProxyFactory::fromConfigurations() +{ + QNetworkConfigurationManager manager; + QList<QNetworkProxy> proxies; + QUrl url(QLatin1String("http://qt.nokia.com")); + //get from known configurations + foreach (QNetworkConfiguration config, manager.allConfigurations()) { + QNetworkProxyQuery query(config, url, QNetworkProxyQuery::UrlRequest); + proxies = QNetworkProxyFactory::systemProxyForQuery(query); + QVERIFY(!proxies.isEmpty()); + foreach (QNetworkProxy proxy, proxies) { + qDebug() << config.name() << " - " << config.identifier() << " - " << formatProxyName(proxy); + } + } + + //get from default configuration + QNetworkProxyQuery defaultquery(url, QNetworkProxyQuery::UrlRequest); + proxies = QNetworkProxyFactory::systemProxyForQuery(defaultquery); + QVERIFY(!proxies.isEmpty()); + foreach (QNetworkProxy proxy, proxies) { + qDebug() << "default - " << formatProxyName(proxy); + } + + //get from active configuration + QNetworkSession session(manager.defaultConfiguration()); + session.open(); + QVERIFY(session.waitForOpened(30000)); + proxies = QNetworkProxyFactory::systemProxyForQuery(defaultquery); + QVERIFY(!proxies.isEmpty()); + foreach (QNetworkProxy proxy, proxies) { + qDebug() << "active - " << formatProxyName(proxy); + } + + //get from known configurations while there is one active + foreach (QNetworkConfiguration config, manager.allConfigurations()) { + QNetworkProxyQuery query(config, url, QNetworkProxyQuery::UrlRequest); + proxies = QNetworkProxyFactory::systemProxyForQuery(query); + QVERIFY(!proxies.isEmpty()); + foreach (QNetworkProxy proxy, proxies) { + qDebug() << config.name() << " - " << config.identifier() << " - " << formatProxyName(proxy); + } + } +} + +void tst_QNetworkProxyFactory::inNetworkAccessManager_data() +{ + QTest::addColumn<QNetworkConfiguration>("config"); + QTest::addColumn<QList<QNetworkProxy> >("proxies"); + QNetworkConfigurationManager manager; + //get from known configurations + foreach (QNetworkConfiguration config, manager.allConfigurations()) { + QNetworkProxyQuery query(config, QUrl(QString("http://qt.nokia.com")), QNetworkProxyQuery::UrlRequest); + QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(query); + QTest::newRow(config.name().toUtf8()) << config << proxies; + } +} + +//Purpose of this test is to check that QNetworkAccessManager uses the proxy from the configuration it +//has been given. Needs two or more working configurations to be a good test. +void tst_QNetworkProxyFactory::inNetworkAccessManager() +{ + QFETCH(QNetworkConfiguration, config); + QFETCH(QList<QNetworkProxy>, proxies); + + int count = factory->requestCounter; + + QNetworkAccessManager manager; + manager.setConfiguration(config); + + //using an internet server, because cellular APs won't have a route to the test server. + QNetworkRequest req(QUrl(QString("http://qt.nokia.com"))); + QNetworkReply *reply = manager.get(req); + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(30); + delete reply; + + if (count == factory->requestCounter) { + //RND phones are preconfigured with several test access points which won't work without a matching SIM + //If the network fails to start, QNAM won't ask the factory for proxies so we can't test. + QSKIP("network configuration didn't start", SkipSingle); + } + + qDebug() << "testing network configuration for" << config.name(); + foreach (QNetworkProxy proxy, factory->returnedList) { + qDebug() << formatProxyName(proxy); + } + qDebug() << " <vs> "; + foreach (QNetworkProxy proxy, proxies) { + qDebug() << formatProxyName(proxy); + } + if (config.type() != QNetworkConfiguration::InternetAccessPoint) + QEXPECT_FAIL("","QNetworkProxyFactory::systemProxyForQuery doesn't work for service networks yet", Continue); + QCOMPARE(factory->returnedList, proxies); +} + +#endif //QT_NO_BEARERMANAGEMENT + QTEST_MAIN(tst_QNetworkProxyFactory) #include "tst_qnetworkproxyfactory.moc" diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index bf1feaf..feb8204 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -4103,6 +4103,7 @@ void tst_QNetworkReply::ioPostToHttpFromMiddleOfQBufferFiveBytes() QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi"; QNetworkRequest request(url); + request.setRawHeader("Content-Type", "application/octet-stream"); QNetworkReplyPtr reply = manager.post(request, &uploadBuffer); connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); @@ -4353,6 +4354,7 @@ void tst_QNetworkReply::ioPostToHttpUploadProgress() // create the request QUrl url = QUrl(QString("http://127.0.0.1:%1/").arg(server.serverPort())); QNetworkRequest request(url); + request.setRawHeader("Content-Type", "application/octet-stream"); QNetworkReplyPtr reply = manager.post(request, &sourceFile); QSignalSpy spy(reply, SIGNAL(uploadProgress(qint64,qint64))); connect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop())); @@ -4964,17 +4966,24 @@ void tst_QNetworkReply::httpProxyCommands() QNetworkProxy proxy(QNetworkProxy::HttpProxy, "127.0.0.1", proxyServer.serverPort()); manager.setProxy(proxy); - QNetworkReplyPtr reply = manager.get(QNetworkRequest(url)); - manager.setProxy(QNetworkProxy()); + QNetworkRequest request(url); + request.setRawHeader("User-Agent", "QNetworkReplyAutoTest/1.0"); + QNetworkReplyPtr reply = manager.get(request); + //clearing the proxy here causes the test to fail. + //the proxy isn't used until after the bearer has been started + //which is correct in general, because system proxy isn't known until that time. + //removing this line is safe, as the proxy is also reset by the cleanup() function + //manager.setProxy(QNetworkProxy()); // wait for the finished signal connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); - QTestEventLoop::instance().enterLoop(1); + QTestEventLoop::instance().enterLoop(15); QVERIFY(!QTestEventLoop::instance().timeout()); //qDebug() << reply->error() << reply->errorString(); + //qDebug() << proxyServer.receivedData; // we don't really care if the request succeeded // especially since it won't succeed in the HTTPS case @@ -4982,6 +4991,12 @@ void tst_QNetworkReply::httpProxyCommands() QString receivedHeader = proxyServer.receivedData.left(expectedCommand.length()); QCOMPARE(receivedHeader, expectedCommand); + + //QTBUG-17223 - make sure the user agent from the request is sent to proxy server even for CONNECT + int uapos = proxyServer.receivedData.indexOf("User-Agent"); + int uaend = proxyServer.receivedData.indexOf("\r\n", uapos); + QByteArray uaheader = proxyServer.receivedData.mid(uapos, uaend - uapos); + QCOMPARE(uaheader, QByteArray("User-Agent: QNetworkReplyAutoTest/1.0")); } class ProxyChangeHelper : public QObject { diff --git a/tests/auto/qsocketnotifier/qsocketnotifier.pro b/tests/auto/qsocketnotifier/qsocketnotifier.pro index c43c96a..27484c8 100644 --- a/tests/auto/qsocketnotifier/qsocketnotifier.pro +++ b/tests/auto/qsocketnotifier/qsocketnotifier.pro @@ -4,7 +4,7 @@ QT = core network requires(contains(QT_CONFIG,private_tests)) -include(../qnativesocketengine/qsocketengine.pri) +include(../platformsocketengine/platformsocketengine.pri) symbian: TARGET.CAPABILITY = NetworkServices diff --git a/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp index 5594dc3..f966e7f 100644 --- a/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp +++ b/tests/auto/qsocketnotifier/tst_qsocketnotifier.cpp @@ -53,6 +53,11 @@ #include <private/qnativesocketengine_p.h> #define NATIVESOCKETENGINE QNativeSocketEngine #endif +#ifdef Q_OS_UNIX +#include <private/qnet_unix_p.h> +#endif +#include <limits> +#include <select.h> class tst_QSocketNotifier : public QObject { @@ -64,6 +69,8 @@ public: private slots: void unexpectedDisconnection(); void mixingWithTimers(); + void posixSockets(); + void bogusFds(); }; tst_QSocketNotifier::tst_QSocketNotifier() @@ -114,6 +121,9 @@ signals: void tst_QSocketNotifier::unexpectedDisconnection() { +#ifdef Q_OS_SYMBIAN + QSKIP("Symbian socket engine pseudo descriptors can't be used for QSocketNotifier", SkipAll); +#else /* Given two sockets and two QSocketNotifiers registered on each their socket. If both sockets receive data, and the first slot @@ -163,10 +173,14 @@ void tst_QSocketNotifier::unexpectedDisconnection() UnexpectedDisconnectTester tester(&readEnd1, &readEnd2); + QTimer timer; + timer.setSingleShot(true); + timer.start(30000); do { // we have to wait until sequence value changes // as any event can make us jump out processing QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); + QVERIFY(timer.isActive); //escape if test would hang } while(tester.sequence <= 0); QVERIFY(readEnd1.state() == QAbstractSocket::ConnectedState); @@ -179,6 +193,7 @@ void tst_QSocketNotifier::unexpectedDisconnection() writeEnd1->close(); writeEnd2->close(); server.close(); +#endif } class MixingWithTimersHelper : public QObject @@ -243,5 +258,99 @@ void tst_QSocketNotifier::mixingWithTimers() QCOMPARE(helper.socketActivated, true); } +void tst_QSocketNotifier::posixSockets() +{ +#ifndef Q_OS_UNIX + QSKIP("test only for posix", SkipAll); +#else + + QTcpServer server; + QVERIFY(server.listen(QHostAddress::LocalHost, 0)); + + int posixSocket = qt_safe_socket(AF_INET, SOCK_STREAM, 0); + sockaddr_in addr; + addr.sin_addr.s_addr = htonl(0x7f000001); + addr.sin_family = AF_INET; + addr.sin_port = htons(server.serverPort()); + qt_safe_connect(posixSocket, (const struct sockaddr*)&addr, sizeof(sockaddr_in)); + QVERIFY(server.waitForNewConnection(5000)); + QScopedPointer<QTcpSocket> passive(server.nextPendingConnection()); + + ::fcntl(posixSocket, F_SETFL, ::fcntl(posixSocket, F_GETFL) | O_NONBLOCK); + + { + QSocketNotifier rn(posixSocket, QSocketNotifier::Read); + connect(&rn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); + QSignalSpy readSpy(&rn, SIGNAL(activated(int))); + QSocketNotifier wn(posixSocket, QSocketNotifier::Write); + connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); + QSignalSpy writeSpy(&wn, SIGNAL(activated(int))); + QSocketNotifier en(posixSocket, QSocketNotifier::Exception); + connect(&en, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop())); + QSignalSpy errorSpy(&en, SIGNAL(activated(int))); + + passive->write("hello",6); + passive->waitForBytesWritten(5000); + + QTestEventLoop::instance().enterLoop(3); + QCOMPARE(readSpy.count(), 1); + QCOMPARE(writeSpy.count(), 0); + QCOMPARE(errorSpy.count(), 0); + + char buffer[100]; + qt_safe_read(posixSocket, buffer, 100); + QCOMPARE(buffer, "hello"); + + qt_safe_write(posixSocket, "goodbye", 8); + + QTestEventLoop::instance().enterLoop(3); + QCOMPARE(readSpy.count(), 1); + QCOMPARE(writeSpy.count(), 1); + QCOMPARE(errorSpy.count(), 0); + QCOMPARE(passive->readAll(), QByteArray("goodbye",8)); + } + qt_safe_close(posixSocket); +#endif +} + +void tst_QSocketNotifier::bogusFds() +{ +#ifndef Q_OS_WIN + QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Internal error"); +#endif + QSocketNotifier max(std::numeric_limits<int>::max(), QSocketNotifier::Read); + QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Invalid socket specified"); +#ifndef Q_OS_WIN + QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Internal error"); +#endif + QSocketNotifier min(std::numeric_limits<int>::min(), QSocketNotifier::Write); +#ifndef Q_OS_WIN + QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Internal error"); +#endif + //bogus magic number is the first pseudo socket descriptor from symbian socket engine. + QSocketNotifier bogus(0x40000000, QSocketNotifier::Exception); + QSocketNotifier largestlegal(FD_SETSIZE - 1, QSocketNotifier::Read); + + QSignalSpy maxspy(&max, SIGNAL(activated(int))); + QSignalSpy minspy(&min, SIGNAL(activated(int))); + QSignalSpy bogspy(&bogus, SIGNAL(activated(int))); + QSignalSpy llspy(&largestlegal, SIGNAL(activated(int))); + + //generate some unrelated socket activity + QTcpServer server; + QVERIFY(server.listen(QHostAddress::LocalHost)); + connect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTcpSocket client; + client.connectToHost(QHostAddress::LocalHost, server.serverPort()); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(server.hasPendingConnections()); + + //check no activity on bogus notifiers + QCOMPARE(maxspy.count(), 0); + QCOMPARE(minspy.count(), 0); + QCOMPARE(bogspy.count(), 0); + QCOMPARE(llspy.count(), 0); +} + QTEST_MAIN(tst_QSocketNotifier) #include <tst_qsocketnotifier.moc> diff --git a/tests/auto/qtcpserver/tst_qtcpserver.cpp b/tests/auto/qtcpserver/tst_qtcpserver.cpp index 9cddc00..2cd870f 100644 --- a/tests/auto/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/qtcpserver/tst_qtcpserver.cpp @@ -430,6 +430,9 @@ void tst_QTcpServer::waitForConnectionTest() void tst_QTcpServer::setSocketDescriptor() { QTcpServer server; +#ifdef Q_OS_SYMBIAN + QTest::ignoreMessage(QtWarningMsg, "QSymbianSocketEngine::initialize - socket descriptor not found"); +#endif QVERIFY(!server.setSocketDescriptor(42)); QCOMPARE(server.serverError(), QAbstractSocket::UnsupportedSocketOperationError); #ifndef Q_OS_SYMBIAN diff --git a/tests/auto/qtcpsocket/test/test.pro b/tests/auto/qtcpsocket/test/test.pro index f4207d6..7bf5ba0 100644 --- a/tests/auto/qtcpsocket/test/test.pro +++ b/tests/auto/qtcpsocket/test/test.pro @@ -13,7 +13,7 @@ vxworks:QT -= gui symbian: { TARGET.EPOCHEAPSIZE="0x100 0x3000000" - TARGET.CAPABILITY = NetworkServices + TARGET.CAPABILITY = NetworkServices ReadUserData } TARGET = tst_qtcpsocket diff --git a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp index 623e02b..f83c4cf 100644 --- a/tests/auto/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/qtcpsocket/tst_qtcpsocket.cpp @@ -476,6 +476,9 @@ void tst_QTcpSocket::setInvalidSocketDescriptor() { QTcpSocket *socket = newSocket(); QCOMPARE(socket->socketDescriptor(), -1); +#ifdef Q_OS_SYMBIAN + QTest::ignoreMessage(QtWarningMsg, "QSymbianSocketEngine::initialize - socket descriptor not found"); +#endif QVERIFY(!socket->setSocketDescriptor(-5, QTcpSocket::UnconnectedState)); QCOMPARE(socket->socketDescriptor(), -1); |