aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/shared/testhttpserver.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-09-25 10:30:59 +0200
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-10-14 08:03:38 +0000
commit35da68a15c12586415484def802839e67372eac1 (patch)
tree76639f2eba2999e519511d51a42c8693b4f27299 /tests/auto/shared/testhttpserver.h
parent9e15fb156a0ef58584661a0599f1f85d7597e87c (diff)
Provide a threaded TestHTTPServer
This allows us to do blocking operations that interact with the test server in the main thread. The threaded server is used in tests that don't explicitly require asynchronous operation. Change-Id: Ibcb28e79a1114cb9cfb812e86aae0a1af71c569e Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests/auto/shared/testhttpserver.h')
-rw-r--r--tests/auto/shared/testhttpserver.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/shared/testhttpserver.h b/tests/auto/shared/testhttpserver.h
index 0fc8e4a79c..bf826b247b 100644
--- a/tests/auto/shared/testhttpserver.h
+++ b/tests/auto/shared/testhttpserver.h
@@ -37,6 +37,9 @@
#include <QTcpServer>
#include <QUrl>
#include <QPair>
+#include <QThread>
+#include <QMutex>
+#include <QWaitCondition>
class TestHTTPServer : public QObject
{
@@ -45,6 +48,7 @@ public:
TestHTTPServer();
bool listen();
+ quint16 port() const;
QUrl baseUrl() const;
QUrl url(const QString &documentPath) const;
QString urlString(const QString &documentPath) const;
@@ -100,5 +104,29 @@ private:
QTcpServer m_server;
};
+class ThreadedTestHTTPServer : public QThread
+{
+ Q_OBJECT
+public:
+ ThreadedTestHTTPServer(const QString &dir, TestHTTPServer::Mode mode = TestHTTPServer::Normal);
+ ThreadedTestHTTPServer(const QHash<QString, TestHTTPServer::Mode> &dirs);
+ ~ThreadedTestHTTPServer();
+
+ QUrl baseUrl() const;
+ QUrl url(const QString &documentPath) const;
+ QString urlString(const QString &documentPath) const;
+
+protected:
+ void run();
+
+private:
+ void start();
+
+ QHash<QString, TestHTTPServer::Mode> m_dirs;
+ quint16 m_port;
+ QMutex m_mutex;
+ QWaitCondition m_condition;
+};
+
#endif // TESTHTTPSERVER_H