From 810074e299f7b2826fbfb8b224082f455eab94e5 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 20 Jan 2010 10:18:20 +1000 Subject: Add support for aliases in test http server. Makes it possible to request many files with unique names, but serve a single file. --- tests/auto/declarative/shared/testhttpserver.cpp | 16 +++++++++++++++- tests/auto/declarative/shared/testhttpserver.h | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/auto/declarative/shared/testhttpserver.cpp b/tests/auto/declarative/shared/testhttpserver.cpp index 215f3c3..6c9d849 100644 --- a/tests/auto/declarative/shared/testhttpserver.cpp +++ b/tests/auto/declarative/shared/testhttpserver.cpp @@ -106,6 +106,15 @@ bool TestHTTPServer::serveDirectory(const QString &dir, Mode mode) return true; } +/* + Add an alias, so that if filename is requested and does not exist, + alias may be returned. +*/ +void TestHTTPServer::addAlias(const QString &filename, const QString &alias) +{ + aliases.insert(filename, alias); +} + bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &body) { m_hasFailed = false; @@ -226,7 +235,12 @@ bool TestHTTPServer::reply(QTcpSocket *socket, const QByteArray &fileName) Mode mode = dirs.at(ii).second; QString dirFile = dir + QLatin1String("/") + QLatin1String(fileName); - + + if (!QFile::exists(dirFile)) { + if (aliases.contains(fileName)) + dirFile = dir + QLatin1String("/") + aliases.value(fileName); + } + QFile file(dirFile); if (file.open(QIODevice::ReadOnly)) { diff --git a/tests/auto/declarative/shared/testhttpserver.h b/tests/auto/declarative/shared/testhttpserver.h index 62fe7b4..2a8709f 100644 --- a/tests/auto/declarative/shared/testhttpserver.h +++ b/tests/auto/declarative/shared/testhttpserver.h @@ -61,6 +61,8 @@ public: bool wait(const QUrl &expect, const QUrl &reply, const QUrl &body); bool hasFailed() const; + void addAlias(const QString &filename, const QString &aliasName); + private slots: void newConnection(); void disconnected(); @@ -80,6 +82,8 @@ private: QByteArray bodyData; bool m_hasFailed; + QHash aliases; + QTcpServer server; }; -- cgit v0.12