diff options
author | Robin Burchell <robin.burchell@jollamobile.com> | 2014-03-20 23:21:49 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-21 00:09:29 +0100 |
commit | aa578c4e296a3bf5117fd878fcac70d1c11bd255 (patch) | |
tree | 3ae73880b0054c99d645bdab3d1d5a043c51ac43 /tests/auto/shared | |
parent | 8f49f50a169db85401eb37daf4fe3a0fc3280603 (diff) |
TestHTTPServer: Make listening an explicit operation that reports failure.
Use this to print the error message when listening fails, and switch to always
stack allocating TestHTTPServer instances for easier cleanup.
Change-Id: I63b2bd38963b66611dc08a5c322615d91a91e675
Reviewed-by: John Brooks <john.brooks@dereferenced.net>
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Reviewed-by: Lorn Potter <lorn.potter@jollamobile.com>
Diffstat (limited to 'tests/auto/shared')
-rw-r--r-- | tests/auto/shared/testhttpserver.cpp | 15 | ||||
-rw-r--r-- | tests/auto/shared/testhttpserver.h | 5 |
2 files changed, 13 insertions, 7 deletions
diff --git a/tests/auto/shared/testhttpserver.cpp b/tests/auto/shared/testhttpserver.cpp index d3de584084..231f22b35b 100644 --- a/tests/auto/shared/testhttpserver.cpp +++ b/tests/auto/shared/testhttpserver.cpp @@ -71,7 +71,8 @@ slowFiles/slowMain.qml \endcode it can be added like this: \code -TestHTTPServer server(14445); +TestHTTPServer server; +QVERIFY2(server.listen(14445), qPrintable(server.errorString())); server.serveDirectory("disconnect", TestHTTPServer::Disconnect); server.serveDirectory("files"); server.serveDirectory("slowFiles", TestHTTPServer::Delay); @@ -87,17 +88,21 @@ The following request urls will then result in the appropriate action: \row \li http://localhost:14445/slowMain.qml \li slowMain.qml returned after 500ms \endtable */ -TestHTTPServer::TestHTTPServer(quint16 port) +TestHTTPServer::TestHTTPServer() : m_state(AwaitingHeader) { QObject::connect(&server, SIGNAL(newConnection()), this, SLOT(newConnection())); - server.listen(QHostAddress::LocalHost, port); } -bool TestHTTPServer::isValid() const +bool TestHTTPServer::listen(quint16 port) { - return server.isListening(); + return server.listen(QHostAddress::LocalHost, port); +} + +QString TestHTTPServer::errorString() const +{ + return server.errorString(); } bool TestHTTPServer::serveDirectory(const QString &dir, Mode mode) diff --git a/tests/auto/shared/testhttpserver.h b/tests/auto/shared/testhttpserver.h index ae7d137143..a71386ddec 100644 --- a/tests/auto/shared/testhttpserver.h +++ b/tests/auto/shared/testhttpserver.h @@ -51,9 +51,10 @@ class TestHTTPServer : public QObject { Q_OBJECT public: - TestHTTPServer(quint16 port); + TestHTTPServer(); - bool isValid() const; + bool listen(quint16 port); + QString errorString() const; enum Mode { Normal, Delay, Disconnect }; bool serveDirectory(const QString &, Mode = Normal); |