diff options
Diffstat (limited to 'tests/auto/gui/image/qpixmap/tst_qpixmap.cpp')
-rw-r--r-- | tests/auto/gui/image/qpixmap/tst_qpixmap.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index ee6b78397a..dd6d97043d 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -139,6 +139,12 @@ private slots: void fromImage_crash(); + void load(); + void loadFromData(); +#if !defined(QT_NO_DATASTREAM) + void loadFromDataStream(); +#endif + void fromData(); void loadFromDataNullValues(); @@ -1191,6 +1197,85 @@ void tst_QPixmap::transformed2() QVERIFY(lenientCompare(actual, expected)); } +void tst_QPixmap::load() +{ + const QString prefix = QFINDTESTDATA("images/"); + if (prefix.isEmpty()) + QFAIL("can not find images directory!"); + const QString filePath = prefix + QLatin1String("designer.png"); + + QPixmap dest(filePath); + QVERIFY(!dest.isNull()); + QVERIFY(!dest.load("image_that_does_not_exist.png")); + QVERIFY(dest.isNull()); + QVERIFY(dest.load(filePath)); + QVERIFY(!dest.isNull()); +} + +void tst_QPixmap::loadFromData() +{ + const QString prefix = QFINDTESTDATA("images/"); + if (prefix.isEmpty()) + QFAIL("can not find images directory!"); + const QString filePath = prefix + QLatin1String("designer.png"); + + QPixmap original(filePath); + QVERIFY(!original.isNull()); + + QByteArray ba; + { + QBuffer buf(&ba); + QVERIFY(buf.open(QIODevice::WriteOnly)); + QVERIFY(original.save(&buf, "BMP")); + } + QVERIFY(!ba.isEmpty()); + + QPixmap dest; + QVERIFY(dest.loadFromData(ba, "BMP")); + QVERIFY(!dest.isNull()); + + QCOMPARE(original, dest); + + QVERIFY(!dest.loadFromData(QByteArray())); + QVERIFY(dest.isNull()); +} + +#if !defined(QT_NO_DATASTREAM) +void tst_QPixmap::loadFromDataStream() +{ + const QString prefix = QFINDTESTDATA("images/"); + if (prefix.isEmpty()) + QFAIL("can not find images directory!"); + const QString filePath = prefix + QLatin1String("designer.png"); + + QPixmap original(filePath); + QVERIFY(!original.isNull()); + + QByteArray ba; + { + QDataStream s(&ba, QIODevice::WriteOnly); + s << original; + } + QVERIFY(!ba.isEmpty()); + + QPixmap dest; + { + QDataStream s(&ba, QIODevice::ReadOnly); + s >> dest; + } + QVERIFY(!dest.isNull()); + + QCOMPARE(original, dest); + + { + ba.clear(); + QDataStream s(&ba, QIODevice::ReadOnly); + s >> dest; + } + QVERIFY(dest.isNull()); +} +#endif // QT_NO_DATASTREAM + void tst_QPixmap::fromImage_crash() { QImage *img = new QImage(64, 64, QImage::Format_ARGB32_Premultiplied); |