summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp')
-rw-r--r--tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp84
1 files changed, 76 insertions, 8 deletions
diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
index ed2095b..ec9f4ec 100644
--- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
+++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
@@ -82,6 +82,8 @@ private slots:
void resized();
void smooth();
void pixmap();
+ void svg();
+ void big();
private:
QDeclarativeEngine engine;
@@ -111,24 +113,29 @@ void tst_qdeclarativeimage::noSource()
void tst_qdeclarativeimage::imageSource_data()
{
QTest::addColumn<QString>("source");
+ QTest::addColumn<qreal>("width");
+ QTest::addColumn<qreal>("height");
QTest::addColumn<bool>("remote");
QTest::addColumn<bool>("async");
QTest::addColumn<QString>("error");
- QTest::newRow("local") << QUrl::fromLocalFile(SRCDIR "/data/colors.png").toString() << false << false << "";
- QTest::newRow("local async") << QUrl::fromLocalFile(SRCDIR "/data/colors1.png").toString() << false << true << "";
- QTest::newRow("local not found") << QUrl::fromLocalFile(SRCDIR "/data/no-such-file.png").toString() << false
+ QTest::newRow("local") << QUrl::fromLocalFile(SRCDIR "/data/colors.png").toString() << 120.0 << 120.0 << false << false << "";
+ QTest::newRow("local async") << QUrl::fromLocalFile(SRCDIR "/data/colors1.png").toString() << 120.0 << 120.0 << false << true << "";
+ QTest::newRow("local not found") << QUrl::fromLocalFile(SRCDIR "/data/no-such-file.png").toString() << 0.0 << 0.0 << false
<< false << "Cannot open QUrl( \"" + QUrl::fromLocalFile(SRCDIR "/data/no-such-file.png").toString() + "\" ) ";
- QTest::newRow("local async not found") << QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString() << false
+ QTest::newRow("local async not found") << QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString() << 0.0 << 0.0 << false
<< true << "\"Cannot open: " + QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString() + "\" ";
- QTest::newRow("remote") << SERVER_ADDR "/colors.png" << true << false << "";
- QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << true << false
+ QTest::newRow("remote") << SERVER_ADDR "/colors.png" << 120.0 << 120.0 << true << false << "";
+ QTest::newRow("remote svg") << SERVER_ADDR "/heart.svg" << 550.0 << 500.0 << true << false << "";
+ QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << 0.0 << 0.0 << true << false
<< "\"Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found\" ";
}
void tst_qdeclarativeimage::imageSource()
{
QFETCH(QString, source);
+ QFETCH(qreal, width);
+ QFETCH(qreal, height);
QFETCH(bool, remote);
QFETCH(bool, async);
QFETCH(QString, error);
@@ -148,6 +155,9 @@ void tst_qdeclarativeimage::imageSource()
component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create());
QVERIFY(obj != 0);
+
+ if (async)
+ QVERIFY(obj->asynchronous() == true);
if (remote || async)
TRY_WAIT(obj->status() == QDeclarativeImage::Loading);
@@ -156,8 +166,8 @@ void tst_qdeclarativeimage::imageSource()
if (error.isEmpty()) {
TRY_WAIT(obj->status() == QDeclarativeImage::Ready);
- QCOMPARE(obj->width(), 120.);
- QCOMPARE(obj->height(), 120.);
+ QCOMPARE(obj->width(), width);
+ QCOMPARE(obj->height(), height);
QCOMPARE(obj->fillMode(), QDeclarativeImage::Stretch);
QCOMPARE(obj->progress(), 1.0);
} else {
@@ -248,6 +258,64 @@ void tst_qdeclarativeimage::pixmap()
delete obj;
}
+void tst_qdeclarativeimage::svg()
+{
+ QString src = QUrl::fromLocalFile(SRCDIR "/data/heart.svg").toString();
+ QString componentStr = "import Qt 4.6\nImage { source: \"" + src + "\"; sourceSize.width: 300; sourceSize.height: 300 }";
+ QDeclarativeComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create());
+ QVERIFY(obj != 0);
+ QCOMPARE(obj->pixmap().width(), 300);
+ QCOMPARE(obj->pixmap().height(), 300);
+ QCOMPARE(obj->width(), 550.0);
+ QCOMPARE(obj->height(), 500.0);
+#if defined(Q_OS_MAC)
+ QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart-mac.png"));
+#elif defined(Q_OS_WIN32)
+ QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart-win32.png"));
+#else
+ QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png"));
+#endif
+
+ obj->setSourceSize(QSize(200,200));
+
+ QCOMPARE(obj->pixmap().width(), 200);
+ QCOMPARE(obj->pixmap().height(), 200);
+ QCOMPARE(obj->width(), 550.0);
+ QCOMPARE(obj->height(), 500.0);
+#if defined(Q_OS_MAC)
+ QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart200-mac.png"));
+#elif defined(Q_OS_WIN32)
+ QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart200-win32.png"));
+#else
+ QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart200.png"));
+#endif
+ delete obj;
+}
+
+void tst_qdeclarativeimage::big()
+{
+ // If the JPEG loader does not implement scaling efficiently, it would
+ // have to build a 400 MB image. That would be a bug in the JPEG loader.
+
+ QString src = QUrl::fromLocalFile(SRCDIR "/data/big.jpeg").toString();
+ QString componentStr = "import Qt 4.6\nImage { source: \"" + src + "\"; sourceSize.width: 256; sourceSize.height: 256 }";
+
+ QDeclarativeComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create());
+ QVERIFY(obj != 0);
+ QCOMPARE(obj->pixmap().width(), 256);
+ QCOMPARE(obj->pixmap().height(), 256);
+ QCOMPARE(obj->width(), 10240.0);
+ QCOMPARE(obj->height(), 10240.0);
+ QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/big256.png"));
+
+ delete obj;
+}
+
+
QTEST_MAIN(tst_qdeclarativeimage)
#include "tst_qdeclarativeimage.moc"