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 |
#include <QtTest/QtTest> |
|
44 |
#include <QtGui/QtGui> |
|
45 |
#ifdef QT3_SUPPORT |
|
46 |
#include <Qt3Support/Qt3Support> |
|
47 |
#endif |
|
48 |
#include <QtSvg/QtSvg> |
|
49 |
||
50 |
#if defined(Q_OS_SYMBIAN) |
|
51 |
# define STRINGIFY(x) #x |
|
52 |
# define TOSTRING(x) STRINGIFY(x) |
|
53 |
# define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) "/" |
|
54 |
#define SVGFILE "tests2.svg" |
|
55 |
#endif |
|
56 |
||
57 |
Q_DECLARE_METATYPE(QBitArray) |
|
58 |
Q_DECLARE_METATYPE(qint64) |
|
59 |
||
60 |
//TESTED_CLASS= |
|
61 |
//TESTED_FILES= |
|
62 |
||
63 |
class tst_QDataStream : public QObject |
|
64 |
{ |
|
65 |
Q_OBJECT |
|
66 |
||
67 |
public: |
|
68 |
tst_QDataStream(); |
|
69 |
virtual ~tst_QDataStream(); |
|
70 |
||
71 |
void stream_data(int noOfElements); |
|
72 |
||
73 |
public slots: |
|
74 |
void init(); |
|
75 |
void cleanup(); |
|
76 |
||
77 |
private slots: |
|
78 |
void getSetCheck(); |
|
79 |
void stream_bool_data(); |
|
80 |
void stream_bool(); |
|
81 |
||
82 |
void stream_QBool_data(); |
|
83 |
void stream_QBool(); |
|
84 |
||
85 |
void stream_QBool_in_4_0(); |
|
86 |
||
87 |
void stream_QBitArray_data(); |
|
88 |
void stream_QBitArray(); |
|
89 |
||
90 |
void stream_QBrush_data(); |
|
91 |
void stream_QBrush(); |
|
92 |
||
93 |
void stream_QColor_data(); |
|
94 |
void stream_QColor(); |
|
95 |
||
96 |
void stream_QByteArray_data(); |
|
97 |
void stream_QByteArray(); |
|
98 |
||
99 |
void stream_QCursor_data(); |
|
100 |
void stream_QCursor(); |
|
101 |
||
102 |
void stream_QDate_data(); |
|
103 |
void stream_QDate(); |
|
104 |
||
105 |
void stream_QTime_data(); |
|
106 |
void stream_QTime(); |
|
107 |
||
108 |
void stream_QDateTime_data(); |
|
109 |
void stream_QDateTime(); |
|
110 |
||
111 |
void stream_QFont_data(); |
|
112 |
void stream_QFont(); |
|
113 |
||
114 |
void stream_QImage_data(); |
|
115 |
void stream_QImage(); |
|
116 |
||
117 |
void stream_QPalette_data(); |
|
118 |
void stream_QPalette(); |
|
119 |
||
120 |
void stream_QColorGroup_data(); |
|
121 |
void stream_QColorGroup(); |
|
122 |
||
123 |
void stream_QPen_data(); |
|
124 |
void stream_QPen(); |
|
125 |
||
126 |
void stream_QPixmap_data(); |
|
127 |
void stream_QPixmap(); |
|
128 |
||
129 |
void stream_QPoint_data(); |
|
130 |
void stream_QPoint(); |
|
131 |
||
132 |
void stream_QRect_data(); |
|
133 |
void stream_QRect(); |
|
134 |
||
135 |
void stream_QPolygon_data(); |
|
136 |
void stream_QPolygon(); |
|
137 |
||
138 |
void stream_QRegion_data(); |
|
139 |
void stream_QRegion(); |
|
140 |
||
141 |
void stream_QSize_data(); |
|
142 |
void stream_QSize(); |
|
143 |
||
144 |
void stream_QString_data(); |
|
145 |
void stream_QString(); |
|
146 |
||
147 |
void stream_QRegExp_data(); |
|
148 |
void stream_QRegExp(); |
|
149 |
||
150 |
void stream_Map_data(); |
|
151 |
void stream_Map(); |
|
152 |
||
153 |
void stream_Hash_data(); |
|
154 |
void stream_Hash(); |
|
155 |
||
156 |
void stream_qint64_data(); |
|
157 |
void stream_qint64(); |
|
158 |
||
159 |
void stream_QWMatrix_data(); |
|
160 |
void stream_QWMatrix(); |
|
161 |
||
162 |
void stream_QIcon_data(); |
|
163 |
void stream_QIcon(); |
|
164 |
||
165 |
void stream_atEnd_data(); |
|
166 |
void stream_atEnd(); |
|
167 |
||
168 |
void stream_QByteArray2(); |
|
169 |
||
170 |
void setVersion_data(); |
|
171 |
void setVersion(); |
|
172 |
||
173 |
void skipRawData_data(); |
|
174 |
void skipRawData(); |
|
175 |
||
176 |
void status_qint8_data(); |
|
177 |
void status_qint8(); |
|
178 |
void status_qint16_data(); |
|
179 |
void status_qint16(); |
|
180 |
void status_qint32_data(); |
|
181 |
void status_qint32(); |
|
182 |
void status_qint64_data(); |
|
183 |
void status_qint64(); |
|
184 |
||
185 |
void status_float_data(); |
|
186 |
void status_float(); |
|
187 |
void status_double_data(); |
|
188 |
void status_double(); |
|
189 |
||
190 |
void status_charptr_QByteArray_data(); |
|
191 |
void status_charptr_QByteArray(); |
|
192 |
||
193 |
void status_QString_data(); |
|
194 |
void status_QString(); |
|
195 |
||
196 |
void status_QBitArray_data(); |
|
197 |
void status_QBitArray(); |
|
198 |
||
199 |
void status_QHash_QMap(); |
|
200 |
||
201 |
void status_QLinkedList_QList_QVector(); |
|
202 |
||
203 |
void streamToAndFromQByteArray(); |
|
204 |
||
205 |
void streamRealDataTypes(); |
|
206 |
||
207 |
void floatingPointPrecision(); |
|
208 |
||
209 |
#ifdef QT3_SUPPORT |
|
210 |
void task_224283(); |
|
211 |
#endif |
|
212 |
||
213 |
void compatibility_Qt3(); |
|
214 |
void compatibility_Qt2(); |
|
215 |
||
216 |
private: |
|
217 |
void writebool(QDataStream *s); |
|
218 |
void writeQBool(QDataStream *s); |
|
219 |
void writeQBitArray(QDataStream *s); |
|
220 |
void writeQBrush(QDataStream *s); |
|
221 |
void writeQColor(QDataStream *s); |
|
222 |
void writeQByteArray(QDataStream *s); |
|
223 |
void writeQCursor(QDataStream *s); |
|
224 |
void writeQWaitCursor(QDataStream *s); |
|
225 |
void writeQDate(QDataStream *s); |
|
226 |
void writeQTime(QDataStream *s); |
|
227 |
void writeQDateTime(QDataStream *s); |
|
228 |
void writeQFont(QDataStream *s); |
|
229 |
void writeQImage(QDataStream *s); |
|
230 |
void writeQPalette(QDataStream *s); |
|
231 |
void writeQColorGroup(QDataStream *s); |
|
232 |
void writeQPen(QDataStream *s); |
|
233 |
void writeQPixmap(QDataStream *s); |
|
234 |
void writeQPoint(QDataStream *s); |
|
235 |
void writeQRect(QDataStream *s); |
|
236 |
void writeQPolygon(QDataStream *s); |
|
237 |
void writeQRegion(QDataStream *s); |
|
238 |
void writeQSize(QDataStream *s); |
|
239 |
void writeQString(QDataStream* dev); |
|
240 |
void writeQRegExp(QDataStream* dev); |
|
241 |
void writeMap(QDataStream* dev); |
|
242 |
void writeHash(QDataStream* dev); |
|
243 |
void writeqint64(QDataStream *s); |
|
244 |
void writeQWMatrix(QDataStream *s); |
|
245 |
void writeQIcon(QDataStream *s); |
|
246 |
||
247 |
void readbool(QDataStream *s); |
|
248 |
void readQBool(QDataStream *s); |
|
249 |
void readQBitArray(QDataStream *s); |
|
250 |
void readQBrush(QDataStream *s); |
|
251 |
void readQColor(QDataStream *s); |
|
252 |
void readQByteArray(QDataStream *s); |
|
253 |
void readQCursor(QDataStream *s); |
|
254 |
void readQDate(QDataStream *s); |
|
255 |
void readQTime(QDataStream *s); |
|
256 |
void readQDateTime(QDataStream *s); |
|
257 |
void readQFont(QDataStream *s); |
|
258 |
void readQImage(QDataStream *s); |
|
259 |
void readQPalette(QDataStream *s); |
|
260 |
void readQColorGroup(QDataStream *s); |
|
261 |
void readQPen(QDataStream *s); |
|
262 |
void readQPixmap(QDataStream *s); |
|
263 |
void readQPoint(QDataStream *s); |
|
264 |
void readQRect(QDataStream *s); |
|
265 |
void readQPolygon(QDataStream *s); |
|
266 |
void readQRegion(QDataStream *s); |
|
267 |
void readQSize(QDataStream *s); |
|
268 |
void readQString(QDataStream *s); |
|
269 |
void readQRegExp(QDataStream *s); |
|
270 |
void readMap(QDataStream *s); |
|
271 |
void readHash(QDataStream *s); |
|
272 |
void readqint64(QDataStream *s); |
|
273 |
void readQWMatrix(QDataStream *s); |
|
274 |
void readQIcon(QDataStream *s); |
|
275 |
||
276 |
private: |
|
277 |
QString svgFile; |
|
278 |
}; |
|
279 |
||
280 |
static int NColorRoles[] = { |
|
281 |
QPalette::NoRole, // No Version |
|
282 |
QPalette::NoRole, // Qt_1_0 |
|
283 |
QPalette::HighlightedText + 1, // Qt_2_0 |
|
284 |
QPalette::HighlightedText + 1, // Qt_2_1 |
|
285 |
QPalette::LinkVisited + 1, // Qt_3_0 |
|
286 |
QPalette::HighlightedText + 1, // Qt_3_1 |
|
287 |
QPalette::HighlightedText + 1, // Qt_3_3 |
|
288 |
QPalette::HighlightedText + 1, // Qt_4_0, Qt_4_1 |
|
289 |
QPalette::HighlightedText + 1, // Qt_4_2 |
|
290 |
QPalette::AlternateBase + 1, // Qt_4_3 |
|
291 |
QPalette::ToolTipText + 1, // Qt_4_4 |
|
292 |
QPalette::ToolTipText + 1, // Qt_4_5 |
|
293 |
QPalette::ToolTipText + 1, // Qt_4_6 |
|
294 |
0 // add the correct value for Qt_4_7 here later |
|
295 |
}; |
|
296 |
||
297 |
// Testing get/set functions |
|
298 |
void tst_QDataStream::getSetCheck() |
|
299 |
{ |
|
300 |
QDataStream obj1; |
|
301 |
// QIODevice * QDataStream::device() |
|
302 |
// void QDataStream::setDevice(QIODevice *) |
|
303 |
QFile *var1 = new QFile; |
|
304 |
obj1.setDevice(var1); |
|
305 |
QCOMPARE((QIODevice *)var1, (QIODevice *)obj1.device()); |
|
306 |
obj1.setDevice((QIODevice *)0); |
|
307 |
QCOMPARE((QIODevice *)0, (QIODevice *)obj1.device()); |
|
308 |
delete var1; |
|
309 |
||
310 |
// Status QDataStream::status() |
|
311 |
// void QDataStream::setStatus(Status) |
|
312 |
obj1.setStatus(QDataStream::Ok); |
|
313 |
QCOMPARE(QDataStream::Ok, obj1.status()); |
|
314 |
obj1.setStatus(QDataStream::ReadPastEnd); |
|
315 |
QCOMPARE(QDataStream::ReadPastEnd, obj1.status()); |
|
316 |
obj1.resetStatus(); |
|
317 |
obj1.setStatus(QDataStream::ReadCorruptData); |
|
318 |
QCOMPARE(QDataStream::ReadCorruptData, obj1.status()); |
|
319 |
} |
|
320 |
||
321 |
tst_QDataStream::tst_QDataStream() |
|
322 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
323 |
svgFile = QLatin1String(SRCDIR SVGFILE); |
0 | 324 |
} |
325 |
||
326 |
tst_QDataStream::~tst_QDataStream() |
|
327 |
{ |
|
328 |
QFile::remove(QLatin1String("qdatastream.out")); |
|
329 |
} |
|
330 |
||
331 |
void tst_QDataStream::init() |
|
332 |
{ |
|
333 |
} |
|
334 |
||
335 |
void tst_QDataStream::cleanup() |
|
336 |
{ |
|
337 |
} |
|
338 |
||
339 |
static int dataIndex(const QString &tag) |
|
340 |
{ |
|
341 |
int pos = tag.lastIndexOf("_"); |
|
342 |
if (pos >= 0) { |
|
343 |
int ret = 0; |
|
344 |
QString count = tag.mid(pos + 1); |
|
345 |
bool ok; |
|
346 |
ret = count.toInt(&ok); |
|
347 |
if (ok) |
|
348 |
return ret; |
|
349 |
} |
|
350 |
return -1; |
|
351 |
} |
|
352 |
||
353 |
static const char * const devices[] = { |
|
354 |
"file", |
|
355 |
"bytearray", |
|
356 |
"buffer", |
|
357 |
0 |
|
358 |
}; |
|
359 |
||
360 |
/* |
|
361 |
IMPORTANT. |
|
362 |
In this testcase i follow a different approach than usual: I don't use the full power of |
|
363 |
QtTestTable and QtTestData. This is done deliberately because QtTestData uses a QDataStream |
|
364 |
itself to handle its data. So it would be a bit inapropriate to fully rely on QtTestData in this |
|
365 |
testcase. |
|
366 |
I do use QString in QtTestData because this is thouroughly tested in the selftest. |
|
367 |
*/ |
|
368 |
void tst_QDataStream::stream_data(int noOfElements) |
|
369 |
{ |
|
370 |
QTest::addColumn<QString>("device"); |
|
371 |
QTest::addColumn<QString>("byteOrder"); |
|
372 |
||
373 |
for (int d=0; devices[d] != 0; d++) { |
|
374 |
QString device = devices[d]; |
|
375 |
for (int b=0; b<2; b++) { |
|
376 |
QString byte_order = b == 0 ? "BigEndian" : "LittleEndian"; |
|
377 |
||
378 |
QString tag = device + "_" + byte_order; |
|
379 |
for (int e=0; e<noOfElements; e++) { |
|
380 |
QTest::newRow(qPrintable(tag + QString("_%1").arg(e))) << device << QString(byte_order); |
|
381 |
} |
|
382 |
} |
|
383 |
} |
|
384 |
} |
|
385 |
||
386 |
static const char* open_xpm[]={ |
|
387 |
"16 13 6 1", |
|
388 |
". c None", |
|
389 |
"b c #ffff00", |
|
390 |
"d c #000000", |
|
391 |
"* c #999999", |
|
392 |
"c c #cccccc", |
|
393 |
"a c #ffffff", |
|
394 |
"...*****........", |
|
395 |
"..*aaaaa*.......", |
|
396 |
".*abcbcba******.", |
|
397 |
".*acbcbcaaaaaa*d", |
|
398 |
".*abcbcbcbcbcb*d", |
|
399 |
"*************b*d", |
|
400 |
"*aaaaaaaaaa**c*d", |
|
401 |
"*abcbcbcbcbbd**d", |
|
402 |
".*abcbcbcbcbcd*d", |
|
403 |
".*acbcbcbcbcbd*d", |
|
404 |
"..*acbcbcbcbb*dd", |
|
405 |
"..*************d", |
|
406 |
"...ddddddddddddd"}; |
|
407 |
||
408 |
#define STREAM_IMPL(TYPE) \ |
|
409 |
QFETCH(QString, device); \ |
|
410 |
if (device == "bytearray") { \ |
|
411 |
QByteArray ba; \ |
|
412 |
QDataStream sout(&ba, QIODevice::WriteOnly); \ |
|
413 |
write##TYPE(&sout); \ |
|
414 |
QDataStream sin(&ba, QIODevice::ReadOnly); \ |
|
415 |
read##TYPE(&sin); \ |
|
416 |
} else if (device == "file") { \ |
|
417 |
QString fileName = "qdatastream.out"; \ |
|
418 |
QFile fOut(fileName); \ |
|
419 |
QVERIFY(fOut.open(QIODevice::WriteOnly)); \ |
|
420 |
QDataStream sout(&fOut); \ |
|
421 |
write##TYPE(&sout); \ |
|
422 |
fOut.close(); \ |
|
423 |
QFile fIn(fileName); \ |
|
424 |
QVERIFY(fIn.open(QIODevice::ReadOnly)); \ |
|
425 |
QDataStream sin(&fIn); \ |
|
426 |
read##TYPE(&sin); \ |
|
427 |
fIn.close(); \ |
|
428 |
} else if (device == "buffer") { \ |
|
429 |
QByteArray ba(10000, '\0'); \ |
|
430 |
QBuffer bOut(&ba); \ |
|
431 |
bOut.open(QIODevice::WriteOnly); \ |
|
432 |
QDataStream sout(&bOut); \ |
|
433 |
write##TYPE(&sout); \ |
|
434 |
bOut.close(); \ |
|
435 |
QBuffer bIn(&ba); \ |
|
436 |
bIn.open(QIODevice::ReadOnly); \ |
|
437 |
QDataStream sin(&bIn); \ |
|
438 |
read##TYPE(&sin); \ |
|
439 |
bIn.close(); \ |
|
440 |
} |
|
441 |
||
442 |
// ************************************ |
|
443 |
||
444 |
static QString QStringData(int index) |
|
445 |
{ |
|
446 |
switch (index) |
|
447 |
{ |
|
448 |
case 0: return QString(); |
|
449 |
case 1: return QString(""); |
|
450 |
case 2: return QString("A"); |
|
451 |
case 3: return QString("ABCDE FGHI"); |
|
452 |
case 4: return QString("This is a long string"); |
|
453 |
case 5: return QString("And again a string with a \nCRLF"); |
|
454 |
case 6: return QString("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRESTUVWXYZ 1234567890 ~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/"); |
|
455 |
} |
|
456 |
return QString("foo"); |
|
457 |
} |
|
458 |
#define MAX_QSTRING_DATA 7 |
|
459 |
||
460 |
void tst_QDataStream::stream_QString_data() |
|
461 |
{ |
|
462 |
stream_data(MAX_QSTRING_DATA); |
|
463 |
} |
|
464 |
||
465 |
void tst_QDataStream::stream_QString() |
|
466 |
{ |
|
467 |
STREAM_IMPL(QString); |
|
468 |
} |
|
469 |
||
470 |
void tst_QDataStream::writeQString(QDataStream* s) |
|
471 |
{ |
|
472 |
QString test(QStringData(dataIndex(QTest::currentDataTag()))); |
|
473 |
*s << test; |
|
474 |
*s << QString("Her er det noe tekst"); |
|
475 |
*s << test; |
|
476 |
*s << QString(); |
|
477 |
*s << test; |
|
478 |
*s << QString(""); |
|
479 |
*s << test; |
|
480 |
*s << QString("nonempty"); |
|
481 |
*s << test; |
|
482 |
} |
|
483 |
||
484 |
void tst_QDataStream::readQString(QDataStream *s) |
|
485 |
{ |
|
486 |
QString S; |
|
487 |
QString test(QStringData(dataIndex(QTest::currentDataTag()))); |
|
488 |
||
489 |
*s >> S; |
|
490 |
QCOMPARE(S, test); |
|
491 |
*s >> S; |
|
492 |
QCOMPARE(S, QString("Her er det noe tekst")); |
|
493 |
*s >> S; |
|
494 |
QCOMPARE(S, test); |
|
495 |
*s >> S; |
|
496 |
QVERIFY(S.isNull()); |
|
497 |
*s >> S; |
|
498 |
QCOMPARE(S, test); |
|
499 |
*s >> S; |
|
500 |
QVERIFY(S.isEmpty()); |
|
501 |
*s >> S; |
|
502 |
QCOMPARE(S, test); |
|
503 |
*s >> S; |
|
504 |
QCOMPARE(S, QString("nonempty")); |
|
505 |
*s >> S; |
|
506 |
QCOMPARE(S, test); |
|
507 |
} |
|
508 |
||
509 |
// ************************************ |
|
510 |
||
511 |
static QRegExp QRegExpData(int index) |
|
512 |
{ |
|
513 |
switch (index) |
|
514 |
{ |
|
515 |
case 0: return QRegExp(); |
|
516 |
case 1: return QRegExp(""); |
|
517 |
case 2: return QRegExp("A", Qt::CaseInsensitive); |
|
518 |
case 3: return QRegExp("ABCDE FGHI", Qt::CaseSensitive, QRegExp::Wildcard); |
|
519 |
case 4: return QRegExp("This is a long string", Qt::CaseInsensitive, QRegExp::FixedString); |
|
520 |
case 5: return QRegExp("And again a string with a \nCRLF", Qt::CaseInsensitive, QRegExp::RegExp); |
|
521 |
case 6: { |
|
522 |
QRegExp rx("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRESTUVWXYZ 1234567890 ~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/"); |
|
523 |
rx.setMinimal(true); |
|
524 |
return rx; |
|
525 |
} |
|
526 |
} |
|
527 |
return QRegExp("foo"); |
|
528 |
} |
|
529 |
#define MAX_QREGEXP_DATA 7 |
|
530 |
||
531 |
void tst_QDataStream::stream_QRegExp_data() |
|
532 |
{ |
|
533 |
stream_data(MAX_QREGEXP_DATA); |
|
534 |
} |
|
535 |
||
536 |
void tst_QDataStream::stream_QRegExp() |
|
537 |
{ |
|
538 |
STREAM_IMPL(QRegExp); |
|
539 |
} |
|
540 |
||
541 |
void tst_QDataStream::writeQRegExp(QDataStream* s) |
|
542 |
{ |
|
543 |
QRegExp test(QRegExpData(dataIndex(QTest::currentDataTag()))); |
|
544 |
*s << test; |
|
545 |
*s << QString("Her er det noe tekst"); |
|
546 |
*s << test; |
|
547 |
*s << QString("nonempty"); |
|
548 |
*s << test; |
|
549 |
*s << QVariant(test); |
|
550 |
} |
|
551 |
||
552 |
void tst_QDataStream::readQRegExp(QDataStream *s) |
|
553 |
{ |
|
554 |
QRegExp R; |
|
555 |
QString S; |
|
556 |
QVariant V; |
|
557 |
QRegExp test(QRegExpData(dataIndex(QTest::currentDataTag()))); |
|
558 |
||
559 |
*s >> R; |
|
560 |
QCOMPARE(R, test); |
|
561 |
*s >> S; |
|
562 |
QCOMPARE(S, QString("Her er det noe tekst")); |
|
563 |
*s >> R; |
|
564 |
QCOMPARE(R, test); |
|
565 |
*s >> S; |
|
566 |
QCOMPARE(S, QString("nonempty")); |
|
567 |
*s >> R; |
|
568 |
QCOMPARE(R, test); |
|
569 |
*s >> V; |
|
570 |
QVERIFY(V.type() == QVariant::RegExp); |
|
571 |
QCOMPARE(V.toRegExp(), test); |
|
572 |
} |
|
573 |
||
574 |
// ************************************ |
|
575 |
||
576 |
typedef QMap<int, QString> Map; |
|
577 |
||
578 |
static Map MapData(int index) |
|
579 |
{ |
|
580 |
Map map; |
|
581 |
||
582 |
switch (index) |
|
583 |
{ |
|
584 |
case 0: |
|
585 |
default: |
|
586 |
break; |
|
587 |
case 1: |
|
588 |
map.insert(1, "a"); |
|
589 |
map.insert(2, "bbb"); |
|
590 |
map.insert(3, "cccccc"); |
|
591 |
break; |
|
592 |
case 2: |
|
593 |
map.insert(1, "a"); |
|
594 |
map.insert(2, "one"); |
|
595 |
map.insertMulti(2, "two"); |
|
596 |
map.insertMulti(2, "three"); |
|
597 |
map.insert(3, "cccccc"); |
|
598 |
} |
|
599 |
return map; |
|
600 |
} |
|
601 |
#define MAX_MAP_DATA 3 |
|
602 |
||
603 |
void tst_QDataStream::stream_Map_data() |
|
604 |
{ |
|
605 |
stream_data(MAX_MAP_DATA); |
|
606 |
} |
|
607 |
||
608 |
void tst_QDataStream::stream_Map() |
|
609 |
{ |
|
610 |
STREAM_IMPL(Map); |
|
611 |
} |
|
612 |
||
613 |
void tst_QDataStream::writeMap(QDataStream* s) |
|
614 |
{ |
|
615 |
Map test(MapData(dataIndex(QTest::currentDataTag()))); |
|
616 |
*s << test; |
|
617 |
*s << test; |
|
618 |
} |
|
619 |
||
620 |
void tst_QDataStream::readMap(QDataStream *s) |
|
621 |
{ |
|
622 |
Map S; |
|
623 |
Map test(MapData(dataIndex(QTest::currentDataTag()))); |
|
624 |
||
625 |
*s >> S; |
|
626 |
QCOMPARE(S, test); |
|
627 |
*s >> S; |
|
628 |
QCOMPARE(S, test); |
|
629 |
} |
|
630 |
||
631 |
// ************************************ |
|
632 |
||
633 |
typedef QHash<int, QString> Hash; |
|
634 |
||
635 |
static Hash HashData(int index) |
|
636 |
{ |
|
637 |
Hash map; |
|
638 |
||
639 |
switch (index) |
|
640 |
{ |
|
641 |
case 0: |
|
642 |
default: |
|
643 |
break; |
|
644 |
case 1: |
|
645 |
map.insert(1, "a"); |
|
646 |
map.insert(2, "bbb"); |
|
647 |
map.insert(3, "cccccc"); |
|
648 |
break; |
|
649 |
case 2: |
|
650 |
map.insert(1, "a"); |
|
651 |
map.insert(2, "one"); |
|
652 |
map.insertMulti(2, "two"); |
|
653 |
map.insertMulti(2, "three"); |
|
654 |
map.insert(3, "cccccc"); |
|
655 |
} |
|
656 |
return map; |
|
657 |
} |
|
658 |
#define MAX_HASH_DATA 3 |
|
659 |
||
660 |
void tst_QDataStream::stream_Hash_data() |
|
661 |
{ |
|
662 |
stream_data(MAX_HASH_DATA); |
|
663 |
} |
|
664 |
||
665 |
void tst_QDataStream::stream_Hash() |
|
666 |
{ |
|
667 |
STREAM_IMPL(Hash); |
|
668 |
} |
|
669 |
||
670 |
void tst_QDataStream::writeHash(QDataStream* s) |
|
671 |
{ |
|
672 |
Hash test(HashData(dataIndex(QTest::currentDataTag()))); |
|
673 |
*s << test; |
|
674 |
*s << test; |
|
675 |
} |
|
676 |
||
677 |
void tst_QDataStream::readHash(QDataStream *s) |
|
678 |
{ |
|
679 |
Hash S; |
|
680 |
Hash test(HashData(dataIndex(QTest::currentDataTag()))); |
|
681 |
||
682 |
*s >> S; |
|
683 |
QCOMPARE(S, test); |
|
684 |
*s >> S; |
|
685 |
QCOMPARE(S, test); |
|
686 |
} |
|
687 |
||
688 |
// ************************************ |
|
689 |
||
690 |
// contains some quint64 testing as well |
|
691 |
||
692 |
#define MAX_qint64_DATA 4 |
|
693 |
||
694 |
static qint64 qint64Data(int index) |
|
695 |
{ |
|
696 |
switch (index) { |
|
697 |
case 0: return qint64(0); |
|
698 |
case 1: return qint64(1); |
|
699 |
case 2: return qint64(-1); |
|
700 |
case 3: return qint64(1) << 40; |
|
701 |
case MAX_qint64_DATA: return -(qint64(1) << 40); |
|
702 |
} |
|
703 |
||
704 |
return -1; |
|
705 |
} |
|
706 |
||
707 |
void tst_QDataStream::stream_qint64_data() |
|
708 |
{ |
|
709 |
stream_data(MAX_qint64_DATA+1); |
|
710 |
} |
|
711 |
||
712 |
void tst_QDataStream::stream_qint64() |
|
713 |
{ |
|
714 |
STREAM_IMPL(qint64); |
|
715 |
} |
|
716 |
||
717 |
void tst_QDataStream::writeqint64(QDataStream* s) |
|
718 |
{ |
|
719 |
qint64 test = qint64Data(dataIndex(QTest::currentDataTag())); |
|
720 |
*s << test; |
|
721 |
*s << int(1); |
|
722 |
*s << (quint64)test; |
|
723 |
} |
|
724 |
||
725 |
void tst_QDataStream::readqint64(QDataStream *s) |
|
726 |
{ |
|
727 |
qint64 test = qint64Data(dataIndex(QTest::currentDataTag())); |
|
728 |
qint64 i64; |
|
729 |
quint64 ui64; |
|
730 |
int i; |
|
731 |
*s >> i64; |
|
732 |
QCOMPARE(i64, test); |
|
733 |
*s >> i; |
|
734 |
QCOMPARE(i, int(1)); |
|
735 |
*s >> ui64; |
|
736 |
QCOMPARE(ui64, (quint64)test); |
|
737 |
} |
|
738 |
||
739 |
// ************************************ |
|
740 |
||
741 |
static bool boolData(int index) |
|
742 |
{ |
|
743 |
switch (index) |
|
744 |
{ |
|
745 |
case 0: return true; |
|
746 |
case 1: return false; |
|
747 |
case 2: return bool(2); |
|
748 |
case 3: return bool(-1); |
|
749 |
case 4: return bool(127); |
|
750 |
} |
|
751 |
||
752 |
return false; |
|
753 |
} |
|
754 |
||
755 |
void tst_QDataStream::stream_bool_data() |
|
756 |
{ |
|
757 |
stream_data(5); |
|
758 |
} |
|
759 |
||
760 |
void tst_QDataStream::stream_bool() |
|
761 |
{ |
|
762 |
STREAM_IMPL(bool); |
|
763 |
} |
|
764 |
||
765 |
void tst_QDataStream::writebool(QDataStream *s) |
|
766 |
{ |
|
767 |
bool d1 = boolData(dataIndex(QTest::currentDataTag())); |
|
768 |
*s << d1; |
|
769 |
} |
|
770 |
||
771 |
void tst_QDataStream::readbool(QDataStream *s) |
|
772 |
{ |
|
773 |
bool expected = boolData(dataIndex(QTest::currentDataTag())); |
|
774 |
||
775 |
bool d1; |
|
776 |
*s >> d1; |
|
777 |
QVERIFY(d1 == expected); |
|
778 |
} |
|
779 |
||
780 |
// ************************************ |
|
781 |
||
782 |
static QBool QBoolData(int index) |
|
783 |
{ |
|
784 |
switch (index) |
|
785 |
{ |
|
786 |
case 0: return QBool(true); |
|
787 |
case 1: return QBool(false); |
|
788 |
case 2: return QBool(bool(2)); |
|
789 |
case 3: return QBool(bool(-1)); |
|
790 |
case 4: return QBool(bool(127)); |
|
791 |
} |
|
792 |
||
793 |
return QBool(false); |
|
794 |
} |
|
795 |
||
796 |
void tst_QDataStream::stream_QBool_data() |
|
797 |
{ |
|
798 |
stream_data(5); |
|
799 |
} |
|
800 |
||
801 |
void tst_QDataStream::stream_QBool() |
|
802 |
{ |
|
803 |
STREAM_IMPL(QBool); |
|
804 |
} |
|
805 |
||
806 |
void tst_QDataStream::writeQBool(QDataStream *s) |
|
807 |
{ |
|
808 |
QBool d1 = QBoolData(dataIndex(QTest::currentDataTag())); |
|
809 |
*s << d1; |
|
810 |
} |
|
811 |
||
812 |
void tst_QDataStream::readQBool(QDataStream *s) |
|
813 |
{ |
|
814 |
QBool expected = QBoolData(dataIndex(QTest::currentDataTag())); |
|
815 |
||
816 |
bool d1 = true; |
|
817 |
*s >> d1; |
|
818 |
QVERIFY(d1 == expected); |
|
819 |
} |
|
820 |
||
821 |
void tst_QDataStream::stream_QBool_in_4_0() |
|
822 |
{ |
|
823 |
QByteArray byteArray; |
|
824 |
QDataStream out(&byteArray, QIODevice::WriteOnly); |
|
825 |
||
826 |
QString str("ABC"); |
|
827 |
out << str.contains('A') << str.contains('Z'); |
|
828 |
||
829 |
QCOMPARE(byteArray.size(), 2); |
|
830 |
} |
|
831 |
||
832 |
// ************************************ |
|
833 |
||
834 |
static void QBitArrayData(QBitArray *b, int index) |
|
835 |
{ |
|
836 |
QString filler = ""; |
|
837 |
switch (index) |
|
838 |
{ |
|
839 |
case 0: filler = ""; break; |
|
840 |
case 1: filler = ""; break; |
|
841 |
case 2: filler = "0"; break; |
|
842 |
case 3: filler = "1"; break; |
|
843 |
case 4: filler = "0000"; break; |
|
844 |
case 5: filler = "0001"; break; |
|
845 |
case 6: filler = "0010"; break; |
|
846 |
case 7: filler = "0100"; break; |
|
847 |
case 8: filler = "1000"; break; |
|
848 |
case 9: filler = "1111"; break; |
|
849 |
case 10: filler = "00000000"; break; |
|
850 |
case 11: filler = "00000001"; break; |
|
851 |
case 12: filler = "11111111"; break; |
|
852 |
case 13: filler = "000000001"; break; |
|
853 |
case 14: filler = "000000000001"; break; |
|
854 |
case 15: filler = "0000000000000001"; break; |
|
855 |
case 16: filler = "0101010101010101010101010101010101010101010101010101010101010101"; break; |
|
856 |
case 17: filler = "1010101010101010101010101010101010101010101010101010101010101010"; break; |
|
857 |
case 18: filler = "1111111111111111111111111111111111111111111111111111111111111111"; break; |
|
858 |
} |
|
859 |
||
860 |
b->resize(filler.length()); |
|
861 |
b->fill(0); // reset all bits to zero |
|
862 |
||
863 |
for (int i = 0; i < filler.length(); ++i) { |
|
864 |
if (filler.at(i) == '1') |
|
865 |
b->setBit(i, TRUE); |
|
866 |
} |
|
867 |
} |
|
868 |
||
869 |
void tst_QDataStream::stream_QBitArray_data() |
|
870 |
{ |
|
871 |
stream_data(19); |
|
872 |
} |
|
873 |
||
874 |
void tst_QDataStream::stream_QBitArray() |
|
875 |
{ |
|
876 |
STREAM_IMPL(QBitArray); |
|
877 |
} |
|
878 |
||
879 |
void tst_QDataStream::writeQBitArray(QDataStream *s) |
|
880 |
{ |
|
881 |
QBitArray d1; |
|
882 |
QBitArrayData(&d1, dataIndex(QTest::currentDataTag())); |
|
883 |
*s << d1; |
|
884 |
} |
|
885 |
||
886 |
void tst_QDataStream::readQBitArray(QDataStream *s) |
|
887 |
{ |
|
888 |
QBitArray expected; |
|
889 |
QBitArrayData(&expected, dataIndex(QTest::currentDataTag())); |
|
890 |
||
891 |
QBitArray d1; |
|
892 |
*s >> d1; |
|
893 |
QVERIFY(d1 == expected); |
|
894 |
} |
|
895 |
||
896 |
// ************************************ |
|
897 |
||
898 |
static QBrush qBrushData(int index) |
|
899 |
{ |
|
900 |
switch (index) |
|
901 |
{ |
|
902 |
case 0: return QBrush(Qt::NoBrush); |
|
903 |
case 1: return QBrush(Qt::SolidPattern); |
|
904 |
case 2: return QBrush(Qt::Dense7Pattern); |
|
905 |
case 3: return QBrush(Qt::red, Qt::NoBrush); |
|
906 |
case 4: return QBrush(Qt::green, Qt::SolidPattern); |
|
907 |
case 5: return QBrush(Qt::blue, Qt::Dense7Pattern); |
|
908 |
case 6: { |
|
909 |
QPixmap pm(open_xpm); |
|
910 |
QBrush custom(Qt::black, pm); |
|
911 |
return custom; |
|
912 |
} |
|
913 |
case 7: |
|
914 |
QLinearGradient gradient(QPoint(2.718, 3.142), QPoint(3.1337, 42)); |
|
915 |
gradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
916 |
gradient.setSpread(QGradient::ReflectSpread); |
|
917 |
gradient.setInterpolationMode(QGradient::ComponentInterpolation); |
|
918 |
gradient.setColorAt(0.2, Qt::red); |
|
919 |
gradient.setColorAt(0.6, Qt::transparent); |
|
920 |
gradient.setColorAt(0.8, Qt::blue); |
|
921 |
return QBrush(gradient); |
|
922 |
} |
|
923 |
||
924 |
return QBrush(Qt::NoBrush); |
|
925 |
} |
|
926 |
||
927 |
void tst_QDataStream::stream_QBrush_data() |
|
928 |
{ |
|
929 |
stream_data(8); |
|
930 |
} |
|
931 |
||
932 |
void tst_QDataStream::stream_QBrush() |
|
933 |
{ |
|
934 |
if (QString(QTest::currentDataTag()).endsWith("6")) |
|
935 |
QSKIP("Custom brushes don't seem to be supported with QDataStream", SkipSingle); |
|
936 |
||
937 |
STREAM_IMPL(QBrush); |
|
938 |
} |
|
939 |
||
940 |
void tst_QDataStream::writeQBrush(QDataStream *s) |
|
941 |
{ |
|
942 |
QBrush brush = qBrushData(dataIndex(QTest::currentDataTag())); |
|
943 |
*s << brush; |
|
944 |
} |
|
945 |
||
946 |
void tst_QDataStream::readQBrush(QDataStream *s) |
|
947 |
{ |
|
948 |
QBrush d2; |
|
949 |
*s >> d2; |
|
950 |
||
951 |
QBrush brush = qBrushData(dataIndex(QTest::currentDataTag())); |
|
952 |
QVERIFY(d2 == brush); |
|
953 |
} |
|
954 |
||
955 |
// ************************************ |
|
956 |
||
957 |
static QColor QColorData(int index) |
|
958 |
{ |
|
959 |
switch (index) |
|
960 |
{ |
|
961 |
case 0: return QColor(0,0,0); |
|
962 |
case 1: return QColor(0,0,0); |
|
963 |
case 2: return QColor(0,0,0); |
|
964 |
case 3: return QColor(0,0,0); |
|
965 |
case 4: return QColor(0,0,0); |
|
966 |
case 5: return QColor(0,0,0); |
|
967 |
case 6: return QColor(0,0,0); |
|
968 |
case 7: return QColor(0,0,0); |
|
969 |
} |
|
970 |
||
971 |
return QColor(0,0,0); |
|
972 |
} |
|
973 |
||
974 |
void tst_QDataStream::stream_QColor_data() |
|
975 |
{ |
|
976 |
stream_data(8); |
|
977 |
} |
|
978 |
||
979 |
void tst_QDataStream::stream_QColor() |
|
980 |
{ |
|
981 |
STREAM_IMPL(QColor); |
|
982 |
} |
|
983 |
||
984 |
void tst_QDataStream::writeQColor(QDataStream *s) |
|
985 |
{ |
|
986 |
QColor d3(QColorData(dataIndex(QTest::currentDataTag()))); |
|
987 |
*s << d3; |
|
988 |
} |
|
989 |
||
990 |
void tst_QDataStream::readQColor(QDataStream *s) |
|
991 |
{ |
|
992 |
QColor test(QColorData(dataIndex(QTest::currentDataTag()))); |
|
993 |
QColor d3; |
|
994 |
*s >> d3; |
|
995 |
QVERIFY(d3 == test); |
|
996 |
} |
|
997 |
||
998 |
||
999 |
// ************************************ |
|
1000 |
||
1001 |
static QByteArray qByteArrayData(int index) |
|
1002 |
{ |
|
1003 |
switch (index) |
|
1004 |
{ |
|
1005 |
case 0: return QByteArray(); |
|
1006 |
case 1: return QByteArray(""); |
|
1007 |
case 2: return QByteArray("foo"); |
|
1008 |
case 3: return QByteArray("foo bar"); |
|
1009 |
case 4: return QByteArray("two\nlines"); |
|
1010 |
case 5: return QByteArray("ABCDEFG"); |
|
1011 |
case 6: return QByteArray("baec zxv 123"); // kept for nostalgic reasons |
|
1012 |
case 7: return QByteArray("jbc;UBC;jd clhdbcahd vcbd vgdv dhvb laifv kadf jkhfbvljd khd lhvjh "); |
|
1013 |
} |
|
1014 |
||
1015 |
return QByteArray("foo"); |
|
1016 |
} |
|
1017 |
||
1018 |
void tst_QDataStream::stream_QByteArray_data() |
|
1019 |
{ |
|
1020 |
stream_data(8); |
|
1021 |
} |
|
1022 |
||
1023 |
void tst_QDataStream::stream_QByteArray() |
|
1024 |
{ |
|
1025 |
STREAM_IMPL(QByteArray); |
|
1026 |
} |
|
1027 |
||
1028 |
void tst_QDataStream::writeQByteArray(QDataStream *s) |
|
1029 |
{ |
|
1030 |
QByteArray d4(qByteArrayData(dataIndex(QTest::currentDataTag()))); |
|
1031 |
*s << d4; |
|
1032 |
} |
|
1033 |
||
1034 |
void tst_QDataStream::readQByteArray(QDataStream *s) |
|
1035 |
{ |
|
1036 |
QByteArray test(qByteArrayData(dataIndex(QTest::currentDataTag()))); |
|
1037 |
QByteArray d4; |
|
1038 |
*s >> d4; |
|
1039 |
QCOMPARE(d4, test); |
|
1040 |
} |
|
1041 |
||
1042 |
// ************************************ |
|
1043 |
#ifndef QT_NO_CURSOR |
|
1044 |
static QCursor qCursorData(int index) |
|
1045 |
{ |
|
1046 |
switch (index) |
|
1047 |
{ |
|
1048 |
#ifdef QT3_SUPPORT |
|
1049 |
case 0: return QCursor(Qt::arrowCursor); |
|
1050 |
case 1: return QCursor(Qt::waitCursor); |
|
1051 |
#else |
|
1052 |
case 0: return QCursor(Qt::ArrowCursor); |
|
1053 |
case 1: return QCursor(Qt::WaitCursor); |
|
1054 |
#endif |
|
1055 |
case 2: return QCursor(Qt::BitmapCursor); |
|
1056 |
case 3: return QCursor(Qt::BlankCursor); |
|
1057 |
case 4: return QCursor(Qt::BlankCursor); |
|
1058 |
case 5: return QCursor(QPixmap(open_xpm), 1, 1); |
|
1059 |
case 6: { QPixmap pm(open_xpm); return QCursor(QBitmap(pm), pm.mask(), 3, 4); } |
|
1060 |
case 7: return QCursor(QPixmap(open_xpm), -1, 5); |
|
1061 |
case 8: return QCursor(QPixmap(open_xpm), 5, -1); |
|
1062 |
} |
|
1063 |
||
1064 |
return QCursor(); |
|
1065 |
} |
|
1066 |
#endif |
|
1067 |
||
1068 |
void tst_QDataStream::stream_QCursor_data() |
|
1069 |
{ |
|
1070 |
#ifndef QT_NO_CURSOR |
|
1071 |
stream_data(9); |
|
1072 |
#endif |
|
1073 |
} |
|
1074 |
||
1075 |
void tst_QDataStream::stream_QCursor() |
|
1076 |
{ |
|
1077 |
#ifndef QT_NO_CURSOR |
|
1078 |
STREAM_IMPL(QCursor); |
|
1079 |
#endif |
|
1080 |
} |
|
1081 |
||
1082 |
void tst_QDataStream::writeQCursor(QDataStream *s) |
|
1083 |
{ |
|
1084 |
#ifndef QT_NO_CURSOR |
|
1085 |
QCursor d5(qCursorData(dataIndex(QTest::currentDataTag()))); |
|
1086 |
*s << d5; |
|
1087 |
#endif |
|
1088 |
} |
|
1089 |
||
1090 |
void tst_QDataStream::readQCursor(QDataStream *s) |
|
1091 |
{ |
|
1092 |
#ifndef QT_NO_CURSOR |
|
1093 |
QCursor test(qCursorData(dataIndex(QTest::currentDataTag()))); |
|
1094 |
QCursor d5; |
|
1095 |
*s >> d5; |
|
1096 |
||
1097 |
QVERIFY(d5.shape() == test.shape()); //## lacks operator== |
|
1098 |
QVERIFY(d5.hotSpot() == test.hotSpot()); |
|
1099 |
QVERIFY((d5.bitmap() != 0 && test.bitmap() != 0) || (d5.bitmap() == 0 && test.bitmap() == 0)); |
|
1100 |
if (d5.bitmap() != 0) |
|
1101 |
QVERIFY(pixmapsAreEqual(d5.bitmap(), test.bitmap())); |
|
1102 |
QVERIFY((d5.mask() != 0 && test.mask() != 0) || (d5.mask() == 0 && test.mask() == 0)); |
|
1103 |
if (d5.mask() != 0) |
|
1104 |
QVERIFY(pixmapsAreEqual(d5.mask(), test.mask())); |
|
1105 |
#endif |
|
1106 |
} |
|
1107 |
||
1108 |
// ************************************ |
|
1109 |
||
1110 |
static QDate qDateData(int index) |
|
1111 |
{ |
|
1112 |
switch (index) |
|
1113 |
{ |
|
1114 |
case 0: return QDate(1752, 9, 14); // the first valid date |
|
1115 |
case 1: return QDate(1900, 1, 1); |
|
1116 |
case 2: return QDate(1976, 4, 5); |
|
1117 |
case 3: return QDate(1960, 5, 27); |
|
1118 |
case 4: return QDate(1999, 12, 31); // w2k effects? |
|
1119 |
case 5: return QDate(2000, 1, 1); |
|
1120 |
case 6: return QDate(2050, 1, 1);// test some values far in the future too |
|
1121 |
case 7: return QDate(3001, 12, 31); |
|
1122 |
case 8: return QDate(4002, 1, 1); |
|
1123 |
case 9: return QDate(4003, 12, 31); |
|
1124 |
case 10: return QDate(5004, 1, 1); |
|
1125 |
case 11: return QDate(5005, 12, 31); |
|
1126 |
case 12: return QDate(6006, 1, 1); |
|
1127 |
case 13: return QDate(6007, 12, 31); |
|
1128 |
case 14: return QDate(7008, 1, 1); |
|
1129 |
case 15: return QDate(7009, 12, 31); |
|
1130 |
} |
|
1131 |
return QDate(); |
|
1132 |
} |
|
1133 |
#define MAX_QDATE_DATA 16 |
|
1134 |
||
1135 |
void tst_QDataStream::stream_QDate_data() |
|
1136 |
{ |
|
1137 |
stream_data(MAX_QDATE_DATA); |
|
1138 |
} |
|
1139 |
||
1140 |
void tst_QDataStream::stream_QDate() |
|
1141 |
{ |
|
1142 |
STREAM_IMPL(QDate); |
|
1143 |
} |
|
1144 |
||
1145 |
void tst_QDataStream::writeQDate(QDataStream *s) |
|
1146 |
{ |
|
1147 |
QDate d6(qDateData(dataIndex(QTest::currentDataTag()))); |
|
1148 |
*s << d6; |
|
1149 |
} |
|
1150 |
||
1151 |
void tst_QDataStream::readQDate(QDataStream *s) |
|
1152 |
{ |
|
1153 |
QDate test(qDateData(dataIndex(QTest::currentDataTag()))); |
|
1154 |
QDate d6; |
|
1155 |
*s >> d6; |
|
1156 |
QVERIFY(d6 == test); |
|
1157 |
} |
|
1158 |
||
1159 |
// ************************************ |
|
1160 |
||
1161 |
static QTime qTimeData(int index) |
|
1162 |
{ |
|
1163 |
switch (index) |
|
1164 |
{ |
|
1165 |
case 0 : return QTime(0, 0, 0, 0); |
|
1166 |
case 1 : return QTime(0, 0, 0, 1); |
|
1167 |
case 2 : return QTime(0, 0, 0, 99); |
|
1168 |
case 3 : return QTime(0, 0, 0, 100); |
|
1169 |
case 4 : return QTime(0, 0, 0, 999); |
|
1170 |
case 5 : return QTime(0, 0, 1, 0); |
|
1171 |
case 6 : return QTime(0, 0, 1, 1); |
|
1172 |
case 7 : return QTime(0, 0, 1, 99); |
|
1173 |
case 8 : return QTime(0, 0, 1, 100); |
|
1174 |
case 9 : return QTime(0, 0, 1, 999); |
|
1175 |
case 10: return QTime(0, 0, 59, 0); |
|
1176 |
case 11: return QTime(0, 0, 59, 1); |
|
1177 |
case 12: return QTime(0, 0, 59, 99); |
|
1178 |
case 13: return QTime(0, 0, 59, 100); |
|
1179 |
case 14: return QTime(0, 0, 59, 999); |
|
1180 |
case 15: return QTime(0, 59, 0, 0); |
|
1181 |
case 16: return QTime(0, 59, 0, 1); |
|
1182 |
case 17: return QTime(0, 59, 0, 99); |
|
1183 |
case 18: return QTime(0, 59, 0, 100); |
|
1184 |
case 19: return QTime(0, 59, 0, 999); |
|
1185 |
case 20: return QTime(0, 59, 1, 0); |
|
1186 |
case 21: return QTime(0, 59, 1, 1); |
|
1187 |
case 22: return QTime(0, 59, 1, 99); |
|
1188 |
case 23: return QTime(0, 59, 1, 100); |
|
1189 |
case 24: return QTime(0, 59, 1, 999); |
|
1190 |
case 25: return QTime(0, 59, 59, 0); |
|
1191 |
case 26: return QTime(0, 59, 59, 1); |
|
1192 |
case 27: return QTime(0, 59, 59, 99); |
|
1193 |
case 28: return QTime(0, 59, 59, 100); |
|
1194 |
case 29: return QTime(0, 59, 59, 999); |
|
1195 |
case 30: return QTime(23, 0, 0, 0); |
|
1196 |
case 31: return QTime(23, 0, 0, 1); |
|
1197 |
case 32: return QTime(23, 0, 0, 99); |
|
1198 |
case 33: return QTime(23, 0, 0, 100); |
|
1199 |
case 34: return QTime(23, 0, 0, 999); |
|
1200 |
case 35: return QTime(23, 0, 1, 0); |
|
1201 |
case 36: return QTime(23, 0, 1, 1); |
|
1202 |
case 37: return QTime(23, 0, 1, 99); |
|
1203 |
case 38: return QTime(23, 0, 1, 100); |
|
1204 |
case 39: return QTime(23, 0, 1, 999); |
|
1205 |
case 40: return QTime(23, 0, 59, 0); |
|
1206 |
case 41: return QTime(23, 0, 59, 1); |
|
1207 |
case 42: return QTime(23, 0, 59, 99); |
|
1208 |
case 43: return QTime(23, 0, 59, 100); |
|
1209 |
case 44: return QTime(23, 0, 59, 999); |
|
1210 |
case 45: return QTime(23, 59, 0, 0); |
|
1211 |
case 46: return QTime(23, 59, 0, 1); |
|
1212 |
case 47: return QTime(23, 59, 0, 99); |
|
1213 |
case 48: return QTime(23, 59, 0, 100); |
|
1214 |
case 49: return QTime(23, 59, 0, 999); |
|
1215 |
case 50: return QTime(23, 59, 1, 0); |
|
1216 |
case 51: return QTime(23, 59, 1, 1); |
|
1217 |
case 52: return QTime(23, 59, 1, 99); |
|
1218 |
case 53: return QTime(23, 59, 1, 100); |
|
1219 |
case 54: return QTime(23, 59, 1, 999); |
|
1220 |
case 55: return QTime(23, 59, 59, 0); |
|
1221 |
case 56: return QTime(23, 59, 59, 1); |
|
1222 |
case 57: return QTime(23, 59, 59, 99); |
|
1223 |
case 58: return QTime(23, 59, 59, 100); |
|
1224 |
case 59: return QTime(23, 59, 59, 999); |
|
1225 |
} |
|
1226 |
return QTime(0, 0, 0); |
|
1227 |
} |
|
1228 |
#define MAX_QTIME_DATA 60 |
|
1229 |
||
1230 |
void tst_QDataStream::stream_QTime_data() |
|
1231 |
{ |
|
1232 |
stream_data(MAX_QTIME_DATA); |
|
1233 |
} |
|
1234 |
||
1235 |
void tst_QDataStream::stream_QTime() |
|
1236 |
{ |
|
1237 |
STREAM_IMPL(QTime); |
|
1238 |
} |
|
1239 |
||
1240 |
void tst_QDataStream::writeQTime(QDataStream *s) |
|
1241 |
{ |
|
1242 |
QTime d7 = qTimeData(dataIndex(QTest::currentDataTag())); |
|
1243 |
*s << d7; |
|
1244 |
} |
|
1245 |
||
1246 |
void tst_QDataStream::readQTime(QDataStream *s) |
|
1247 |
{ |
|
1248 |
QTime test = qTimeData(dataIndex(QTest::currentDataTag())); |
|
1249 |
QTime d7; |
|
1250 |
*s >> d7; |
|
1251 |
QVERIFY(d7 == test); |
|
1252 |
} |
|
1253 |
||
1254 |
// ************************************ |
|
1255 |
||
1256 |
static QDateTime qDateTimeData(int index) |
|
1257 |
{ |
|
1258 |
switch (index) |
|
1259 |
{ |
|
1260 |
case 0: return QDateTime(QDate(1900, 1, 1), QTime(0,0,0,0)); |
|
1261 |
case 1: return QDateTime(QDate(1900, 1, 2), QTime(1,1,1,1)); |
|
1262 |
case 2: return QDateTime(QDate(1900, 1, 3), QTime(12,0,0,0)); |
|
1263 |
case 3: return QDateTime(QDate(1900, 1, 4), QTime(23,59,59,999)); |
|
1264 |
case 4: return QDateTime(QDate(1999, 1, 1), QTime(0,0,0,0)); |
|
1265 |
case 5: return QDateTime(QDate(1999, 1, 2), QTime(1,1,1,1)); |
|
1266 |
case 6: return QDateTime(QDate(1999, 1, 3), QTime(12,0,0,0)); |
|
1267 |
case 7: return QDateTime(QDate(1999, 1, 4), QTime(23,59,59,999)); |
|
1268 |
case 8: return QDateTime(QDate(2000, 1, 1), QTime(0,0,0,0)); |
|
1269 |
case 9: return QDateTime(QDate(2000, 1, 2), QTime(1,1,1,1)); |
|
1270 |
case 10: return QDateTime(QDate(2000, 1, 3), QTime(12,0,0,0)); |
|
1271 |
case 11: return QDateTime(QDate(2000, 1, 4), QTime(23,59,59,999)); |
|
1272 |
case 12: return QDateTime(QDate(2000, 12, 31), QTime(0,0,0,0)); |
|
1273 |
case 13: return QDateTime(QDate(2000, 12, 31), QTime(1,1,1,1)); |
|
1274 |
case 14: return QDateTime(QDate(2000, 12, 31), QTime(12,0,0,0)); |
|
1275 |
case 15: return QDateTime(QDate(2000, 12, 31), QTime(23,59,59,999)); |
|
1276 |
} |
|
1277 |
return QDateTime(QDate(1900, 1, 1), QTime(0,0,0)); |
|
1278 |
} |
|
1279 |
#define MAX_QDATETIME_DATA 16 |
|
1280 |
||
1281 |
void tst_QDataStream::stream_QDateTime_data() |
|
1282 |
{ |
|
1283 |
stream_data(MAX_QDATETIME_DATA); |
|
1284 |
} |
|
1285 |
||
1286 |
void tst_QDataStream::stream_QDateTime() |
|
1287 |
{ |
|
1288 |
STREAM_IMPL(QDateTime); |
|
1289 |
} |
|
1290 |
||
1291 |
void tst_QDataStream::writeQDateTime(QDataStream *s) |
|
1292 |
{ |
|
1293 |
QDateTime dt(qDateTimeData(dataIndex(QTest::currentDataTag()))); |
|
1294 |
*s << dt; |
|
1295 |
} |
|
1296 |
||
1297 |
void tst_QDataStream::readQDateTime(QDataStream *s) |
|
1298 |
{ |
|
1299 |
QDateTime test(qDateTimeData(dataIndex(QTest::currentDataTag()))); |
|
1300 |
QDateTime d8; |
|
1301 |
*s >> d8; |
|
1302 |
QVERIFY(d8 == test); |
|
1303 |
} |
|
1304 |
||
1305 |
// ************************************ |
|
1306 |
||
1307 |
static QFont qFontData(int index) |
|
1308 |
{ |
|
1309 |
switch (index) |
|
1310 |
{ |
|
1311 |
case 0: return QFont("Courier", 20, QFont::Bold, TRUE); |
|
1312 |
case 1: return QFont("Courier", 18, QFont::Bold, FALSE); |
|
1313 |
case 2: return QFont("Courier", 16, QFont::Light, TRUE); |
|
1314 |
case 3: return QFont("Courier", 14, QFont::Normal, FALSE); |
|
1315 |
case 4: return QFont("Courier", 12, QFont::DemiBold, TRUE); |
|
1316 |
case 5: return QFont("Courier", 10, QFont::Black, FALSE); |
|
1317 |
case 6: |
|
1318 |
{ |
|
1319 |
QFont f("Helvetica", 10, QFont::Normal, FALSE); |
|
1320 |
f.setPixelSize(2); |
|
1321 |
f.setUnderline(FALSE); |
|
1322 |
f.setStrikeOut(FALSE); |
|
1323 |
f.setFixedPitch(FALSE); |
|
1324 |
return f; |
|
1325 |
} |
|
1326 |
case 7: |
|
1327 |
{ |
|
1328 |
QFont f("Helvetica", 10, QFont::Bold, FALSE); |
|
1329 |
f.setPixelSize(4); |
|
1330 |
f.setUnderline(TRUE); |
|
1331 |
f.setStrikeOut(FALSE); |
|
1332 |
f.setFixedPitch(FALSE); |
|
1333 |
return f; |
|
1334 |
} |
|
1335 |
case 8: |
|
1336 |
{ |
|
1337 |
QFont f("Helvetica", 10, QFont::Light, FALSE); |
|
1338 |
f.setPixelSize(6); |
|
1339 |
f.setUnderline(FALSE); |
|
1340 |
f.setStrikeOut(TRUE); |
|
1341 |
f.setFixedPitch(FALSE); |
|
1342 |
return f; |
|
1343 |
} |
|
1344 |
case 9: |
|
1345 |
{ |
|
1346 |
QFont f("Helvetica", 10, QFont::DemiBold, FALSE); |
|
1347 |
f.setPixelSize(8); |
|
1348 |
f.setUnderline(FALSE); |
|
1349 |
f.setStrikeOut(FALSE); |
|
1350 |
f.setFixedPitch(TRUE); |
|
1351 |
return f; |
|
1352 |
} |
|
1353 |
case 10: |
|
1354 |
{ |
|
1355 |
QFont f("Helvetica", 10, QFont::Black, FALSE); |
|
1356 |
f.setPixelSize(10); |
|
1357 |
f.setUnderline(TRUE); |
|
1358 |
f.setStrikeOut(TRUE); |
|
1359 |
f.setFixedPitch(FALSE); |
|
1360 |
return f; |
|
1361 |
} |
|
1362 |
case 11: |
|
1363 |
{ |
|
1364 |
QFont f("Helvetica", 10, QFont::Normal, TRUE); |
|
1365 |
f.setPixelSize(12); |
|
1366 |
f.setUnderline(FALSE); |
|
1367 |
f.setStrikeOut(TRUE); |
|
1368 |
f.setFixedPitch(TRUE); |
|
1369 |
return f; |
|
1370 |
} |
|
1371 |
case 12: |
|
1372 |
{ |
|
1373 |
QFont f("Helvetica", 10, QFont::Bold, TRUE); |
|
1374 |
f.setPixelSize(14); |
|
1375 |
f.setUnderline(TRUE); |
|
1376 |
f.setStrikeOut(TRUE); |
|
1377 |
f.setFixedPitch(TRUE); |
|
1378 |
return f; |
|
1379 |
} |
|
1380 |
case 13: |
|
1381 |
{ |
|
1382 |
QFont f("Helvetica", 10, QFont::Bold, TRUE); |
|
1383 |
f.setStretch(200); |
|
1384 |
return f; |
|
1385 |
} |
|
1386 |
} |
|
1387 |
return QFont("Courier", 18, QFont::Bold, TRUE); |
|
1388 |
} |
|
1389 |
#define MAX_QFONT_DATA 14 |
|
1390 |
||
1391 |
void tst_QDataStream::stream_QFont_data() |
|
1392 |
{ |
|
1393 |
stream_data(MAX_QFONT_DATA); |
|
1394 |
} |
|
1395 |
||
1396 |
void tst_QDataStream::stream_QFont() |
|
1397 |
{ |
|
1398 |
STREAM_IMPL(QFont); |
|
1399 |
} |
|
1400 |
||
1401 |
void tst_QDataStream::writeQFont(QDataStream *s) |
|
1402 |
{ |
|
1403 |
QFont d9(qFontData(dataIndex(QTest::currentDataTag()))); |
|
1404 |
*s << d9; |
|
1405 |
} |
|
1406 |
||
1407 |
void tst_QDataStream::readQFont(QDataStream *s) |
|
1408 |
{ |
|
1409 |
QFont test(qFontData(dataIndex(QTest::currentDataTag()))); |
|
1410 |
QFont d9; |
|
1411 |
*s >> d9; |
|
1412 |
||
1413 |
// maybe a bit overkill ... |
|
1414 |
QCOMPARE(d9.family(), test.family()); |
|
1415 |
QCOMPARE(d9.pointSize(), test.pointSize()); |
|
1416 |
QCOMPARE(d9.pixelSize(), test.pixelSize()); |
|
1417 |
QCOMPARE(d9.weight(), test.weight()); |
|
1418 |
QCOMPARE(d9.bold(), test.bold()); |
|
1419 |
QCOMPARE(d9.italic(), test.italic()); |
|
1420 |
QCOMPARE(d9.underline(), test.underline()); |
|
1421 |
QCOMPARE(d9.overline(), test.overline()); |
|
1422 |
QCOMPARE(d9.strikeOut(), test.strikeOut()); |
|
1423 |
QCOMPARE(d9.fixedPitch(), test.fixedPitch()); |
|
1424 |
QCOMPARE(d9.styleHint(), test.styleHint()); |
|
1425 |
QCOMPARE(d9.toString(), test.toString()); |
|
1426 |
||
1427 |
QCOMPARE(d9, test); |
|
1428 |
} |
|
1429 |
||
1430 |
// ************************************ |
|
1431 |
||
1432 |
void tst_QDataStream::stream_QImage_data() |
|
1433 |
{ |
|
1434 |
stream_data(1); |
|
1435 |
} |
|
1436 |
||
1437 |
void tst_QDataStream::stream_QImage() |
|
1438 |
{ |
|
1439 |
STREAM_IMPL(QImage); |
|
1440 |
} |
|
1441 |
||
1442 |
void tst_QDataStream::writeQImage(QDataStream *s) |
|
1443 |
{ |
|
1444 |
QImage d12(open_xpm); |
|
1445 |
//debug("Orig alpha: %i", (int)d12.hasAlphaBuffer()); |
|
1446 |
*s << d12; |
|
1447 |
} |
|
1448 |
||
1449 |
void tst_QDataStream::readQImage(QDataStream *s) |
|
1450 |
{ |
|
1451 |
QImage ref(open_xpm); |
|
1452 |
||
1453 |
QImage d12; |
|
1454 |
*s >> d12; |
|
1455 |
QVERIFY(d12 == ref); |
|
1456 |
||
1457 |
// do some extra neurotic tests |
|
1458 |
QVERIFY(d12.size() == ref.size()); |
|
1459 |
QVERIFY(d12.isNull() == ref.isNull()); |
|
1460 |
QVERIFY(d12.width() == ref.width()); |
|
1461 |
QVERIFY(d12.height() == ref.height()); |
|
1462 |
QVERIFY(d12.depth() == ref.depth()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1463 |
QVERIFY(d12.colorCount() == ref.colorCount()); |
0 | 1464 |
#ifdef QT3_SUPPORT |
1465 |
QVERIFY(d12.hasAlphaBuffer() == ref.hasAlphaBuffer()); |
|
1466 |
#else |
|
1467 |
QVERIFY(d12.hasAlphaChannel() == ref.hasAlphaChannel()); |
|
1468 |
#endif |
|
1469 |
||
1470 |
// qDebug("Alpha: %i %i", (int)d12.hasAlphaBuffer(), ref.hasAlphaBuffer()); |
|
1471 |
// qDebug("Feil %i %i: %x != %x", 3, 0, d12.pixel(3, 0), ref.pixel(3, 0)); |
|
1472 |
// |
|
1473 |
// ################ Bug : ref and orig has ff in alpha; readback has 0 |
|
1474 |
// ### (Was like this in 1.44 as well) |
|
1475 |
// |
|
1476 |
// for(int i = 0; i < d12.height(); i++) |
|
1477 |
// for(int j = 0; j < d12.width(); j++) |
|
1478 |
// if (d12.pixel(j, i) != ref.pixel(j, i)) |
|
1479 |
// qDebug("Feil %i %i", j, i); |
|
1480 |
// |
|
1481 |
} |
|
1482 |
||
1483 |
// ************************************ |
|
1484 |
#ifdef QT3_SUPPORT |
|
1485 |
static QPalette qPaletteData(int index) |
|
1486 |
{ |
|
1487 |
QColorGroup g1( |
|
1488 |
QBrush(Qt::red, Qt::SolidPattern), |
|
1489 |
QBrush(Qt::blue, Qt::Dense1Pattern), |
|
1490 |
QBrush(Qt::green, Qt::Dense2Pattern), |
|
1491 |
QBrush(Qt::blue, Qt::Dense3Pattern), |
|
1492 |
QBrush(Qt::cyan, Qt::Dense4Pattern), |
|
1493 |
QBrush(Qt::magenta, Qt::Dense5Pattern), |
|
1494 |
QBrush(Qt::black, Qt::Dense6Pattern), |
|
1495 |
QBrush(Qt::darkGray, Qt::Dense7Pattern), |
|
1496 |
QBrush(Qt::gray, Qt::CrossPattern)); |
|
1497 |
QColorGroup g2( |
|
1498 |
QBrush(Qt::cyan, Qt::Dense3Pattern), |
|
1499 |
QBrush(Qt::blue, Qt::Dense4Pattern), |
|
1500 |
QBrush(Qt::magenta, Qt::Dense5Pattern), |
|
1501 |
QBrush(Qt::black, Qt::Dense6Pattern), |
|
1502 |
QBrush(Qt::darkGray, Qt::Dense7Pattern), |
|
1503 |
QBrush(Qt::gray, Qt::CrossPattern), |
|
1504 |
QBrush(Qt::green, Qt::SolidPattern), |
|
1505 |
QBrush(Qt::blue, Qt::Dense1Pattern), |
|
1506 |
QBrush(Qt::red, Qt::Dense2Pattern)); |
|
1507 |
QColorGroup g3( |
|
1508 |
QBrush(Qt::black, Qt::Dense6Pattern), |
|
1509 |
QBrush(Qt::darkGray, Qt::Dense7Pattern), |
|
1510 |
QBrush(Qt::red, Qt::CrossPattern), |
|
1511 |
QBrush(Qt::gray, Qt::SolidPattern), |
|
1512 |
QBrush(Qt::blue, Qt::Dense1Pattern), |
|
1513 |
QBrush(Qt::cyan, Qt::Dense2Pattern), |
|
1514 |
QBrush(Qt::magenta, Qt::Dense3Pattern), |
|
1515 |
QBrush(Qt::blue, Qt::Dense4Pattern), |
|
1516 |
QBrush(Qt::magenta, Qt::Dense5Pattern)); |
|
1517 |
||
1518 |
switch (index) |
|
1519 |
{ |
|
1520 |
case 0: return QPalette(Qt::green); |
|
1521 |
case 1: return QPalette(Qt::cyan, Qt::blue); |
|
1522 |
case 2: return QPalette(Qt::red, Qt::yellow); |
|
1523 |
case 3: return QPalette(g1, g2, g3); |
|
1524 |
case 4: return QPalette(g2, g3, g1); |
|
1525 |
case 5: return QPalette(g3, g1, g2); |
|
1526 |
case 6: return QPalette(g3, g2, g1); |
|
1527 |
} |
|
1528 |
return QPalette(Qt::black); |
|
1529 |
} |
|
1530 |
#endif |
|
1531 |
#define MAX_QPALETTE_DATA 7 |
|
1532 |
||
1533 |
void tst_QDataStream::stream_QPalette_data() |
|
1534 |
{ |
|
1535 |
stream_data(MAX_QPALETTE_DATA); |
|
1536 |
} |
|
1537 |
||
1538 |
void tst_QDataStream::stream_QPalette() |
|
1539 |
{ |
|
1540 |
STREAM_IMPL(QPalette); |
|
1541 |
} |
|
1542 |
||
1543 |
void tst_QDataStream::writeQPalette(QDataStream *s) |
|
1544 |
{ |
|
1545 |
#ifdef QT3_SUPPORT |
|
1546 |
QPalette d13(qPaletteData(dataIndex(QTest::currentDataTag()))); |
|
1547 |
*s << d13; |
|
1548 |
#else |
|
1549 |
QSKIP("No Qt3 Support", SkipAll); |
|
1550 |
#endif |
|
1551 |
} |
|
1552 |
||
1553 |
void tst_QDataStream::readQPalette(QDataStream *s) |
|
1554 |
{ |
|
1555 |
#ifdef QT3_SUPPORT |
|
1556 |
QPalette test(qPaletteData(dataIndex(QTest::currentDataTag()))); |
|
1557 |
QPalette d13; |
|
1558 |
*s >> d13; |
|
1559 |
QVERIFY(d13 == test); |
|
1560 |
QVERIFY(d13.active() == test.active()); |
|
1561 |
QVERIFY(d13.inactive() == test.inactive()); |
|
1562 |
QVERIFY(d13.disabled() == test.disabled()); |
|
1563 |
#else |
|
1564 |
QSKIP("No Qt3 Support", SkipAll); |
|
1565 |
#endif |
|
1566 |
} |
|
1567 |
||
1568 |
// ************************************ |
|
1569 |
#ifdef QT3_SUPPORT |
|
1570 |
static QColorGroup QColorGroupData(int index) |
|
1571 |
{ |
|
1572 |
switch (index) |
|
1573 |
{ |
|
1574 |
case 0: return QColorGroup( |
|
1575 |
QBrush(Qt::red, Qt::SolidPattern), |
|
1576 |
QBrush(Qt::blue, Qt::Dense1Pattern), |
|
1577 |
QBrush(Qt::green, Qt::Dense2Pattern), |
|
1578 |
QBrush(Qt::blue, Qt::Dense3Pattern), |
|
1579 |
QBrush(Qt::cyan, Qt::Dense4Pattern), |
|
1580 |
QBrush(Qt::magenta, Qt::Dense5Pattern), |
|
1581 |
QBrush(Qt::black, Qt::Dense6Pattern), |
|
1582 |
QBrush(Qt::darkGray, Qt::Dense7Pattern), |
|
1583 |
QBrush(Qt::gray, Qt::CrossPattern)); |
|
1584 |
case 1: return QColorGroup( |
|
1585 |
QBrush(Qt::cyan, Qt::Dense3Pattern), |
|
1586 |
QBrush(Qt::blue, Qt::Dense4Pattern), |
|
1587 |
QBrush(Qt::magenta, Qt::Dense5Pattern), |
|
1588 |
QBrush(Qt::black, Qt::Dense6Pattern), |
|
1589 |
QBrush(Qt::darkGray, Qt::Dense7Pattern), |
|
1590 |
QBrush(Qt::gray, Qt::CrossPattern), |
|
1591 |
QBrush(Qt::green, Qt::SolidPattern), |
|
1592 |
QBrush(Qt::blue, Qt::Dense1Pattern), |
|
1593 |
QBrush(Qt::red, Qt::Dense2Pattern)); |
|
1594 |
case 2: return QColorGroup( |
|
1595 |
QBrush(Qt::black, Qt::Dense6Pattern), |
|
1596 |
QBrush(Qt::darkGray, Qt::Dense7Pattern), |
|
1597 |
QBrush(Qt::red, Qt::CrossPattern), |
|
1598 |
QBrush(Qt::gray, Qt::SolidPattern), |
|
1599 |
QBrush(Qt::blue, Qt::Dense1Pattern), |
|
1600 |
QBrush(Qt::cyan, Qt::Dense2Pattern), |
|
1601 |
QBrush(Qt::magenta, Qt::Dense3Pattern), |
|
1602 |
QBrush(Qt::blue, Qt::Dense4Pattern), |
|
1603 |
QBrush(Qt::magenta, Qt::Dense5Pattern)); |
|
1604 |
} |
|
1605 |
return QColorGroup(); |
|
1606 |
} |
|
1607 |
#endif |
|
1608 |
||
1609 |
#define MAX_QCOLORGROUP_DATA 3 |
|
1610 |
||
1611 |
void tst_QDataStream::stream_QColorGroup_data() |
|
1612 |
{ |
|
1613 |
stream_data(MAX_QCOLORGROUP_DATA); |
|
1614 |
} |
|
1615 |
||
1616 |
void tst_QDataStream::stream_QColorGroup() |
|
1617 |
{ |
|
1618 |
STREAM_IMPL(QColorGroup); |
|
1619 |
} |
|
1620 |
||
1621 |
void tst_QDataStream::writeQColorGroup(QDataStream *s) |
|
1622 |
{ |
|
1623 |
#ifdef QT3_SUPPORT |
|
1624 |
QColorGroup d13(QColorGroupData(dataIndex(QTest::currentDataTag()))); |
|
1625 |
*s << d13; |
|
1626 |
#else |
|
1627 |
QSKIP("No Qt3 Support", SkipAll); |
|
1628 |
#endif |
|
1629 |
} |
|
1630 |
||
1631 |
void tst_QDataStream::readQColorGroup(QDataStream *s) |
|
1632 |
{ |
|
1633 |
#ifdef QT3_SUPPORT |
|
1634 |
QColorGroup test(QColorGroupData(dataIndex(QTest::currentDataTag()))); |
|
1635 |
QColorGroup d14; |
|
1636 |
*s >> d14; |
|
1637 |
QVERIFY(d14 == test); |
|
1638 |
#else |
|
1639 |
QSKIP("No Qt3 Support", SkipAll); |
|
1640 |
#endif |
|
1641 |
} |
|
1642 |
||
1643 |
// ************************************ |
|
1644 |
||
1645 |
static QPen qPenData(int index) |
|
1646 |
{ |
|
1647 |
switch (index) |
|
1648 |
{ |
|
1649 |
case 0: { |
|
1650 |
QPen p(Qt::blue, 0, Qt::NoPen); |
|
1651 |
p.setCapStyle(Qt::FlatCap); |
|
1652 |
p.setJoinStyle(Qt::MiterJoin); |
|
1653 |
return p; |
|
1654 |
} |
|
1655 |
case 1: { |
|
1656 |
QPen p(Qt::red, 1, Qt::SolidLine); |
|
1657 |
p.setCapStyle(Qt::SquareCap); |
|
1658 |
p.setJoinStyle(Qt::BevelJoin); |
|
1659 |
return p; |
|
1660 |
} |
|
1661 |
case 2: { |
|
1662 |
QPen p(Qt::red, 4, Qt::DashDotDotLine); |
|
1663 |
p.setCapStyle(Qt::RoundCap); |
|
1664 |
p.setJoinStyle(Qt::RoundJoin); |
|
1665 |
return p; |
|
1666 |
} |
|
1667 |
case 3: { |
|
1668 |
QPen p(Qt::blue, 12, Qt::NoPen); |
|
1669 |
p.setCapStyle(Qt::FlatCap); |
|
1670 |
p.setJoinStyle(Qt::RoundJoin); |
|
1671 |
return p; |
|
1672 |
} |
|
1673 |
case 4: { |
|
1674 |
QPen p(Qt::red, 99, Qt::SolidLine); |
|
1675 |
p.setCapStyle(Qt::SquareCap); |
|
1676 |
p.setJoinStyle(Qt::MiterJoin); |
|
1677 |
return p; |
|
1678 |
} |
|
1679 |
case 5: { |
|
1680 |
QPen p(Qt::red, 255, Qt::DashDotLine); |
|
1681 |
p.setCapStyle(Qt::RoundCap); |
|
1682 |
p.setJoinStyle(Qt::BevelJoin); |
|
1683 |
return p; |
|
1684 |
} |
|
1685 |
case 6: { |
|
1686 |
QPen p(Qt::red, 256, Qt::DashDotLine); |
|
1687 |
p.setCapStyle(Qt::RoundCap); |
|
1688 |
p.setJoinStyle(Qt::BevelJoin); |
|
1689 |
return p; |
|
1690 |
} |
|
1691 |
case 7: { |
|
1692 |
QPen p(Qt::red, 0.25, Qt::DashDotLine); |
|
1693 |
p.setCapStyle(Qt::RoundCap); |
|
1694 |
p.setJoinStyle(Qt::BevelJoin); |
|
1695 |
return p; |
|
1696 |
} |
|
1697 |
} |
|
1698 |
||
1699 |
return QPen(); |
|
1700 |
} |
|
1701 |
#define MAX_QPEN_DATA 8 |
|
1702 |
||
1703 |
void tst_QDataStream::stream_QPen_data() |
|
1704 |
{ |
|
1705 |
stream_data(MAX_QPEN_DATA); |
|
1706 |
} |
|
1707 |
||
1708 |
void tst_QDataStream::stream_QPen() |
|
1709 |
{ |
|
1710 |
/* |
|
1711 |
edba: |
|
1712 |
data6 fails because the width is clipped to a byte (max 255) in the datastream. |
|
1713 |
This limitation is not documented. |
|
1714 |
*/ |
|
1715 |
||
1716 |
STREAM_IMPL(QPen); |
|
1717 |
} |
|
1718 |
||
1719 |
void tst_QDataStream::writeQPen(QDataStream *s) |
|
1720 |
{ |
|
1721 |
QPen d15(qPenData(dataIndex(QTest::currentDataTag()))); |
|
1722 |
*s << d15; |
|
1723 |
} |
|
1724 |
||
1725 |
void tst_QDataStream::readQPen(QDataStream *s) |
|
1726 |
{ |
|
1727 |
QPen origPen(qPenData(dataIndex(QTest::currentDataTag()))); |
|
1728 |
QPen d15; |
|
1729 |
*s >> d15; |
|
1730 |
QCOMPARE(d15.style(), origPen.style()); |
|
1731 |
QCOMPARE(d15.width(), origPen.width()); |
|
1732 |
QCOMPARE(d15.color(), origPen.color()); |
|
1733 |
QVERIFY(d15.capStyle() == origPen.capStyle()); |
|
1734 |
QVERIFY(d15.joinStyle() == origPen.joinStyle()); |
|
1735 |
QVERIFY(d15 == origPen); |
|
1736 |
} |
|
1737 |
||
1738 |
// ************************************ |
|
1739 |
||
1740 |
// pixmap testing is currently limited to one pixmap only. |
|
1741 |
// |
|
1742 |
void tst_QDataStream::stream_QPixmap_data() |
|
1743 |
{ |
|
1744 |
#ifndef Q_OS_WINCE |
|
1745 |
stream_data(1); |
|
1746 |
#endif |
|
1747 |
} |
|
1748 |
||
1749 |
void tst_QDataStream::stream_QPixmap() |
|
1750 |
{ |
|
1751 |
#ifdef Q_OS_WINCE |
|
1752 |
QSKIP("Test depends on more memory than available on Qt/CE", SkipAll); |
|
1753 |
#endif |
|
1754 |
STREAM_IMPL(QIcon); |
|
1755 |
} |
|
1756 |
||
1757 |
void tst_QDataStream::stream_QIcon_data() |
|
1758 |
{ |
|
1759 |
#ifndef Q_OS_WINCE |
|
1760 |
stream_data(1); |
|
1761 |
#endif |
|
1762 |
} |
|
1763 |
||
1764 |
void tst_QDataStream::stream_QIcon() |
|
1765 |
{ |
|
1766 |
#ifdef Q_OS_WINCE |
|
1767 |
QSKIP("Test depends on more memory than available on Qt/CE", SkipAll); |
|
1768 |
#endif |
|
1769 |
STREAM_IMPL(QIcon); |
|
1770 |
} |
|
1771 |
||
1772 |
void tst_QDataStream::writeQPixmap(QDataStream *s) |
|
1773 |
{ |
|
1774 |
QPixmap d16(open_xpm); |
|
1775 |
*s << d16; |
|
1776 |
} |
|
1777 |
||
1778 |
void tst_QDataStream::readQPixmap(QDataStream *s) |
|
1779 |
{ |
|
1780 |
QPixmap pm(open_xpm); |
|
1781 |
QPixmap d16; |
|
1782 |
*s >> d16; |
|
1783 |
QVERIFY(!d16.isNull() && !pm.isNull()); |
|
1784 |
QVERIFY(d16.width() == pm.width()); |
|
1785 |
QVERIFY(d16.height() == pm.height()); |
|
1786 |
QVERIFY(d16.size() == pm.size()); |
|
1787 |
QVERIFY(d16.rect() == pm.rect()); |
|
1788 |
QVERIFY(d16.depth() == pm.depth()); |
|
1789 |
// bit depth must be 24 or above for pixmap comparison |
|
1790 |
#ifdef QT3_SUPPORT |
|
1791 |
if (Q3PaintDeviceMetrics(&pm).depth() < 24) |
|
1792 |
QSKIP("Don't do pixmap comparison when depth < 24", SkipAll); |
|
1793 |
QCOMPARE(d16, QPixmap(pm)); |
|
1794 |
#endif |
|
1795 |
} |
|
1796 |
||
1797 |
void tst_QDataStream::writeQIcon(QDataStream *s) |
|
1798 |
{ |
|
1799 |
QPixmap pm(open_xpm); |
|
1800 |
QIcon d16(pm); |
|
1801 |
*s << d16; |
|
1802 |
||
1803 |
QIcon svg(svgFile); |
|
1804 |
*s << svg; |
|
1805 |
} |
|
1806 |
||
1807 |
void tst_QDataStream::readQIcon(QDataStream *s) |
|
1808 |
{ |
|
1809 |
QPixmap pm(open_xpm); |
|
1810 |
QIcon icon(pm); |
|
1811 |
QIcon d16; |
|
1812 |
*s >> d16; |
|
1813 |
QVERIFY(!d16.isNull() && !icon.isNull()); |
|
1814 |
QCOMPARE(d16.pixmap(100), pm); |
|
1815 |
||
1816 |
QIcon svg; |
|
1817 |
*s >> svg; |
|
1818 |
QVERIFY(!svg.isNull()); |
|
1819 |
||
1820 |
QImage image(200, 200, QImage::Format_ARGB32_Premultiplied); |
|
1821 |
image.fill(0); |
|
1822 |
QPainter p(&image); |
|
1823 |
p.drawPixmap(0, 0, svg.pixmap(200, 200)); |
|
1824 |
p.end(); |
|
1825 |
||
1826 |
QIcon svg2(svgFile); |
|
1827 |
QImage image2(200, 200, QImage::Format_ARGB32_Premultiplied); |
|
1828 |
image2.fill(0); |
|
1829 |
p.begin(&image2); |
|
1830 |
p.drawPixmap(0, 0, svg2.pixmap(200, 200)); |
|
1831 |
p.end(); |
|
1832 |
QCOMPARE(image, image2); |
|
1833 |
} |
|
1834 |
||
1835 |
// ************************************ |
|
1836 |
||
1837 |
QPoint qPointData(int index) |
|
1838 |
{ |
|
1839 |
switch (index) |
|
1840 |
{ |
|
1841 |
case 0: return QPoint(0, 0); |
|
1842 |
case 1: return QPoint(-1, 0); |
|
1843 |
case 2: return QPoint(0, -1); |
|
1844 |
case 3: return QPoint(1, 0); |
|
1845 |
case 4: return QPoint(0, 1); |
|
1846 |
case 5: return QPoint(-1, -1); |
|
1847 |
case 6: return QPoint(1, 1); |
|
1848 |
case 7: return QPoint(255, 255); |
|
1849 |
case 8: return QPoint(256, 256); |
|
1850 |
case 9: return QPoint(-254, -254); |
|
1851 |
case 10: return QPoint(-255, -255); |
|
1852 |
} |
|
1853 |
||
1854 |
return QPoint(); |
|
1855 |
} |
|
1856 |
#define MAX_QPOINT_DATA 11 |
|
1857 |
||
1858 |
||
1859 |
void tst_QDataStream::stream_QPoint_data() |
|
1860 |
{ |
|
1861 |
stream_data(MAX_QPOINT_DATA); |
|
1862 |
} |
|
1863 |
||
1864 |
void tst_QDataStream::stream_QPoint() |
|
1865 |
{ |
|
1866 |
STREAM_IMPL(QPoint); |
|
1867 |
} |
|
1868 |
||
1869 |
void tst_QDataStream::writeQPoint(QDataStream *s) |
|
1870 |
{ |
|
1871 |
QPoint d17(qPointData(dataIndex(QTest::currentDataTag()))); |
|
1872 |
*s << d17; |
|
1873 |
||
1874 |
QPointF d17f = d17; |
|
1875 |
*s << d17f; |
|
1876 |
} |
|
1877 |
||
1878 |
void tst_QDataStream::readQPoint(QDataStream *s) |
|
1879 |
{ |
|
1880 |
QPoint ref(qPointData(dataIndex(QTest::currentDataTag()))); |
|
1881 |
QPoint d17; |
|
1882 |
*s >> d17; |
|
1883 |
QVERIFY(d17 == ref); |
|
1884 |
||
1885 |
QPointF d17f; |
|
1886 |
*s >> d17f; |
|
1887 |
QVERIFY(d17f == QPointF(ref)); |
|
1888 |
} |
|
1889 |
||
1890 |
// ************************************ |
|
1891 |
||
1892 |
static QRect qRectData(int index) |
|
1893 |
{ |
|
1894 |
switch (index) |
|
1895 |
{ |
|
1896 |
case 0: return QRect(0, 0, 0, 0); |
|
1897 |
case 1: return QRect(1, 1, 1, 1); |
|
1898 |
case 2: return QRect(1, 2, 3, 4); |
|
1899 |
case 3: return QRect(-1, -1, -1, -1); |
|
1900 |
case 4: return QRect(-1, -2, -3, -4); |
|
1901 |
case 5: return QRect(255, -5, 256, -6); |
|
1902 |
case 6: return QRect(-7, 255, -8, 256); |
|
1903 |
case 7: return QRect(9, -255, 10, -255); |
|
1904 |
case 8: return QRect(-255, 11, -255, 12); |
|
1905 |
case 9: return QRect(256, 512, 1024, 2048); |
|
1906 |
case 10: return QRect(-256, -512, -1024, -2048); |
|
1907 |
} |
|
1908 |
return QRect(); |
|
1909 |
} |
|
1910 |
#define MAX_QRECT_DATA 11 |
|
1911 |
||
1912 |
void tst_QDataStream::stream_QRect_data() |
|
1913 |
{ |
|
1914 |
stream_data(MAX_QRECT_DATA); |
|
1915 |
} |
|
1916 |
||
1917 |
void tst_QDataStream::stream_QRect() |
|
1918 |
{ |
|
1919 |
STREAM_IMPL(QRect); |
|
1920 |
} |
|
1921 |
||
1922 |
void tst_QDataStream::writeQRect(QDataStream *s) |
|
1923 |
{ |
|
1924 |
QRect d18(qRectData(dataIndex(QTest::currentDataTag()))); |
|
1925 |
*s << d18; |
|
1926 |
||
1927 |
QRectF d18f(d18); |
|
1928 |
*s << d18f; |
|
1929 |
} |
|
1930 |
||
1931 |
void tst_QDataStream::readQRect(QDataStream *s) |
|
1932 |
{ |
|
1933 |
QRect ref(qRectData(dataIndex(QTest::currentDataTag()))); |
|
1934 |
QRect d18; |
|
1935 |
*s >> d18; |
|
1936 |
QVERIFY(d18 == ref); |
|
1937 |
||
1938 |
QRectF d18f; |
|
1939 |
*s >> d18f; |
|
1940 |
QVERIFY(d18f == QRectF(ref)); |
|
1941 |
} |
|
1942 |
||
1943 |
// ************************************ |
|
1944 |
||
1945 |
static QPolygon qPolygonData(int index) |
|
1946 |
{ |
|
1947 |
QPoint p0(0, 0); |
|
1948 |
QPoint p1(1, 1); |
|
1949 |
QPoint p2(-1, -1); |
|
1950 |
QPoint p3(1, -1); |
|
1951 |
QPoint p4(-1, 1); |
|
1952 |
QPoint p5(0, 255); |
|
1953 |
QPoint p6(0, 256); |
|
1954 |
QPoint p7(0, 1024); |
|
1955 |
QPoint p8(255, 0); |
|
1956 |
QPoint p9(256, 0); |
|
1957 |
QPoint p10(1024, 0); |
|
1958 |
QPoint p11(345, 678); |
|
1959 |
QPoint p12(23456, 99999); |
|
1960 |
QPoint p13(-99998, -34567); |
|
1961 |
QPoint p14(45678, -99999); |
|
1962 |
||
1963 |
switch (index) |
|
1964 |
{ |
|
1965 |
case 0: return QPolygon(0); |
|
1966 |
case 1: { |
|
1967 |
QPolygon p(1); |
|
1968 |
p.setPoint(0, p0); |
|
1969 |
return p; |
|
1970 |
} |
|
1971 |
case 2: { |
|
1972 |
QPolygon p(1); |
|
1973 |
p.setPoint(0, p5); |
|
1974 |
return p; |
|
1975 |
} |
|
1976 |
case 3: { |
|
1977 |
QPolygon p(1); |
|
1978 |
p.setPoint(0, p12); |
|
1979 |
return p; |
|
1980 |
} |
|
1981 |
case 4: { |
|
1982 |
QPolygon p(3); |
|
1983 |
p.setPoint(0, p1); |
|
1984 |
p.setPoint(1, p10); |
|
1985 |
p.setPoint(2, p13); |
|
1986 |
return p; |
|
1987 |
} |
|
1988 |
case 5: { |
|
1989 |
QPolygon p(6); |
|
1990 |
p.setPoint(0, p2); |
|
1991 |
p.setPoint(1, p11); |
|
1992 |
p.setPoint(2, p14); |
|
1993 |
return p; |
|
1994 |
} |
|
1995 |
case 6: { |
|
1996 |
QPolygon p(15); |
|
1997 |
p.setPoint(0, p0); |
|
1998 |
p.setPoint(1, p1); |
|
1999 |
p.setPoint(2, p2); |
|
2000 |
p.setPoint(3, p3); |
|
2001 |
p.setPoint(4, p4); |
|
2002 |
p.setPoint(5, p5); |
|
2003 |
p.setPoint(6, p6); |
|
2004 |
p.setPoint(7, p7); |
|
2005 |
p.setPoint(8, p8); |
|
2006 |
p.setPoint(9, p9); |
|
2007 |
p.setPoint(10, p10); |
|
2008 |
p.setPoint(11, p11); |
|
2009 |
p.setPoint(12, p12); |
|
2010 |
p.setPoint(13, p13); |
|
2011 |
p.setPoint(14, p14); |
|
2012 |
return p; |
|
2013 |
} |
|
2014 |
} |
|
2015 |
return QRect(); |
|
2016 |
} |
|
2017 |
#define MAX_QPOINTARRAY_DATA 7 |
|
2018 |
||
2019 |
void tst_QDataStream::stream_QPolygon_data() |
|
2020 |
{ |
|
2021 |
stream_data(1); |
|
2022 |
} |
|
2023 |
||
2024 |
void tst_QDataStream::stream_QPolygon() |
|
2025 |
{ |
|
2026 |
STREAM_IMPL(QPolygon); |
|
2027 |
} |
|
2028 |
||
2029 |
void tst_QDataStream::writeQPolygon(QDataStream *s) |
|
2030 |
{ |
|
2031 |
QPolygon d19(qPolygonData(dataIndex(QTest::currentDataTag()))); |
|
2032 |
*s << d19; |
|
2033 |
||
2034 |
QPolygonF d19f(d19); |
|
2035 |
*s << d19f; |
|
2036 |
} |
|
2037 |
||
2038 |
void tst_QDataStream::readQPolygon(QDataStream *s) |
|
2039 |
{ |
|
2040 |
QPolygon ref(qPolygonData(dataIndex(QTest::currentDataTag()))); |
|
2041 |
QPolygon d19; |
|
2042 |
*s >> d19; |
|
2043 |
QVERIFY(d19 == ref); |
|
2044 |
||
2045 |
QPolygonF d19f; |
|
2046 |
*s >> d19f; |
|
2047 |
QVERIFY(d19f == QPolygonF(ref)); |
|
2048 |
} |
|
2049 |
||
2050 |
// ************************************ |
|
2051 |
||
2052 |
static QRegion qRegionData(int index) |
|
2053 |
{ |
|
2054 |
switch (index) |
|
2055 |
{ |
|
2056 |
case 0: return QRegion(0, 0, 0, 0, QRegion::Rectangle); |
|
2057 |
case 1: { |
|
2058 |
QRegion r(1, 2, 300, 400, QRegion::Rectangle); |
|
2059 |
if (r != QRegion(1, 2, 300, 400, QRegion::Rectangle)) |
|
2060 |
qDebug("Error creating a region"); |
|
2061 |
return r; |
|
2062 |
} |
|
2063 |
case 2: return QRegion(100, 100, 1024, 768, QRegion::Rectangle); |
|
2064 |
case 3: return QRegion(-100, -100, 1024, 1024, QRegion::Rectangle); |
|
2065 |
case 4: return QRegion(100, -100, 2048, 4096, QRegion::Rectangle); |
|
2066 |
case 5: return QRegion(-100, 100, 4096, 2048, QRegion::Rectangle); |
|
2067 |
case 6: return QRegion(0, 0, 0, 0, QRegion::Ellipse); |
|
2068 |
#if defined(Q_OS_SYMBIAN) || (!defined(Q_OS_UNIX) && !defined(Q_OS_WINCE)) // all our Unix platforms use X regions. |
|
2069 |
case 7: return QRegion(1, 2, 300, 400, QRegion::Ellipse); |
|
2070 |
case 8: return QRegion(100, 100, 1024, 768, QRegion::Ellipse); |
|
2071 |
case 9: return QRegion(-100, -100, 1024, 1024, QRegion::Ellipse); |
|
2072 |
case 10: return QRegion(100, -100, 2048, 4096, QRegion::Ellipse); |
|
2073 |
case 11: return QRegion(-100, 100, 4096, 2048, QRegion::Ellipse); |
|
2074 |
// simplest X11 case that fails: |
|
2075 |
case 12: return QRegion(0, 0, 3, 3, QRegion::Ellipse); |
|
2076 |
#else |
|
2077 |
case 7: |
|
2078 |
qWarning("Skipping streaming of elliptical regions on embedded, Mac OS X, and X11;" |
|
2079 |
" our pointarray stuff is not that great at approximating."); |
|
2080 |
#endif |
|
2081 |
} |
|
2082 |
return QRegion(); |
|
2083 |
} |
|
2084 |
#define MAX_QREGION_DATA 12 |
|
2085 |
||
2086 |
void tst_QDataStream::stream_QRegion_data() |
|
2087 |
{ |
|
2088 |
stream_data(MAX_QREGION_DATA); |
|
2089 |
} |
|
2090 |
||
2091 |
void tst_QDataStream::stream_QRegion() |
|
2092 |
{ |
|
2093 |
STREAM_IMPL(QRegion); |
|
2094 |
} |
|
2095 |
||
2096 |
void tst_QDataStream::writeQRegion(QDataStream *s) |
|
2097 |
{ |
|
2098 |
QRegion r(qRegionData(dataIndex(QTest::currentDataTag()))); |
|
2099 |
*s << r; |
|
2100 |
} |
|
2101 |
||
2102 |
void tst_QDataStream::readQRegion(QDataStream *s) |
|
2103 |
{ |
|
2104 |
QRegion ref(qRegionData(dataIndex(QTest::currentDataTag()))); |
|
2105 |
QRegion r; |
|
2106 |
*s >> r; |
|
2107 |
QVERIFY(r == ref); |
|
2108 |
} |
|
2109 |
||
2110 |
// ************************************ |
|
2111 |
||
2112 |
static QSize qSizeData(int index) |
|
2113 |
{ |
|
2114 |
switch (index) |
|
2115 |
{ |
|
2116 |
case 0: return QSize(0, 0); |
|
2117 |
case 1: return QSize(-1, 0); |
|
2118 |
case 2: return QSize(0, -1); |
|
2119 |
case 3: return QSize(1, 0); |
|
2120 |
case 4: return QSize(0, 1); |
|
2121 |
case 5: return QSize(-1, -1); |
|
2122 |
case 6: return QSize(1, 1); |
|
2123 |
case 7: return QSize(255, 255); |
|
2124 |
case 8: return QSize(256, 256); |
|
2125 |
case 9: return QSize(-254, -254); |
|
2126 |
case 10: return QSize(-255, -255); |
|
2127 |
} |
|
2128 |
return QSize(); |
|
2129 |
} |
|
2130 |
#define MAX_QSIZE_DATA 11 |
|
2131 |
||
2132 |
void tst_QDataStream::stream_QSize_data() |
|
2133 |
{ |
|
2134 |
stream_data(MAX_QSIZE_DATA); |
|
2135 |
} |
|
2136 |
||
2137 |
void tst_QDataStream::stream_QSize() |
|
2138 |
{ |
|
2139 |
STREAM_IMPL(QSize); |
|
2140 |
} |
|
2141 |
||
2142 |
void tst_QDataStream::writeQSize(QDataStream *s) |
|
2143 |
{ |
|
2144 |
QSize d21(qSizeData(dataIndex(QTest::currentDataTag()))); |
|
2145 |
*s << d21; |
|
2146 |
||
2147 |
QSizeF d21f(d21); |
|
2148 |
*s << d21f; |
|
2149 |
} |
|
2150 |
||
2151 |
void tst_QDataStream::readQSize(QDataStream *s) |
|
2152 |
{ |
|
2153 |
QSize ref(qSizeData(dataIndex(QTest::currentDataTag()))); |
|
2154 |
QSize d21; |
|
2155 |
*s >> d21; |
|
2156 |
QVERIFY(d21 == ref); |
|
2157 |
||
2158 |
QSizeF d21f; |
|
2159 |
*s >> d21f; |
|
2160 |
QVERIFY(d21f == QSizeF(ref)); |
|
2161 |
} |
|
2162 |
||
2163 |
// ************************************ |
|
2164 |
||
2165 |
void tst_QDataStream::stream_QWMatrix_data() |
|
2166 |
{ |
|
2167 |
stream_data(1); |
|
2168 |
} |
|
2169 |
||
2170 |
void tst_QDataStream::stream_QWMatrix() |
|
2171 |
{ |
|
2172 |
STREAM_IMPL(QWMatrix); |
|
2173 |
} |
|
2174 |
||
2175 |
void tst_QDataStream::writeQWMatrix(QDataStream *s) |
|
2176 |
{ |
|
2177 |
#ifdef QT3_SUPPORT |
|
2178 |
// QStringList: Qt 2.0 specific |
|
2179 |
QWMatrix d23(1.2, 2.3, 3.4, 4.5, 5.6, 6.7); |
|
2180 |
*s << d23; |
|
2181 |
#else |
|
2182 |
QSKIP("No Qt3 Support", SkipAll); |
|
2183 |
#endif |
|
2184 |
} |
|
2185 |
||
2186 |
void tst_QDataStream::readQWMatrix(QDataStream *s) |
|
2187 |
{ |
|
2188 |
#ifdef QT3_SUPPORT |
|
2189 |
// QStringList: Qt 2.0 specific |
|
2190 |
||
2191 |
QWMatrix d23; |
|
2192 |
*s >> d23; |
|
2193 |
// QVERIFY(d23 == QWMatrix(1.2, 2.3, 3.4, 4.5, 5.6, 6.7)); |
|
2194 |
QWMatrix m(1.2, 2.3, 3.4, 4.5, 5.6, 6.7); |
|
2195 |
// Because of double vs. float rounding differences: |
|
2196 |
QVERIFY(QABS(d23.m11() - m.m11()) < 1e-6); |
|
2197 |
QVERIFY(QABS(d23.m12() - m.m12()) < 1e-6); |
|
2198 |
QVERIFY(QABS(d23.m21() - m.m21()) < 1e-6); |
|
2199 |
QVERIFY(QABS(d23.m22() - m.m22()) < 1e-6); |
|
2200 |
QVERIFY(QABS(d23.dx() - m.dx()) < 1e-6); |
|
2201 |
QVERIFY(QABS(d23.dy() - m.dy()) < 1e-6); |
|
2202 |
#else |
|
2203 |
QSKIP("No Qt3 Support", SkipAll); |
|
2204 |
#endif |
|
2205 |
} |
|
2206 |
||
2207 |
// *********************** atEnd ****************************** |
|
2208 |
||
2209 |
void tst_QDataStream::stream_atEnd_data() |
|
2210 |
{ |
|
2211 |
stream_data(MAX_QSTRING_DATA); |
|
2212 |
} |
|
2213 |
||
2214 |
void tst_QDataStream::stream_atEnd() |
|
2215 |
{ |
|
2216 |
QFETCH(QString, device); |
|
2217 |
if (device == "bytearray") { |
|
2218 |
QByteArray ba; |
|
2219 |
QDataStream sout(&ba, QIODevice::WriteOnly); |
|
2220 |
writeQString(&sout); |
|
2221 |
||
2222 |
QDataStream sin(&ba, QIODevice::ReadOnly); |
|
2223 |
readQString(&sin); |
|
2224 |
QVERIFY(sin.atEnd()); |
|
2225 |
} else if (device == "file") { |
|
2226 |
QString fileName = "qdatastream.out"; |
|
2227 |
QFile fOut(fileName); |
|
2228 |
QVERIFY(fOut.open(QIODevice::WriteOnly)); |
|
2229 |
QDataStream sout(&fOut); |
|
2230 |
writeQString(&sout); |
|
2231 |
fOut.close(); |
|
2232 |
||
2233 |
QFile fIn(fileName); |
|
2234 |
QVERIFY(fIn.open(QIODevice::ReadOnly)); |
|
2235 |
QDataStream sin(&fIn); |
|
2236 |
readQString(&sin); |
|
2237 |
QVERIFY(sin.atEnd()); |
|
2238 |
fIn.close(); |
|
2239 |
} else if (device == "buffer") { |
|
2240 |
{ |
|
2241 |
QByteArray ba(0); |
|
2242 |
QBuffer bOut(&ba); |
|
2243 |
bOut.open(QIODevice::WriteOnly); |
|
2244 |
QDataStream sout(&bOut); |
|
2245 |
writeQString(&sout); |
|
2246 |
bOut.close(); |
|
2247 |
||
2248 |
QBuffer bIn(&ba); |
|
2249 |
bIn.open(QIODevice::ReadOnly); |
|
2250 |
QDataStream sin(&bIn); |
|
2251 |
readQString(&sin); |
|
2252 |
QVERIFY(sin.atEnd()); |
|
2253 |
bIn.close(); |
|
2254 |
} |
|
2255 |
||
2256 |
// Do the same test again, but this time with an initial size for the bytearray. |
|
2257 |
{ |
|
2258 |
#ifdef QT3_SUPPORT |
|
2259 |
QByteArray ba(10000); |
|
2260 |
#else |
|
2261 |
QByteArray ba(10000, '\0'); |
|
2262 |
#endif |
|
2263 |
QBuffer bOut(&ba); |
|
2264 |
bOut.open(QIODevice::WriteOnly | QIODevice::Truncate); |
|
2265 |
QDataStream sout(&bOut); |
|
2266 |
writeQString(&sout); |
|
2267 |
bOut.close(); |
|
2268 |
||
2269 |
QBuffer bIn(&ba); |
|
2270 |
bIn.open(QIODevice::ReadOnly); |
|
2271 |
QDataStream sin(&bIn); |
|
2272 |
readQString(&sin); |
|
2273 |
QVERIFY(sin.atEnd()); |
|
2274 |
bIn.close(); |
|
2275 |
} |
|
2276 |
} |
|
2277 |
} |
|
2278 |
||
2279 |
void tst_QDataStream::stream_QByteArray2() |
|
2280 |
{ |
|
2281 |
QByteArray ba; |
|
2282 |
{ |
|
2283 |
QDataStream s(&ba, QIODevice::WriteOnly); |
|
2284 |
s << QByteArray("hallo"); |
|
2285 |
s << QByteArray(""); |
|
2286 |
s << QByteArray(); |
|
2287 |
} |
|
2288 |
||
2289 |
{ |
|
2290 |
QDataStream s(&ba, QIODevice::ReadOnly); |
|
2291 |
QByteArray res; |
|
2292 |
s >> res; |
|
2293 |
QCOMPARE(res, QByteArray("hallo")); |
|
2294 |
s >> res; |
|
2295 |
QCOMPARE(res, QByteArray("")); |
|
2296 |
QVERIFY(res.isEmpty()); |
|
2297 |
QVERIFY(!res.isNull()); |
|
2298 |
s >> res; |
|
2299 |
QCOMPARE(res, QByteArray()); |
|
2300 |
QVERIFY(res.isEmpty()); |
|
2301 |
QVERIFY(res.isNull()); |
|
2302 |
} |
|
2303 |
} |
|
2304 |
||
2305 |
void tst_QDataStream::setVersion_data() |
|
2306 |
{ |
|
2307 |
QTest::addColumn<int>("vers"); |
|
2308 |
QDataStream latest; |
|
2309 |
||
2310 |
for (int vers = 1; vers <= latest.version(); ++vers) |
|
2311 |
QTest::newRow(qPrintable(QString("v_%1").arg(vers))) << vers; |
|
2312 |
||
2313 |
||
2314 |
} |
|
2315 |
||
2316 |
void tst_QDataStream::setVersion() |
|
2317 |
{ |
|
2318 |
QDataStream latest; |
|
2319 |
QFETCH(int, vers); |
|
2320 |
||
2321 |
/* |
|
2322 |
Test QKeySequence. |
|
2323 |
*/ |
|
2324 |
QByteArray ba1; |
|
2325 |
{ |
|
2326 |
QDataStream out(&ba1, QIODevice::WriteOnly); |
|
2327 |
out.setVersion(vers); |
|
2328 |
out << QKeySequence(Qt::Key_A) << QKeySequence(Qt::Key_B, Qt::Key_C) |
|
2329 |
<< (quint32)0xDEADBEEF; |
|
2330 |
} |
|
2331 |
{ |
|
2332 |
QKeySequence keyseq1, keyseq2; |
|
2333 |
quint32 deadbeef; |
|
2334 |
QDataStream in(&ba1, QIODevice::ReadOnly); |
|
2335 |
in.setVersion(vers); |
|
2336 |
in >> keyseq1 >> keyseq2 >> deadbeef; |
|
2337 |
QVERIFY(keyseq1 == QKeySequence(Qt::Key_A)); |
|
2338 |
if (vers >= 5) { |
|
2339 |
QVERIFY(keyseq2 == QKeySequence(Qt::Key_B, Qt::Key_C)); |
|
2340 |
} else { |
|
2341 |
QVERIFY(keyseq2 == QKeySequence(Qt::Key_B)); |
|
2342 |
} |
|
2343 |
QVERIFY(deadbeef == 0xDEADBEEF); |
|
2344 |
} |
|
2345 |
||
2346 |
/* |
|
2347 |
Test QPalette. |
|
2348 |
*/ |
|
2349 |
||
2350 |
||
2351 |
// revise the test if new color roles or color groups are added |
|
2352 |
QVERIFY(QPalette::NColorRoles == QPalette::ToolTipText + 1); |
|
2353 |
QVERIFY(QPalette::NColorGroups == 3); |
|
2354 |
||
2355 |
QByteArray ba2; |
|
2356 |
QPalette pal1, pal2; |
|
2357 |
for (int grp = 0; grp < (int)QPalette::NColorGroups; ++grp) { |
|
2358 |
for (int role = 0; role < (int)QPalette::NColorRoles; ++role) { |
|
2359 |
// random stuff |
|
2360 |
pal1.setColor((QPalette::ColorGroup)grp, (QPalette::ColorRole)role, |
|
2361 |
QColor(grp * 13, 255 - grp, role)); |
|
2362 |
pal2.setColor((QPalette::ColorGroup)grp, (QPalette::ColorRole)role, |
|
2363 |
QColor(role * 11, 254 - role, grp)); |
|
2364 |
} |
|
2365 |
} |
|
2366 |
||
2367 |
{ |
|
2368 |
QDataStream out(&ba2, QIODevice::WriteOnly); |
|
2369 |
out.setVersion(vers); |
|
2370 |
out << pal1 << pal2 << (quint32)0xCAFEBABE; |
|
2371 |
} |
|
2372 |
{ |
|
2373 |
QPalette inPal1, inPal2; |
|
2374 |
quint32 cafebabe; |
|
2375 |
QDataStream in(&ba2, QIODevice::ReadOnly); |
|
2376 |
in.setVersion(vers); |
|
2377 |
in >> inPal1 >> inPal2; |
|
2378 |
in >> cafebabe; |
|
2379 |
||
2380 |
QCOMPARE(cafebabe, 0xCAFEBABE); |
|
2381 |
||
2382 |
QCOMPARE(NColorRoles[latest.version()], (int)QPalette::NColorRoles); //if this fails you need to update the NColorRoles array |
|
2383 |
||
2384 |
if (vers == 1) { |
|
2385 |
for (int grp = 0; grp < (int)QPalette::NColorGroups; ++grp) { |
|
2386 |
QVERIFY(pal1.color((QPalette::ColorGroup)grp, QPalette::Foreground) |
|
2387 |
== inPal1.color((QPalette::ColorGroup)grp, QPalette::Foreground)); |
|
2388 |
QVERIFY(pal1.color((QPalette::ColorGroup)grp, QPalette::Background) |
|
2389 |
== inPal1.color((QPalette::ColorGroup)grp, QPalette::Background)); |
|
2390 |
QVERIFY(pal1.color((QPalette::ColorGroup)grp, QPalette::Light) |
|
2391 |
== inPal1.color((QPalette::ColorGroup)grp, QPalette::Light)); |
|
2392 |
QVERIFY(pal1.color((QPalette::ColorGroup)grp, QPalette::Dark) |
|
2393 |
== inPal1.color((QPalette::ColorGroup)grp, QPalette::Dark)); |
|
2394 |
QVERIFY(pal1.color((QPalette::ColorGroup)grp, QPalette::Mid) |
|
2395 |
== inPal1.color((QPalette::ColorGroup)grp, QPalette::Mid)); |
|
2396 |
QVERIFY(pal1.color((QPalette::ColorGroup)grp, QPalette::Text) |
|
2397 |
== inPal1.color((QPalette::ColorGroup)grp, QPalette::Text)); |
|
2398 |
QVERIFY(pal1.color((QPalette::ColorGroup)grp, QPalette::Base) |
|
2399 |
== inPal1.color((QPalette::ColorGroup)grp, QPalette::Base)); |
|
2400 |
||
2401 |
QVERIFY(pal1.color((QPalette::ColorGroup)grp, QPalette::Midlight) |
|
2402 |
!= inPal1.color((QPalette::ColorGroup)grp, QPalette::Midlight)); |
|
2403 |
} |
|
2404 |
} else { |
|
2405 |
if (NColorRoles[vers] < QPalette::NColorRoles) { |
|
2406 |
QVERIFY(pal1 != inPal1); |
|
2407 |
QVERIFY(pal2 != inPal2); |
|
2408 |
||
2409 |
for (int grp = 0; grp < (int)QPalette::NColorGroups; ++grp) { |
|
2410 |
for (int i = NColorRoles[vers]; i < QPalette::NColorRoles; ++i) { |
|
2411 |
inPal1.setColor((QPalette::ColorGroup)grp, (QPalette::ColorRole)i, |
|
2412 |
pal1.color((QPalette::ColorGroup)grp, (QPalette::ColorRole)i)); |
|
2413 |
inPal2.setColor((QPalette::ColorGroup)grp, (QPalette::ColorRole)i, |
|
2414 |
pal2.color((QPalette::ColorGroup)grp, (QPalette::ColorRole)i)); |
|
2415 |
} |
|
2416 |
} |
|
2417 |
} |
|
2418 |
QVERIFY(pal1 == inPal1); |
|
2419 |
QVERIFY(pal2 == inPal2); |
|
2420 |
} |
|
2421 |
} |
|
2422 |
} |
|
2423 |
||
2424 |
class SequentialBuffer : public QBuffer |
|
2425 |
{ |
|
2426 |
public: |
|
2427 |
SequentialBuffer(QByteArray *data) : QBuffer(data) { offset = 0; } |
|
2428 |
||
2429 |
bool isSequential() const { return true; } |
|
2430 |
bool seek(qint64 pos) { offset = pos; return QBuffer::seek(pos); } |
|
2431 |
qint64 pos() const { return qint64(offset); } |
|
2432 |
||
2433 |
protected: |
|
2434 |
qint64 readData(char *data, qint64 maxSize) |
|
2435 |
{ |
|
2436 |
qint64 ret = QBuffer::readData(data, maxSize); |
|
2437 |
offset += ret; |
|
2438 |
return ret; |
|
2439 |
} |
|
2440 |
||
2441 |
private: |
|
2442 |
int offset; |
|
2443 |
}; |
|
2444 |
||
2445 |
void tst_QDataStream::skipRawData_data() |
|
2446 |
{ |
|
2447 |
QTest::addColumn<QString>("deviceType"); |
|
2448 |
QTest::addColumn<QByteArray>("data"); |
|
2449 |
QTest::addColumn<int>("read"); |
|
2450 |
QTest::addColumn<int>("skip"); |
|
2451 |
QTest::addColumn<int>("skipped"); |
|
2452 |
QTest::addColumn<char>("expect"); |
|
2453 |
||
2454 |
QByteArray bigData; |
|
2455 |
bigData.fill('a', 20000); |
|
2456 |
bigData[10001] = 'x'; |
|
2457 |
||
2458 |
QTest::newRow("1") << QString("sequential") << QByteArray("abcdefghij") << 3 << 6 << 6 << 'j'; |
|
2459 |
QTest::newRow("2") << QString("random-access") << QByteArray("abcdefghij") << 3 << 6 << 6 << 'j'; |
|
2460 |
QTest::newRow("3") << QString("sequential") << bigData << 1 << 10000 << 10000 << 'x'; |
|
2461 |
QTest::newRow("4") << QString("random-access") << bigData << 1 << 10000 << 10000 << 'x'; |
|
2462 |
QTest::newRow("5") << QString("sequential") << bigData << 1 << 20000 << 19999 << '\0'; |
|
2463 |
QTest::newRow("6") << QString("random-access") << bigData << 1 << 20000 << 19999 << '\0'; |
|
2464 |
} |
|
2465 |
||
2466 |
void tst_QDataStream::skipRawData() |
|
2467 |
{ |
|
2468 |
QFETCH(QString, deviceType); |
|
2469 |
QFETCH(QByteArray, data); |
|
2470 |
QFETCH(int, read); |
|
2471 |
QFETCH(int, skip); |
|
2472 |
QFETCH(int, skipped); |
|
2473 |
QFETCH(char, expect); |
|
2474 |
qint8 dummy; |
|
2475 |
||
2476 |
QIODevice *dev = 0; |
|
2477 |
if (deviceType == "sequential") { |
|
2478 |
dev = new SequentialBuffer(&data); |
|
2479 |
} else if (deviceType == "random-access") { |
|
2480 |
dev = new QBuffer(&data); |
|
2481 |
} |
|
2482 |
QVERIFY(dev); |
|
2483 |
dev->open(QIODevice::ReadOnly); |
|
2484 |
||
2485 |
QDataStream in(dev); |
|
2486 |
for (int i = 0; i < read; ++i) |
|
2487 |
in >> dummy; |
|
2488 |
||
2489 |
QCOMPARE(in.skipRawData(skip), skipped); |
|
2490 |
in >> dummy; |
|
2491 |
QCOMPARE((char)dummy, expect); |
|
2492 |
||
2493 |
delete dev; |
|
2494 |
} |
|
2495 |
||
2496 |
#define TEST_qint(T, UT) \ |
|
2497 |
void tst_QDataStream::status_##T() \ |
|
2498 |
{ \ |
|
2499 |
QFETCH(QByteArray, bigEndianData); \ |
|
2500 |
QFETCH(QByteArray, littleEndianData); \ |
|
2501 |
QFETCH(int, expectedStatus); \ |
|
2502 |
QFETCH(qint64, expectedValue); \ |
|
2503 |
\ |
|
2504 |
{ \ |
|
2505 |
QDataStream stream(&bigEndianData, QIODevice::ReadOnly); \ |
|
2506 |
T i; \ |
|
2507 |
stream >> i; \ |
|
2508 |
QCOMPARE((int) stream.status(), expectedStatus); \ |
|
2509 |
QCOMPARE(i, (T) expectedValue); \ |
|
2510 |
} \ |
|
2511 |
{ \ |
|
2512 |
QDataStream stream(&bigEndianData, QIODevice::ReadOnly); \ |
|
2513 |
UT i; \ |
|
2514 |
stream >> i; \ |
|
2515 |
QCOMPARE((int) stream.status(), expectedStatus); \ |
|
2516 |
QCOMPARE((T) i, (T) expectedValue); \ |
|
2517 |
} \ |
|
2518 |
{ \ |
|
2519 |
QDataStream stream(&littleEndianData, QIODevice::ReadOnly); \ |
|
2520 |
stream.setByteOrder(QDataStream::LittleEndian); \ |
|
2521 |
T i; \ |
|
2522 |
stream >> i; \ |
|
2523 |
QCOMPARE((int) stream.status(), expectedStatus); \ |
|
2524 |
QCOMPARE(i, (T) expectedValue); \ |
|
2525 |
} \ |
|
2526 |
{ \ |
|
2527 |
QDataStream stream(&littleEndianData, QIODevice::ReadOnly); \ |
|
2528 |
stream.setByteOrder(QDataStream::LittleEndian); \ |
|
2529 |
UT i; \ |
|
2530 |
stream >> i; \ |
|
2531 |
QCOMPARE((int) stream.status(), expectedStatus); \ |
|
2532 |
QCOMPARE((T) i, (T) expectedValue); \ |
|
2533 |
} \ |
|
2534 |
} |
|
2535 |
||
2536 |
#define TEST_FLOAT(T) \ |
|
2537 |
void tst_QDataStream::status_##T() \ |
|
2538 |
{ \ |
|
2539 |
QFETCH(QByteArray, bigEndianData); \ |
|
2540 |
QFETCH(QByteArray, littleEndianData); \ |
|
2541 |
QFETCH(int, expectedStatus); \ |
|
2542 |
QFETCH(double, expectedValue); \ |
|
2543 |
\ |
|
2544 |
QDataStream::FloatingPointPrecision prec = sizeof(T) == sizeof(double) ? QDataStream::DoublePrecision : QDataStream::SinglePrecision; \ |
|
2545 |
\ |
|
2546 |
{ \ |
|
2547 |
QDataStream stream(&bigEndianData, QIODevice::ReadOnly); \ |
|
2548 |
stream.setFloatingPointPrecision(prec); \ |
|
2549 |
T i; \ |
|
2550 |
stream >> i; \ |
|
2551 |
QCOMPARE((int) stream.status(), expectedStatus); \ |
|
2552 |
QCOMPARE((float) i, (float) expectedValue); \ |
|
2553 |
} \ |
|
2554 |
{ \ |
|
2555 |
QDataStream stream(&littleEndianData, QIODevice::ReadOnly); \ |
|
2556 |
stream.setByteOrder(QDataStream::LittleEndian); \ |
|
2557 |
stream.setFloatingPointPrecision(prec); \ |
|
2558 |
T i; \ |
|
2559 |
stream >> i; \ |
|
2560 |
QCOMPARE((int) stream.status(), expectedStatus); \ |
|
2561 |
QCOMPARE((float) i, (float) expectedValue); \ |
|
2562 |
} \ |
|
2563 |
} |
|
2564 |
||
2565 |
void tst_QDataStream::status_qint8_data() |
|
2566 |
{ |
|
2567 |
QTest::addColumn<QByteArray>("bigEndianData"); |
|
2568 |
QTest::addColumn<QByteArray>("littleEndianData"); |
|
2569 |
QTest::addColumn<int>("expectedStatus"); |
|
2570 |
QTest::addColumn<qint64>("expectedValue"); |
|
2571 |
||
2572 |
// ok |
|
2573 |
QTest::newRow("0") << QByteArray(1, '\x0') << QByteArray(1, '\x0') << (int) QDataStream::Ok << qint64(0); |
|
2574 |
QTest::newRow("-1") << QByteArray(1, '\xff') << QByteArray(1, '\xff') << (int) QDataStream::Ok << qint64(-1); |
|
2575 |
QTest::newRow("1") << QByteArray(1, '\x01') << QByteArray(1, '\x01') << (int) QDataStream::Ok << qint64(1); |
|
2576 |
QTest::newRow("37") << QByteArray(1, '\x25') << QByteArray(1, '\x25') << (int) QDataStream::Ok << qint64(37); |
|
2577 |
QTest::newRow("37j") << QByteArray("\x25j") << QByteArray("\x25j") << (int) QDataStream::Ok << qint64(37); |
|
2578 |
||
2579 |
// past end |
|
2580 |
QTest::newRow("empty") << QByteArray() << QByteArray() << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2581 |
} |
|
2582 |
||
2583 |
TEST_qint(qint8, quint8) |
|
2584 |
||
2585 |
void tst_QDataStream::status_qint16_data() |
|
2586 |
{ |
|
2587 |
QTest::addColumn<QByteArray>("bigEndianData"); |
|
2588 |
QTest::addColumn<QByteArray>("littleEndianData"); |
|
2589 |
QTest::addColumn<int>("expectedStatus"); |
|
2590 |
QTest::addColumn<qint64>("expectedValue"); |
|
2591 |
||
2592 |
// ok |
|
2593 |
QTest::newRow("0") << QByteArray(2, '\x0') << QByteArray(2, '\x0') << (int) QDataStream::Ok << qint64(0); |
|
2594 |
QTest::newRow("-1") << QByteArray("\xff\xff", 2) << QByteArray("\xff\xff", 2) << (int) QDataStream::Ok << qint64(-1); |
|
2595 |
QTest::newRow("1") << QByteArray("\x00\x01", 2) << QByteArray("\x01\x00", 2) << (int) QDataStream::Ok << qint64(1); |
|
2596 |
QTest::newRow("37") << QByteArray("\x00\x25", 2) << QByteArray("\x25\x00", 2) << (int) QDataStream::Ok << qint64(37); |
|
2597 |
QTest::newRow("37j") << QByteArray("\x00\x25j", 3) << QByteArray("\x25\x00j", 3) << (int) QDataStream::Ok << qint64(37); |
|
2598 |
QTest::newRow("0x1234") << QByteArray("\x12\x34", 2) << QByteArray("\x34\x12", 2) << (int) QDataStream::Ok << qint64(0x1234); |
|
2599 |
||
2600 |
// past end |
|
2601 |
QTest::newRow("empty") << QByteArray() << QByteArray() << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2602 |
QTest::newRow("end 1") << QByteArray("", 1) << QByteArray("", 1) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2603 |
QTest::newRow("end 2") << QByteArray("\x25", 1) << QByteArray("\x25", 1) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2604 |
} |
|
2605 |
||
2606 |
TEST_qint(qint16, quint16) |
|
2607 |
||
2608 |
void tst_QDataStream::status_qint32_data() |
|
2609 |
{ |
|
2610 |
QTest::addColumn<QByteArray>("bigEndianData"); |
|
2611 |
QTest::addColumn<QByteArray>("littleEndianData"); |
|
2612 |
QTest::addColumn<int>("expectedStatus"); |
|
2613 |
QTest::addColumn<qint64>("expectedValue"); |
|
2614 |
||
2615 |
// ok |
|
2616 |
QTest::newRow("0") << QByteArray(4, '\x0') << QByteArray(4, '\x0') << (int) QDataStream::Ok << qint64(0); |
|
2617 |
QTest::newRow("-1") << QByteArray("\xff\xff\xff\xff", 4) << QByteArray("\xff\xff\xff\xff", 4) << (int) QDataStream::Ok << qint64(-1); |
|
2618 |
QTest::newRow("1") << QByteArray("\x00\x00\x00\x01", 4) << QByteArray("\x01\x00\x00\x00", 4) << (int) QDataStream::Ok << qint64(1); |
|
2619 |
QTest::newRow("37") << QByteArray("\x00\x00\x00\x25", 4) << QByteArray("\x25\x00\x00\x00", 4) << (int) QDataStream::Ok << qint64(37); |
|
2620 |
QTest::newRow("37j") << QByteArray("\x00\x00\x00\x25j", 5) << QByteArray("\x25\x00\x00\x00j", 5) << (int) QDataStream::Ok << qint64(37); |
|
2621 |
QTest::newRow("0x12345678") << QByteArray("\x12\x34\x56\x78", 4) << QByteArray("\x78\x56\x34\x12", 4) << (int) QDataStream::Ok << qint64(0x12345678); |
|
2622 |
||
2623 |
// past end |
|
2624 |
QTest::newRow("empty") << QByteArray() << QByteArray() << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2625 |
QTest::newRow("end 1") << QByteArray("", 1) << QByteArray("", 1) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2626 |
QTest::newRow("end 2") << QByteArray("\x25", 1) << QByteArray("\x25", 1) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2627 |
QTest::newRow("end 3") << QByteArray("11", 2) << QByteArray("11", 2) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2628 |
QTest::newRow("end 4") << QByteArray("111", 3) << QByteArray("111", 3) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2629 |
} |
|
2630 |
||
2631 |
TEST_qint(qint32, quint32) |
|
2632 |
||
2633 |
void tst_QDataStream::status_qint64_data() |
|
2634 |
{ |
|
2635 |
QTest::addColumn<QByteArray>("bigEndianData"); |
|
2636 |
QTest::addColumn<QByteArray>("littleEndianData"); |
|
2637 |
QTest::addColumn<int>("expectedStatus"); |
|
2638 |
QTest::addColumn<qint64>("expectedValue"); |
|
2639 |
||
2640 |
// ok |
|
2641 |
QTest::newRow("0") << QByteArray(8, '\x0') << QByteArray(8, '\x0') << (int) QDataStream::Ok << qint64(0); |
|
2642 |
QTest::newRow("-1") << QByteArray("\xff\xff\xff\xff\xff\xff\xff\xff", 8) << QByteArray("\xff\xff\xff\xff\xff\xff\xff\xff", 8) << (int) QDataStream::Ok << qint64(-1); |
|
2643 |
QTest::newRow("1") << QByteArray("\x00\x00\x00\x00\x00\x00\x00\x01", 8) << QByteArray("\x01\x00\x00\x00\x00\x00\x00\x00", 8) << (int) QDataStream::Ok << qint64(1); |
|
2644 |
QTest::newRow("37") << QByteArray("\x00\x00\x00\x00\x00\x00\x00\x25", 8) << QByteArray("\x25\x00\x00\x00\x00\x00\x00\x00", 8) << (int) QDataStream::Ok << qint64(37); |
|
2645 |
QTest::newRow("37j") << QByteArray("\x00\x00\x00\x00\x00\x00\x00\x25j", 9) << QByteArray("\x25\x00\x00\x00\x00\x00\x00\x00j", 9) << (int) QDataStream::Ok << qint64(37); |
|
2646 |
QTest::newRow("0x123456789ABCDEF0") << QByteArray("\x12\x34\x56\x78\x9a\xbc\xde\xf0", 8) << QByteArray("\xf0\xde\xbc\x9a\x78\x56\x34\x12", 8) << (int) QDataStream::Ok << (qint64)Q_INT64_C(0x123456789ABCDEF0); |
|
2647 |
||
2648 |
// past end |
|
2649 |
QTest::newRow("empty") << QByteArray() << QByteArray() << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2650 |
QTest::newRow("end 1") << QByteArray("", 1) << QByteArray("", 1) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2651 |
QTest::newRow("end 2") << QByteArray("\x25", 1) << QByteArray("\x25", 1) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2652 |
QTest::newRow("end 3") << QByteArray("11", 2) << QByteArray("11", 2) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2653 |
QTest::newRow("end 4") << QByteArray("111", 3) << QByteArray("111", 3) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2654 |
QTest::newRow("end 5") << QByteArray("1111", 4) << QByteArray("1111", 4) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2655 |
QTest::newRow("end 6") << QByteArray("11111", 5) << QByteArray("11111", 5) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2656 |
QTest::newRow("end 7") << QByteArray("111111", 6) << QByteArray("111111", 6) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2657 |
QTest::newRow("end 8") << QByteArray("1111111", 7) << QByteArray("1111111", 7) << (int) QDataStream::ReadPastEnd << qint64(0); |
|
2658 |
} |
|
2659 |
||
2660 |
TEST_qint(qint64, quint64) |
|
2661 |
||
2662 |
void tst_QDataStream::status_float_data() |
|
2663 |
{ |
|
2664 |
QTest::addColumn<QByteArray>("bigEndianData"); |
|
2665 |
QTest::addColumn<QByteArray>("littleEndianData"); |
|
2666 |
QTest::addColumn<int>("expectedStatus"); |
|
2667 |
QTest::addColumn<double>("expectedValue"); |
|
2668 |
||
2669 |
// ok |
|
2670 |
QTest::newRow("0") << QByteArray(4, '\0') << QByteArray(4, '\0') << (int) QDataStream::Ok << (double) 0.0; |
|
2671 |
QTest::newRow("-1") << QByteArray("\xbf\x80\x00\x00", 4) << QByteArray("\x00\x00\x80\xbf", 4) << (int) QDataStream::Ok << (double) -1; |
|
2672 |
QTest::newRow("1") << QByteArray("\x3f\x80\x00\x00", 4) << QByteArray("\x00\x00\x80\x3f", 4) << (int) QDataStream::Ok << (double) 1; |
|
2673 |
QTest::newRow("37") << QByteArray("\x42\x14\x00\x00", 4) << QByteArray("\x00\x00\x14\x42", 4) << (int) QDataStream::Ok << (double) 37; |
|
2674 |
QTest::newRow("37j") << QByteArray("\x42\x14\x00\x00j", 5) << QByteArray("\x00\x00\x14\x42j", 5) << (int) QDataStream::Ok << (double) 37; |
|
2675 |
QTest::newRow("3.14") << QByteArray("\x40\x48\xf5\xc3", 4) << QByteArray("\xc3\xf5\x48\x40", 4) << (int) QDataStream::Ok << (double) 3.14; |
|
2676 |
||
2677 |
// past end |
|
2678 |
QTest::newRow("empty") << QByteArray() << QByteArray() << (int) QDataStream::ReadPastEnd << double(0); |
|
2679 |
QTest::newRow("end 1") << QByteArray("", 1) << QByteArray("", 1) << (int) QDataStream::ReadPastEnd << double(0); |
|
2680 |
QTest::newRow("end 2") << QByteArray("\x25", 1) << QByteArray("\x25", 1) << (int) QDataStream::ReadPastEnd << double(0); |
|
2681 |
QTest::newRow("end 3") << QByteArray("11", 2) << QByteArray("11", 2) << (int) QDataStream::ReadPastEnd << double(0); |
|
2682 |
QTest::newRow("end 4") << QByteArray("111", 3) << QByteArray("111", 3) << (int) QDataStream::ReadPastEnd << double(0); |
|
2683 |
} |
|
2684 |
||
2685 |
TEST_FLOAT(float) |
|
2686 |
||
2687 |
void tst_QDataStream::status_double_data() |
|
2688 |
{ |
|
2689 |
QTest::addColumn<QByteArray>("bigEndianData"); |
|
2690 |
QTest::addColumn<QByteArray>("littleEndianData"); |
|
2691 |
QTest::addColumn<int>("expectedStatus"); |
|
2692 |
QTest::addColumn<double>("expectedValue"); |
|
2693 |
||
2694 |
// ok |
|
2695 |
QTest::newRow("0") << QByteArray("\x00\x00\x00\x00\x00\x00\x00\x00", 8) << QByteArray("\x00\x00\x00\x00\x00\x00\x00\x00", 8) << (int) QDataStream::Ok << (double) 0; |
|
2696 |
QTest::newRow("-1") << QByteArray("\xbf\xf0\x00\x00\x00\x00\x00\x00", 8) << QByteArray("\x00\x00\x00\x00\x00\x00\xf0\xbf", 8) << (int) QDataStream::Ok << (double) -1; |
|
2697 |
QTest::newRow("1") << QByteArray("\x3f\xf0\x00\x00\x00\x00\x00\x00", 8) << QByteArray("\x00\x00\x00\x00\x00\x00\xf0\x3f", 8) << (int) QDataStream::Ok << (double) 1; |
|
2698 |
QTest::newRow("37") << QByteArray("\x40\x42\x80\x00\x00\x00\x00\x00", 8) << QByteArray("\x00\x00\x00\x00\x00\x80\x42\x40", 8) << (int) QDataStream::Ok << (double) 37; |
|
2699 |
QTest::newRow("37j") << QByteArray("\x40\x42\x80\x00\x00\x00\x00\x00j", 9) << QByteArray("\x00\x00\x00\x00\x00\x80\x42\x40j", 9) << (int) QDataStream::Ok << (double) 37; |
|
2700 |
QTest::newRow("3.14") << QByteArray("\x40\x09\x1e\xb8\x60\x00\x00\x00", 8) << QByteArray("\x00\x00\x00\x60\xb8\x1e\x09\x40", 8) << (int) QDataStream::Ok << (double) 3.14; |
|
2701 |
QTest::newRow("1234.5678") << QByteArray("\x40\x93\x4a\x45\x6d\x5c\xfa\xad", 8) << QByteArray("\xad\xfa\x5c\x6d\x45\x4a\x93\x40", 8) << (int) QDataStream::Ok << (double) 1234.5678; |
|
2702 |
||
2703 |
// past end |
|
2704 |
QTest::newRow("empty") << QByteArray() << QByteArray() << (int) QDataStream::ReadPastEnd << double(0); |
|
2705 |
QTest::newRow("end 1") << QByteArray("", 1) << QByteArray("", 1) << (int) QDataStream::ReadPastEnd << double(0); |
|
2706 |
QTest::newRow("end 2") << QByteArray("\x25", 1) << QByteArray("\x25", 1) << (int) QDataStream::ReadPastEnd << double(0); |
|
2707 |
QTest::newRow("end 3") << QByteArray("11", 2) << QByteArray("11", 2) << (int) QDataStream::ReadPastEnd << double(0); |
|
2708 |
QTest::newRow("end 4") << QByteArray("111", 3) << QByteArray("111", 3) << (int) QDataStream::ReadPastEnd << double(0); |
|
2709 |
QTest::newRow("end 5") << QByteArray("1111", 4) << QByteArray("1111", 4) << (int) QDataStream::ReadPastEnd << double(0); |
|
2710 |
QTest::newRow("end 6") << QByteArray("11111", 5) << QByteArray("11111", 5) << (int) QDataStream::ReadPastEnd << double(0); |
|
2711 |
QTest::newRow("end 7") << QByteArray("111111", 6) << QByteArray("111111", 6) << (int) QDataStream::ReadPastEnd << double(0); |
|
2712 |
QTest::newRow("end 8") << QByteArray("1111111", 7) << QByteArray("1111111", 7) << (int) QDataStream::ReadPastEnd << double(0); |
|
2713 |
} |
|
2714 |
||
2715 |
TEST_FLOAT(double) |
|
2716 |
||
2717 |
void tst_QDataStream::status_charptr_QByteArray_data() |
|
2718 |
{ |
|
2719 |
QTest::addColumn<QByteArray>("data"); |
|
2720 |
QTest::addColumn<int>("expectedStatus"); |
|
2721 |
QTest::addColumn<QByteArray>("expectedString"); |
|
2722 |
||
2723 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
2724 |
#ifdef QT3_SUPPORT |
|
2725 |
QByteArray oneMbMinus1(1024 * 1024 - 1); |
|
2726 |
#else |
|
2727 |
QByteArray oneMbMinus1(1024 * 1024 - 1, '\0'); |
|
2728 |
#endif |
|
2729 |
for (int i = 0; i < oneMbMinus1.size(); ++i) |
|
2730 |
oneMbMinus1[i] = 0x1 | (8 * ((uchar)i / 9)); |
|
2731 |
QByteArray threeMbMinus1 = oneMbMinus1 + 'j' + oneMbMinus1 + 'k' + oneMbMinus1; |
|
2732 |
#endif |
|
2733 |
||
2734 |
// ok |
|
2735 |
QTest::newRow("size 0") << QByteArray("\x00\x00\x00\x00", 4) << (int) QDataStream::Ok << QByteArray(); |
|
2736 |
QTest::newRow("size 1") << QByteArray("\x00\x00\x00\x01j", 5) << (int) QDataStream::Ok << QByteArray("j"); |
|
2737 |
QTest::newRow("size 2") << QByteArray("\x00\x00\x00\x02jk", 6) << (int) QDataStream::Ok << QByteArray("jk"); |
|
2738 |
QTest::newRow("size 3") << QByteArray("\x00\x00\x00\x03jkl", 7) << (int) QDataStream::Ok << QByteArray("jkl"); |
|
2739 |
QTest::newRow("size 4") << QByteArray("\x00\x00\x00\x04jklm", 8) << (int) QDataStream::Ok << QByteArray("jklm"); |
|
2740 |
QTest::newRow("size 4j") << QByteArray("\x00\x00\x00\x04jklmj", 8) << (int) QDataStream::Ok << QByteArray("jklm"); |
|
2741 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
2742 |
QTest::newRow("size 1MB-1") << QByteArray("\x00\x0f\xff\xff", 4) + oneMbMinus1 + QByteArray("j") << (int) QDataStream::Ok << oneMbMinus1; |
|
2743 |
QTest::newRow("size 1MB") << QByteArray("\x00\x10\x00\x00", 4) + oneMbMinus1 + QByteArray("jkl") << (int) QDataStream::Ok << oneMbMinus1 + "j"; |
|
2744 |
QTest::newRow("size 1MB+1") << QByteArray("\x00\x10\x00\x01", 4) + oneMbMinus1 + QByteArray("jkl") << (int) QDataStream::Ok << oneMbMinus1 + "jk"; |
|
2745 |
QTest::newRow("size 3MB-1") << QByteArray("\x00\x2f\xff\xff", 4) + threeMbMinus1 + QByteArray("j") << (int) QDataStream::Ok << threeMbMinus1; |
|
2746 |
QTest::newRow("size 3MB") << QByteArray("\x00\x30\x00\x00", 4) + threeMbMinus1 + QByteArray("jkl") << (int) QDataStream::Ok << threeMbMinus1 + "j"; |
|
2747 |
QTest::newRow("size 3MB+1") << QByteArray("\x00\x30\x00\x01", 4) + threeMbMinus1 + QByteArray("jkl") << (int) QDataStream::Ok << threeMbMinus1 + "jk"; |
|
2748 |
#endif |
|
2749 |
||
2750 |
// past end |
|
2751 |
QTest::newRow("empty") << QByteArray() << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2752 |
QTest::newRow("trunclen 1") << QByteArray("x") << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2753 |
QTest::newRow("trunclen 2") << QByteArray("xx") << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2754 |
QTest::newRow("trunclen 3") << QByteArray("xxx") << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2755 |
QTest::newRow("truncdata 1") << QByteArray("xxxx") << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2756 |
QTest::newRow("truncdata 2") << QByteArray("xxxxyyyy") << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2757 |
QTest::newRow("badsize 1") << QByteArray("\x00\x00\x00\x01", 4) << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2758 |
QTest::newRow("badsize 2") << QByteArray("\x00\x00\x00\x02j", 5) << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2759 |
QTest::newRow("badsize 3") << QByteArray("\x00\x00\x00\x03jk", 6) << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2760 |
QTest::newRow("badsize 4") << QByteArray("\x00\x00\x00\x04jkl", 7) << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2761 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
2762 |
QTest::newRow("badsize 1MB") << QByteArray("\x00\x10\x00\x00", 4) + oneMbMinus1 << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2763 |
QTest::newRow("badsize 1MB+1") << QByteArray("\x00\x10\x00\x01", 4) + oneMbMinus1 + QByteArray("j") << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2764 |
QTest::newRow("badsize 3MB") << QByteArray("\x00\x30\x00\x00", 4) + threeMbMinus1 << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2765 |
QTest::newRow("badsize 3MB+1") << QByteArray("\x00\x30\x00\x01", 4) + threeMbMinus1 + QByteArray("j") << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2766 |
#endif |
|
2767 |
QTest::newRow("size -1") << QByteArray("\xff\xff\xff\xff", 4) << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2768 |
QTest::newRow("size -2") << QByteArray("\xff\xff\xff\xfe", 4) << (int) QDataStream::ReadPastEnd << QByteArray(); |
|
2769 |
} |
|
2770 |
||
2771 |
void tst_QDataStream::status_charptr_QByteArray() |
|
2772 |
{ |
|
2773 |
QFETCH(QByteArray, data); |
|
2774 |
QFETCH(int, expectedStatus); |
|
2775 |
QFETCH(QByteArray, expectedString); |
|
2776 |
||
2777 |
{ |
|
2778 |
QDataStream stream(&data, QIODevice::ReadOnly); |
|
2779 |
char *buf; |
|
2780 |
stream >> buf; |
|
2781 |
||
2782 |
QCOMPARE((int)qstrlen(buf), expectedString.size()); |
|
2783 |
QCOMPARE(QByteArray(buf), expectedString); |
|
2784 |
QCOMPARE(int(stream.status()), expectedStatus); |
|
2785 |
delete [] buf; |
|
2786 |
} |
|
2787 |
{ |
|
2788 |
QDataStream stream(&data, QIODevice::ReadOnly); |
|
2789 |
char *buf; |
|
2790 |
uint len; |
|
2791 |
stream.readBytes(buf, len); |
|
2792 |
||
2793 |
QCOMPARE((int)len, expectedString.size()); |
|
2794 |
QCOMPARE(QByteArray(buf, len), expectedString); |
|
2795 |
QCOMPARE(int(stream.status()), expectedStatus); |
|
2796 |
delete [] buf; |
|
2797 |
} |
|
2798 |
{ |
|
2799 |
QDataStream stream(&data, QIODevice::ReadOnly); |
|
2800 |
QByteArray buf; |
|
2801 |
stream >> buf; |
|
2802 |
||
2803 |
if (data.startsWith("\xff\xff\xff\xff")) { |
|
2804 |
// QByteArray, unlike 'char *', supports the null/empty distinction |
|
2805 |
QVERIFY(buf.isNull()); |
|
2806 |
} else { |
|
2807 |
QCOMPARE(buf.size(), expectedString.size()); |
|
2808 |
QCOMPARE(buf, expectedString); |
|
2809 |
QCOMPARE(int(stream.status()), expectedStatus); |
|
2810 |
} |
|
2811 |
} |
|
2812 |
} |
|
2813 |
||
2814 |
static QByteArray qstring2qbytearray(const QString &str) |
|
2815 |
{ |
|
2816 |
#ifdef QT3_SUPPORT |
|
2817 |
QByteArray ba(str.size() * 2); |
|
2818 |
#else |
|
2819 |
QByteArray ba(str.size() * 2 , '\0'); |
|
2820 |
#endif |
|
2821 |
for (int i = 0; i < str.size(); ++i) { |
|
2822 |
// BigEndian |
|
2823 |
ba[2 * i] = str[i].row(); |
|
2824 |
ba[2 * i + 1] = str[i].cell(); |
|
2825 |
} |
|
2826 |
return ba; |
|
2827 |
} |
|
2828 |
||
2829 |
void tst_QDataStream::status_QString_data() |
|
2830 |
{ |
|
2831 |
QTest::addColumn<QByteArray>("data"); |
|
2832 |
QTest::addColumn<int>("expectedStatus"); |
|
2833 |
QTest::addColumn<QString>("expectedString"); |
|
2834 |
||
2835 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
2836 |
QString oneMbMinus1; |
|
2837 |
oneMbMinus1.resize(1024 * 1024 - 1); |
|
2838 |
for (int i = 0; i < oneMbMinus1.size(); ++i) |
|
2839 |
oneMbMinus1[i] = 0x1 | (8 * ((uchar)i / 9)); |
|
2840 |
QString threeMbMinus1 = oneMbMinus1 + QChar('j') + oneMbMinus1 + QChar('k') + oneMbMinus1; |
|
2841 |
||
2842 |
QByteArray threeMbMinus1Data = qstring2qbytearray(threeMbMinus1); |
|
2843 |
QByteArray oneMbMinus1Data = qstring2qbytearray(oneMbMinus1); |
|
2844 |
#endif |
|
2845 |
||
2846 |
// ok |
|
2847 |
QTest::newRow("size 0") << QByteArray("\x00\x00\x00\x00", 4) << (int) QDataStream::Ok << QString(); |
|
2848 |
QTest::newRow("size 1") << QByteArray("\x00\x00\x00\x02\x00j", 6) << (int) QDataStream::Ok << QString("j"); |
|
2849 |
QTest::newRow("size 2") << QByteArray("\x00\x00\x00\x04\x00j\x00k", 8) << (int) QDataStream::Ok << QString("jk"); |
|
2850 |
QTest::newRow("size 3") << QByteArray("\x00\x00\x00\x06\x00j\x00k\x00l", 10) << (int) QDataStream::Ok << QString("jkl"); |
|
2851 |
QTest::newRow("size 4") << QByteArray("\x00\x00\x00\x08\x00j\x00k\x00l\x00m", 12) << (int) QDataStream::Ok << QString("jklm"); |
|
2852 |
QTest::newRow("size 4j") << QByteArray("\x00\x00\x00\x08\x00j\x00k\x00l\x00mjj", 14) << (int) QDataStream::Ok << QString("jklm"); |
|
2853 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
2854 |
QTest::newRow("size 1MB-1") << QByteArray("\x00\x1f\xff\xfe", 4) + oneMbMinus1Data + QByteArray("jj") << (int) QDataStream::Ok << oneMbMinus1; |
|
2855 |
QTest::newRow("size 1MB") << QByteArray("\x00\x20\x00\x00", 4) + oneMbMinus1Data + QByteArray("\x00j\x00k\x00l", 6) << (int) QDataStream::Ok << oneMbMinus1 + "j"; |
|
2856 |
QTest::newRow("size 1MB+1") << QByteArray("\x00\x20\x00\x02", 4) + oneMbMinus1Data + QByteArray("\x00j\x00k\x00l", 6) << (int) QDataStream::Ok << oneMbMinus1 + "jk"; |
|
2857 |
QTest::newRow("size 3MB-1") << QByteArray("\x00\x5f\xff\xfe", 4) + threeMbMinus1Data + QByteArray("jj") << (int) QDataStream::Ok << threeMbMinus1; |
|
2858 |
QTest::newRow("size 3MB") << QByteArray("\x00\x60\x00\x00", 4) + threeMbMinus1Data + QByteArray("\x00j\x00k\x00l", 6) << (int) QDataStream::Ok << threeMbMinus1 + "j"; |
|
2859 |
QTest::newRow("size 3MB+1") << QByteArray("\x00\x60\x00\x02", 4) + threeMbMinus1Data + QByteArray("\x00j\x00k\x00l", 6) << (int) QDataStream::Ok << threeMbMinus1 + "jk"; |
|
2860 |
#endif |
|
2861 |
||
2862 |
// past end |
|
2863 |
QTest::newRow("empty") << QByteArray() << (int) QDataStream::ReadPastEnd << QString(); |
|
2864 |
QTest::newRow("trunclen 1") << QByteArray("x") << (int) QDataStream::ReadPastEnd << QString(); |
|
2865 |
QTest::newRow("trunclen 2") << QByteArray("xx") << (int) QDataStream::ReadPastEnd << QString(); |
|
2866 |
QTest::newRow("trunclen 3") << QByteArray("xxx") << (int) QDataStream::ReadPastEnd << QString(); |
|
2867 |
QTest::newRow("truncdata 1") << QByteArray("xxxx") << (int) QDataStream::ReadPastEnd << QString(); |
|
2868 |
QTest::newRow("truncdata 2") << QByteArray("xxxxyyyy") << (int) QDataStream::ReadPastEnd << QString(); |
|
2869 |
QTest::newRow("badsize 1") << QByteArray("\x00\x00\x00\x02", 4) << (int) QDataStream::ReadPastEnd << QString(); |
|
2870 |
QTest::newRow("badsize 2") << QByteArray("\x00\x00\x00\x04jj", 6) << (int) QDataStream::ReadPastEnd << QString(); |
|
2871 |
QTest::newRow("badsize 3") << QByteArray("\x00\x00\x00\x06jjkk", 8) << (int) QDataStream::ReadPastEnd << QString(); |
|
2872 |
QTest::newRow("badsize 4") << QByteArray("\x00\x00\x00\x08jjkkll", 10) << (int) QDataStream::ReadPastEnd << QString(); |
|
2873 |
#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) |
|
2874 |
QTest::newRow("badsize 1MB") << QByteArray("\x00\x20\x00\x00", 4) + oneMbMinus1Data << (int) QDataStream::ReadPastEnd << QString(); |
|
2875 |
QTest::newRow("badsize 1MB+1") << QByteArray("\x00\x20\x00\x02", 4) + oneMbMinus1Data + QByteArray("j") << (int) QDataStream::ReadPastEnd << QString(); |
|
2876 |
QTest::newRow("badsize 3MB") << QByteArray("\x00\x60\x00\x00", 4) + threeMbMinus1Data << (int) QDataStream::ReadPastEnd << QString(); |
|
2877 |
QTest::newRow("badsize 3MB+1") << QByteArray("\x00\x60\x00\x02", 4) + threeMbMinus1Data + QByteArray("j") << (int) QDataStream::ReadPastEnd << QString(); |
|
2878 |
QTest::newRow("size -2") << QByteArray("\xff\xff\xff\xfe", 4) << (int) QDataStream::ReadPastEnd << QString(); |
|
2879 |
QTest::newRow("size MAX") << QByteArray("\x7f\xff\xff\xfe", 4) << (int) QDataStream::ReadPastEnd << QString(); |
|
2880 |
#endif |
|
2881 |
||
2882 |
// corrupt data |
|
2883 |
QTest::newRow("corrupt1") << QByteArray("yyyy") << (int) QDataStream::ReadCorruptData << QString(); |
|
2884 |
QTest::newRow("size -3") << QByteArray("\xff\xff\xff\xfd", 4) << (int) QDataStream::ReadCorruptData << QString(); |
|
2885 |
} |
|
2886 |
||
2887 |
void tst_QDataStream::status_QString() |
|
2888 |
{ |
|
2889 |
QFETCH(QByteArray, data); |
|
2890 |
QFETCH(int, expectedStatus); |
|
2891 |
QFETCH(QString, expectedString); |
|
2892 |
||
2893 |
QDataStream stream(&data, QIODevice::ReadOnly); |
|
2894 |
QString str; |
|
2895 |
stream >> str; |
|
2896 |
||
2897 |
QCOMPARE(str.size(), expectedString.size()); |
|
2898 |
QCOMPARE(str, expectedString); |
|
2899 |
QCOMPARE(int(stream.status()), expectedStatus); |
|
2900 |
} |
|
2901 |
||
2902 |
static QBitArray bitarray(const QString &str) |
|
2903 |
{ |
|
2904 |
QBitArray array(str.size()); |
|
2905 |
for (int i = 0; i < str.size(); ++i) |
|
2906 |
array[i] = (str[i] != '0'); |
|
2907 |
return array; |
|
2908 |
} |
|
2909 |
||
2910 |
void tst_QDataStream::status_QBitArray_data() |
|
2911 |
{ |
|
2912 |
QTest::addColumn<QByteArray>("data"); |
|
2913 |
QTest::addColumn<int>("expectedStatus"); |
|
2914 |
QTest::addColumn<QBitArray>("expectedString"); |
|
2915 |
||
2916 |
// ok |
|
2917 |
QTest::newRow("size 0") << QByteArray("\x00\x00\x00\x00", 4) << (int) QDataStream::Ok << QBitArray(); |
|
2918 |
QTest::newRow("size 1a") << QByteArray("\x00\x00\x00\x01\x00", 5) << (int) QDataStream::Ok << bitarray("0"); |
|
2919 |
QTest::newRow("size 1b") << QByteArray("\x00\x00\x00\x01\x01", 5) << (int) QDataStream::Ok << bitarray("1"); |
|
2920 |
QTest::newRow("size 2") << QByteArray("\x00\x00\x00\x02\x03", 5) << (int) QDataStream::Ok << bitarray("11"); |
|
2921 |
QTest::newRow("size 3") << QByteArray("\x00\x00\x00\x03\x07", 5) << (int) QDataStream::Ok << bitarray("111"); |
|
2922 |
QTest::newRow("size 4") << QByteArray("\x00\x00\x00\x04\x0f", 5) << (int) QDataStream::Ok << bitarray("1111"); |
|
2923 |
QTest::newRow("size 5") << QByteArray("\x00\x00\x00\x05\x1f", 5) << (int) QDataStream::Ok << bitarray("11111"); |
|
2924 |
QTest::newRow("size 6") << QByteArray("\x00\x00\x00\x06\x3f", 5) << (int) QDataStream::Ok << bitarray("111111"); |
|
2925 |
QTest::newRow("size 7a") << QByteArray("\x00\x00\x00\x07\x7f", 5) << (int) QDataStream::Ok << bitarray("1111111"); |
|
2926 |
QTest::newRow("size 7b") << QByteArray("\x00\x00\x00\x07\x7e", 5) << (int) QDataStream::Ok << bitarray("0111111"); |
|
2927 |
QTest::newRow("size 7c") << QByteArray("\x00\x00\x00\x07\x00", 5) << (int) QDataStream::Ok << bitarray("0000000"); |
|
2928 |
QTest::newRow("size 7d") << QByteArray("\x00\x00\x00\x07\x39", 5) << (int) QDataStream::Ok << bitarray("1001110"); |
|
2929 |
QTest::newRow("size 8") << QByteArray("\x00\x00\x00\x08\xff", 5) << (int) QDataStream::Ok << bitarray("11111111"); |
|
2930 |
QTest::newRow("size 9") << QByteArray("\x00\x00\x00\x09\xff\x01", 6) << (int) QDataStream::Ok << bitarray("111111111"); |
|
2931 |
QTest::newRow("size 15") << QByteArray("\x00\x00\x00\x0f\xff\x7f", 6) << (int) QDataStream::Ok << bitarray("111111111111111"); |
|
2932 |
QTest::newRow("size 16") << QByteArray("\x00\x00\x00\x10\xff\xff", 6) << (int) QDataStream::Ok << bitarray("1111111111111111"); |
|
2933 |
QTest::newRow("size 17") << QByteArray("\x00\x00\x00\x11\xff\xff\x01", 7) << (int) QDataStream::Ok << bitarray("11111111111111111"); |
|
2934 |
QTest::newRow("size 32") << QByteArray("\x00\x00\x00\x20\xff\xff\xff\xff", 8) << (int) QDataStream::Ok << bitarray("11111111111111111111111111111111"); |
|
2935 |
||
2936 |
// past end |
|
2937 |
QTest::newRow("empty") << QByteArray() << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2938 |
QTest::newRow("badsize 0a") << QByteArray("\x00", 1) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2939 |
QTest::newRow("badsize 0a") << QByteArray("\x00\x00", 2) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2940 |
QTest::newRow("badsize 0a") << QByteArray("\x00\x00\x00", 3) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2941 |
QTest::newRow("badsize 1") << QByteArray("\x00\x00\x00\x01", 4) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2942 |
QTest::newRow("badsize 2") << QByteArray("\x00\x00\x00\x02", 4) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2943 |
QTest::newRow("badsize 3") << QByteArray("\x00\x00\x00\x03", 4) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2944 |
QTest::newRow("badsize 7") << QByteArray("\x00\x00\x00\x04", 4) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2945 |
QTest::newRow("size 8") << QByteArray("\x00\x00\x00\x08", 4) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2946 |
QTest::newRow("size 9") << QByteArray("\x00\x00\x00\x09\xff", 5) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2947 |
QTest::newRow("size 15") << QByteArray("\x00\x00\x00\x0f\xff", 5) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2948 |
QTest::newRow("size 16") << QByteArray("\x00\x00\x00\x10\xff", 5) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2949 |
QTest::newRow("size 17") << QByteArray("\x00\x00\x00\x11\xff\xff", 6) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2950 |
QTest::newRow("size 32") << QByteArray("\x00\x00\x00\x20\xff\xff\xff", 7) << (int) QDataStream::ReadPastEnd << QBitArray(); |
|
2951 |
||
2952 |
// corrupt data |
|
2953 |
QTest::newRow("junk 1a") << QByteArray("\x00\x00\x00\x01\x02", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2954 |
QTest::newRow("junk 1b") << QByteArray("\x00\x00\x00\x01\x04", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2955 |
QTest::newRow("junk 1c") << QByteArray("\x00\x00\x00\x01\x08", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2956 |
QTest::newRow("junk 1d") << QByteArray("\x00\x00\x00\x01\x10", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2957 |
QTest::newRow("junk 1e") << QByteArray("\x00\x00\x00\x01\x20", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2958 |
QTest::newRow("junk 1f") << QByteArray("\x00\x00\x00\x01\x40", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2959 |
QTest::newRow("junk 1g") << QByteArray("\x00\x00\x00\x01\x80", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2960 |
QTest::newRow("junk 2") << QByteArray("\x00\x00\x00\x02\x04", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2961 |
QTest::newRow("junk 3") << QByteArray("\x00\x00\x00\x03\x08", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2962 |
QTest::newRow("junk 4") << QByteArray("\x00\x00\x00\x04\x10", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2963 |
QTest::newRow("junk 5") << QByteArray("\x00\x00\x00\x05\x20", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2964 |
QTest::newRow("junk 6") << QByteArray("\x00\x00\x00\x06\x40", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2965 |
QTest::newRow("junk 7") << QByteArray("\x00\x00\x00\x07\x80", 5) << (int) QDataStream::ReadCorruptData << QBitArray(); |
|
2966 |
} |
|
2967 |
||
2968 |
void tst_QDataStream::status_QBitArray() |
|
2969 |
{ |
|
2970 |
QFETCH(QByteArray, data); |
|
2971 |
QFETCH(int, expectedStatus); |
|
2972 |
QFETCH(QBitArray, expectedString); |
|
2973 |
||
2974 |
QDataStream stream(&data, QIODevice::ReadOnly); |
|
2975 |
QBitArray str; |
|
2976 |
stream >> str; |
|
2977 |
||
2978 |
QCOMPARE(int(stream.status()), expectedStatus); |
|
2979 |
QCOMPARE(str.size(), expectedString.size()); |
|
2980 |
QCOMPARE(str, expectedString); |
|
2981 |
} |
|
2982 |
||
2983 |
#define MAP_TEST(byteArray, expectedStatus, expectedHash) \ |
|
2984 |
{ \ |
|
2985 |
QByteArray ba = byteArray; \ |
|
2986 |
QDataStream stream(&ba, QIODevice::ReadOnly); \ |
|
2987 |
stream >> hash; \ |
|
2988 |
QCOMPARE((int)stream.status(), (int)expectedStatus); \ |
|
2989 |
QCOMPARE(hash.size(), expectedHash.size()); \ |
|
2990 |
QCOMPARE(hash, expectedHash); \ |
|
2991 |
} \ |
|
2992 |
{ \ |
|
2993 |
QByteArray ba = byteArray; \ |
|
2994 |
StringMap expectedMap; \ |
|
2995 |
StringHash::const_iterator it = expectedHash.constBegin(); \ |
|
2996 |
for (; it != expectedHash.constEnd(); ++it) \ |
|
2997 |
expectedMap.insert(it.key(), it.value()); \ |
|
2998 |
QDataStream stream(&ba, QIODevice::ReadOnly); \ |
|
2999 |
stream >> map; \ |
|
3000 |
QCOMPARE((int)stream.status(), (int)expectedStatus); \ |
|
3001 |
QCOMPARE(map.size(), expectedMap.size()); \ |
|
3002 |
QCOMPARE(map, expectedMap); \ |
|
3003 |
} |
|
3004 |
||
3005 |
void tst_QDataStream::status_QHash_QMap() |
|
3006 |
{ |
|
3007 |
typedef QHash<QString, QString> StringHash; |
|
3008 |
typedef QMap<QString, QString> StringMap; |
|
3009 |
StringHash hash; |
|
3010 |
StringMap map; |
|
3011 |
||
3012 |
StringHash hash1; |
|
3013 |
hash1.insert("", ""); |
|
3014 |
||
3015 |
StringHash hash2; |
|
3016 |
hash2.insert("J", "K"); |
|
3017 |
hash2.insert("L", "MN"); |
|
3018 |
||
3019 |
// ok |
|
3020 |
MAP_TEST(QByteArray("\x00\x00\x00\x00", 4), QDataStream::Ok, StringHash()); |
|
3021 |
MAP_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", 12), QDataStream::Ok, hash1); |
|
3022 |
MAP_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x02\x00J\x00\x00\x00\x02\x00K" |
|
3023 |
"\x00\x00\x00\x02\x00L\x00\x00\x00\x04\x00M\x00N", 30), QDataStream::Ok, hash2); |
|
3024 |
||
3025 |
// past end |
|
3026 |
MAP_TEST(QByteArray(), QDataStream::ReadPastEnd, StringHash()); |
|
3027 |
MAP_TEST(QByteArray("\x00", 1), QDataStream::ReadPastEnd, StringHash()); |
|
3028 |
MAP_TEST(QByteArray("\x00\x00", 2), QDataStream::ReadPastEnd, StringHash()); |
|
3029 |
MAP_TEST(QByteArray("\x00\x00\x00", 3), QDataStream::ReadPastEnd, StringHash()); |
|
3030 |
MAP_TEST(QByteArray("\x00\x00\x00\x01", 4), QDataStream::ReadPastEnd, StringHash()); |
|
3031 |
for (int i = 4; i < 12; ++i) { |
|
3032 |
MAP_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00", i), QDataStream::ReadPastEnd, StringHash()); |
|
3033 |
} |
|
3034 |
||
3035 |
// corrupt data |
|
3036 |
MAP_TEST(QByteArray("\x00\x00\x00\x01\x00\x00\x00\x01", 8), QDataStream::ReadCorruptData, StringHash()); |
|
3037 |
MAP_TEST(QByteArray("\x00\x00\x00\x02\x00\x00\x00\x01\x00J\x00\x00\x00\x01\x00K" |
|
3038 |
"\x00\x00\x00\x01\x00L\x00\x00\x00\x02\x00M\x00N", 30), QDataStream::ReadCorruptData, StringHash()); |
|
3039 |
} |
|
3040 |
||
3041 |
#define LIST_TEST(byteArray, expectedStatus, expectedList) \ |
|
3042 |
{ \ |
|
3043 |
QByteArray ba = byteArray; \ |
|
3044 |
QDataStream stream(&ba, QIODevice::ReadOnly); \ |
|
3045 |
stream >> list; \ |
|
3046 |
QCOMPARE((int)stream.status(), (int)expectedStatus); \ |
|
3047 |
QCOMPARE(list.size(), expectedList.size()); \ |
|
3048 |
QCOMPARE(list, expectedList); \ |
|
3049 |
} \ |
|
3050 |
{ \ |
|
3051 |
LinkedList expectedLinkedList; \ |
|
3052 |
for (int i = 0; i < expectedList.count(); ++i) \ |
|
3053 |
expectedLinkedList << expectedList.at(i); \ |
|
3054 |
QByteArray ba = byteArray; \ |
|
3055 |
QDataStream stream(&ba, QIODevice::ReadOnly); \ |
|
3056 |
stream >> linkedList; \ |
|
3057 |
QCOMPARE((int)stream.status(), (int)expectedStatus); \ |
|
3058 |
QCOMPARE(linkedList.size(), expectedLinkedList.size()); \ |
|
3059 |
QCOMPARE(linkedList, expectedLinkedList); \ |
|
3060 |
} \ |
|
3061 |
{ \ |
|
3062 |
Vector expectedVector; \ |
|
3063 |
for (int i = 0; i < expectedList.count(); ++i) \ |
|
3064 |
expectedVector << expectedList.at(i); \ |
|
3065 |
QByteArray ba = byteArray; \ |
|
3066 |
QDataStream stream(&ba, QIODevice::ReadOnly); \ |
|
3067 |
stream >> vector; \ |
|
3068 |
QCOMPARE((int)stream.status(), (int)expectedStatus); \ |
|
3069 |
QCOMPARE(vector.size(), expectedVector.size()); \ |
|
3070 |
QCOMPARE(vector, expectedVector); \ |
|
3071 |
} |
|
3072 |
||
3073 |
void tst_QDataStream::status_QLinkedList_QList_QVector() |
|
3074 |
{ |
|
3075 |
typedef QLinkedList<QString> LinkedList; |
|
3076 |
typedef QList<QString> List; |
|
3077 |
typedef QVector<QString> Vector; |
|
3078 |
LinkedList linkedList; |
|
3079 |
List list; |
|
3080 |
Vector vector; |
|
3081 |
||
3082 |
LIST_TEST(QByteArray(), QDataStream::ReadPastEnd, List()); |
|
3083 |
LIST_TEST(QByteArray("\x00\x00\x00\x00", 4), QDataStream::Ok, List()); |
|
3084 |
} |
|
3085 |
||
3086 |
void tst_QDataStream::streamToAndFromQByteArray() |
|
3087 |
{ |
|
3088 |
QByteArray data; |
|
3089 |
QDataStream in(&data, QIODevice::WriteOnly); |
|
3090 |
QDataStream out(&data, QIODevice::ReadOnly); |
|
3091 |
||
3092 |
quint32 x = 0xdeadbeef; |
|
3093 |
quint32 y; |
|
3094 |
in << x; |
|
3095 |
out >> y; |
|
3096 |
||
3097 |
QCOMPARE(y, x); |
|
3098 |
} |
|
3099 |
||
3100 |
void tst_QDataStream::streamRealDataTypes() |
|
3101 |
{ |
|
3102 |
// Generate QPicture from SVG. |
|
3103 |
QSvgRenderer renderer(svgFile); |
|
3104 |
QVERIFY(renderer.isValid()); |
|
3105 |
QPicture picture; |
|
3106 |
picture.setBoundingRect(QRect(QPoint(0, 0), renderer.defaultSize())); |
|
3107 |
QPainter painter(&picture); |
|
3108 |
renderer.render(&painter); |
|
3109 |
painter.end(); |
|
3110 |
||
3111 |
// Generate path |
|
3112 |
QPainterPath path; |
|
3113 |
path.lineTo(10, 0); |
|
3114 |
path.cubicTo(0, 0, 10, 10, 20, 20); |
|
3115 |
path.arcTo(4, 5, 6, 7, 8, 9); |
|
3116 |
path.quadTo(1, 2, 3, 4); |
|
3117 |
||
3118 |
QColor color(64, 64, 64); |
|
3119 |
color.setAlphaF(0.5); |
|
3120 |
QRadialGradient radialGradient(5, 6, 7, 8, 9); |
|
3121 |
QBrush radialBrush(radialGradient); |
|
3122 |
QConicalGradient conicalGradient(5, 6, 7); |
|
3123 |
QBrush conicalBrush(conicalGradient); |
|
3124 |
||
3125 |
for (int i = 0; i < 2; ++i) { |
|
3126 |
QFile file; |
|
3127 |
if (i == 0) { |
|
3128 |
file.setFileName(SRCDIR "datastream.q42"); |
|
3129 |
} else { |
|
3130 |
file.setFileName("datastream.tmp"); |
|
3131 |
||
3132 |
// Generate data |
|
3133 |
QVERIFY(file.open(QIODevice::WriteOnly)); |
|
3134 |
QDataStream stream(&file); |
|
3135 |
stream.setVersion(QDataStream::Qt_4_2); |
|
3136 |
stream << qreal(0) << qreal(1.0) << qreal(1.1) << qreal(3.14) << qreal(-3.14) << qreal(-1); |
|
3137 |
stream << QPointF(3, 5) << QRectF(-1, -2, 3, 4) << (QPolygonF() << QPointF(0, 0) << QPointF(1, 2)); |
|
3138 |
stream << QMatrix().rotate(90).scale(2, 2); |
|
3139 |
stream << path; |
|
3140 |
stream << picture; |
|
3141 |
stream << QTextLength(QTextLength::VariableLength, 1.5); |
|
3142 |
stream << color; |
|
3143 |
stream << radialBrush << conicalBrush; |
|
3144 |
stream << QPen(QBrush(Qt::red), 1.5); |
|
3145 |
||
3146 |
file.close(); |
|
3147 |
} |
|
3148 |
||
3149 |
QPointF point; |
|
3150 |
QRectF rect; |
|
3151 |
QPolygonF polygon; |
|
3152 |
QMatrix matrix; |
|
3153 |
QPainterPath p; |
|
3154 |
QPicture pict; |
|
3155 |
QTextLength textLength; |
|
3156 |
QColor col; |
|
3157 |
QBrush rGrad; |
|
3158 |
QBrush cGrad; |
|
3159 |
QPen pen; |
|
3160 |
||
3161 |
QVERIFY(file.open(QIODevice::ReadOnly)); |
|
3162 |
QDataStream stream(&file); |
|
3163 |
stream.setVersion(QDataStream::Qt_4_2); |
|
3164 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3165 |
if (i == 0) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3166 |
// the reference stream for 4.2 contains doubles, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3167 |
// so we must read them out as doubles! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3168 |
double a, b, c, d, e, f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3169 |
stream >> a; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3170 |
QCOMPARE(a, 0.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3171 |
stream >> b; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3172 |
QCOMPARE(b, 1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3173 |
stream >> c; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3174 |
QCOMPARE(c, 1.1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3175 |
stream >> d; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3176 |
QCOMPARE(d, 3.14); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3177 |
stream >> e; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3178 |
QCOMPARE(e, -3.14); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3179 |
stream >> f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3180 |
QCOMPARE(f, -1.0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3181 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3182 |
qreal a, b, c, d, e, f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3183 |
stream >> a; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3184 |
QCOMPARE(a, qreal(0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3185 |
stream >> b; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3186 |
QCOMPARE(b, qreal(1.0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3187 |
stream >> c; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3188 |
QCOMPARE(c, qreal(1.1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3189 |
stream >> d; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3190 |
QCOMPARE(d, qreal(3.14)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3191 |
stream >> e; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3192 |
QCOMPARE(e, qreal(-3.14)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3193 |
stream >> f; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3194 |
QCOMPARE(f, qreal(-1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3195 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3196 |
stream >> point; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3197 |
QCOMPARE(point, QPointF(3, 5)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3198 |
stream >> rect; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3199 |
QCOMPARE(rect, QRectF(-1, -2, 3, 4)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3200 |
stream >> polygon; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3201 |
QCOMPARE((QVector<QPointF> &)polygon, (QPolygonF() << QPointF(0, 0) << QPointF(1, 2))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3202 |
stream >> matrix; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3203 |
QCOMPARE(matrix, QMatrix().rotate(90).scale(2, 2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3204 |
stream >> p; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3205 |
QCOMPARE(p, path); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3206 |
if (i == 1) { |
0 | 3207 |
stream >> pict; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3208 |
|
0 | 3209 |
QByteArray pictA, pictB; |
3210 |
QBuffer bufA, bufB; |
|
3211 |
QVERIFY(bufA.open(QIODevice::ReadWrite)); |
|
3212 |
QVERIFY(bufB.open(QIODevice::ReadWrite)); |
|
3213 |
||
3214 |
picture.save(&bufA); |
|
3215 |
pict.save(&bufB); |
|
3216 |
||
3217 |
QCOMPARE(pictA, pictB); |
|
3218 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3219 |
stream >> textLength; |
0 | 3220 |
QCOMPARE(textLength, QTextLength(QTextLength::VariableLength, 1.5)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3221 |
stream >> col; |
0 | 3222 |
QCOMPARE(col, color); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3223 |
stream >> rGrad; |
0 | 3224 |
QCOMPARE(rGrad.style(), radialBrush.style()); |
3225 |
QCOMPARE(rGrad.matrix(), radialBrush.matrix()); |
|
3226 |
QCOMPARE(rGrad.gradient()->type(), radialBrush.gradient()->type()); |
|
3227 |
QCOMPARE(rGrad.gradient()->stops(), radialBrush.gradient()->stops()); |
|
3228 |
QCOMPARE(rGrad.gradient()->spread(), radialBrush.gradient()->spread()); |
|
3229 |
QCOMPARE(((QRadialGradient *)rGrad.gradient())->center(), ((QRadialGradient *)radialBrush.gradient())->center()); |
|
3230 |
QCOMPARE(((QRadialGradient *)rGrad.gradient())->focalPoint(), ((QRadialGradient *)radialBrush.gradient())->focalPoint()); |
|
3231 |
QCOMPARE(((QRadialGradient *)rGrad.gradient())->radius(), ((QRadialGradient *)radialBrush.gradient())->radius()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3232 |
stream >> cGrad; |
0 | 3233 |
QCOMPARE(cGrad.style(), conicalBrush.style()); |
3234 |
QCOMPARE(cGrad.matrix(), conicalBrush.matrix()); |
|
3235 |
QCOMPARE(cGrad.gradient()->type(), conicalBrush.gradient()->type()); |
|
3236 |
QCOMPARE(cGrad.gradient()->stops(), conicalBrush.gradient()->stops()); |
|
3237 |
QCOMPARE(cGrad.gradient()->spread(), conicalBrush.gradient()->spread()); |
|
3238 |
QCOMPARE(((QConicalGradient *)cGrad.gradient())->center(), ((QConicalGradient *)conicalBrush.gradient())->center()); |
|
3239 |
QCOMPARE(((QConicalGradient *)cGrad.gradient())->angle(), ((QConicalGradient *)conicalBrush.gradient())->angle()); |
|
3240 |
||
3241 |
QCOMPARE(cGrad, conicalBrush); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3242 |
stream >> pen; |
0 | 3243 |
QCOMPARE(pen.widthF(), qreal(1.5)); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3244 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3245 |
QCOMPARE(stream.status(), QDataStream::Ok); |
0 | 3246 |
} |
3247 |
} |
|
3248 |
||
3249 |
#ifdef QT3_SUPPORT |
|
3250 |
void tst_QDataStream::task_224283() |
|
3251 |
{ |
|
3252 |
static const char sdata[] = "\0\0\0\12" "123456789"; |
|
3253 |
QByteArray expected = QByteArray::fromRawData(sdata, sizeof sdata); // includes the NUL |
|
3254 |
Q3CString original = "123456789"; |
|
3255 |
||
3256 |
QByteArray data; |
|
3257 |
{ |
|
3258 |
QDataStream out(&data, QIODevice::WriteOnly); |
|
3259 |
out.setVersion(QDataStream::Qt_3_3); |
|
3260 |
out << original; |
|
3261 |
} |
|
3262 |
QCOMPARE(data, expected); |
|
3263 |
||
3264 |
{ |
|
3265 |
QDataStream in(data); |
|
3266 |
in.setVersion(QDataStream::Qt_3_3); |
|
3267 |
Q3CString s; |
|
3268 |
in >> s; |
|
3269 |
QVERIFY(s.length() == 9); |
|
3270 |
QCOMPARE(s, original); |
|
3271 |
} |
|
3272 |
} |
|
3273 |
#endif |
|
3274 |
||
3275 |
void tst_QDataStream::compatibility_Qt3() |
|
3276 |
{ |
|
3277 |
QByteArray ba("hello"); |
|
3278 |
QVariant var = ba; |
|
3279 |
const quint32 invalidColor = 0x49000000; |
|
3280 |
QByteArray stream; |
|
3281 |
{ |
|
3282 |
QDataStream out(&stream, QIODevice::WriteOnly); |
|
3283 |
out.setVersion(QDataStream::Qt_3_3); |
|
3284 |
out << var; |
|
3285 |
out << QColor(); |
|
3286 |
out << QColor(Qt::darkYellow); |
|
3287 |
out << QColor(Qt::darkCyan); |
|
3288 |
out << invalidColor; |
|
3289 |
} |
|
3290 |
{ |
|
3291 |
QDataStream in(stream); |
|
3292 |
in.setVersion(QDataStream::Qt_3_3); |
|
3293 |
||
3294 |
//task 196100 |
|
3295 |
quint32 type; |
|
3296 |
in >> type; |
|
3297 |
//29 is the type of a QByteArray in Qt3 |
|
3298 |
QCOMPARE(type, quint32(29)); |
|
3299 |
QByteArray ba2; |
|
3300 |
in >> ba2; |
|
3301 |
QCOMPARE(ba2, ba); |
|
3302 |
||
3303 |
//task196415 |
|
3304 |
quint32 color; |
|
3305 |
in >> color; |
|
3306 |
QCOMPARE(color, invalidColor); |
|
3307 |
in >> color; |
|
3308 |
QCOMPARE(color, QColor(Qt::darkYellow).rgb()); |
|
3309 |
QColor col; |
|
3310 |
in >> col; |
|
3311 |
QCOMPARE(col, QColor(Qt::darkCyan)); |
|
3312 |
in >> col; |
|
3313 |
QVERIFY(!col.isValid()); |
|
3314 |
} |
|
3315 |
{ |
|
3316 |
QLinearGradient gradient(QPointF(0,0), QPointF(1,1)); |
|
3317 |
gradient.setColorAt(0, Qt::red); |
|
3318 |
gradient.setColorAt(1, Qt::blue); |
|
3319 |
||
3320 |
QBrush brush(gradient); |
|
3321 |
QPalette palette; |
|
3322 |
palette.setBrush(QPalette::Button, brush); |
|
3323 |
palette.setColor(QPalette::Light, Qt::green); |
|
3324 |
||
3325 |
QByteArray stream; |
|
3326 |
{ |
|
3327 |
QDataStream out(&stream, QIODevice::WriteOnly); |
|
3328 |
out.setVersion(QDataStream::Qt_3_3); |
|
3329 |
out << palette; |
|
3330 |
out << brush; |
|
3331 |
} |
|
3332 |
QBrush in_brush; |
|
3333 |
QPalette in_palette; |
|
3334 |
{ |
|
3335 |
QDataStream in(stream); |
|
3336 |
in.setVersion(QDataStream::Qt_3_3); |
|
3337 |
in >> in_palette; |
|
3338 |
in >> in_brush; |
|
3339 |
} |
|
3340 |
QVERIFY(in_brush.style() == Qt::NoBrush); |
|
3341 |
QVERIFY(in_palette.brush(QPalette::Button).style() == Qt::NoBrush); |
|
3342 |
QVERIFY(in_palette.color(QPalette::Light) == Qt::green); |
|
3343 |
} |
|
3344 |
} |
|
3345 |
||
3346 |
void tst_QDataStream::compatibility_Qt2() |
|
3347 |
{ |
|
3348 |
QLinearGradient gradient(QPointF(0,0), QPointF(1,1)); |
|
3349 |
gradient.setColorAt(0, Qt::red); |
|
3350 |
gradient.setColorAt(1, Qt::blue); |
|
3351 |
||
3352 |
QBrush brush(gradient); |
|
3353 |
QPalette palette; |
|
3354 |
palette.setBrush(QPalette::Button, brush); |
|
3355 |
palette.setColor(QPalette::Light, Qt::green); |
|
3356 |
||
3357 |
QByteArray stream; |
|
3358 |
{ |
|
3359 |
QDataStream out(&stream, QIODevice::WriteOnly); |
|
3360 |
out.setVersion(QDataStream::Qt_2_1); |
|
3361 |
out << palette; |
|
3362 |
out << brush; |
|
3363 |
} |
|
3364 |
QBrush in_brush; |
|
3365 |
QPalette in_palette; |
|
3366 |
{ |
|
3367 |
QDataStream in(stream); |
|
3368 |
in.setVersion(QDataStream::Qt_2_1); |
|
3369 |
in >> in_palette; |
|
3370 |
in >> in_brush; |
|
3371 |
} |
|
3372 |
QVERIFY(in_brush.style() == Qt::NoBrush); |
|
3373 |
QVERIFY(in_palette.brush(QPalette::Button).style() == Qt::NoBrush); |
|
3374 |
QVERIFY(in_palette.color(QPalette::Light) == Qt::green); |
|
3375 |
} |
|
3376 |
||
3377 |
void tst_QDataStream::floatingPointPrecision() |
|
3378 |
{ |
|
3379 |
QByteArray ba; |
|
3380 |
{ |
|
3381 |
QDataStream stream(&ba, QIODevice::WriteOnly); |
|
3382 |
QCOMPARE(QDataStream::DoublePrecision, stream.floatingPointPrecision()); |
|
3383 |
||
3384 |
float f = 123.0f; |
|
3385 |
stream << f; |
|
3386 |
QCOMPARE(ba.size(), int(sizeof(double))); |
|
3387 |
||
3388 |
double d = 234.0; |
|
3389 |
stream << d; |
|
3390 |
QCOMPARE(ba.size(), int(sizeof(double)*2)); |
|
3391 |
||
3392 |
stream.setFloatingPointPrecision(QDataStream::SinglePrecision); |
|
3393 |
||
3394 |
f = 123.0f; |
|
3395 |
stream << f; |
|
3396 |
QCOMPARE(ba.size(), int(sizeof(double)*2 + sizeof(float))); |
|
3397 |
||
3398 |
d = 234.0; |
|
3399 |
stream << d; |
|
3400 |
QCOMPARE(ba.size(), int(sizeof(double)*2 + sizeof(float)*2)); |
|
3401 |
} |
|
3402 |
||
3403 |
{ |
|
3404 |
QDataStream stream(ba); |
|
3405 |
||
3406 |
float f = 0.0f; |
|
3407 |
stream >> f; |
|
3408 |
QCOMPARE(123.0f, f); |
|
3409 |
||
3410 |
double d = 0.0; |
|
3411 |
stream >> d; |
|
3412 |
QCOMPARE(234.0, d); |
|
3413 |
||
3414 |
f = 0.0f; |
|
3415 |
stream.setFloatingPointPrecision(QDataStream::SinglePrecision); |
|
3416 |
stream >> f; |
|
3417 |
QCOMPARE(123.0f, f); |
|
3418 |
||
3419 |
d = 0.0; |
|
3420 |
stream >> d; |
|
3421 |
QCOMPARE(234.0, d); |
|
3422 |
} |
|
3423 |
||
3424 |
} |
|
3425 |
||
3426 |
QTEST_MAIN(tst_QDataStream) |
|
3427 |
#include "tst_qdatastream.moc" |
|
3428 |