diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2009-11-16 06:14:25 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2009-11-16 06:14:25 (GMT) |
commit | 6b0c2119fc87be3a512d312e8ddfd77d1aa3607b (patch) | |
tree | 1b622c78344569456bfc1c22e30450600d36766d /tests | |
parent | a172096d8b3ef3b4acacda5e769d3713d8dab651 (diff) | |
parent | 5e907741f941703731116f73a07da8dfdc482d36 (diff) | |
download | Qt-6b0c2119fc87be3a512d312e8ddfd77d1aa3607b.zip Qt-6b0c2119fc87be3a512d312e8ddfd77d1aa3607b.tar.gz Qt-6b0c2119fc87be3a512d312e8ddfd77d1aa3607b.tar.bz2 |
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qmlgraphicsloader/data/NoResize.qml (renamed from tests/auto/declarative/qmlgraphicsloader/NoResize.qml) | 0 | ||||
-rw-r--r-- | tests/auto/declarative/qmlgraphicsloader/data/Rect120x60.qml (renamed from tests/auto/declarative/qmlgraphicsloader/Rect120x60.qml) | 0 | ||||
-rw-r--r-- | tests/auto/declarative/qmlgraphicsloader/data/SetSourceComponent.qml (renamed from tests/auto/declarative/qmlgraphicsloader/SetSourceComponent.qml) | 0 | ||||
-rw-r--r-- | tests/auto/declarative/qmlgraphicsloader/data/SizeToItem.qml (renamed from tests/auto/declarative/qmlgraphicsloader/SizeToItem.qml) | 0 | ||||
-rw-r--r-- | tests/auto/declarative/qmlgraphicsloader/data/SizeToLoader.qml (renamed from tests/auto/declarative/qmlgraphicsloader/SizeToLoader.qml) | 0 | ||||
-rw-r--r-- | tests/auto/declarative/qmlgraphicsloader/qmlgraphicsloader.pro | 8 | ||||
-rw-r--r-- | tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp | 97 |
7 files changed, 78 insertions, 27 deletions
diff --git a/tests/auto/declarative/qmlgraphicsloader/NoResize.qml b/tests/auto/declarative/qmlgraphicsloader/data/NoResize.qml index cfbb55a..cfbb55a 100644 --- a/tests/auto/declarative/qmlgraphicsloader/NoResize.qml +++ b/tests/auto/declarative/qmlgraphicsloader/data/NoResize.qml diff --git a/tests/auto/declarative/qmlgraphicsloader/Rect120x60.qml b/tests/auto/declarative/qmlgraphicsloader/data/Rect120x60.qml index aa4b0c2..aa4b0c2 100644 --- a/tests/auto/declarative/qmlgraphicsloader/Rect120x60.qml +++ b/tests/auto/declarative/qmlgraphicsloader/data/Rect120x60.qml diff --git a/tests/auto/declarative/qmlgraphicsloader/SetSourceComponent.qml b/tests/auto/declarative/qmlgraphicsloader/data/SetSourceComponent.qml index 1db56c4..1db56c4 100644 --- a/tests/auto/declarative/qmlgraphicsloader/SetSourceComponent.qml +++ b/tests/auto/declarative/qmlgraphicsloader/data/SetSourceComponent.qml diff --git a/tests/auto/declarative/qmlgraphicsloader/SizeToItem.qml b/tests/auto/declarative/qmlgraphicsloader/data/SizeToItem.qml index b52fa03..b52fa03 100644 --- a/tests/auto/declarative/qmlgraphicsloader/SizeToItem.qml +++ b/tests/auto/declarative/qmlgraphicsloader/data/SizeToItem.qml diff --git a/tests/auto/declarative/qmlgraphicsloader/SizeToLoader.qml b/tests/auto/declarative/qmlgraphicsloader/data/SizeToLoader.qml index 1a107e1..1a107e1 100644 --- a/tests/auto/declarative/qmlgraphicsloader/SizeToLoader.qml +++ b/tests/auto/declarative/qmlgraphicsloader/data/SizeToLoader.qml diff --git a/tests/auto/declarative/qmlgraphicsloader/qmlgraphicsloader.pro b/tests/auto/declarative/qmlgraphicsloader/qmlgraphicsloader.pro index 8be8cdf..4837075 100644 --- a/tests/auto/declarative/qmlgraphicsloader/qmlgraphicsloader.pro +++ b/tests/auto/declarative/qmlgraphicsloader/qmlgraphicsloader.pro @@ -1,7 +1,11 @@ load(qttest_p4) -contains(QT_CONFIG,declarative): QT += declarative gui +contains(QT_CONFIG,declarative): QT += declarative gui network macx:CONFIG -= app_bundle -SOURCES += tst_qmlgraphicsloader.cpp +INCLUDEPATH += ../shared/ +HEADERS += ../shared/testhttpserver.h +SOURCES += tst_qmlgraphicsloader.cpp \ + ../shared/testhttpserver.cpp DEFINES += SRCDIR=\\\"$$PWD\\\" + diff --git a/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp b/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp index a88026b..a5f769e 100644 --- a/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp +++ b/tests/auto/declarative/qmlgraphicsloader/tst_qmlgraphicsloader.cpp @@ -42,6 +42,23 @@ #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcomponent.h> #include <private/qmlgraphicsloader_p.h> +#include "testhttpserver.h" + +#define SERVER_PORT 14445 + +inline QUrl TEST_FILE(const QString &filename) +{ + return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); +} + +#define TRY_WAIT(expr) \ + do { \ + for (int ii = 0; ii < 6; ++ii) { \ + if ((expr)) break; \ + QTest::qWait(50); \ + } \ + QVERIFY((expr)); \ + } while (false) class tst_QmlGraphicsLoader : public QObject @@ -60,23 +77,13 @@ private slots: void sizeLoaderToItem(); void sizeItemToLoader(); void noResize(); + void networkRequest(); + void failNetworkRequest(); private: QmlEngine engine; }; -/* -inline QUrl TEST_FILE(const QString &filename) -{ - QFileInfo fileInfo(__FILE__); - return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(filename)); -} - -inline QUrl TEST_FILE(const char *filename) -{ - return TEST_FILE(QLatin1String(filename)); -} -*/ tst_QmlGraphicsLoader::tst_QmlGraphicsLoader() { @@ -84,11 +91,11 @@ tst_QmlGraphicsLoader::tst_QmlGraphicsLoader() void tst_QmlGraphicsLoader::url() { - QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"Rect120x60.qml\" }"), QUrl("file://" SRCDIR "/")); + QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"Rect120x60.qml\" }"), TEST_FILE("")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); QVERIFY(loader->item()); - QVERIFY(loader->source() == QUrl("file://" SRCDIR "/Rect120x60.qml")); + QVERIFY(loader->source() == QUrl("file://" SRCDIR "/data/Rect120x60.qml")); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->status(), QmlGraphicsLoader::Ready); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); @@ -98,7 +105,7 @@ void tst_QmlGraphicsLoader::url() void tst_QmlGraphicsLoader::component() { - QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); + QmlComponent component(&engine, TEST_FILE("/SetSourceComponent.qml")); QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(component.create()); QVERIFY(item); @@ -114,9 +121,9 @@ void tst_QmlGraphicsLoader::component() void tst_QmlGraphicsLoader::invalidUrl() { - QTest::ignoreMessage(QtWarningMsg, "(:-1: File error for URL file://" SRCDIR "/IDontExist.qml) "); + QTest::ignoreMessage(QtWarningMsg, "(:-1: File error for URL file://" SRCDIR "/data/IDontExist.qml) "); - QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"IDontExist.qml\" }"), QUrl("file://" SRCDIR "/")); + QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"IDontExist.qml\" }"), TEST_FILE("")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); QVERIFY(loader->item() == 0); @@ -136,7 +143,7 @@ void tst_QmlGraphicsLoader::clear() " source: 'Rect120x60.qml'\n" " Timer { interval: 200; running: true; onTriggered: loader.source = '' }\n" " }") - , QUrl("file://" SRCDIR "/")); + , TEST_FILE("")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); QVERIFY(loader->item()); @@ -153,7 +160,7 @@ void tst_QmlGraphicsLoader::clear() delete loader; } { - QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); + QmlComponent component(&engine, TEST_FILE("/SetSourceComponent.qml")); QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(component.create()); QVERIFY(item); @@ -183,7 +190,7 @@ void tst_QmlGraphicsLoader::urlToComponent() " source: \"Rect120x60.qml\"\n" " Timer { interval: 100; running: true; onTriggered: loader.sourceComponent = myComp }\n" "}" ) - , QUrl("file://" SRCDIR "/")); + , TEST_FILE("")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QTest::qWait(500); QVERIFY(loader != 0); @@ -198,7 +205,7 @@ void tst_QmlGraphicsLoader::urlToComponent() void tst_QmlGraphicsLoader::componentToUrl() { - QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml")); + QmlComponent component(&engine, TEST_FILE("/SetSourceComponent.qml")); QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(component.create()); QVERIFY(item); @@ -208,7 +215,7 @@ void tst_QmlGraphicsLoader::componentToUrl() QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); - loader->setSource(QUrl("file://" SRCDIR "/Rect120x60.qml")); + loader->setSource(TEST_FILE("/Rect120x60.qml")); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); @@ -220,7 +227,7 @@ void tst_QmlGraphicsLoader::componentToUrl() void tst_QmlGraphicsLoader::sizeLoaderToItem() { - QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToItem.qml")); + QmlComponent component(&engine, TEST_FILE("/SizeToItem.qml")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); QVERIFY(loader->resizeMode() == QmlGraphicsLoader::SizeLoaderToItem); @@ -245,7 +252,7 @@ void tst_QmlGraphicsLoader::sizeLoaderToItem() void tst_QmlGraphicsLoader::sizeItemToLoader() { - QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToLoader.qml")); + QmlComponent component(&engine, TEST_FILE("/SizeToLoader.qml")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); QVERIFY(loader->resizeMode() == QmlGraphicsLoader::SizeItemToLoader); @@ -266,7 +273,7 @@ void tst_QmlGraphicsLoader::sizeItemToLoader() void tst_QmlGraphicsLoader::noResize() { - QmlComponent component(&engine, QUrl("file://" SRCDIR "/NoResize.qml")); + QmlComponent component(&engine, TEST_FILE("/NoResize.qml")); QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); QVERIFY(loader != 0); QCOMPARE(loader->width(), 200.0); @@ -278,6 +285,46 @@ void tst_QmlGraphicsLoader::noResize() QCOMPARE(rect->height(), 60.0); } +void tst_QmlGraphicsLoader::networkRequest() +{ + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + server.serveDirectory("data"); + + QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"http://127.0.0.1:14445/Rect120x60.qml\" }"), TEST_FILE("")); + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); + QVERIFY(loader != 0); + + TRY_WAIT(loader->status() == QmlGraphicsLoader::Ready); + + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1); + + delete loader; +} + +void tst_QmlGraphicsLoader::failNetworkRequest() +{ + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + server.serveDirectory("data"); + + QTest::ignoreMessage(QtWarningMsg, "(:-1: Network error for URL http://127.0.0.1:14445/IDontExist.qml) "); + + QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"http://127.0.0.1:14445/IDontExist.qml\" }"), TEST_FILE("")); + QmlGraphicsLoader *loader = qobject_cast<QmlGraphicsLoader*>(component.create()); + QVERIFY(loader != 0); + + TRY_WAIT(loader->status() == QmlGraphicsLoader::Error); + + QVERIFY(loader->item() == 0); + QCOMPARE(loader->progress(), 0.0); + QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 0); + + delete loader; +} + QTEST_MAIN(tst_QmlGraphicsLoader) #include "tst_qmlgraphicsloader.moc" |