1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | |
30 | #include <QtTest/QtTest> |
31 | |
32 | #include <qcoreapplication.h> |
33 | #include <qdebug.h> |
34 | #include <qnetworkproxy.h> |
35 | |
36 | class tst_QNetworkProxy : public QObject |
37 | { |
38 | Q_OBJECT |
39 | |
40 | public: |
41 | tst_QNetworkProxy(); |
42 | virtual ~tst_QNetworkProxy(); |
43 | |
44 | private slots: |
45 | void getSetCheck(); |
46 | void capabilitiesPerType(); |
47 | }; |
48 | |
49 | tst_QNetworkProxy::tst_QNetworkProxy() |
50 | { |
51 | } |
52 | |
53 | tst_QNetworkProxy::~tst_QNetworkProxy() |
54 | { |
55 | } |
56 | |
57 | // Testing get/set functions |
58 | void tst_QNetworkProxy::getSetCheck() |
59 | { |
60 | QNetworkProxy obj1; |
61 | // quint16 QNetworkProxy::port() |
62 | // void QNetworkProxy::setPort(quint16) |
63 | obj1.setPort(quint16(0)); |
64 | QCOMPARE(quint16(0), obj1.port()); |
65 | obj1.setPort(quint16(0xffff)); |
66 | QCOMPARE(quint16(0xffff), obj1.port()); |
67 | |
68 | obj1.setType(QNetworkProxy::DefaultProxy); |
69 | QCOMPARE(obj1.type(), QNetworkProxy::DefaultProxy); |
70 | obj1.setType(QNetworkProxy::HttpProxy); |
71 | QCOMPARE(obj1.type(), QNetworkProxy::HttpProxy); |
72 | obj1.setType(QNetworkProxy::Socks5Proxy); |
73 | QCOMPARE(obj1.type(), QNetworkProxy::Socks5Proxy); |
74 | } |
75 | |
76 | void tst_QNetworkProxy::capabilitiesPerType() |
77 | { |
78 | QNetworkProxy proxy(QNetworkProxy::Socks5Proxy); |
79 | QVERIFY(proxy.capabilities() & QNetworkProxy::TunnelingCapability); |
80 | QVERIFY(proxy.capabilities() & QNetworkProxy::HostNameLookupCapability); |
81 | QVERIFY(proxy.capabilities() & QNetworkProxy::UdpTunnelingCapability); |
82 | |
83 | proxy.setType(QNetworkProxy::NoProxy); |
84 | // verify that the capabilities changed |
85 | QVERIFY(!(proxy.capabilities() & QNetworkProxy::HostNameLookupCapability)); |
86 | QVERIFY(proxy.capabilities() & QNetworkProxy::UdpTunnelingCapability); |
87 | |
88 | proxy.setType(QNetworkProxy::HttpProxy); |
89 | QVERIFY(proxy.capabilities() & QNetworkProxy::HostNameLookupCapability); |
90 | QVERIFY(!(proxy.capabilities() & QNetworkProxy::UdpTunnelingCapability)); |
91 | |
92 | // now set the capabilities on stone: |
93 | proxy.setCapabilities(QNetworkProxy::TunnelingCapability | QNetworkProxy::UdpTunnelingCapability); |
94 | QCOMPARE(proxy.capabilities(), QNetworkProxy::TunnelingCapability | QNetworkProxy::UdpTunnelingCapability); |
95 | |
96 | // changing the type shouldn't change the capabilities any more |
97 | proxy.setType(QNetworkProxy::Socks5Proxy); |
98 | QCOMPARE(proxy.capabilities(), QNetworkProxy::TunnelingCapability | QNetworkProxy::UdpTunnelingCapability); |
99 | } |
100 | |
101 | QTEST_MAIN(tst_QNetworkProxy) |
102 | #include "tst_qnetworkproxy.moc" |
103 | |