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 --- .../quick/qquicktext/data/embeddedImagesRemote.qml | 2 +- .../qquicktext/data/embeddedImagesRemoteError.qml | 2 +- .../data/embeddedImagesRemoteRelative.qml | 2 +- tests/auto/quick/qquicktext/tst_qquicktext.cpp | 35 +++++++++++++++------- 4 files changed, 28 insertions(+), 13 deletions(-) (limited to 'tests/auto/quick/qquicktext') diff --git a/tests/auto/quick/qquicktext/data/embeddedImagesRemote.qml b/tests/auto/quick/qquicktext/data/embeddedImagesRemote.qml index 5d241f9231..8ae91876a3 100644 --- a/tests/auto/quick/qquicktext/data/embeddedImagesRemote.qml +++ b/tests/auto/quick/qquicktext/data/embeddedImagesRemote.qml @@ -2,5 +2,5 @@ import QtQuick 2.0 Text { textFormat: Text.RichText - text: "" + text: "" } diff --git a/tests/auto/quick/qquicktext/data/embeddedImagesRemoteError.qml b/tests/auto/quick/qquicktext/data/embeddedImagesRemoteError.qml index adeed8834d..9263fa40c2 100644 --- a/tests/auto/quick/qquicktext/data/embeddedImagesRemoteError.qml +++ b/tests/auto/quick/qquicktext/data/embeddedImagesRemoteError.qml @@ -2,5 +2,5 @@ import QtQuick 2.0 Text { textFormat: Text.RichText - text: "" + text: "" } diff --git a/tests/auto/quick/qquicktext/data/embeddedImagesRemoteRelative.qml b/tests/auto/quick/qquicktext/data/embeddedImagesRemoteRelative.qml index 2835d813db..583f0f9834 100644 --- a/tests/auto/quick/qquicktext/data/embeddedImagesRemoteRelative.qml +++ b/tests/auto/quick/qquicktext/data/embeddedImagesRemoteRelative.qml @@ -3,5 +3,5 @@ import QtQuick 2.0 Text { textFormat: Text.RichText text: "" - baseUrl: "http://127.0.0.1:14459/text.html" + baseUrl: serverBaseUrl + "/text.html" } diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 7453268f63..c26cf85b37 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -50,9 +50,6 @@ DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD) -#define SERVER_PORT 14459 -#define SERVER_ADDR "http://127.0.0.1:14459" - Q_DECLARE_METATYPE(QQuickText::TextFormat) QT_BEGIN_NAMESPACE @@ -2049,7 +2046,7 @@ void tst_qquicktext::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 Text: Error downloading " SERVER_ADDR "/notexists.png - server replied: Not found"; + << testFileUrl("embeddedImagesRemoteError.qml").toString()+":3:1: QML Text: Error downloading {{ServerBaseUrl}}/notexists.png - server replied: Not found"; QTest::newRow("remote") << testFileUrl("embeddedImagesRemoteRelative.qml") << ""; } @@ -2061,13 +2058,16 @@ void tst_qquicktext::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()); - QQuickView *view = new QQuickView(qmlfile); + QQuickView *view = new QQuickView; + view->rootContext()->setContextProperty(QStringLiteral("serverBaseUrl"), server.baseUrl()); + view->setSource(qmlfile); view->show(); view->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(view)); @@ -2777,22 +2777,33 @@ void tst_qquicktext::imgTagsBaseUrl_data() << 181.; QTest::newRow("absolute remote") - << QUrl(SERVER_ADDR "/images/heart200.png") + << QUrl("http://testserver/images/heart200.png") << QUrl() << QUrl() << 181.; QTest::newRow("relative remote base 1") << QUrl("images/heart200.png") - << QUrl(SERVER_ADDR "/") + << QUrl("http://testserver/") << testFileUrl("nonexistant/app.qml") << 181.; QTest::newRow("relative remote base 2") << QUrl("heart200.png") - << QUrl(SERVER_ADDR "/images/") + << QUrl("http://testserver/images/") << testFileUrl("nonexistant/app.qml") << 181.; } +static QUrl substituteTestServerUrl(const QUrl &serverUrl, const QUrl &testUrl) +{ + QUrl result = testUrl; + if (result.host() == QStringLiteral("testserver")) { + result.setScheme(serverUrl.scheme()); + result.setHost(serverUrl.host()); + result.setPort(serverUrl.port()); + } + return result; +} + void tst_qquicktext::imgTagsBaseUrl() { QFETCH(QUrl, src); @@ -2801,9 +2812,13 @@ void tst_qquicktext::imgTagsBaseUrl() QFETCH(qreal, imgHeight); TestHTTPServer server; - QVERIFY2(server.listen(SERVER_PORT), qPrintable(server.errorString())); + QVERIFY2(server.listen(), qPrintable(server.errorString())); server.serveDirectory(testFile("")); + src = substituteTestServerUrl(server.baseUrl(), src); + baseUrl = substituteTestServerUrl(server.baseUrl(), baseUrl); + contextUrl = substituteTestServerUrl(server.baseUrl(), contextUrl); + QByteArray baseUrlFragment; if (!baseUrl.isEmpty()) baseUrlFragment = "; baseUrl: \"" + baseUrl.toEncoded() + "\""; -- cgit v1.2.3