summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlgraphicsborderimage
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2009-11-18 06:21:44 (GMT)
committerBea Lam <bea.lam@nokia.com>2009-11-18 06:21:44 (GMT)
commit1c719c4ea6abef35ccae67f6052d8baa74b4e2b3 (patch)
tree40288143420c302a7cd77a729c68ecfbc6c0e26f /tests/auto/declarative/qmlgraphicsborderimage
parente2dbda508f2a65e1ca8c31df6339b1bbec14e933 (diff)
downloadQt-1c719c4ea6abef35ccae67f6052d8baa74b4e2b3.zip
Qt-1c719c4ea6abef35ccae67f6052d8baa74b4e2b3.tar.gz
Qt-1c719c4ea6abef35ccae67f6052d8baa74b4e2b3.tar.bz2
Set state to QmlGraphicsBorderImage::Error if local file is not found,
and add more unit tests.
Diffstat (limited to 'tests/auto/declarative/qmlgraphicsborderimage')
-rw-r--r--tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro5
-rw-r--r--tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp124
2 files changed, 110 insertions, 19 deletions
diff --git a/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro b/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro
index 82da769..1f606e5 100644
--- a/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro
+++ b/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro
@@ -1,8 +1,9 @@
load(qttest_p4)
-contains(QT_CONFIG,declarative): QT += declarative gui
+contains(QT_CONFIG,declarative): QT += declarative gui network
macx:CONFIG -= app_bundle
-SOURCES += tst_qmlgraphicsborderimage.cpp
+HEADERS += ../shared/testhttpserver.h
+SOURCES += tst_qmlgraphicsborderimage.cpp ../shared/testhttpserver.cpp
# Define SRCDIR equal to test's source directory
DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp
index aa732c5..06a05dd 100644
--- a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp
+++ b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp
@@ -40,11 +40,32 @@
****************************************************************************/
#include <qtest.h>
#include <QTextDocument>
+#include <QTcpServer>
+#include <QTcpSocket>
+#include <QDir>
+
#include <QtDeclarative/qmlengine.h>
#include <QtDeclarative/qmlcomponent.h>
#include <private/qmlgraphicsborderimage_p.h>
#include <private/qmlgraphicsimagebase_p.h>
#include <private/qmlgraphicsscalegrid_p_p.h>
+#include <private/qmlgraphicsloader_p.h>
+
+#include "../shared/testhttpserver.h"
+
+
+#define SERVER_PORT 14445
+#define SERVER_ADDR "http://127.0.0.1:14445"
+
+#define TRY_WAIT(expr) \
+ do { \
+ for (int ii = 0; ii < 6; ++ii) { \
+ if ((expr)) break; \
+ QTest::qWait(50); \
+ } \
+ QVERIFY((expr)); \
+ } while (false)
+
class tst_qmlgraphicsborderimage : public QObject
@@ -55,11 +76,13 @@ public:
private slots:
void noSource();
- void simple();
+ void imageSource();
+ void imageSource_data();
void resized();
void smooth();
void tileModes();
- void sciFile();
+ void sciSource();
+ void sciSource_data();
void invalidSciFile();
private:
@@ -85,21 +108,53 @@ void tst_qmlgraphicsborderimage::noSource()
delete obj;
}
-void tst_qmlgraphicsborderimage::simple()
+void tst_qmlgraphicsborderimage::imageSource()
{
- QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\" }";
+ QFETCH(QString, source);
+ QFETCH(bool, remote);
+ QFETCH(bool, valid);
+
+ TestHTTPServer server(SERVER_PORT);
+ if (remote) {
+ QVERIFY(server.isValid());
+ server.serveDirectory(SRCDIR "/data");
+ }
+
+ QString componentStr = "import Qt 4.6\nBorderImage { source: \"" + source + "\" }";
QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://"));
QmlGraphicsBorderImage *obj = qobject_cast<QmlGraphicsBorderImage*>(component.create());
QVERIFY(obj != 0);
- QCOMPARE(obj->source(), QUrl("file://" SRCDIR "/data/colors.png"));
- QCOMPARE(obj->width(), 120.);
- QCOMPARE(obj->height(), 120.);
- QCOMPARE(obj->horizontalTileMode(), QmlGraphicsBorderImage::Stretch);
- QCOMPARE(obj->verticalTileMode(), QmlGraphicsBorderImage::Stretch);
+
+ if (remote)
+ TRY_WAIT(obj->status() == QmlGraphicsBorderImage::Loading);
+
+ QCOMPARE(obj->source(), remote ? source : QUrl::fromLocalFile(source));
+
+ if (valid) {
+ TRY_WAIT(obj->status() == QmlGraphicsBorderImage::Ready);
+ QCOMPARE(obj->width(), 120.);
+ QCOMPARE(obj->height(), 120.);
+ QCOMPARE(obj->horizontalTileMode(), QmlGraphicsBorderImage::Stretch);
+ QCOMPARE(obj->verticalTileMode(), QmlGraphicsBorderImage::Stretch);
+ } else {
+ TRY_WAIT(obj->status() == QmlGraphicsBorderImage::Error);
+ }
delete obj;
}
+void tst_qmlgraphicsborderimage::imageSource_data()
+{
+ QTest::addColumn<QString>("source");
+ QTest::addColumn<bool>("remote");
+ QTest::addColumn<bool>("valid");
+
+ QTest::newRow("local") << SRCDIR "/data/colors.png" << false << true;
+ QTest::newRow("local not found") << SRCDIR "/data/no-such-file.png" << false << false;
+ QTest::newRow("remote") << SERVER_ADDR "/colors.png" << true << true;
+ QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << true << false;
+}
+
void tst_qmlgraphicsborderimage::resized()
{
QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 300; height: 300 }";
@@ -157,24 +212,57 @@ void tst_qmlgraphicsborderimage::tileModes()
}
}
-void tst_qmlgraphicsborderimage::sciFile()
+void tst_qmlgraphicsborderimage::sciSource()
{
- QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors-round.sci\"; width: 300; height: 300 }";
+ QFETCH(QString, source);
+ QFETCH(bool, remote);
+ QFETCH(bool, valid);
+
+ TestHTTPServer server(SERVER_PORT);
+ if (remote) {
+ QVERIFY(server.isValid());
+ server.serveDirectory(SRCDIR "/data");
+ }
+
+ QString componentStr = "import Qt 4.6\nBorderImage { source: \"" + source + "\"; width: 300; height: 300 }";
QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://"));
QmlGraphicsBorderImage *obj = qobject_cast<QmlGraphicsBorderImage*>(component.create());
QVERIFY(obj != 0);
+
+ if (remote)
+ TRY_WAIT(obj->status() == QmlGraphicsBorderImage::Loading);
+
+ QCOMPARE(obj->source(), remote ? source : QUrl::fromLocalFile(source));
QCOMPARE(obj->width(), 300.);
QCOMPARE(obj->height(), 300.);
- QCOMPARE(obj->border()->left(), 10);
- QCOMPARE(obj->border()->top(), 20);
- QCOMPARE(obj->border()->right(), 30);
- QCOMPARE(obj->border()->bottom(), 40);
- QCOMPARE(obj->horizontalTileMode(), QmlGraphicsBorderImage::Round);
- QCOMPARE(obj->verticalTileMode(), QmlGraphicsBorderImage::Repeat);
+
+ if (valid) {
+ TRY_WAIT(obj->status() == QmlGraphicsBorderImage::Ready);
+ QCOMPARE(obj->border()->left(), 10);
+ QCOMPARE(obj->border()->top(), 20);
+ QCOMPARE(obj->border()->right(), 30);
+ QCOMPARE(obj->border()->bottom(), 40);
+ QCOMPARE(obj->horizontalTileMode(), QmlGraphicsBorderImage::Round);
+ QCOMPARE(obj->verticalTileMode(), QmlGraphicsBorderImage::Repeat);
+ } else {
+ TRY_WAIT(obj->status() == QmlGraphicsBorderImage::Error);
+ }
delete obj;
}
+void tst_qmlgraphicsborderimage::sciSource_data()
+{
+ QTest::addColumn<QString>("source");
+ QTest::addColumn<bool>("remote");
+ QTest::addColumn<bool>("valid");
+
+ QTest::newRow("local") << SRCDIR "/data/colors-round.sci" << false << true;
+ QTest::newRow("local not found") << SRCDIR "/data/no-such-file.sci" << false << false;
+ QTest::newRow("remote") << SERVER_ADDR "/colors-round.sci" << true << true;
+ QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.sci" << true << false;
+}
+
void tst_qmlgraphicsborderimage::invalidSciFile()
{
QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/invalid.sci\"; width: 300; height: 300 }";
@@ -190,6 +278,8 @@ void tst_qmlgraphicsborderimage::invalidSciFile()
delete obj;
}
+
+
QTEST_MAIN(tst_qmlgraphicsborderimage)
#include "tst_qmlgraphicsborderimage.moc"