From 79d56651edc05133ebae13bb93733373b10380f9 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 22 Apr 2015 17:15:30 +0200 Subject: Prospective fix for flakey "network" related QML tests Replace hard-coded server ports with dynamically allocated ports. Change-Id: Iab8f9a88343a9f2c49af3cd700c954c13c3bf121 Reviewed-by: Frederik Gladhorn --- .../qquicktextedit/data/embeddedImagesRemote.qml | 3 +- .../data/embeddedImagesRemoteError.qml | 3 +- .../data/embeddedImagesRemoteRelative.qml | 3 +- .../quick/qquicktextedit/tst_qquicktextedit.cpp | 37 ++++++++++++++-------- 4 files changed, 29 insertions(+), 17 deletions(-) (limited to 'tests/auto/quick/qquicktextedit') diff --git a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemote.qml b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemote.qml index a823882692..6fc12edf35 100644 --- a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemote.qml +++ b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemote.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 TextEdit { + property string serverBaseUrl; textFormat: TextEdit.RichText - text: "" + text: "" } diff --git a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteError.qml b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteError.qml index c6172b68dc..7ac59e2db4 100644 --- a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteError.qml +++ b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteError.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 TextEdit { + property string serverBaseUrl; textFormat: TextEdit.RichText - text: "" + text: "" } diff --git a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteRelative.qml b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteRelative.qml index ee39e089ea..12894ec741 100644 --- a/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteRelative.qml +++ b/tests/auto/quick/qquicktextedit/data/embeddedImagesRemoteRelative.qml @@ -1,7 +1,8 @@ import QtQuick 2.0 TextEdit { + property string serverBaseUrl; textFormat: TextEdit.RichText text: "" - baseUrl: "http://127.0.0.1:42332/text.html" + baseUrl: serverBaseUrl + "/text.html" } diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index c61504ef99..c6c54a4e42 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -62,9 +62,6 @@ #include #endif -#define SERVER_PORT 42332 -#define SERVER_ADDR "http://localhost:42332" - Q_DECLARE_METATYPE(QQuickTextEdit::SelectionMode) Q_DECLARE_METATYPE(Qt::Key) DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD) @@ -2598,12 +2595,12 @@ void tst_qquicktextedit::cursorDelegate() void tst_qquicktextedit::remoteCursorDelegate() { TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); QQuickView view; - QQmlComponent component(view.engine(), QUrl(SERVER_ADDR "/RemoteCursor.qml")); + QQmlComponent component(view.engine(), server.url("/RemoteCursor.qml")); view.rootContext()->setContextProperty("contextDelegate", &component); view.setSource(testFileUrl("cursorTestRemote.qml")); @@ -2726,8 +2723,8 @@ void tst_qquicktextedit::delegateLoading_data() // import installed QTest::newRow("pass") << "cursorHttpTestPass.qml" << ""; - QTest::newRow("fail1") << "cursorHttpTestFail1.qml" << "http://localhost:42332/FailItem.qml: Remote host closed the connection"; - QTest::newRow("fail2") << "cursorHttpTestFail2.qml" << "http://localhost:42332/ErrItem.qml:4:5: Fungus is not a type"; + QTest::newRow("fail1") << "cursorHttpTestFail1.qml" << "{{ServerBaseUrl}}/FailItem.qml: Remote host closed the connection"; + QTest::newRow("fail2") << "cursorHttpTestFail2.qml" << "{{ServerBaseUrl}}/ErrItem.qml:4:5: Fungus is not a type"; } void tst_qquicktextedit::delegateLoading() @@ -2736,12 +2733,14 @@ void tst_qquicktextedit::delegateLoading() QFETCH(QString, error); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("httpfail"), TestHTTPServer::Disconnect); server.serveDirectory(testFile("httpslow"), TestHTTPServer::Delay); server.serveDirectory(testFile("http")); - QQuickView view(QUrl(QLatin1String(SERVER_ADDR "/") + qmlfile)); + error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString()); + + QQuickView view(server.url(qmlfile)); view.show(); view.requestActivate(); @@ -5221,8 +5220,8 @@ void tst_qquicktextedit::embeddedImages_data() QTest::newRow("local") << testFileUrl("embeddedImagesLocalRelative.qml") << ""; QTest::newRow("remote") << testFileUrl("embeddedImagesRemote.qml") << ""; QTest::newRow("remote-error") << testFileUrl("embeddedImagesRemoteError.qml") - << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML TextEdit: Error downloading http://127.0.0.1:42332/notexists.png - server replied: Not found"; - QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; + << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML TextEdit: Error downloading {{ServerBaseUrl}}/notexists.png - server replied: Not found"; + QTest::newRow("remote-relative") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; } void tst_qquicktextedit::embeddedImages() @@ -5231,16 +5230,26 @@ void tst_qquicktextedit::embeddedImages() QFETCH(QString, error); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("http")); + error.replace(QStringLiteral("{{ServerBaseUrl}}"), server.baseUrl().toString()); + if (!error.isEmpty()) QTest::ignoreMessage(QtWarningMsg, error.toLatin1()); QQmlComponent textComponent(&engine, qmlfile); - QQuickTextEdit *textObject = qobject_cast(textComponent.create()); - + QQuickTextEdit *textObject = qobject_cast(textComponent.beginCreate(engine.rootContext())); QVERIFY(textObject != 0); + + const int baseUrlPropertyIndex = textObject->metaObject()->indexOfProperty("serverBaseUrl"); + if (baseUrlPropertyIndex != -1) { + QMetaProperty prop = textObject->metaObject()->property(baseUrlPropertyIndex); + QVERIFY(prop.write(textObject, server.baseUrl().toString())); + } + + textComponent.completeCreate(); + QTRY_COMPARE(QQuickTextEditPrivate::get(textObject)->document->resourcesLoading(), 0); QPixmap pm(testFile("http/exists.png")); -- cgit v1.2.3