author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
// When using WinSock2 on Windows, it's the first thing that can be included |
|
44 |
// (except qglobal.h), or else you'll get tons of compile errors |
|
45 |
#include <qglobal.h> |
|
46 |
||
47 |
// MinGW doesn't provide getaddrinfo(), so we test for Q_OS_WIN |
|
48 |
// and Q_CC_GNU, which indirectly tells us whether we're using MinGW. |
|
49 |
#if defined(Q_OS_WIN) && defined(Q_CC_GNU) |
|
50 |
# define QT_NO_GETADDRINFO |
|
51 |
#endif |
|
52 |
||
53 |
#if defined(Q_OS_WIN) && !defined(QT_NO_GETADDRINFO) |
|
54 |
# include <winsock2.h> |
|
55 |
# include <ws2tcpip.h> |
|
56 |
#endif |
|
57 |
||
58 |
#include <QtTest/QtTest> |
|
59 |
#include <qcoreapplication.h> |
|
60 |
#include <QDebug> |
|
61 |
#include <QTcpSocket> |
|
62 |
#include <private/qthread_p.h> |
|
63 |
#include <QTcpServer> |
|
64 |
||
65 |
#include <time.h> |
|
66 |
#include <qlibrary.h> |
|
67 |
#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) |
|
68 |
#include <windows.h> |
|
69 |
#else |
|
70 |
#include <unistd.h> |
|
71 |
#include <signal.h> |
|
72 |
#endif |
|
73 |
||
74 |
#include <qhostinfo.h> |
|
75 |
||
76 |
#if !defined(QT_NO_GETADDRINFO) |
|
77 |
# if !defined(Q_OS_WINCE) |
|
78 |
# include <sys/types.h> |
|
79 |
# else |
|
80 |
# include <types.h> |
|
81 |
# endif |
|
82 |
# if defined(Q_OS_UNIX) |
|
83 |
# include <sys/socket.h> |
|
84 |
# endif |
|
85 |
# if !defined(Q_OS_WIN) |
|
86 |
# include <netdb.h> |
|
87 |
# endif |
|
88 |
#endif |
|
89 |
||
90 |
#include "../network-settings.h" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
#include "../../shared/util.h" |
0 | 92 |
|
93 |
//TESTED_CLASS= |
|
94 |
//TESTED_FILES= |
|
95 |
||
96 |
const char * const lupinellaIp = "10.3.4.6"; |
|
97 |
||
98 |
||
99 |
class tst_QHostInfo : public QObject |
|
100 |
{ |
|
101 |
Q_OBJECT |
|
102 |
||
103 |
public: |
|
104 |
tst_QHostInfo(); |
|
105 |
virtual ~tst_QHostInfo(); |
|
106 |
||
107 |
||
108 |
public slots: |
|
109 |
void init(); |
|
110 |
void cleanup(); |
|
111 |
private slots: |
|
112 |
void getSetCheck(); |
|
113 |
void staticInformation(); |
|
114 |
void initTestCase(); |
|
115 |
void lookupIPv4_data(); |
|
116 |
void lookupIPv4(); |
|
117 |
void lookupIPv6_data(); |
|
118 |
void lookupIPv6(); |
|
119 |
void reverseLookup_data(); |
|
120 |
void reverseLookup(); |
|
121 |
||
122 |
void blockingLookup_data(); |
|
123 |
void blockingLookup(); |
|
124 |
||
125 |
void raceCondition(); |
|
126 |
void threadSafety(); |
|
127 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
void multipleSameLookups(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
void multipleDifferentLookups(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
|
0 | 131 |
protected slots: |
132 |
void resultsReady(const QHostInfo &); |
|
133 |
||
134 |
private: |
|
135 |
bool ipv6LookupsAvailable; |
|
136 |
bool ipv6Available; |
|
137 |
bool lookupDone; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
int lookupsDoneCounter; |
0 | 139 |
QHostInfo lookupResults; |
140 |
}; |
|
141 |
||
142 |
// Testing get/set functions |
|
143 |
void tst_QHostInfo::getSetCheck() |
|
144 |
{ |
|
145 |
QHostInfo obj1; |
|
146 |
// HostInfoError QHostInfo::error() |
|
147 |
// void QHostInfo::setError(HostInfoError) |
|
148 |
obj1.setError(QHostInfo::HostInfoError(0)); |
|
149 |
QCOMPARE(QHostInfo::HostInfoError(0), obj1.error()); |
|
150 |
obj1.setError(QHostInfo::HostInfoError(1)); |
|
151 |
QCOMPARE(QHostInfo::HostInfoError(1), obj1.error()); |
|
152 |
||
153 |
// int QHostInfo::lookupId() |
|
154 |
// void QHostInfo::setLookupId(int) |
|
155 |
obj1.setLookupId(0); |
|
156 |
QCOMPARE(0, obj1.lookupId()); |
|
157 |
obj1.setLookupId(INT_MIN); |
|
158 |
QCOMPARE(INT_MIN, obj1.lookupId()); |
|
159 |
obj1.setLookupId(INT_MAX); |
|
160 |
QCOMPARE(INT_MAX, obj1.lookupId()); |
|
161 |
} |
|
162 |
||
163 |
void tst_QHostInfo::staticInformation() |
|
164 |
{ |
|
165 |
qDebug() << "Hostname:" << QHostInfo::localHostName(); |
|
166 |
qDebug() << "Domain name:" << QHostInfo::localDomainName(); |
|
167 |
} |
|
168 |
||
169 |
tst_QHostInfo::tst_QHostInfo() |
|
170 |
{ |
|
171 |
Q_SET_DEFAULT_IAP |
|
172 |
} |
|
173 |
||
174 |
tst_QHostInfo::~tst_QHostInfo() |
|
175 |
{ |
|
176 |
} |
|
177 |
||
178 |
void tst_QHostInfo::initTestCase() |
|
179 |
{ |
|
180 |
ipv6Available = false; |
|
181 |
ipv6LookupsAvailable = false; |
|
182 |
#if !defined(QT_NO_GETADDRINFO) |
|
183 |
// check if the system getaddrinfo can do IPv6 lookups |
|
184 |
struct addrinfo hint, *result = 0; |
|
185 |
memset(&hint, 0, sizeof hint); |
|
186 |
hint.ai_family = AF_UNSPEC; |
|
187 |
# ifdef AI_ADDRCONFIG |
|
188 |
hint.ai_flags = AI_ADDRCONFIG; |
|
189 |
# endif |
|
190 |
||
191 |
int res = getaddrinfo("::1", "80", &hint, &result); |
|
192 |
if (res == 0) { |
|
193 |
// this test worked |
|
194 |
freeaddrinfo(result); |
|
195 |
res = getaddrinfo("ipv6-test.dev.troll.no", "80", &hint, &result); |
|
196 |
if (res == 0 && result != 0 && result->ai_family != AF_INET) { |
|
197 |
freeaddrinfo(result); |
|
198 |
ipv6LookupsAvailable = true; |
|
199 |
} |
|
200 |
} |
|
201 |
#endif |
|
202 |
||
203 |
QTcpServer server; |
|
204 |
if (server.listen(QHostAddress("::1"))) { |
|
205 |
// We have IPv6 support |
|
206 |
ipv6Available = true; |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
void tst_QHostInfo::init() |
|
211 |
{ |
|
212 |
} |
|
213 |
||
214 |
void tst_QHostInfo::cleanup() |
|
215 |
{ |
|
216 |
} |
|
217 |
||
218 |
void tst_QHostInfo::lookupIPv4_data() |
|
219 |
{ |
|
220 |
QTest::addColumn<QString>("hostname"); |
|
221 |
QTest::addColumn<QString>("addresses"); |
|
222 |
QTest::addColumn<int>("err"); |
|
223 |
||
224 |
#ifdef Q_OS_SYMBIAN |
|
225 |
// Test server lookup |
|
226 |
QTest::newRow("lookup_01") << QtNetworkSettings::serverName() << QtNetworkSettings::serverIP().toString() << int(QHostInfo::NoError); |
|
227 |
QTest::newRow("literal_ip4") << QtNetworkSettings::serverIP().toString() << QtNetworkSettings::serverIP().toString() << int(QHostInfo::NoError); |
|
228 |
QTest::newRow("multiple_ip4") << "multi.dev.troll.no" << "1.2.3.4 1.2.3.5 10.3.3.31" << int(QHostInfo::NoError); |
|
229 |
#else |
|
230 |
QTest::newRow("empty") << "" << "" << int(QHostInfo::HostNotFound); |
|
231 |
||
232 |
QTest::newRow("single_ip4") << "lupinella.troll.no" << lupinellaIp << int(QHostInfo::NoError); |
|
233 |
QTest::newRow("multiple_ip4") << "multi.dev.troll.no" << "1.2.3.4 1.2.3.5 10.3.3.31" << int(QHostInfo::NoError); |
|
234 |
QTest::newRow("literal_ip4") << lupinellaIp << lupinellaIp << int(QHostInfo::NoError); |
|
235 |
#endif |
|
236 |
QTest::newRow("notfound") << "this-name-does-not-exist-hopefully." << "" << int(QHostInfo::HostNotFound); |
|
237 |
||
238 |
QTest::newRow("idn-ace") << "xn--alqualond-34a.troll.no" << "10.3.3.55" << int(QHostInfo::NoError); |
|
239 |
QTest::newRow("idn-unicode") << QString::fromLatin1("alqualond\353.troll.no") << "10.3.3.55" << int(QHostInfo::NoError); |
|
240 |
} |
|
241 |
||
242 |
void tst_QHostInfo::lookupIPv4() |
|
243 |
{ |
|
244 |
QFETCH(QString, hostname); |
|
245 |
QFETCH(int, err); |
|
246 |
QFETCH(QString, addresses); |
|
247 |
||
248 |
lookupDone = false; |
|
249 |
QHostInfo::lookupHost(hostname, this, SLOT(resultsReady(const QHostInfo&))); |
|
250 |
||
251 |
QTestEventLoop::instance().enterLoop(10); |
|
252 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
|
253 |
QVERIFY(lookupDone); |
|
254 |
||
255 |
if ((int)lookupResults.error() != (int)err) { |
|
256 |
qWarning() << hostname << "=>" << lookupResults.errorString(); |
|
257 |
} |
|
258 |
QCOMPARE((int)lookupResults.error(), (int)err); |
|
259 |
||
260 |
QStringList tmp; |
|
261 |
for (int i = 0; i < lookupResults.addresses().count(); ++i) |
|
262 |
tmp.append(lookupResults.addresses().at(i).toString()); |
|
263 |
tmp.sort(); |
|
264 |
||
265 |
QStringList expected = addresses.split(' '); |
|
266 |
expected.sort(); |
|
267 |
||
268 |
QCOMPARE(tmp.join(" "), expected.join(" ")); |
|
269 |
} |
|
270 |
||
271 |
void tst_QHostInfo::lookupIPv6_data() |
|
272 |
{ |
|
273 |
QTest::addColumn<QString>("hostname"); |
|
274 |
QTest::addColumn<QString>("addresses"); |
|
275 |
QTest::addColumn<int>("err"); |
|
276 |
||
277 |
QTest::newRow("ip6") << "www.ipv6-net.org" << "62.93.217.177 2001:618:1401:0:0:0:0:4" << int(QHostInfo::NoError); |
|
278 |
||
279 |
// avoid using real IPv6 addresses here because this will do a DNS query |
|
280 |
// real addresses are between 2000:: and 3fff:ffff:ffff:ffff:ffff:ffff:ffff |
|
281 |
QTest::newRow("literal_ip6") << "f001:6b0:1:ea:202:a5ff:fecd:13a6" << "f001:6b0:1:ea:202:a5ff:fecd:13a6" << int(QHostInfo::NoError); |
|
282 |
QTest::newRow("literal_shortip6") << "f001:618:1401::4" << "f001:618:1401:0:0:0:0:4" << int(QHostInfo::NoError); |
|
283 |
} |
|
284 |
||
285 |
void tst_QHostInfo::lookupIPv6() |
|
286 |
{ |
|
287 |
QFETCH(QString, hostname); |
|
288 |
QFETCH(int, err); |
|
289 |
QFETCH(QString, addresses); |
|
290 |
||
291 |
if (!ipv6LookupsAvailable) |
|
292 |
QSKIP("This platform does not support IPv6 lookups", SkipAll); |
|
293 |
||
294 |
lookupDone = false; |
|
295 |
QHostInfo::lookupHost(hostname, this, SLOT(resultsReady(const QHostInfo&))); |
|
296 |
||
297 |
QTestEventLoop::instance().enterLoop(3); |
|
298 |
QVERIFY(!QTestEventLoop::instance().timeout()); |
|
299 |
QVERIFY(lookupDone); |
|
300 |
||
301 |
QCOMPARE((int)lookupResults.error(), (int)err); |
|
302 |
||
303 |
QStringList tmp; |
|
304 |
for (int i = 0; i < lookupResults.addresses().count(); ++i) |
|
305 |
tmp.append(lookupResults.addresses().at(i).toString()); |
|
306 |
tmp.sort(); |
|
307 |
||
308 |
QStringList expected = addresses.split(' '); |
|
309 |
expected.sort(); |
|
310 |
||
311 |
QCOMPARE(tmp.join(" ").toLower(), expected.join(" ").toLower()); |
|
312 |
} |
|
313 |
||
314 |
void tst_QHostInfo::reverseLookup_data() |
|
315 |
{ |
|
316 |
QTest::addColumn<QString>("address"); |
|
317 |
QTest::addColumn<QStringList>("hostNames"); |
|
318 |
QTest::addColumn<int>("err"); |
|
319 |
||
320 |
QTest::newRow("trolltech.com") << QString("62.70.27.69") << QStringList(QString("diverse.troll.no")) << 0; |
|
321 |
||
322 |
// ### Use internal DNS instead. Discussed with Andreas. |
|
323 |
//QTest::newRow("classical.hexago.com") << QString("2001:5c0:0:2::24") << QStringList(QString("classical.hexago.com")) << 0; |
|
324 |
QTest::newRow("origin.cisco.com") << QString("12.159.148.94") << QStringList(QString("origin.cisco.com")) << 0; |
|
325 |
QTest::newRow("bogus-name") << QString("1::2::3::4") << QStringList() << 1; |
|
326 |
} |
|
327 |
||
328 |
void tst_QHostInfo::reverseLookup() |
|
329 |
{ |
|
330 |
QFETCH(QString, address); |
|
331 |
QFETCH(QStringList, hostNames); |
|
332 |
QFETCH(int, err); |
|
333 |
||
334 |
if (!ipv6LookupsAvailable && hostNames.contains("classical.hexago.com")) { |
|
335 |
QSKIP("IPv6 lookups are not supported on this platform", SkipSingle); |
|
336 |
} |
|
337 |
#if defined(Q_OS_HPUX) && defined(__ia64) |
|
338 |
if (hostNames.contains("classical.hexago.com")) |
|
339 |
QSKIP("HP-UX 11i does not support IPv6 reverse lookups.", SkipSingle); |
|
340 |
#endif |
|
341 |
||
342 |
QHostInfo info = QHostInfo::fromName(address); |
|
343 |
||
344 |
if (err == 0) { |
|
345 |
QVERIFY(hostNames.contains(info.hostName())); |
|
346 |
QCOMPARE(info.addresses().first(), QHostAddress(address)); |
|
347 |
} else { |
|
348 |
QCOMPARE(info.hostName(), address); |
|
349 |
QCOMPARE(info.error(), QHostInfo::HostNotFound); |
|
350 |
} |
|
351 |
||
352 |
} |
|
353 |
||
354 |
void tst_QHostInfo::blockingLookup_data() |
|
355 |
{ |
|
356 |
lookupIPv4_data(); |
|
357 |
if (ipv6LookupsAvailable) |
|
358 |
lookupIPv6_data(); |
|
359 |
} |
|
360 |
||
361 |
void tst_QHostInfo::blockingLookup() |
|
362 |
{ |
|
363 |
QFETCH(QString, hostname); |
|
364 |
QFETCH(int, err); |
|
365 |
QFETCH(QString, addresses); |
|
366 |
||
367 |
QHostInfo hostInfo = QHostInfo::fromName(hostname); |
|
368 |
QStringList tmp; |
|
369 |
for (int i = 0; i < hostInfo.addresses().count(); ++i) |
|
370 |
tmp.append(hostInfo.addresses().at(i).toString()); |
|
371 |
tmp.sort(); |
|
372 |
||
373 |
if ((int)hostInfo.error() != (int)err) { |
|
374 |
qWarning() << hostname << "=>" << lookupResults.errorString(); |
|
375 |
} |
|
376 |
QCOMPARE((int)hostInfo.error(), (int)err); |
|
377 |
||
378 |
QStringList expected = addresses.split(' '); |
|
379 |
expected.sort(); |
|
380 |
||
381 |
QCOMPARE(tmp.join(" ").toUpper(), expected.join(" ").toUpper()); |
|
382 |
} |
|
383 |
||
384 |
void tst_QHostInfo::raceCondition() |
|
385 |
{ |
|
386 |
for (int i = 0; i < 1000; ++i) { |
|
387 |
QTcpSocket socket; |
|
388 |
socket.connectToHost("notavalidname.troll.no", 80); |
|
389 |
} |
|
390 |
} |
|
391 |
||
392 |
class LookupThread : public QThread |
|
393 |
{ |
|
394 |
protected: |
|
395 |
inline void run() |
|
396 |
{ |
|
397 |
QHostInfo info = QHostInfo::fromName("qt.nokia.com"); |
|
398 |
QCOMPARE(info.addresses().at(0).toString(), QString("87.238.50.178")); |
|
399 |
} |
|
400 |
}; |
|
401 |
||
402 |
void tst_QHostInfo::threadSafety() |
|
403 |
{ |
|
404 |
const int nattempts = 5; |
|
405 |
#if defined(Q_OS_WINCE) |
|
406 |
const int runs = 10; |
|
407 |
#else |
|
408 |
const int runs = 100; |
|
409 |
#endif |
|
410 |
LookupThread thr[nattempts]; |
|
411 |
for (int j = 0; j < runs; ++j) { |
|
412 |
for (int i = 0; i < nattempts; ++i) |
|
413 |
thr[i].start(); |
|
414 |
for (int k = nattempts - 1; k >= 0; --k) |
|
415 |
thr[k].wait(); |
|
416 |
} |
|
417 |
} |
|
418 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
419 |
// this test is for the multi-threaded QHostInfo rewrite. It is about getting results at all, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
420 |
// not about getting correct IPs |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
void tst_QHostInfo::multipleSameLookups() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
const int COUNT = 10; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
424 |
lookupsDoneCounter = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
425 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
for (int i = 0; i < COUNT; i++) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
427 |
QHostInfo::lookupHost("localhost", this, SLOT(resultsReady(const QHostInfo))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
428 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
QTRY_VERIFY(lookupsDoneCounter == COUNT); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
430 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
431 |
// spin two seconds more to see if it is not more :) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
432 |
QTestEventLoop::instance().enterLoop(2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
433 |
QTRY_VERIFY(lookupsDoneCounter == COUNT); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
434 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
435 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
436 |
// this test is for the multi-threaded QHostInfo rewrite. It is about getting results at all, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
// not about getting correct IPs |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
void tst_QHostInfo::multipleDifferentLookups() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
439 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
440 |
QStringList hostnameList; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
441 |
hostnameList << "www.ovi.com" << "www.nokia.com" << "qt.nokia.com" << "www.trolltech.com" << "troll.no" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
442 |
<< "www.qtcentre.org" << "forum.nokia.com" << "www.forum.nokia.com" << "wiki.forum.nokia.com" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
443 |
<< "www.nokia.no" << "nokia.de" << "127.0.0.1" << "----"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
444 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
445 |
const int COUNT = hostnameList.size(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
446 |
lookupsDoneCounter = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
447 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
448 |
for (int i = 0; i < hostnameList.size(); i++) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
449 |
QHostInfo::lookupHost(hostnameList.at(i), this, SLOT(resultsReady(const QHostInfo))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
450 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
451 |
// give some time |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
452 |
QTestEventLoop::instance().enterLoop(5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
453 |
// try_verify gives some more time |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
454 |
QTRY_VERIFY(lookupsDoneCounter == COUNT); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
455 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
456 |
// spin two seconds more to see if it is not more than expected |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
457 |
QTestEventLoop::instance().enterLoop(2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
458 |
QTRY_VERIFY(lookupsDoneCounter == COUNT); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
459 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
460 |
|
0 | 461 |
void tst_QHostInfo::resultsReady(const QHostInfo &hi) |
462 |
{ |
|
463 |
lookupDone = true; |
|
464 |
lookupResults = hi; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
lookupsDoneCounter++; |
0 | 466 |
QTestEventLoop::instance().exitLoop(); |
467 |
} |
|
468 |
||
469 |
QTEST_MAIN(tst_QHostInfo) |
|
470 |
#include "tst_qhostinfo.moc" |