Changeset View
Changeset View
Standalone View
Standalone View
src/bugzillaintegration/libbugzilla/autotests/connectiontest.cpp
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 73 | connect(&t, &QTcpServer::newConnection, | |||
---|---|---|---|---|---|
75 | QTcpSocket *socket = t.nextPendingConnection(); | 75 | QTcpSocket *socket = t.nextPendingConnection(); | ||
76 | socket->waitForReadyRead(); | 76 | socket->waitForReadyRead(); | ||
77 | QString httpBlob = socket->readAll(); | 77 | QString httpBlob = socket->readAll(); | ||
78 | qDebug() << httpBlob; | 78 | qDebug() << httpBlob; | ||
79 | // The query is important to see if this actually gets properly | 79 | // The query is important to see if this actually gets properly | ||
80 | // passed along! | 80 | // passed along! | ||
81 | if (httpBlob.startsWith("GET /hi?informal=yes")) { | 81 | if (httpBlob.startsWith("GET /hi?informal=yes")) { | ||
82 | QFile file(QFINDTESTDATA("data/hi.http")); | 82 | QFile file(QFINDTESTDATA("data/hi.http")); | ||
83 | Q_ASSERT(file.open(QFile::ReadOnly | QFile::Text)); | 83 | file.open(QFile::ReadOnly | QFile::Text); | ||
84 | socket->write(file.readAll()); | 84 | socket->write(file.readAll()); | ||
85 | socket->waitForBytesWritten(); | 85 | socket->waitForBytesWritten(); | ||
86 | socket->disconnect(); | 86 | socket->disconnect(); | ||
87 | socket->close(); | 87 | socket->close(); | ||
88 | return; | 88 | return; | ||
89 | } | 89 | } | ||
90 | qDebug() << httpBlob; | 90 | qDebug() << httpBlob; | ||
91 | Q_ASSERT_X(false, "server", "Unexpected request"); | 91 | Q_ASSERT_X(false, "server", "Unexpected request"); | ||
Show All 18 Lines | 105 | { | |||
110 | QCOMPARE(t.listen(QHostAddress::LocalHost, 0), true); | 110 | QCOMPARE(t.listen(QHostAddress::LocalHost, 0), true); | ||
111 | connect(&t, &QTcpServer::newConnection, | 111 | connect(&t, &QTcpServer::newConnection, | ||
112 | &t, [&t]() { | 112 | &t, [&t]() { | ||
113 | QTcpSocket *socket = t.nextPendingConnection(); | 113 | QTcpSocket *socket = t.nextPendingConnection(); | ||
114 | socket->waitForReadyRead(); | 114 | socket->waitForReadyRead(); | ||
115 | QString httpBlob = socket->readAll(); | 115 | QString httpBlob = socket->readAll(); | ||
116 | qDebug() << httpBlob; | 116 | qDebug() << httpBlob; | ||
117 | QFile file(QFINDTESTDATA("data/error.http")); | 117 | QFile file(QFINDTESTDATA("data/error.http")); | ||
118 | QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); | 118 | file.open(QFile::ReadOnly | QFile::Text); | ||
119 | socket->write(file.readAll()); | 119 | socket->write(file.readAll()); | ||
120 | socket->waitForBytesWritten(); | 120 | socket->waitForBytesWritten(); | ||
121 | socket->disconnect(); | 121 | socket->disconnect(); | ||
122 | socket->close(); | 122 | socket->close(); | ||
123 | return; | 123 | return; | ||
124 | }); | 124 | }); | ||
125 | 125 | | |||
126 | QUrl root("http://localhost"); | 126 | QUrl root("http://localhost"); | ||
Show All 27 Lines | 153 | connect(socket, &QTcpSocket::readyRead, | |||
154 | socket, [&readBlob, socket] { | 154 | socket, [&readBlob, socket] { | ||
155 | readBlob += socket->readAll(); | 155 | readBlob += socket->readAll(); | ||
156 | readBlob.replace("\r\n", "\n"); | 156 | readBlob.replace("\r\n", "\n"); | ||
157 | auto parts = readBlob.split("\n"); | 157 | auto parts = readBlob.split("\n"); | ||
158 | if (parts.contains("PUT /put HTTP/1.1") && | 158 | if (parts.contains("PUT /put HTTP/1.1") && | ||
159 | parts.contains("Content-Length: 12") && | 159 | parts.contains("Content-Length: 12") && | ||
160 | parts.contains("hello there!")) { | 160 | parts.contains("hello there!")) { | ||
161 | QFile file(QFINDTESTDATA("data/put.http")); | 161 | QFile file(QFINDTESTDATA("data/put.http")); | ||
162 | QVERIFY(file.open(QFile::ReadOnly | QFile::Text)); | 162 | file.open(QFile::ReadOnly | QFile::Text); | ||
163 | QByteArray ret = file.readAll(); | 163 | QByteArray ret = file.readAll(); | ||
164 | ret.replace("\n", "\r\n"); | 164 | ret.replace("\n", "\r\n"); | ||
165 | qDebug() << ret; | 165 | qDebug() << ret; | ||
166 | socket->write(ret); | 166 | socket->write(ret); | ||
167 | socket->waitForBytesWritten(); | 167 | socket->waitForBytesWritten(); | ||
168 | socket->disconnect(); | 168 | socket->disconnect(); | ||
169 | socket->close(); | 169 | socket->close(); | ||
170 | qDebug() << "socket closed"; | 170 | qDebug() << "socket closed"; | ||
171 | } | 171 | } | ||
172 | }); | 172 | }); | ||
173 | }); | 173 | }); | ||
174 | thread.start(); | 174 | thread.start(); | ||
175 | 175 | | |||
176 | QMutex portMutex; | 176 | QMutex portMutex; | ||
177 | QWaitCondition portCondition; | 177 | QWaitCondition portCondition; | ||
178 | quint16 port; | 178 | quint16 port; | ||
179 | portMutex.lock(); | 179 | portMutex.lock(); | ||
180 | QTimer::singleShot(0, server, [server, &portMutex, &portCondition, &port]() { | 180 | QTimer::singleShot(0, server, [server, &portMutex, &portCondition, &port]() { | ||
181 | Q_ASSERT(server->listen(QHostAddress::LocalHost, 0)); | 181 | server->listen(QHostAddress::LocalHost, 0); | ||
182 | QMutexLocker locker(&portMutex); | 182 | QMutexLocker locker(&portMutex); | ||
183 | port = server->serverPort(); | 183 | port = server->serverPort(); | ||
184 | portCondition.wakeAll(); | 184 | portCondition.wakeAll(); | ||
185 | }); | 185 | }); | ||
186 | portCondition.wait(&portMutex); | 186 | portCondition.wait(&portMutex); | ||
187 | portMutex.unlock(); | 187 | portMutex.unlock(); | ||
188 | 188 | | |||
189 | QUrl root("http://localhost"); | 189 | QUrl root("http://localhost"); | ||
Show All 25 Lines |