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#include <QString>
30#ifdef QT_NETWORK_LIB
31#include <QtNetwork/QHostInfo>
32#endif
33
34class QtNetworkSettings
35{
36public:
37
38 static QString serverLocalName()
39 {
40 return QString("qt-test-server");
41 }
42 static QString serverDomainName()
43 {
44 return QString("qt-test-net");
45 }
46 static QString serverName()
47 {
48 return serverLocalName() + "." + serverDomainName();
49 }
50 static QString winServerName()
51 {
52 return serverName();
53 }
54 static QString wildcardServerName()
55 {
56 return "qt-test-server.wildcard.dev." + serverDomainName();
57 }
58
59#ifdef QT_NETWORK_LIB
60 static QHostAddress serverIP()
61 {
62 return QHostInfo::fromName(name: serverName()).addresses().first();
63 }
64#endif
65
66 static bool compareReplyIMAP(QByteArray const& actual)
67 {
68 const QByteArray expected[] = {
69
70 // Mandriva; old test server
71 QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] " )
72 .append(a: QtNetworkSettings::serverName().toLatin1())
73 .append(s: " Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"),
74
75 // Ubuntu 10.04; new test server
76 QByteArray( "* OK " )
77 .append(a: QtNetworkSettings::serverLocalName().toLatin1())
78 .append(s: " Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n"),
79
80 // Feel free to add more as needed
81 };
82
83 for (const QByteArray &ba : expected) {
84 if (ba == actual) {
85 return true;
86 }
87 }
88
89 return false;
90 }
91
92 static bool compareReplyIMAPSSL(QByteArray const& actual)
93 {
94 const QByteArray expected[] = {
95
96 // Mandriva; old test server
97 QByteArray( "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] " )
98 .append(a: QtNetworkSettings::serverName().toLatin1())
99 .append(s: " Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"),
100
101 // Ubuntu 10.04; new test server
102 QByteArray( "* OK " )
103 .append(a: QtNetworkSettings::serverLocalName().toLatin1())
104 .append(s: " Cyrus IMAP4 v2.2.13-Debian-2.2.13-19 server ready\r\n"),
105
106 // Feel free to add more as needed
107 };
108
109 for (const QByteArray &ba : expected) {
110 if (ba == actual) {
111 return true;
112 }
113 }
114
115 return false;
116 }
117
118 static bool compareReplyFtp(QByteArray const& actual)
119 {
120 const QByteArray expected[] = {
121
122 // A few different vsFTPd versions.
123 // Feel free to add more as needed
124 QByteArray( "220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n" ),
125 QByteArray( "220 (vsFTPd 2.2.2)\r\n221 Goodbye.\r\n" ),
126
127 };
128
129 for (const QByteArray &ba : expected) {
130 if (ba == actual) {
131 return true;
132 }
133 }
134
135 return false;
136 }
137
138#ifdef QT_NETWORK_LIB
139 static bool verifyTestNetworkSettings()
140 {
141 QHostInfo testServerResult = QHostInfo::fromName(name: QtNetworkSettings::serverName());
142 if (testServerResult.error() != QHostInfo::NoError) {
143 qWarning() << "Could not lookup" << QtNetworkSettings::serverName();
144 qWarning() << "Please configure the test environment!";
145 qWarning() << "See /etc/hosts or network-settings.h";
146 return false;
147 }
148 return true;
149 }
150#endif
151};
152

source code of qtxmlpatterns/tests/auto/network-settings.h