Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Molkentin <danimo@owncloud.com>2015-05-06 18:01:05 +0300
committerDaniel Molkentin <danimo@owncloud.com>2015-05-06 18:01:05 +0300
commit77a28a81ebc2632398a1eb7103ce978563c33b27 (patch)
tree37a8379655765219f0afa35c55f4a05c976cf30e /test/mockserver
parentee71024496d25e1392080a5ad2a17113bcd2e27a (diff)
Bump to 1.9
Diffstat (limited to 'test/mockserver')
-rw-r--r--test/mockserver/CMakeLists.txt21
-rw-r--r--test/mockserver/httpserver.cpp63
-rw-r--r--test/mockserver/httpserver.h26
-rw-r--r--test/mockserver/main.cpp23
4 files changed, 133 insertions, 0 deletions
diff --git a/test/mockserver/CMakeLists.txt b/test/mockserver/CMakeLists.txt
new file mode 100644
index 000000000..fecf3d606
--- /dev/null
+++ b/test/mockserver/CMakeLists.txt
@@ -0,0 +1,21 @@
+project(gui)
+set(CMAKE_AUTOMOC TRUE)
+
+set(MOCKSERVER_NAME mockserver)
+
+#qt_wrap_ui(mockserver_UI_SRCS ${mockserver_UI})
+
+set(mockserver_SRCS
+ main.cpp
+ httpserver.cpp
+)
+
+set(mockserver_HDRS
+ httpserver.h
+)
+
+# add_executable( ${MOCKSERVER_NAME} main.cpp ${final_src})
+add_executable(${MOCKSERVER_NAME} WIN32 ${mockserver_SRCS} ${mockserver_HDRS})
+qt5_use_modules(${MOCKSERVER_NAME} Network Xml)
+target_link_libraries(${MOCKSERVER_NAME} ${QT_LIBRARIES})
+
diff --git a/test/mockserver/httpserver.cpp b/test/mockserver/httpserver.cpp
new file mode 100644
index 000000000..9f3e1a1d7
--- /dev/null
+++ b/test/mockserver/httpserver.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "httpserver.h"
+
+HttpServer::HttpServer(quint16 port, QObject* parent)
+ : QTcpServer(parent)
+{
+ listen(QHostAddress::Any, port);
+}
+
+void HttpServer::readClient()
+{
+ QTcpSocket* socket = (QTcpSocket*)sender();
+ if (socket->canReadLine()) {
+ QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
+ if (tokens[0] == "GET") {
+ QTextStream os(socket);
+ os.setAutoDetectUnicode(true);
+ os << "HTTP/1.0 200 Ok\r\n"
+ "Content-Type: text/html; charset=\"utf-8\"\r\n"
+ "\r\n"
+ "<h1>Nothing to see here</h1>\n"
+ << QDateTime::currentDateTime().toString() << "\n";
+ socket->close();
+
+ QtServiceBase::instance()->logMessage("Wrote to client");
+
+ if (socket->state() == QTcpSocket::UnconnectedState) {
+ delete socket;
+ QtServiceBase::instance()->logMessage("Connection closed");
+ }
+ }
+ }
+}
+void HttpServer::discardClient()
+{
+ QTcpSocket* socket = (QTcpSocket*)sender();
+ socket->deleteLater();
+
+ QtServiceBase::instance()->logMessage("Connection closed");
+}
+
+
+void HttpServer::incomingConnection(int socket)
+{
+ if (disabled)
+ return;
+ QTcpSocket* s = new QTcpSocket(this);
+ connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
+ connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
+ s->setSocketDescriptor(socket);
+}
diff --git a/test/mockserver/httpserver.h b/test/mockserver/httpserver.h
new file mode 100644
index 000000000..010fd80c9
--- /dev/null
+++ b/test/mockserver/httpserver.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include <QTcpServer>
+
+class HttpServer : public QTcpServer
+ {
+ Q_OBJECT
+ public:
+ HttpServer(qint16 port, QObject* parent = 0);
+ void incomingConnection(int socket);
+
+ private slots:
+ void readClient();
+ void discardClient();
+ };
diff --git a/test/mockserver/main.cpp b/test/mockserver/main.cpp
new file mode 100644
index 000000000..f35cab9f7
--- /dev/null
+++ b/test/mockserver/main.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include <QCoreApplication>
+
+#include "httpserver.h"
+
+int main(int argc, char* argv[])
+{
+ QCoreApplication app(argc, argv);
+ HttpServer server;
+ return app.exec();
+}