tests/auto/qdatastream/tst_qdatastream.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   318     QCOMPARE(QDataStream::ReadCorruptData, obj1.status());
   318     QCOMPARE(QDataStream::ReadCorruptData, obj1.status());
   319 }
   319 }
   320 
   320 
   321 tst_QDataStream::tst_QDataStream()
   321 tst_QDataStream::tst_QDataStream()
   322 {
   322 {
   323     svgFile = QLatin1String(SRCDIR) + QLatin1String("/") +
   323     svgFile = QLatin1String(SRCDIR SVGFILE);
   324               QLatin1String(SVGFILE);
       
   325 }
   324 }
   326 
   325 
   327 tst_QDataStream::~tst_QDataStream()
   326 tst_QDataStream::~tst_QDataStream()
   328 {
   327 {
   329     QFile::remove(QLatin1String("qdatastream.out"));
   328     QFile::remove(QLatin1String("qdatastream.out"));
  1459     QVERIFY(d12.size() == ref.size());
  1458     QVERIFY(d12.size() == ref.size());
  1460     QVERIFY(d12.isNull() == ref.isNull());
  1459     QVERIFY(d12.isNull() == ref.isNull());
  1461     QVERIFY(d12.width() == ref.width());
  1460     QVERIFY(d12.width() == ref.width());
  1462     QVERIFY(d12.height() == ref.height());
  1461     QVERIFY(d12.height() == ref.height());
  1463     QVERIFY(d12.depth() == ref.depth());
  1462     QVERIFY(d12.depth() == ref.depth());
  1464     QVERIFY(d12.numColors() == ref.numColors());
  1463     QVERIFY(d12.colorCount() == ref.colorCount());
  1465 #ifdef QT3_SUPPORT
  1464 #ifdef QT3_SUPPORT
  1466     QVERIFY(d12.hasAlphaBuffer() == ref.hasAlphaBuffer());
  1465     QVERIFY(d12.hasAlphaBuffer() == ref.hasAlphaBuffer());
  1467 #else
  1466 #else
  1468     QVERIFY(d12.hasAlphaChannel() == ref.hasAlphaChannel());
  1467     QVERIFY(d12.hasAlphaChannel() == ref.hasAlphaChannel());
  1469 #endif
  1468 #endif
  3098     QCOMPARE(y, x);
  3097     QCOMPARE(y, x);
  3099 }
  3098 }
  3100 
  3099 
  3101 void tst_QDataStream::streamRealDataTypes()
  3100 void tst_QDataStream::streamRealDataTypes()
  3102 {
  3101 {
  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.
  3102     // Generate QPicture from SVG.
  3120     QSvgRenderer renderer(svgFile);
  3103     QSvgRenderer renderer(svgFile);
  3121     QVERIFY(renderer.isValid());
  3104     QVERIFY(renderer.isValid());
  3122     QPicture picture;
  3105     QPicture picture;
  3123     picture.setBoundingRect(QRect(QPoint(0, 0), renderer.defaultSize()));
  3106     picture.setBoundingRect(QRect(QPoint(0, 0), renderer.defaultSize()));
  3161             stream << QPen(QBrush(Qt::red), 1.5);
  3144             stream << QPen(QBrush(Qt::red), 1.5);
  3162 
  3145 
  3163             file.close();
  3146             file.close();
  3164         }
  3147         }
  3165 
  3148 
  3166         qreal a, b, c, d, e, f;
       
  3167         QPointF point;
  3149         QPointF point;
  3168         QRectF rect;
  3150         QRectF rect;
  3169         QPolygonF polygon;
  3151         QPolygonF polygon;
  3170         QMatrix matrix;
  3152         QMatrix matrix;
  3171         QPainterPath p;
  3153         QPainterPath p;
  3178 
  3160 
  3179         QVERIFY(file.open(QIODevice::ReadOnly));
  3161         QVERIFY(file.open(QIODevice::ReadOnly));
  3180         QDataStream stream(&file);
  3162         QDataStream stream(&file);
  3181         stream.setVersion(QDataStream::Qt_4_2);
  3163         stream.setVersion(QDataStream::Qt_4_2);
  3182 
  3164 
  3183         stream >> a >> b >> c >> d >> e >> f >> point
  3165         if (i == 0) {
  3184                >> rect >> polygon >> matrix >> p;
  3166             // the reference stream for 4.2 contains doubles,
  3185         if (i == 1)
  3167             // so we must read them out as doubles!
       
  3168             double a, b, c, d, e, f;
       
  3169             stream >> a;
       
  3170             QCOMPARE(a, 0.0);
       
  3171             stream >> b;
       
  3172             QCOMPARE(b, 1.0);
       
  3173             stream >> c;
       
  3174             QCOMPARE(c, 1.1);
       
  3175             stream >> d;
       
  3176             QCOMPARE(d, 3.14);
       
  3177             stream >> e;
       
  3178             QCOMPARE(e, -3.14);
       
  3179             stream >> f;
       
  3180             QCOMPARE(f, -1.0);
       
  3181         } else {
       
  3182             qreal a, b, c, d, e, f;
       
  3183             stream >> a;
       
  3184             QCOMPARE(a, qreal(0));
       
  3185             stream >> b;
       
  3186             QCOMPARE(b, qreal(1.0));
       
  3187             stream >> c;
       
  3188             QCOMPARE(c, qreal(1.1));
       
  3189             stream >> d;
       
  3190             QCOMPARE(d, qreal(3.14));
       
  3191             stream >> e;
       
  3192             QCOMPARE(e, qreal(-3.14));
       
  3193             stream >> f;
       
  3194             QCOMPARE(f, qreal(-1));
       
  3195         }
       
  3196         stream >> point;
       
  3197         QCOMPARE(point, QPointF(3, 5));
       
  3198         stream >> rect;
       
  3199         QCOMPARE(rect, QRectF(-1, -2, 3, 4));
       
  3200         stream >> polygon;
       
  3201         QCOMPARE((QVector<QPointF> &)polygon, (QPolygonF() << QPointF(0, 0) << QPointF(1, 2)));
       
  3202         stream >> matrix;
       
  3203         QCOMPARE(matrix, QMatrix().rotate(90).scale(2, 2));
       
  3204         stream >> p;
       
  3205         QCOMPARE(p, path);
       
  3206         if (i == 1) {
  3186             stream >> pict;
  3207             stream >> pict;
  3187         stream >> textLength >> col >> rGrad >> cGrad
  3208 
  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;
  3209             QByteArray pictA, pictB;
  3206             QBuffer bufA, bufB;
  3210             QBuffer bufA, bufB;
  3207             QVERIFY(bufA.open(QIODevice::ReadWrite));
  3211             QVERIFY(bufA.open(QIODevice::ReadWrite));
  3208             QVERIFY(bufB.open(QIODevice::ReadWrite));
  3212             QVERIFY(bufB.open(QIODevice::ReadWrite));
  3209 
  3213 
  3210             picture.save(&bufA);
  3214             picture.save(&bufA);
  3211             pict.save(&bufB);
  3215             pict.save(&bufB);
  3212 
  3216 
  3213             QCOMPARE(pictA, pictB);
  3217             QCOMPARE(pictA, pictB);
  3214         }
  3218         }
       
  3219         stream >> textLength;
  3215         QCOMPARE(textLength, QTextLength(QTextLength::VariableLength, 1.5));
  3220         QCOMPARE(textLength, QTextLength(QTextLength::VariableLength, 1.5));
       
  3221         stream >> col;
  3216         QCOMPARE(col, color);
  3222         QCOMPARE(col, color);
       
  3223         stream >> rGrad;
  3217         QCOMPARE(rGrad.style(), radialBrush.style());
  3224         QCOMPARE(rGrad.style(), radialBrush.style());
  3218         QCOMPARE(rGrad.matrix(), radialBrush.matrix());
  3225         QCOMPARE(rGrad.matrix(), radialBrush.matrix());
  3219         QCOMPARE(rGrad.gradient()->type(), radialBrush.gradient()->type());
  3226         QCOMPARE(rGrad.gradient()->type(), radialBrush.gradient()->type());
  3220         QCOMPARE(rGrad.gradient()->stops(), radialBrush.gradient()->stops());
  3227         QCOMPARE(rGrad.gradient()->stops(), radialBrush.gradient()->stops());
  3221         QCOMPARE(rGrad.gradient()->spread(), radialBrush.gradient()->spread());
  3228         QCOMPARE(rGrad.gradient()->spread(), radialBrush.gradient()->spread());
  3222         QCOMPARE(((QRadialGradient *)rGrad.gradient())->center(), ((QRadialGradient *)radialBrush.gradient())->center());
  3229         QCOMPARE(((QRadialGradient *)rGrad.gradient())->center(), ((QRadialGradient *)radialBrush.gradient())->center());
  3223         QCOMPARE(((QRadialGradient *)rGrad.gradient())->focalPoint(), ((QRadialGradient *)radialBrush.gradient())->focalPoint());
  3230         QCOMPARE(((QRadialGradient *)rGrad.gradient())->focalPoint(), ((QRadialGradient *)radialBrush.gradient())->focalPoint());
  3224         QCOMPARE(((QRadialGradient *)rGrad.gradient())->radius(), ((QRadialGradient *)radialBrush.gradient())->radius());
  3231         QCOMPARE(((QRadialGradient *)rGrad.gradient())->radius(), ((QRadialGradient *)radialBrush.gradient())->radius());
       
  3232         stream >> cGrad;
  3225         QCOMPARE(cGrad.style(), conicalBrush.style());
  3233         QCOMPARE(cGrad.style(), conicalBrush.style());
  3226         QCOMPARE(cGrad.matrix(), conicalBrush.matrix());
  3234         QCOMPARE(cGrad.matrix(), conicalBrush.matrix());
  3227         QCOMPARE(cGrad.gradient()->type(), conicalBrush.gradient()->type());
  3235         QCOMPARE(cGrad.gradient()->type(), conicalBrush.gradient()->type());
  3228         QCOMPARE(cGrad.gradient()->stops(), conicalBrush.gradient()->stops());
  3236         QCOMPARE(cGrad.gradient()->stops(), conicalBrush.gradient()->stops());
  3229         QCOMPARE(cGrad.gradient()->spread(), conicalBrush.gradient()->spread());
  3237         QCOMPARE(cGrad.gradient()->spread(), conicalBrush.gradient()->spread());
  3230         QCOMPARE(((QConicalGradient *)cGrad.gradient())->center(), ((QConicalGradient *)conicalBrush.gradient())->center());
  3238         QCOMPARE(((QConicalGradient *)cGrad.gradient())->center(), ((QConicalGradient *)conicalBrush.gradient())->center());
  3231         QCOMPARE(((QConicalGradient *)cGrad.gradient())->angle(), ((QConicalGradient *)conicalBrush.gradient())->angle());
  3239         QCOMPARE(((QConicalGradient *)cGrad.gradient())->angle(), ((QConicalGradient *)conicalBrush.gradient())->angle());
  3232 
  3240 
  3233         QCOMPARE(cGrad, conicalBrush);
  3241         QCOMPARE(cGrad, conicalBrush);
       
  3242         stream >> pen;
  3234         QCOMPARE(pen.widthF(), qreal(1.5));
  3243         QCOMPARE(pen.widthF(), qreal(1.5));
  3235     }
  3244 
  3236 #if defined(Q_OS_SYMBIAN)
  3245         QCOMPARE(stream.status(), QDataStream::Ok);
  3237     #undef qreal
  3246     }
  3238 #endif
       
  3239 }
  3247 }
  3240 
  3248 
  3241 #ifdef QT3_SUPPORT
  3249 #ifdef QT3_SUPPORT
  3242 void tst_QDataStream::task_224283()
  3250 void tst_QDataStream::task_224283()
  3243 {
  3251 {