1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the test suite of the Qt Toolkit. |
7 ** This file is part of the test suite of the Qt Toolkit. |
8 ** |
8 ** |
49 #include <QtNetwork/qsslkey.h> |
49 #include <QtNetwork/qsslkey.h> |
50 #include <QtNetwork/qsslsocket.h> |
50 #include <QtNetwork/qsslsocket.h> |
51 #include <QtNetwork/qtcpserver.h> |
51 #include <QtNetwork/qtcpserver.h> |
52 #include <QtTest/QtTest> |
52 #include <QtTest/QtTest> |
53 |
53 |
54 #ifndef TEST_QNETWORK_PROXY |
|
55 #define TEST_QNETWORK_PROXY |
|
56 #endif |
|
57 #ifdef TEST_QNETWORK_PROXY |
|
58 #include <QNetworkProxy> |
54 #include <QNetworkProxy> |
59 #include <QAuthenticator> |
55 #include <QAuthenticator> |
60 #endif |
|
61 |
56 |
62 #include "../network-settings.h" |
57 #include "../network-settings.h" |
63 |
58 |
64 Q_DECLARE_METATYPE(QAbstractSocket::SocketState) |
59 Q_DECLARE_METATYPE(QAbstractSocket::SocketState) |
65 Q_DECLARE_METATYPE(QAbstractSocket::SocketError) |
60 Q_DECLARE_METATYPE(QAbstractSocket::SocketError) |
251 { |
246 { |
252 QTest::addColumn<bool>("setProxy"); |
247 QTest::addColumn<bool>("setProxy"); |
253 QTest::addColumn<int>("proxyType"); |
248 QTest::addColumn<int>("proxyType"); |
254 |
249 |
255 QTest::newRow("WithoutProxy") << false << 0; |
250 QTest::newRow("WithoutProxy") << false << 0; |
256 #ifdef TEST_QNETWORK_PROXY |
|
257 QTest::newRow("WithSocks5Proxy") << true << int(Socks5Proxy); |
251 QTest::newRow("WithSocks5Proxy") << true << int(Socks5Proxy); |
258 QTest::newRow("WithSocks5ProxyAuth") << true << int(Socks5Proxy | AuthBasic); |
252 QTest::newRow("WithSocks5ProxyAuth") << true << int(Socks5Proxy | AuthBasic); |
259 |
253 |
260 QTest::newRow("WithHttpProxy") << true << int(HttpProxy); |
254 QTest::newRow("WithHttpProxy") << true << int(HttpProxy); |
261 QTest::newRow("WithHttpProxyBasicAuth") << true << int(HttpProxy | AuthBasic); |
255 QTest::newRow("WithHttpProxyBasicAuth") << true << int(HttpProxy | AuthBasic); |
262 // uncomment the line below when NTLM works |
256 // uncomment the line below when NTLM works |
263 // QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm); |
257 // QTest::newRow("WithHttpProxyNtlmAuth") << true << int(HttpProxy | AuthNtlm); |
264 #endif |
|
265 } |
258 } |
266 |
259 |
267 void tst_QSslSocket::init() |
260 void tst_QSslSocket::init() |
268 { |
261 { |
269 QFETCH_GLOBAL(bool, setProxy); |
262 QFETCH_GLOBAL(bool, setProxy); |
270 if (setProxy) { |
263 if (setProxy) { |
271 #ifdef TEST_QNETWORK_PROXY |
|
272 QFETCH_GLOBAL(int, proxyType); |
264 QFETCH_GLOBAL(int, proxyType); |
273 QString fluke = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first().toString(); |
265 QString fluke = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first().toString(); |
274 QNetworkProxy proxy; |
266 QNetworkProxy proxy; |
275 |
267 |
276 switch (proxyType) { |
268 switch (proxyType) { |
293 case HttpProxy | AuthNtlm: |
285 case HttpProxy | AuthNtlm: |
294 proxy = QNetworkProxy(QNetworkProxy::HttpProxy, fluke, 3130); |
286 proxy = QNetworkProxy(QNetworkProxy::HttpProxy, fluke, 3130); |
295 break; |
287 break; |
296 } |
288 } |
297 QNetworkProxy::setApplicationProxy(proxy); |
289 QNetworkProxy::setApplicationProxy(proxy); |
298 #endif |
|
299 } |
290 } |
300 } |
291 } |
301 |
292 |
302 void tst_QSslSocket::cleanup() |
293 void tst_QSslSocket::cleanup() |
303 { |
294 { |
304 #ifdef TEST_QNETWORK_PROXY |
|
305 QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy); |
295 QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy); |
306 #endif |
|
307 } |
296 } |
308 |
297 |
309 #ifndef QT_NO_OPENSSL |
298 #ifndef QT_NO_OPENSSL |
310 QSslSocketPtr tst_QSslSocket::newSocket() |
299 QSslSocketPtr tst_QSslSocket::newSocket() |
311 { |
300 { |