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 <QtCore/QtCore> |
|
44 |
#include <QtNetwork/QtNetwork> |
|
45 |
#include <QtTest/QtTest> |
|
46 |
||
47 |
#include "../network-settings.h" |
|
48 |
||
49 |
//TESTED_CLASS= |
|
50 |
//TESTED_FILES= |
|
51 |
||
52 |
#ifdef Q_OS_SYMBIAN |
|
53 |
#define SRCDIR "" |
|
54 |
#endif |
|
55 |
||
56 |
class tst_QIODevice : public QObject |
|
57 |
{ |
|
58 |
Q_OBJECT |
|
59 |
||
60 |
public: |
|
61 |
tst_QIODevice(); |
|
62 |
virtual ~tst_QIODevice(); |
|
63 |
||
64 |
||
65 |
public slots: |
|
66 |
void init(); |
|
67 |
void cleanup(); |
|
68 |
private slots: |
|
69 |
void getSetCheck(); |
|
70 |
void constructing_QTcpSocket(); |
|
71 |
void constructing_QFile(); |
|
72 |
void read_QByteArray(); |
|
73 |
void unget(); |
|
74 |
void peek(); |
|
75 |
void getch(); |
|
76 |
void putch(); |
|
77 |
||
78 |
void readLine_data(); |
|
79 |
void readLine(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
void readLine2_data(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
void readLine2(); |
0 | 83 |
}; |
84 |
||
85 |
// Testing get/set functions |
|
86 |
void tst_QIODevice::getSetCheck() |
|
87 |
{ |
|
88 |
// OpenMode QIODevice::openMode() |
|
89 |
// void QIODevice::setOpenMode(OpenMode) |
|
90 |
class MyIODevice : public QIODevice { |
|
91 |
public: |
|
92 |
void setOpenMode(OpenMode openMode) { QIODevice::setOpenMode(openMode); } |
|
93 |
}; |
|
94 |
QTcpSocket var1; |
|
95 |
MyIODevice *obj1 = reinterpret_cast<MyIODevice*>(&var1); |
|
96 |
obj1->setOpenMode(QIODevice::OpenMode(QIODevice::NotOpen)); |
|
97 |
QCOMPARE(QIODevice::OpenMode(QIODevice::NotOpen), obj1->openMode()); |
|
98 |
obj1->setOpenMode(QIODevice::OpenMode(QIODevice::ReadWrite)); |
|
99 |
QCOMPARE(QIODevice::OpenMode(QIODevice::ReadWrite), obj1->openMode()); |
|
100 |
} |
|
101 |
||
102 |
tst_QIODevice::tst_QIODevice() |
|
103 |
{ |
|
104 |
Q_SET_DEFAULT_IAP |
|
105 |
} |
|
106 |
||
107 |
tst_QIODevice::~tst_QIODevice() |
|
108 |
{ |
|
109 |
} |
|
110 |
||
111 |
void tst_QIODevice::init() |
|
112 |
{ |
|
113 |
} |
|
114 |
||
115 |
void tst_QIODevice::cleanup() |
|
116 |
{ |
|
117 |
} |
|
118 |
||
119 |
//---------------------------------------------------------------------------------- |
|
120 |
void tst_QIODevice::constructing_QTcpSocket() |
|
121 |
{ |
|
122 |
#if defined(Q_OS_WINCE) && defined(WINCE_EMULATOR_TEST) |
|
123 |
QSKIP("Networking tests in a WinCE emulator are unstable", SkipAll); |
|
124 |
#endif |
|
125 |
QTcpSocket socket; |
|
126 |
QIODevice *device = &socket; |
|
127 |
||
128 |
QVERIFY(!device->isOpen()); |
|
129 |
||
130 |
socket.connectToHost(QtNetworkSettings::serverName(), 143); |
|
131 |
QVERIFY(socket.waitForConnected(5000)); |
|
132 |
QVERIFY(device->isOpen()); |
|
133 |
||
134 |
while (!device->canReadLine()) |
|
135 |
QVERIFY(device->waitForReadyRead(5000)); |
|
136 |
||
137 |
char buf[1024]; |
|
138 |
memset(buf, 0, sizeof(buf)); |
|
139 |
qlonglong lineLength = device->readLine(buf, sizeof(buf)); |
|
140 |
QVERIFY(lineLength > 0); |
|
141 |
QCOMPARE(socket.pos(), qlonglong(0)); |
|
142 |
||
143 |
socket.close(); |
|
144 |
socket.connectToHost(QtNetworkSettings::serverName(), 143); |
|
145 |
QVERIFY(socket.waitForConnected(5000)); |
|
146 |
QVERIFY(device->isOpen()); |
|
147 |
||
148 |
while (!device->canReadLine()) |
|
149 |
QVERIFY(device->waitForReadyRead(5000)); |
|
150 |
||
151 |
char buf2[1024]; |
|
152 |
memset(buf2, 0, sizeof(buf2)); |
|
153 |
QCOMPARE(socket.readLine(buf2, sizeof(buf2)), lineLength); |
|
154 |
||
155 |
char *c1 = buf; |
|
156 |
char *c2 = buf2; |
|
157 |
while (*c1 && *c2) { |
|
158 |
QCOMPARE(*c1, *c2); |
|
159 |
++c1; |
|
160 |
++c2; |
|
161 |
} |
|
162 |
QCOMPARE(*c1, *c2); |
|
163 |
} |
|
164 |
||
165 |
//---------------------------------------------------------------------------------- |
|
166 |
void tst_QIODevice::constructing_QFile() |
|
167 |
{ |
|
168 |
QFile file; |
|
169 |
QIODevice *device = &file; |
|
170 |
||
171 |
QVERIFY(!device->isOpen()); |
|
172 |
||
173 |
file.setFileName(SRCDIR "tst_qiodevice.cpp"); |
|
174 |
QVERIFY(file.open(QFile::ReadOnly)); |
|
175 |
QVERIFY(device->isOpen()); |
|
176 |
QCOMPARE((int) device->openMode(), (int) QFile::ReadOnly); |
|
177 |
||
178 |
char buf[1024]; |
|
179 |
memset(buf, 0, sizeof(buf)); |
|
180 |
qlonglong lineLength = device->readLine(buf, sizeof(buf)); |
|
181 |
QVERIFY(lineLength > 0); |
|
182 |
QCOMPARE(file.pos(), lineLength); |
|
183 |
||
184 |
file.seek(0); |
|
185 |
char buf2[1024]; |
|
186 |
memset(buf2, 0, sizeof(buf2)); |
|
187 |
QCOMPARE(file.readLine(buf2, sizeof(buf2)), lineLength); |
|
188 |
||
189 |
char *c1 = buf; |
|
190 |
char *c2 = buf2; |
|
191 |
while (*c1 && *c2) { |
|
192 |
QCOMPARE(*c1, *c2); |
|
193 |
++c1; |
|
194 |
++c2; |
|
195 |
} |
|
196 |
QCOMPARE(*c1, *c2); |
|
197 |
} |
|
198 |
||
199 |
||
200 |
void tst_QIODevice::read_QByteArray() |
|
201 |
{ |
|
202 |
QFile f(SRCDIR "tst_qiodevice.cpp"); |
|
203 |
f.open(QIODevice::ReadOnly); |
|
204 |
||
205 |
QByteArray b = f.read(10); |
|
206 |
QCOMPARE(b.length(), 10); |
|
207 |
||
208 |
b = f.read(256); |
|
209 |
QCOMPARE(b.length(), 256); |
|
210 |
||
211 |
b = f.read(0); |
|
212 |
QCOMPARE(b.length(), 0); |
|
213 |
} |
|
214 |
||
215 |
//-------------------------------------------------------------------- |
|
216 |
void tst_QIODevice::unget() |
|
217 |
{ |
|
218 |
#if defined(Q_OS_WINCE) && defined(WINCE_EMULATOR_TEST) |
|
219 |
QSKIP("Networking tests in a WinCE emulator are unstable", SkipAll); |
|
220 |
#endif |
|
221 |
QBuffer buffer; |
|
222 |
buffer.open(QBuffer::ReadWrite); |
|
223 |
buffer.write("ZXCV"); |
|
224 |
buffer.seek(0); |
|
225 |
QCOMPARE(buffer.read(4), QByteArray("ZXCV")); |
|
226 |
QCOMPARE(buffer.pos(), qint64(4)); |
|
227 |
||
228 |
buffer.ungetChar('a'); |
|
229 |
buffer.ungetChar('b'); |
|
230 |
buffer.ungetChar('c'); |
|
231 |
buffer.ungetChar('d'); |
|
232 |
||
233 |
QCOMPARE(buffer.pos(), qint64(0)); |
|
234 |
||
235 |
char buf[6]; |
|
236 |
QCOMPARE(buffer.readLine(buf, 5), qint64(4)); |
|
237 |
QCOMPARE(buffer.pos(), qint64(4)); |
|
238 |
QCOMPARE(static_cast<const char*>(buf), "dcba"); |
|
239 |
||
240 |
buffer.ungetChar('a'); |
|
241 |
buffer.ungetChar('b'); |
|
242 |
buffer.ungetChar('c'); |
|
243 |
buffer.ungetChar('d'); |
|
244 |
||
245 |
QCOMPARE(buffer.pos(), qint64(0)); |
|
246 |
||
247 |
for (int i = 0; i < 5; ++i) { |
|
248 |
buf[0] = '@'; |
|
249 |
buf[1] = '@'; |
|
250 |
QTest::ignoreMessage(QtWarningMsg, |
|
251 |
"QIODevice::readLine: Called with maxSize < 2"); |
|
252 |
QCOMPARE(buffer.readLine(buf, 1), qint64(-1)); |
|
253 |
QCOMPARE(buffer.readLine(buf, 2), qint64(i < 4 ? 1 : -1)); |
|
254 |
switch (i) { |
|
255 |
case 0: QCOMPARE(buf[0], 'd'); break; |
|
256 |
case 1: QCOMPARE(buf[0], 'c'); break; |
|
257 |
case 2: QCOMPARE(buf[0], 'b'); break; |
|
258 |
case 3: QCOMPARE(buf[0], 'a'); break; |
|
259 |
case 4: QCOMPARE(buf[0], '\0'); break; |
|
260 |
} |
|
261 |
QCOMPARE(buf[1], i < 4 ? '\0' : '@'); |
|
262 |
} |
|
263 |
||
264 |
buffer.ungetChar('\n'); |
|
265 |
QCOMPARE(buffer.readLine(), QByteArray("\n")); |
|
266 |
||
267 |
buffer.seek(1); |
|
268 |
buffer.readLine(buf, 3); |
|
269 |
QCOMPARE(static_cast<const char*>(buf), "XC"); |
|
270 |
||
271 |
buffer.seek(4); |
|
272 |
buffer.ungetChar('Q'); |
|
273 |
QCOMPARE(buffer.readLine(buf, 3), qint64(1)); |
|
274 |
||
275 |
for (int i = 0; i < 2; ++i) { |
|
276 |
QTcpSocket socket; |
|
277 |
QIODevice *dev; |
|
278 |
QByteArray result; |
|
279 |
const char *lineResult; |
|
280 |
if (i == 0) { |
|
281 |
dev = &buffer; |
|
282 |
result = QByteArray("ZXCV"); |
|
283 |
lineResult = "ZXCV"; |
|
284 |
} else { |
|
285 |
socket.connectToHost(QtNetworkSettings::serverName(), 80); |
|
286 |
socket.write("GET / HTTP/1.0\r\n\r\n"); |
|
287 |
QVERIFY(socket.waitForReadyRead()); |
|
288 |
dev = &socket; |
|
289 |
result = QByteArray("HTTP"); |
|
290 |
lineResult = "Date"; |
|
291 |
} |
|
292 |
char ch, ch2; |
|
293 |
dev->seek(0); |
|
294 |
dev->getChar(&ch); |
|
295 |
dev->ungetChar(ch); |
|
296 |
QCOMPARE(dev->peek(4), result); |
|
297 |
dev->getChar(&ch); |
|
298 |
dev->getChar(&ch2); |
|
299 |
dev->ungetChar(ch2); |
|
300 |
dev->ungetChar(ch); |
|
301 |
QCOMPARE(dev->read(1), result.left(1)); |
|
302 |
QCOMPARE(dev->read(3), result.right(3)); |
|
303 |
||
304 |
if (i == 0) |
|
305 |
dev->seek(0); |
|
306 |
else |
|
307 |
dev->readLine(); |
|
308 |
dev->getChar(&ch); |
|
309 |
dev->ungetChar(ch); |
|
310 |
dev->readLine(buf, 5); |
|
311 |
QCOMPARE(static_cast<const char*>(buf), lineResult); |
|
312 |
||
313 |
if (i == 1) |
|
314 |
socket.close(); |
|
315 |
} |
|
316 |
} |
|
317 |
||
318 |
//-------------------------------------------------------------------- |
|
319 |
void tst_QIODevice::peek() |
|
320 |
{ |
|
321 |
QBuffer buffer; |
|
322 |
QFile::remove("peektestfile"); |
|
323 |
QFile file("peektestfile"); |
|
324 |
||
325 |
for (int i = 0; i < 2; ++i) { |
|
326 |
QIODevice *device = i ? (QIODevice *)&file : (QIODevice *)&buffer; |
|
327 |
||
328 |
device->open(QBuffer::ReadWrite); |
|
329 |
device->write("ZXCV"); |
|
330 |
||
331 |
device->seek(0); |
|
332 |
QCOMPARE(device->peek(4), QByteArray("ZXCV")); |
|
333 |
QCOMPARE(device->pos(), qint64(0)); |
|
334 |
device->write("ABCDE"); |
|
335 |
device->seek(3); |
|
336 |
QCOMPARE(device->peek(1), QByteArray("D")); |
|
337 |
QCOMPARE(device->peek(5), QByteArray("DE")); |
|
338 |
device->seek(0); |
|
339 |
QCOMPARE(device->read(4), QByteArray("ABCD")); |
|
340 |
QCOMPARE(device->pos(), qint64(4)); |
|
341 |
||
342 |
device->seek(0); |
|
343 |
device->write("ZXCV"); |
|
344 |
device->seek(0); |
|
345 |
char buf[5]; |
|
346 |
buf[4] = 0; |
|
347 |
device->peek(buf, 4); |
|
348 |
QCOMPARE(static_cast<const char *>(buf), "ZXCV"); |
|
349 |
QCOMPARE(device->pos(), qint64(0)); |
|
350 |
device->read(buf, 4); |
|
351 |
QCOMPARE(static_cast<const char *>(buf), "ZXCV"); |
|
352 |
QCOMPARE(device->pos(), qint64(4)); |
|
353 |
} |
|
354 |
QFile::remove("peektestfile"); |
|
355 |
} |
|
356 |
||
357 |
void tst_QIODevice::getch() |
|
358 |
{ |
|
359 |
#ifdef QT3_SUPPORT |
|
360 |
QBuffer buffer; |
|
361 |
buffer.open(QBuffer::ReadWrite); |
|
362 |
buffer.write("\xff\x7f\x80\x00", 4); |
|
363 |
buffer.reset(); |
|
364 |
QCOMPARE(buffer.getch(), 0xff); |
|
365 |
QCOMPARE(buffer.getch(), 0x7f); |
|
366 |
QCOMPARE(buffer.getch(), 0x80); |
|
367 |
QCOMPARE(buffer.getch(), 0x00); |
|
368 |
||
369 |
buffer.ungetch(0x00); |
|
370 |
buffer.ungetch(0x80); |
|
371 |
buffer.ungetch(0x7f); |
|
372 |
buffer.ungetch(0xff); |
|
373 |
||
374 |
QCOMPARE(buffer.getch(), 0xff); |
|
375 |
QCOMPARE(buffer.getch(), 0x7f); |
|
376 |
QCOMPARE(buffer.getch(), 0x80); |
|
377 |
QCOMPARE(buffer.getch(), 0x00); |
|
378 |
#endif |
|
379 |
} |
|
380 |
||
381 |
void tst_QIODevice::putch() |
|
382 |
{ |
|
383 |
#ifdef QT3_SUPPORT |
|
384 |
QBuffer buffer; |
|
385 |
buffer.open(QBuffer::ReadWrite); |
|
386 |
buffer.putch(0xff); |
|
387 |
buffer.putch(0x7f); |
|
388 |
buffer.putch(0x80); |
|
389 |
buffer.putch(0x00); |
|
390 |
buffer.reset(); |
|
391 |
QCOMPARE(buffer.getch(), 0xff); |
|
392 |
QCOMPARE(buffer.getch(), 0x7f); |
|
393 |
QCOMPARE(buffer.getch(), 0x80); |
|
394 |
QCOMPARE(buffer.getch(), 0x00); |
|
395 |
#endif |
|
396 |
} |
|
397 |
||
398 |
void tst_QIODevice::readLine_data() |
|
399 |
{ |
|
400 |
QTest::addColumn<QByteArray>("data"); |
|
401 |
||
402 |
QTest::newRow("0") << QByteArray("\nAA"); |
|
403 |
QTest::newRow("1") << QByteArray("A\nAA"); |
|
404 |
||
405 |
QByteArray data(9000, 'A'); |
|
406 |
data[8193] = '\n'; |
|
407 |
QTest::newRow("8194") << data; |
|
408 |
data[8193] = 'A'; |
|
409 |
data[8192] = '\n'; |
|
410 |
QTest::newRow("8193") << data; |
|
411 |
data[8192] = 'A'; |
|
412 |
data[8191] = '\n'; |
|
413 |
QTest::newRow("8192") << data; |
|
414 |
data[8191] = 'A'; |
|
415 |
data[8190] = '\n'; |
|
416 |
QTest::newRow("8191") << data; |
|
417 |
||
418 |
data[5999] = '\n'; |
|
419 |
QTest::newRow("6000") << data; |
|
420 |
||
421 |
data[4095] = '\n'; |
|
422 |
QTest::newRow("4096") << data; |
|
423 |
||
424 |
data[4094] = '\n'; |
|
425 |
data[4095] = 'A'; |
|
426 |
QTest::newRow("4095") << data; |
|
427 |
} |
|
428 |
||
429 |
void tst_QIODevice::readLine() |
|
430 |
{ |
|
431 |
QFETCH(QByteArray, data); |
|
432 |
QBuffer buffer(&data); |
|
433 |
QVERIFY(buffer.open(QIODevice::ReadWrite)); |
|
434 |
QVERIFY(buffer.canReadLine()); |
|
435 |
||
436 |
int linelen = data.indexOf('\n') + 1; |
|
437 |
QByteArray line; |
|
438 |
line.reserve(linelen + 100); |
|
439 |
||
440 |
int result = buffer.readLine(line.data(), linelen + 100); |
|
441 |
QCOMPARE(result, linelen); |
|
442 |
||
443 |
// try the exact length of the line (plus terminating \0) |
|
444 |
QVERIFY(buffer.seek(0)); |
|
445 |
result = buffer.readLine(line.data(), linelen + 1); |
|
446 |
QCOMPARE(result, linelen); |
|
447 |
||
448 |
// try with a line length limit |
|
449 |
QVERIFY(buffer.seek(0)); |
|
450 |
line = buffer.readLine(linelen + 100); |
|
451 |
QCOMPARE(line.size(), linelen); |
|
452 |
||
453 |
// try without a length limit |
|
454 |
QVERIFY(buffer.seek(0)); |
|
455 |
line = buffer.readLine(); |
|
456 |
QCOMPARE(line.size(), linelen); |
|
457 |
} |
|
458 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
459 |
void tst_QIODevice::readLine2_data() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
460 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
461 |
QTest::addColumn<QByteArray>("line"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
462 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
463 |
QTest::newRow("1024 - 4") << QByteArray(1024 - 4, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
464 |
QTest::newRow("1024 - 3") << QByteArray(1024 - 3, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
QTest::newRow("1024 - 2") << QByteArray(1024 - 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
466 |
QTest::newRow("1024 - 1") << QByteArray(1024 - 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
467 |
QTest::newRow("1024" ) << QByteArray(1024 , 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
468 |
QTest::newRow("1024 + 1") << QByteArray(1024 + 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
469 |
QTest::newRow("1024 + 2") << QByteArray(1024 + 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
470 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
471 |
QTest::newRow("4096 - 4") << QByteArray(4096 - 4, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
472 |
QTest::newRow("4096 - 3") << QByteArray(4096 - 3, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
473 |
QTest::newRow("4096 - 2") << QByteArray(4096 - 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
474 |
QTest::newRow("4096 - 1") << QByteArray(4096 - 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
QTest::newRow("4096" ) << QByteArray(4096 , 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
476 |
QTest::newRow("4096 + 1") << QByteArray(4096 + 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
477 |
QTest::newRow("4096 + 2") << QByteArray(4096 + 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
479 |
QTest::newRow("8192 - 4") << QByteArray(8192 - 4, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
480 |
QTest::newRow("8192 - 3") << QByteArray(8192 - 3, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
481 |
QTest::newRow("8192 - 2") << QByteArray(8192 - 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
QTest::newRow("8192 - 1") << QByteArray(8192 - 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
QTest::newRow("8192" ) << QByteArray(8192 , 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
484 |
QTest::newRow("8192 + 1") << QByteArray(8192 + 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
QTest::newRow("8192 + 2") << QByteArray(8192 + 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
487 |
QTest::newRow("16384 - 4") << QByteArray(16384 - 4, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
488 |
QTest::newRow("16384 - 3") << QByteArray(16384 - 3, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
489 |
QTest::newRow("16384 - 2") << QByteArray(16384 - 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
490 |
QTest::newRow("16384 - 1") << QByteArray(16384 - 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
491 |
QTest::newRow("16384" ) << QByteArray(16384 , 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
492 |
QTest::newRow("16384 + 1") << QByteArray(16384 + 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
493 |
QTest::newRow("16384 + 2") << QByteArray(16384 + 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
494 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
495 |
QTest::newRow("20000") << QByteArray(20000, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
496 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
497 |
QTest::newRow("32768 - 4") << QByteArray(32768 - 4, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
498 |
QTest::newRow("32768 - 3") << QByteArray(32768 - 3, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
499 |
QTest::newRow("32768 - 2") << QByteArray(32768 - 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
500 |
QTest::newRow("32768 - 1") << QByteArray(32768 - 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
501 |
QTest::newRow("32768" ) << QByteArray(32768 , 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
502 |
QTest::newRow("32768 + 1") << QByteArray(32768 + 1, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
503 |
QTest::newRow("32768 + 2") << QByteArray(32768 + 2, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
504 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
505 |
QTest::newRow("40000") << QByteArray(40000, 'x'); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
506 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
507 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
508 |
void tst_QIODevice::readLine2() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
509 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
510 |
QFETCH(QByteArray, line); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
511 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
512 |
int length = line.size(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
513 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
514 |
QByteArray data("First line.\r\n"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
515 |
data.append(line); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
516 |
data.append("\r\n"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
517 |
data.append(line); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
518 |
data.append("\r\n"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
519 |
data.append("\r\n0123456789"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
520 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
521 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
522 |
QBuffer buffer(&data); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
523 |
buffer.open(QIODevice::ReadOnly); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
524 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
525 |
buffer.seek(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
526 |
QByteArray temp; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
527 |
temp.resize(64536); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
528 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(13)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
529 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
530 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
531 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
532 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
533 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(-1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
534 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
535 |
buffer.seek(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
536 |
QCOMPARE(buffer.readLine().size(), 13); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
QCOMPARE(buffer.readLine().size(), length + 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
538 |
QCOMPARE(buffer.readLine().size(), length + 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
539 |
QCOMPARE(buffer.readLine().size(), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
540 |
QCOMPARE(buffer.readLine().size(), 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
541 |
QVERIFY(buffer.readLine().isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
542 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
543 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
544 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
545 |
QBuffer buffer(&data); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
546 |
buffer.open(QIODevice::ReadOnly | QIODevice::Text); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
547 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
548 |
buffer.seek(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
549 |
QByteArray temp; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
550 |
temp.resize(64536); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(12)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
552 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
553 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
554 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(10)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
556 |
QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(-1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
557 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
558 |
buffer.seek(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
QCOMPARE(buffer.readLine().size(), 12); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
QCOMPARE(buffer.readLine().size(), length + 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
QCOMPARE(buffer.readLine().size(), length + 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
QCOMPARE(buffer.readLine().size(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
QCOMPARE(buffer.readLine().size(), 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
564 |
QVERIFY(buffer.readLine().isNull()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
565 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
566 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
567 |
|
0 | 568 |
QTEST_MAIN(tst_QIODevice) |
569 |
#include "tst_qiodevice.moc" |