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