author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
#include <qcoreapplication.h> |
|
46 |
#include <qfileinfo.h> |
|
47 |
#include <qdatastream.h> |
|
48 |
#include <qudpsocket.h> |
|
49 |
#include <qhostaddress.h> |
|
50 |
#include <qhostinfo.h> |
|
51 |
#include <qmap.h> |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
52 |
#include <QNetworkProxy> |
0 | 53 |
|
54 |
#include <qstringlist.h> |
|
55 |
#include "../network-settings.h" |
|
56 |
||
57 |
Q_DECLARE_METATYPE(QHostAddress) |
|
58 |
||
59 |
//TESTED_CLASS= |
|
60 |
//TESTED_FILES= |
|
61 |
||
62 |
QT_FORWARD_DECLARE_CLASS(QUdpSocket) |
|
63 |
||
64 |
class tst_QUdpSocket : public QObject |
|
65 |
{ |
|
66 |
Q_OBJECT |
|
67 |
||
68 |
public: |
|
69 |
tst_QUdpSocket(); |
|
70 |
virtual ~tst_QUdpSocket(); |
|
71 |
||
72 |
||
73 |
public slots: |
|
74 |
void initTestCase_data(); |
|
75 |
void init(); |
|
76 |
void cleanup(); |
|
77 |
private slots: |
|
78 |
void constructing(); |
|
79 |
void unconnectedServerAndClientTest(); |
|
80 |
void broadcasting(); |
|
81 |
void loop_data(); |
|
82 |
void loop(); |
|
83 |
void ipv6Loop_data(); |
|
84 |
void ipv6Loop(); |
|
85 |
void readLine(); |
|
86 |
void pendingDatagramSize(); |
|
87 |
void writeDatagram(); |
|
88 |
void performance(); |
|
89 |
void bindMode(); |
|
90 |
void writeDatagramToNonExistingPeer_data(); |
|
91 |
void writeDatagramToNonExistingPeer(); |
|
92 |
void writeToNonExistingPeer_data(); |
|
93 |
void writeToNonExistingPeer(); |
|
94 |
void outOfProcessConnectedClientServerTest(); |
|
95 |
void outOfProcessUnconnectedClientServerTest(); |
|
96 |
void zeroLengthDatagram(); |
|
97 |
||
98 |
protected slots: |
|
99 |
void empty_readyReadSlot(); |
|
100 |
void empty_connectedSlot(); |
|
101 |
}; |
|
102 |
||
103 |
tst_QUdpSocket::tst_QUdpSocket() |
|
104 |
{ |
|
105 |
Q_SET_DEFAULT_IAP |
|
106 |
} |
|
107 |
||
108 |
tst_QUdpSocket::~tst_QUdpSocket() |
|
109 |
{ |
|
110 |
} |
|
111 |
||
112 |
void tst_QUdpSocket::initTestCase_data() |
|
113 |
{ |
|
114 |
QTest::addColumn<bool>("setProxy"); |
|
115 |
QTest::addColumn<int>("proxyType"); |
|
116 |
||
117 |
QTest::newRow("WithoutProxy") << false << 0; |
|
118 |
QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy); |
|
119 |
} |
|
120 |
||
121 |
void tst_QUdpSocket::init() |
|
122 |
{ |
|
123 |
QFETCH_GLOBAL(bool, setProxy); |
|
124 |
if (setProxy) { |
|
125 |
QFETCH_GLOBAL(int, proxyType); |
|
126 |
if (proxyType == QNetworkProxy::Socks5Proxy) { |
|
127 |
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080)); |
|
128 |
} |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
void tst_QUdpSocket::cleanup() |
|
133 |
{ |
|
134 |
QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy); |
|
135 |
} |
|
136 |
||
137 |
||
138 |
//---------------------------------------------------------------------------------- |
|
139 |
||
140 |
void tst_QUdpSocket::constructing() |
|
141 |
{ |
|
142 |
QUdpSocket socket; |
|
143 |
||
144 |
QVERIFY(socket.isSequential()); |
|
145 |
QVERIFY(!socket.isOpen()); |
|
146 |
QVERIFY(socket.socketType() == QUdpSocket::UdpSocket); |
|
147 |
QCOMPARE((int) socket.bytesAvailable(), 0); |
|
148 |
QCOMPARE(socket.canReadLine(), false); |
|
149 |
QCOMPARE(socket.readLine(), QByteArray()); |
|
150 |
QCOMPARE(socket.socketDescriptor(), -1); |
|
151 |
QCOMPARE(socket.error(), QUdpSocket::UnknownSocketError); |
|
152 |
QCOMPARE(socket.errorString(), QString("Unknown error")); |
|
153 |
||
154 |
// Check the state of the socket api |
|
155 |
} |
|
156 |
||
157 |
void tst_QUdpSocket::unconnectedServerAndClientTest() |
|
158 |
{ |
|
159 |
QUdpSocket serverSocket; |
|
160 |
||
161 |
qRegisterMetaType<QAbstractSocket::SocketState>("QAbstractSocket::SocketState"); |
|
162 |
||
163 |
QSignalSpy stateChangedSpy(&serverSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState))); |
|
164 |
QVERIFY2(serverSocket.bind(), serverSocket.errorString().toLatin1().constData()); |
|
165 |
QCOMPARE(stateChangedSpy.count(), 1); |
|
166 |
||
167 |
const char *message[] = {"Yo mista", "Yo", "Wassap"}; |
|
168 |
||
169 |
QHostAddress serverAddress = QHostAddress::LocalHost; |
|
170 |
if (!(serverSocket.localAddress() == QHostAddress::Any)) |
|
171 |
serverAddress = serverSocket.localAddress(); |
|
172 |
||
173 |
for (int i = 0; i < 3; ++i) { |
|
174 |
QUdpSocket clientSocket; |
|
175 |
QCOMPARE(int(clientSocket.writeDatagram(message[i], strlen(message[i]), |
|
176 |
serverAddress, serverSocket.localPort())), |
|
177 |
int(strlen(message[i]))); |
|
178 |
char buf[1024]; |
|
179 |
QHostAddress host; |
|
180 |
quint16 port; |
|
181 |
QVERIFY(serverSocket.waitForReadyRead(5000)); |
|
182 |
QCOMPARE(int(serverSocket.readDatagram(buf, sizeof(buf), &host, &port)), |
|
183 |
int(strlen(message[i]))); |
|
184 |
buf[strlen(message[i])] = '\0'; |
|
185 |
QCOMPARE(QByteArray(buf), QByteArray(message[i])); |
|
186 |
} |
|
187 |
} |
|
188 |
||
189 |
//---------------------------------------------------------------------------------- |
|
190 |
||
191 |
void tst_QUdpSocket::broadcasting() |
|
192 |
{ |
|
193 |
QFETCH_GLOBAL(bool, setProxy); |
|
194 |
if (setProxy) { |
|
195 |
QFETCH_GLOBAL(int, proxyType); |
|
196 |
if (proxyType == QNetworkProxy::Socks5Proxy) { |
|
197 |
QSKIP("With socks5 Broadcast is not supported.", SkipSingle); |
|
198 |
} |
|
199 |
} |
|
200 |
#ifdef Q_OS_AIX |
|
201 |
QSKIP("Broadcast does not work on darko", SkipAll); |
|
202 |
#endif |
|
203 |
const char *message[] = {"Yo mista", "", "Yo", "Wassap"}; |
|
204 |
||
205 |
for (int i = 0; i < 4; ++i) { |
|
206 |
QUdpSocket serverSocket; |
|
207 |
QVERIFY2(serverSocket.bind(QHostAddress::Any, 5000), serverSocket.errorString().toLatin1().constData()); |
|
208 |
||
209 |
QCOMPARE(serverSocket.state(), QUdpSocket::BoundState); |
|
210 |
||
211 |
connect(&serverSocket, SIGNAL(readyRead()), SLOT(empty_readyReadSlot())); |
|
212 |
||
213 |
QUdpSocket broadcastSocket; |
|
214 |
||
215 |
for (int j = 0; j < 100; ++j) { |
|
216 |
broadcastSocket.writeDatagram(message[i], strlen(message[i]), |
|
217 |
QHostAddress::Broadcast, 5000); |
|
218 |
QTestEventLoop::instance().enterLoop(15); |
|
219 |
if (QTestEventLoop::instance().timeout()) { |
|
220 |
#if defined(Q_OS_FREEBSD) |
|
221 |
QEXPECT_FAIL("", |
|
222 |
"Broadcasting to 255.255.255.255 does not work on FreeBSD", |
|
223 |
Abort); |
|
224 |
QVERIFY(false); // seems that QFAIL() doesn't respect the QEXPECT_FAIL() :/ |
|
225 |
#endif |
|
226 |
QFAIL("Network operation timed out"); |
|
227 |
} |
|
228 |
QVERIFY(serverSocket.hasPendingDatagrams()); |
|
229 |
||
230 |
do { |
|
231 |
QByteArray arr; arr.resize(serverSocket.pendingDatagramSize() + 1); |
|
232 |
QHostAddress host; |
|
233 |
quint16 port; |
|
234 |
QCOMPARE((int) serverSocket.readDatagram(arr.data(), arr.size() - 1, &host, &port), |
|
235 |
(int) strlen(message[i])); |
|
236 |
arr.resize(strlen(message[i])); |
|
237 |
QCOMPARE(arr, QByteArray(message[i])); |
|
238 |
} while (serverSocket.hasPendingDatagrams()); |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
//---------------------------------------------------------------------------------- |
|
244 |
||
245 |
void tst_QUdpSocket::loop_data() |
|
246 |
{ |
|
247 |
QTest::addColumn<QByteArray>("peterMessage"); |
|
248 |
QTest::addColumn<QByteArray>("paulMessage"); |
|
249 |
QTest::addColumn<bool>("success"); |
|
250 |
||
251 |
QTest::newRow("\"Almond!\" | \"Joy!\"") << QByteArray("Almond!") << QByteArray("Joy!") << true; |
|
252 |
QTest::newRow("\"A\" | \"B\"") << QByteArray("A") << QByteArray("B") << true; |
|
253 |
QTest::newRow("\"AB\" | \"B\"") << QByteArray("AB") << QByteArray("B") << true; |
|
254 |
QTest::newRow("\"AB\" | \"BB\"") << QByteArray("AB") << QByteArray("BB") << true; |
|
255 |
QTest::newRow("\"A\\0B\" | \"B\\0B\"") << QByteArray::fromRawData("A\0B", 3) << QByteArray::fromRawData("B\0B", 3) << true; |
|
256 |
QTest::newRow("\"(nil)\" | \"(nil)\"") << QByteArray() << QByteArray() << true; |
|
257 |
QTest::newRow("Bigmessage") << QByteArray(600, '@') << QByteArray(600, '@') << true; |
|
258 |
} |
|
259 |
||
260 |
void tst_QUdpSocket::loop() |
|
261 |
{ |
|
262 |
QFETCH(QByteArray, peterMessage); |
|
263 |
QFETCH(QByteArray, paulMessage); |
|
264 |
QFETCH(bool, success); |
|
265 |
||
266 |
QUdpSocket peter; |
|
267 |
QUdpSocket paul; |
|
268 |
||
269 |
QVERIFY2(peter.bind(), peter.errorString().toLatin1().constData()); |
|
270 |
QVERIFY2(paul.bind(), paul.errorString().toLatin1().constData()); |
|
271 |
||
272 |
QHostAddress peterAddress = QHostAddress::LocalHost; |
|
273 |
if (!(peter.localAddress() == QHostAddress::Any)) |
|
274 |
peterAddress = peter.localAddress(); |
|
275 |
QHostAddress pualAddress = QHostAddress::LocalHost; |
|
276 |
if (!(paul.localAddress() == QHostAddress::Any)) |
|
277 |
pualAddress = paul.localAddress(); |
|
278 |
||
279 |
QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.length(), |
|
280 |
pualAddress, paul.localPort()), qint64(peterMessage.length())); |
|
281 |
QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.length(), |
|
282 |
peterAddress, peter.localPort()), qint64(paulMessage.length())); |
|
283 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
QVERIFY(peter.waitForReadyRead(9000)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
QVERIFY(paul.waitForReadyRead(9000)); |
0 | 286 |
char peterBuffer[16*1024]; |
287 |
char paulBuffer[16*1024]; |
|
288 |
if (success) { |
|
289 |
QCOMPARE(peter.readDatagram(peterBuffer, sizeof(peterBuffer)), qint64(paulMessage.length())); |
|
290 |
QCOMPARE(paul.readDatagram(paulBuffer, sizeof(peterBuffer)), qint64(peterMessage.length())); |
|
291 |
} else { |
|
292 |
QVERIFY(peter.readDatagram(peterBuffer, sizeof(peterBuffer)) != paulMessage.length()); |
|
293 |
QVERIFY(paul.readDatagram(paulBuffer, sizeof(peterBuffer)) != peterMessage.length()); |
|
294 |
} |
|
295 |
||
296 |
QCOMPARE(QByteArray(peterBuffer, paulMessage.length()), paulMessage); |
|
297 |
QCOMPARE(QByteArray(paulBuffer, peterMessage.length()), peterMessage); |
|
298 |
} |
|
299 |
||
300 |
//---------------------------------------------------------------------------------- |
|
301 |
||
302 |
void tst_QUdpSocket::ipv6Loop_data() |
|
303 |
{ |
|
304 |
loop_data(); |
|
305 |
} |
|
306 |
||
307 |
void tst_QUdpSocket::ipv6Loop() |
|
308 |
{ |
|
309 |
#if defined(Q_OS_SYMBIAN) |
|
310 |
QSKIP("Symbian IPv6 is not yet supported", SkipAll); |
|
311 |
#endif |
|
312 |
QFETCH(QByteArray, peterMessage); |
|
313 |
QFETCH(QByteArray, paulMessage); |
|
314 |
QFETCH(bool, success); |
|
315 |
||
316 |
QUdpSocket peter; |
|
317 |
QUdpSocket paul; |
|
318 |
||
319 |
quint16 peterPort = 28124; |
|
320 |
quint16 paulPort = 28123; |
|
321 |
||
322 |
if (!peter.bind(QHostAddress::LocalHostIPv6, peterPort)) { |
|
323 |
QCOMPARE(peter.error(), QUdpSocket::UnsupportedSocketOperationError); |
|
324 |
} else { |
|
325 |
QVERIFY(paul.bind(QHostAddress::LocalHostIPv6, paulPort)); |
|
326 |
||
327 |
QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.length(), QHostAddress("::1"), |
|
328 |
paulPort), qint64(peterMessage.length())); |
|
329 |
QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.length(), |
|
330 |
QHostAddress("::1"), peterPort), qint64(paulMessage.length())); |
|
331 |
||
332 |
char peterBuffer[16*1024]; |
|
333 |
char paulBuffer[16*1024]; |
|
334 |
#if !defined(Q_OS_WINCE) |
|
335 |
QVERIFY(peter.waitForReadyRead(5000)); |
|
336 |
QVERIFY(paul.waitForReadyRead(5000)); |
|
337 |
#else |
|
338 |
QVERIFY(peter.waitForReadyRead(15000)); |
|
339 |
QVERIFY(paul.waitForReadyRead(15000)); |
|
340 |
#endif |
|
341 |
if (success) { |
|
342 |
QCOMPARE(peter.readDatagram(peterBuffer, sizeof(peterBuffer)), qint64(paulMessage.length())); |
|
343 |
QCOMPARE(paul.readDatagram(paulBuffer, sizeof(peterBuffer)), qint64(peterMessage.length())); |
|
344 |
} else { |
|
345 |
QVERIFY(peter.readDatagram(peterBuffer, sizeof(peterBuffer)) != paulMessage.length()); |
|
346 |
QVERIFY(paul.readDatagram(paulBuffer, sizeof(peterBuffer)) != peterMessage.length()); |
|
347 |
} |
|
348 |
||
349 |
QCOMPARE(QByteArray(peterBuffer, paulMessage.length()), paulMessage); |
|
350 |
QCOMPARE(QByteArray(paulBuffer, peterMessage.length()), peterMessage); |
|
351 |
} |
|
352 |
} |
|
353 |
||
354 |
void tst_QUdpSocket::empty_readyReadSlot() |
|
355 |
{ |
|
356 |
QTestEventLoop::instance().exitLoop(); |
|
357 |
} |
|
358 |
||
359 |
void tst_QUdpSocket::empty_connectedSlot() |
|
360 |
{ |
|
361 |
QTestEventLoop::instance().exitLoop(); |
|
362 |
} |
|
363 |
||
364 |
//---------------------------------------------------------------------------------- |
|
365 |
||
366 |
void tst_QUdpSocket::readLine() |
|
367 |
{ |
|
368 |
QUdpSocket socket1; |
|
369 |
QVERIFY2(socket1.bind(), socket1.errorString().toLatin1().constData()); |
|
370 |
||
371 |
QUdpSocket socket2; |
|
372 |
socket2.connectToHost("127.0.0.1", socket1.localPort()); |
|
373 |
QVERIFY(socket2.waitForConnected(5000)); |
|
374 |
} |
|
375 |
||
376 |
//---------------------------------------------------------------------------------- |
|
377 |
||
378 |
void tst_QUdpSocket::pendingDatagramSize() |
|
379 |
{ |
|
380 |
QUdpSocket server; |
|
381 |
QVERIFY2(server.bind(), server.errorString().toLatin1().constData()); |
|
382 |
||
383 |
QHostAddress serverAddress = QHostAddress::LocalHost; |
|
384 |
if (!(server.localAddress() == QHostAddress::Any)) |
|
385 |
serverAddress = server.localAddress(); |
|
386 |
||
387 |
QUdpSocket client; |
|
388 |
QVERIFY(client.writeDatagram("this is", 7, serverAddress, server.localPort()) == 7); |
|
389 |
QVERIFY(client.writeDatagram(0, 0, serverAddress, server.localPort()) == 0); |
|
390 |
QVERIFY(client.writeDatagram("3 messages", 10, serverAddress, server.localPort()) == 10); |
|
391 |
||
392 |
char c = 0; |
|
393 |
QVERIFY(server.waitForReadyRead()); |
|
394 |
if (server.hasPendingDatagrams()) { |
|
395 |
#if defined Q_OS_HPUX && defined __ia64 |
|
396 |
QEXPECT_FAIL("", "HP-UX 11i v2 can't determine the datagram size correctly.", Abort); |
|
397 |
#endif |
|
398 |
QCOMPARE(server.pendingDatagramSize(), qint64(7)); |
|
399 |
c = '\0'; |
|
400 |
QCOMPARE(server.readDatagram(&c, 1), qint64(1)); |
|
401 |
QCOMPARE(c, 't'); |
|
402 |
c = '\0'; |
|
403 |
} else { |
|
404 |
QSKIP("does not have the 1st datagram", SkipSingle); |
|
405 |
} |
|
406 |
||
407 |
if (server.hasPendingDatagrams()) { |
|
408 |
QCOMPARE(server.pendingDatagramSize(), qint64(0)); |
|
409 |
QCOMPARE(server.readDatagram(&c, 1), qint64(0)); |
|
410 |
QCOMPARE(c, '\0'); // untouched |
|
411 |
c = '\0'; |
|
412 |
} else { |
|
413 |
QSKIP("does not have the 2nd datagram", SkipSingle); |
|
414 |
} |
|
415 |
||
416 |
if (server.hasPendingDatagrams()) { |
|
417 |
QCOMPARE(server.pendingDatagramSize(), qint64(10)); |
|
418 |
QCOMPARE(server.readDatagram(&c, 1), qint64(1)); |
|
419 |
QCOMPARE(c, '3'); |
|
420 |
} else { |
|
421 |
QSKIP("does not have the 3rd datagram", SkipSingle); |
|
422 |
} |
|
423 |
} |
|
424 |
||
425 |
||
426 |
void tst_QUdpSocket::writeDatagram() |
|
427 |
{ |
|
428 |
QUdpSocket server; |
|
429 |
QVERIFY2(server.bind(), server.errorString().toLatin1().constData()); |
|
430 |
||
431 |
QHostAddress serverAddress = QHostAddress::LocalHost; |
|
432 |
if (!(server.localAddress() == QHostAddress::Any)) |
|
433 |
serverAddress = server.localAddress(); |
|
434 |
||
435 |
QUdpSocket client; |
|
436 |
||
437 |
qRegisterMetaType<qint64>("qint64"); |
|
438 |
qRegisterMetaType<QAbstractSocket::SocketError>("QAbstractSocket::SocketError"); |
|
439 |
||
440 |
for(int i=0;;i++) { |
|
441 |
QSignalSpy errorspy(&client, SIGNAL(error(QAbstractSocket::SocketError))); |
|
442 |
QSignalSpy bytesspy(&client, SIGNAL(bytesWritten(qint64))); |
|
443 |
||
444 |
qint64 written = client.writeDatagram(QByteArray(i * 1024, 'w'), serverAddress, |
|
445 |
server.localPort()); |
|
446 |
||
447 |
if (written != i * 1024) { |
|
448 |
#if defined (Q_OS_HPUX) |
|
449 |
QSKIP("HP-UX 11.11 on hai (PA-RISC 64) truncates too long datagrams.", SkipSingle); |
|
450 |
#endif |
|
451 |
QCOMPARE(bytesspy.count(), 0); |
|
452 |
QCOMPARE(errorspy.count(), 1); |
|
453 |
QCOMPARE(*static_cast<const int *>(errorspy.at(0).at(0).constData()), |
|
454 |
int(QUdpSocket::DatagramTooLargeError)); |
|
455 |
QCOMPARE(client.error(), QUdpSocket::DatagramTooLargeError); |
|
456 |
break; |
|
457 |
} |
|
458 |
QVERIFY(bytesspy.count() == 1); |
|
459 |
QCOMPARE(*static_cast<const qint64 *>(bytesspy.at(0).at(0).constData()), |
|
460 |
qint64(i * 1024)); |
|
461 |
QCOMPARE(errorspy.count(), 0); |
|
462 |
if (!server.waitForReadyRead(5000)) |
|
463 |
QSKIP(QString("UDP packet lost at size %1, unable to complete the test.").arg(i * 1024).toLatin1().data(), SkipSingle); |
|
464 |
QCOMPARE(server.pendingDatagramSize(), qint64(i * 1024)); |
|
465 |
QCOMPARE(server.readDatagram(0, 0), qint64(0)); |
|
466 |
} |
|
467 |
} |
|
468 |
||
469 |
void tst_QUdpSocket::performance() |
|
470 |
{ |
|
471 |
#if defined(Q_OS_SYMBIAN) |
|
472 |
// Large packets seems not to go through on Symbian |
|
473 |
// Reason might be also fragmentation due to VPN connection etc |
|
474 |
||
475 |
QFETCH_GLOBAL(bool, setProxy); |
|
476 |
QFETCH_GLOBAL(int, proxyType); |
|
477 |
||
478 |
int arrSize = 8192; |
|
479 |
if (setProxy && proxyType == QNetworkProxy::Socks5Proxy) |
|
480 |
arrSize = 1024; |
|
481 |
||
482 |
QByteArray arr(arrSize, '@'); |
|
483 |
#else |
|
484 |
QByteArray arr(8192, '@'); |
|
485 |
#endif // Q_OS_SYMBIAN |
|
486 |
||
487 |
QUdpSocket server; |
|
488 |
QVERIFY2(server.bind(), server.errorString().toLatin1().constData()); |
|
489 |
||
490 |
QHostAddress serverAddress = QHostAddress::LocalHost; |
|
491 |
if (!(server.localAddress() == QHostAddress::Any)) |
|
492 |
serverAddress = server.localAddress(); |
|
493 |
||
494 |
QUdpSocket client; |
|
495 |
client.connectToHost(serverAddress, server.localPort()); |
|
496 |
||
497 |
QTime stopWatch; |
|
498 |
stopWatch.start(); |
|
499 |
||
500 |
qint64 nbytes = 0; |
|
501 |
while (stopWatch.elapsed() < 5000) { |
|
502 |
for (int i = 0; i < 100; ++i) { |
|
503 |
if (client.write(arr.data(), arr.size()) > 0) { |
|
504 |
do { |
|
505 |
nbytes += server.readDatagram(arr.data(), arr.size()); |
|
506 |
} while (server.hasPendingDatagrams()); |
|
507 |
} |
|
508 |
} |
|
509 |
} |
|
510 |
||
511 |
float secs = stopWatch.elapsed() / 1000.0; |
|
512 |
qDebug("\t%.2fMB/%.2fs: %.2fMB/s", float(nbytes / (1024.0*1024.0)), |
|
513 |
secs, float(nbytes / (1024.0*1024.0)) / secs); |
|
514 |
||
515 |
#if defined(Q_OS_SYMBIAN) |
|
516 |
if(nbytes == 0) { |
|
517 |
qDebug("No bytes passed through local UDP socket, since UDP socket write returns EWOULDBLOCK"); |
|
518 |
qDebug("Should try with blocking sockets, but it is not currently possible due to Open C defect"); |
|
519 |
} |
|
520 |
#endif |
|
521 |
||
522 |
} |
|
523 |
||
524 |
void tst_QUdpSocket::bindMode() |
|
525 |
{ |
|
526 |
QFETCH_GLOBAL(bool, setProxy); |
|
527 |
if (setProxy) { |
|
528 |
QFETCH_GLOBAL(int, proxyType); |
|
529 |
if (proxyType == QNetworkProxy::Socks5Proxy) { |
|
530 |
QSKIP("With socks5 explicit port binding is not supported.", SkipAll); |
|
531 |
} |
|
532 |
} |
|
533 |
||
534 |
QUdpSocket socket; |
|
535 |
QVERIFY2(socket.bind(), socket.errorString().toLatin1().constData()); |
|
536 |
QUdpSocket socket2; |
|
537 |
QVERIFY(!socket2.bind(socket.localPort())); |
|
538 |
#if defined(Q_OS_SYMBIAN) |
|
539 |
if(RProcess().HasCapability(ECapabilityNetworkControl)) { |
|
540 |
qDebug("Test executed *with* NetworkControl capability"); |
|
541 |
// In Symbian OS ReuseAddressHint together with NetworkControl capability |
|
542 |
// gives application *always* right to bind to port. I.e. it does not matter |
|
543 |
// if first socket was bound with any bind flag. Since autotests in Symbian |
|
544 |
// are currently executed with ALL -TCB rights, this path is the one executed. |
|
545 |
QVERIFY(socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint)); |
|
546 |
socket.close(); |
|
547 |
socket2.close(); |
|
548 |
||
549 |
QVERIFY2(socket.bind(0, QUdpSocket::ShareAddress), socket.errorString().toLatin1().constData()); |
|
550 |
QVERIFY(!socket2.bind(socket.localPort())); |
|
551 |
QVERIFY2(socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint), socket2.errorString().toLatin1().constData()); |
|
552 |
socket.close(); |
|
553 |
socket2.close(); |
|
554 |
||
555 |
QVERIFY2(socket.bind(0, QUdpSocket::DontShareAddress), socket.errorString().toLatin1().constData()); |
|
556 |
QVERIFY(!socket2.bind(socket.localPort())); |
|
557 |
QVERIFY(socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint)); |
|
558 |
socket.close(); |
|
559 |
socket2.close(); |
|
560 |
} else { |
|
561 |
qDebug("Test executed *without* NetworkControl capability"); |
|
562 |
// If we don't have NetworkControl capability, attempt to bind already bound |
|
563 |
// address will *always* fail. I.e. it does not matter if first socket was |
|
564 |
// bound with any bind flag. |
|
565 |
QVERIFY(!socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint)); |
|
566 |
socket.close(); |
|
567 |
||
568 |
QVERIFY2(socket.bind(0, QUdpSocket::ShareAddress), socket.errorString().toLatin1().constData()); |
|
569 |
QVERIFY(!socket2.bind(socket.localPort())); |
|
570 |
QVERIFY2(!socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint), socket2.errorString().toLatin1().constData()); |
|
571 |
socket.close(); |
|
572 |
||
573 |
QVERIFY2(socket.bind(0, QUdpSocket::DontShareAddress), socket.errorString().toLatin1().constData()); |
|
574 |
QVERIFY(!socket2.bind(socket.localPort())); |
|
575 |
QVERIFY(!socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint)); |
|
576 |
socket.close(); |
|
577 |
} |
|
578 |
#elif defined(Q_OS_UNIX) |
|
579 |
QVERIFY(!socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint)); |
|
580 |
socket.close(); |
|
581 |
QVERIFY2(socket.bind(0, QUdpSocket::ShareAddress), socket.errorString().toLatin1().constData()); |
|
582 |
QVERIFY2(socket2.bind(socket.localPort()), socket2.errorString().toLatin1().constData()); |
|
583 |
socket2.close(); |
|
584 |
QVERIFY2(socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint), socket2.errorString().toLatin1().constData()); |
|
585 |
#else |
|
586 |
||
587 |
// Depending on the user's privileges, this or will succeed or |
|
588 |
// fail. Admins are allowed to reuse the address, but nobody else. |
|
589 |
if (!socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint), socket2.errorString().toLatin1().constData()) |
|
590 |
qWarning("Failed to bind with QUdpSocket::ReuseAddressHint, user isn't an adminstrator?"); |
|
591 |
socket.close(); |
|
592 |
QVERIFY2(socket.bind(0, QUdpSocket::ShareAddress), socket.errorString().toLatin1().constData()); |
|
593 |
QVERIFY(!socket2.bind(socket.localPort())); |
|
594 |
socket.close(); |
|
595 |
QVERIFY2(socket.bind(0, QUdpSocket::DontShareAddress), socket.errorString().toLatin1().constData()); |
|
596 |
QVERIFY(!socket2.bind(socket.localPort())); |
|
597 |
QVERIFY(!socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint)); |
|
598 |
#endif |
|
599 |
} |
|
600 |
||
601 |
void tst_QUdpSocket::writeDatagramToNonExistingPeer_data() |
|
602 |
{ |
|
603 |
QTest::addColumn<bool>("bind"); |
|
604 |
QTest::addColumn<QHostAddress>("peerAddress"); |
|
605 |
QHostAddress localhost(QHostAddress::LocalHost); |
|
606 |
#if !defined(Q_OS_SYMBIAN) |
|
607 |
QHostAddress remote = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first(); |
|
608 |
#endif |
|
609 |
||
610 |
QTest::newRow("localhost-unbound") << false << localhost; |
|
611 |
QTest::newRow("localhost-bound") << true << localhost; |
|
612 |
#if !defined(Q_OS_SYMBIAN) |
|
613 |
QTest::newRow("remote-unbound") << false << remote; |
|
614 |
QTest::newRow("remote-bound") << true << remote; |
|
615 |
#endif |
|
616 |
} |
|
617 |
||
618 |
void tst_QUdpSocket::writeDatagramToNonExistingPeer() |
|
619 |
{ |
|
620 |
QFETCH(bool, bind); |
|
621 |
QFETCH(QHostAddress, peerAddress); |
|
622 |
||
623 |
quint16 peerPort = 33533 + int(bind); |
|
624 |
||
625 |
QUdpSocket sUdp; |
|
626 |
QSignalSpy sReadyReadSpy(&sUdp, SIGNAL(readyRead())); |
|
627 |
if (bind) |
|
628 |
QVERIFY(sUdp.bind()); |
|
629 |
QCOMPARE(sUdp.writeDatagram("", 1, peerAddress, peerPort), qint64(1)); |
|
630 |
QTestEventLoop::instance().enterLoop(1); |
|
631 |
QCOMPARE(sReadyReadSpy.count(), 0); |
|
632 |
} |
|
633 |
||
634 |
void tst_QUdpSocket::writeToNonExistingPeer_data() |
|
635 |
{ |
|
636 |
QTest::addColumn<QHostAddress>("peerAddress"); |
|
637 |
QHostAddress localhost(QHostAddress::LocalHost); |
|
638 |
#if !defined(Q_OS_SYMBIAN) |
|
639 |
QHostAddress remote = QHostInfo::fromName(QtNetworkSettings::serverName()).addresses().first(); |
|
640 |
#endif |
|
641 |
// write (required to be connected) |
|
642 |
QTest::newRow("localhost") << localhost; |
|
643 |
#if !defined(Q_OS_SYMBIAN) |
|
644 |
QTest::newRow("remote") << remote; |
|
645 |
#endif |
|
646 |
} |
|
647 |
||
648 |
void tst_QUdpSocket::writeToNonExistingPeer() |
|
649 |
{ |
|
650 |
QSKIP("Connected-mode UDP sockets and their behaviour are erratic", SkipAll); |
|
651 |
QFETCH(QHostAddress, peerAddress); |
|
652 |
quint16 peerPort = 34534; |
|
653 |
qRegisterMetaType<QAbstractSocket::SocketError>("QAbstractSocket::SocketError"); |
|
654 |
||
655 |
QUdpSocket sConnected; |
|
656 |
QSignalSpy sConnectedReadyReadSpy(&sConnected, SIGNAL(readyRead())); |
|
657 |
QSignalSpy sConnectedErrorSpy(&sConnected, SIGNAL(error(QAbstractSocket::SocketError))); |
|
658 |
sConnected.connectToHost(peerAddress, peerPort, QIODevice::ReadWrite); |
|
659 |
||
660 |
// the first write succeeds... |
|
661 |
QCOMPARE(sConnected.write("", 1), qint64(1)); |
|
662 |
||
663 |
// the second one should fail! |
|
664 |
QTest::qSleep(1000); // do not process events |
|
665 |
QCOMPARE(sConnected.write("", 1), qint64(-1)); |
|
666 |
QCOMPARE(int(sConnected.error()), int(QUdpSocket::ConnectionRefusedError)); |
|
667 |
||
668 |
// the third one will succeed... |
|
669 |
QCOMPARE(sConnected.write("", 1), qint64(1)); |
|
670 |
QTestEventLoop::instance().enterLoop(1); |
|
671 |
QCOMPARE(sConnectedReadyReadSpy.count(), 0); |
|
672 |
QCOMPARE(sConnectedErrorSpy.count(), 1); |
|
673 |
QCOMPARE(int(sConnected.error()), int(QUdpSocket::ConnectionRefusedError)); |
|
674 |
||
675 |
// we should now get a read error |
|
676 |
QCOMPARE(sConnected.write("", 1), qint64(1)); |
|
677 |
QTest::qSleep(1000); // do not process events |
|
678 |
char buf[2]; |
|
679 |
QVERIFY(!sConnected.hasPendingDatagrams()); |
|
680 |
QCOMPARE(sConnected.bytesAvailable(), Q_INT64_C(0)); |
|
681 |
QCOMPARE(sConnected.pendingDatagramSize(), Q_INT64_C(-1)); |
|
682 |
QCOMPARE(sConnected.readDatagram(buf, 2), Q_INT64_C(-1)); |
|
683 |
QCOMPARE(int(sConnected.error()), int(QUdpSocket::ConnectionRefusedError)); |
|
684 |
||
685 |
QCOMPARE(sConnected.write("", 1), qint64(1)); |
|
686 |
QTest::qSleep(1000); // do not process events |
|
687 |
QCOMPARE(sConnected.read(buf, 2), Q_INT64_C(0)); |
|
688 |
QCOMPARE(int(sConnected.error()), int(QUdpSocket::ConnectionRefusedError)); |
|
689 |
||
690 |
// we should still be connected |
|
691 |
QCOMPARE(int(sConnected.state()), int(QUdpSocket::ConnectedState)); |
|
692 |
} |
|
693 |
||
694 |
void tst_QUdpSocket::outOfProcessConnectedClientServerTest() |
|
695 |
{ |
|
696 |
#if defined(Q_OS_WINCE) || defined (Q_OS_SYMBIAN) |
|
697 |
QSKIP("This test depends on reading data from QProcess (not supported on Qt/WinCE and Symbian).", SkipAll); |
|
698 |
#endif |
|
699 |
#if defined(QT_NO_PROCESS) |
|
700 |
QSKIP("Qt was compiled with QT_NO_PROCESS", SkipAll); |
|
701 |
#else |
|
702 |
||
703 |
QProcess serverProcess; |
|
704 |
serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"), |
|
705 |
QIODevice::ReadWrite | QIODevice::Text); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
QVERIFY2(serverProcess.waitForStarted(3000), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
707 |
qPrintable("Failed to start subprocess: " + serverProcess.errorString())); |
0 | 708 |
|
709 |
// Wait until the server has started and reports success. |
|
710 |
while (!serverProcess.canReadLine()) |
|
711 |
QVERIFY(serverProcess.waitForReadyRead(3000)); |
|
712 |
QByteArray serverGreeting = serverProcess.readLine(); |
|
713 |
QVERIFY(serverGreeting != QByteArray("XXX\n")); |
|
714 |
int serverPort = serverGreeting.trimmed().toInt(); |
|
715 |
QVERIFY(serverPort > 0 && serverPort < 65536); |
|
716 |
||
717 |
QProcess clientProcess; |
|
718 |
clientProcess.start(QString::fromLatin1("clientserver/clientserver connectedclient %1 %2") |
|
719 |
.arg(QLatin1String("127.0.0.1")).arg(serverPort), |
|
720 |
QIODevice::ReadWrite | QIODevice::Text); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
721 |
QVERIFY2(clientProcess.waitForStarted(3000), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
722 |
qPrintable("Failed to start subprocess: " + clientProcess.errorString())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
723 |
|
0 | 724 |
// Wait until the server has started and reports success. |
725 |
while (!clientProcess.canReadLine()) |
|
726 |
QVERIFY(clientProcess.waitForReadyRead(3000)); |
|
727 |
QByteArray clientGreeting = clientProcess.readLine(); |
|
728 |
QCOMPARE(clientGreeting, QByteArray("ok\n")); |
|
729 |
||
730 |
// Let the client and server talk for 3 seconds |
|
731 |
QTest::qWait(3000); |
|
732 |
||
733 |
QStringList serverData = QString::fromLocal8Bit(serverProcess.readAll()).split("\n"); |
|
734 |
QStringList clientData = QString::fromLocal8Bit(clientProcess.readAll()).split("\n"); |
|
735 |
QVERIFY(serverData.size() > 5); |
|
736 |
QVERIFY(clientData.size() > 5); |
|
737 |
||
738 |
for (int i = 0; i < clientData.size() / 2; ++i) { |
|
739 |
QCOMPARE(clientData.at(i * 2), QString("readData()")); |
|
740 |
QCOMPARE(serverData.at(i * 3), QString("readData()")); |
|
741 |
||
742 |
QString cdata = clientData.at(i * 2 + 1); |
|
743 |
QString sdata = serverData.at(i * 3 + 1); |
|
744 |
QVERIFY(cdata.startsWith(QLatin1String("got "))); |
|
745 |
||
746 |
QCOMPARE(cdata.mid(4).trimmed().toInt(), sdata.mid(4).trimmed().toInt() * 2); |
|
747 |
QVERIFY(serverData.at(i * 3 + 2).startsWith(QLatin1String("sending "))); |
|
748 |
QCOMPARE(serverData.at(i * 3 + 2).trimmed().mid(8).toInt(), |
|
749 |
sdata.mid(4).trimmed().toInt() * 2); |
|
750 |
} |
|
751 |
||
752 |
clientProcess.kill(); |
|
753 |
QVERIFY(clientProcess.waitForFinished()); |
|
754 |
serverProcess.kill(); |
|
755 |
QVERIFY(serverProcess.waitForFinished()); |
|
756 |
#endif |
|
757 |
} |
|
758 |
||
759 |
void tst_QUdpSocket::outOfProcessUnconnectedClientServerTest() |
|
760 |
{ |
|
761 |
#if defined(Q_OS_WINCE) || defined (Q_OS_SYMBIAN) |
|
762 |
QSKIP("This test depends on reading data from QProcess (not supported on Qt/WinCE and Symbian).", SkipAll); |
|
763 |
#endif |
|
764 |
#if defined(QT_NO_PROCESS) |
|
765 |
QSKIP("Qt was compiled with QT_NO_PROCESS", SkipAll); |
|
766 |
#else |
|
767 |
||
768 |
QProcess serverProcess; |
|
769 |
serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"), |
|
770 |
QIODevice::ReadWrite | QIODevice::Text); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
QVERIFY2(serverProcess.waitForStarted(3000), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
qPrintable("Failed to start subprocess: " + serverProcess.errorString())); |
0 | 773 |
|
774 |
// Wait until the server has started and reports success. |
|
775 |
while (!serverProcess.canReadLine()) |
|
776 |
QVERIFY(serverProcess.waitForReadyRead(3000)); |
|
777 |
QByteArray serverGreeting = serverProcess.readLine(); |
|
778 |
QVERIFY(serverGreeting != QByteArray("XXX\n")); |
|
779 |
int serverPort = serverGreeting.trimmed().toInt(); |
|
780 |
QVERIFY(serverPort > 0 && serverPort < 65536); |
|
781 |
||
782 |
QProcess clientProcess; |
|
783 |
clientProcess.start(QString::fromLatin1("clientserver/clientserver unconnectedclient %1 %2") |
|
784 |
.arg(QLatin1String("127.0.0.1")).arg(serverPort), |
|
785 |
QIODevice::ReadWrite | QIODevice::Text); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
786 |
QVERIFY2(clientProcess.waitForStarted(3000), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
787 |
qPrintable("Failed to start subprocess: " + clientProcess.errorString())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
788 |
|
0 | 789 |
// Wait until the server has started and reports success. |
790 |
while (!clientProcess.canReadLine()) |
|
791 |
QVERIFY(clientProcess.waitForReadyRead(3000)); |
|
792 |
QByteArray clientGreeting = clientProcess.readLine(); |
|
793 |
QCOMPARE(clientGreeting, QByteArray("ok\n")); |
|
794 |
||
795 |
// Let the client and server talk for 3 seconds |
|
796 |
QTest::qWait(3000); |
|
797 |
||
798 |
QStringList serverData = QString::fromLocal8Bit(serverProcess.readAll()).split("\n"); |
|
799 |
QStringList clientData = QString::fromLocal8Bit(clientProcess.readAll()).split("\n"); |
|
800 |
||
801 |
QVERIFY(serverData.size() > 5); |
|
802 |
QVERIFY(clientData.size() > 5); |
|
803 |
||
804 |
for (int i = 0; i < clientData.size() / 2; ++i) { |
|
805 |
QCOMPARE(clientData.at(i * 2), QString("readData()")); |
|
806 |
QCOMPARE(serverData.at(i * 3), QString("readData()")); |
|
807 |
||
808 |
QString cdata = clientData.at(i * 2 + 1); |
|
809 |
QString sdata = serverData.at(i * 3 + 1); |
|
810 |
QVERIFY(cdata.startsWith(QLatin1String("got "))); |
|
811 |
||
812 |
QCOMPARE(cdata.mid(4).trimmed().toInt(), sdata.mid(4).trimmed().toInt() * 2); |
|
813 |
QVERIFY(serverData.at(i * 3 + 2).startsWith(QLatin1String("sending "))); |
|
814 |
QCOMPARE(serverData.at(i * 3 + 2).trimmed().mid(8).toInt(), |
|
815 |
sdata.mid(4).trimmed().toInt() * 2); |
|
816 |
} |
|
817 |
||
818 |
clientProcess.kill(); |
|
819 |
QVERIFY(clientProcess.waitForFinished()); |
|
820 |
serverProcess.kill(); |
|
821 |
QVERIFY(serverProcess.waitForFinished()); |
|
822 |
#endif |
|
823 |
} |
|
824 |
||
825 |
void tst_QUdpSocket::zeroLengthDatagram() |
|
826 |
{ |
|
827 |
QFETCH_GLOBAL(bool, setProxy); |
|
828 |
if (setProxy) |
|
829 |
return; |
|
830 |
||
831 |
QUdpSocket receiver; |
|
832 |
QVERIFY(receiver.bind()); |
|
833 |
||
834 |
QVERIFY(!receiver.waitForReadyRead(100)); |
|
835 |
QVERIFY(!receiver.hasPendingDatagrams()); |
|
836 |
||
837 |
QUdpSocket sender; |
|
838 |
QCOMPARE(sender.writeDatagram(QByteArray(), QHostAddress::LocalHost, receiver.localPort()), qint64(0)); |
|
839 |
||
840 |
QVERIFY(receiver.waitForReadyRead(1000)); |
|
841 |
QVERIFY(receiver.hasPendingDatagrams()); |
|
842 |
||
843 |
char buf; |
|
844 |
QCOMPARE(receiver.readDatagram(&buf, 1), qint64(0)); |
|
845 |
} |
|
846 |
||
847 |
QTEST_MAIN(tst_QUdpSocket) |
|
848 |
#include "tst_qudpsocket.moc" |