begin upnp tests
This commit is contained in:
parent
c59c9f4173
commit
45e7e4798e
@ -57,9 +57,7 @@ private slots:
|
|||||||
void getFiles_data();
|
void getFiles_data();
|
||||||
void getFiles();
|
void getFiles();
|
||||||
|
|
||||||
private:
|
void upnpDiscovery();
|
||||||
// for debugging
|
|
||||||
void printResponse(QNetworkReply *reply);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -204,8 +202,6 @@ void TestWebserver::checkAllowedMethodCall()
|
|||||||
|
|
||||||
clientSpy.wait();
|
clientSpy.wait();
|
||||||
|
|
||||||
printResponse(reply);
|
|
||||||
|
|
||||||
QCOMPARE(clientSpy.count(), 1);
|
QCOMPARE(clientSpy.count(), 1);
|
||||||
|
|
||||||
if (expectedStatusCode == 405){
|
if (expectedStatusCode == 405){
|
||||||
@ -342,8 +338,6 @@ void TestWebserver::getFiles()
|
|||||||
clientSpy.wait();
|
clientSpy.wait();
|
||||||
QVERIFY2(clientSpy.count() == 1, "expected exactly 1 response from webserver");
|
QVERIFY2(clientSpy.count() == 1, "expected exactly 1 response from webserver");
|
||||||
|
|
||||||
printResponse(reply);
|
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(&ok);
|
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(&ok);
|
||||||
QVERIFY2(ok, "Could not convert statuscode from response to int");
|
QVERIFY2(ok, "Could not convert statuscode from response to int");
|
||||||
@ -352,18 +346,38 @@ void TestWebserver::getFiles()
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestWebserver::printResponse(QNetworkReply *reply)
|
void TestWebserver::upnpDiscovery()
|
||||||
{
|
{
|
||||||
qDebug() << "-------------------------------";
|
QUdpSocket *socket = new QUdpSocket(this);
|
||||||
qDebug() << "Response header:";
|
socket->setSocketOption(QAbstractSocket::MulticastTtlOption,QVariant(1));
|
||||||
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
|
socket->setSocketOption(QAbstractSocket::MulticastLoopbackOption,QVariant(1));
|
||||||
foreach (const QNetworkReply::RawHeaderPair &headerPair, reply->rawHeaderPairs()) {
|
|
||||||
qDebug() << headerPair.first << ":" << headerPair.second;
|
QHostAddress host = QHostAddress("239.255.255.250");
|
||||||
}
|
|
||||||
qDebug() << "-------------------------------";
|
QVERIFY(socket->bind(QHostAddress::AnyIPv4, 1900, QUdpSocket::ShareAddress));
|
||||||
qDebug() << "Response payload";
|
QVERIFY(socket->joinMulticastGroup(host));
|
||||||
qDebug() << reply->readAll();
|
|
||||||
qDebug() << "-------------------------------";
|
//QSignalSpy spy(socket, SIGNAL(readyRead()));
|
||||||
|
|
||||||
|
QByteArray ssdpSearchMessage = QByteArray("M-SEARCH * HTTP/1.1\r\n"
|
||||||
|
"HOST:239.255.255.250:1900\r\n"
|
||||||
|
"MAN:\"ssdp:discover\"\r\n"
|
||||||
|
"MX:4\r\n"
|
||||||
|
"ST: ssdp:all\r\n\r\n");
|
||||||
|
|
||||||
|
socket->writeDatagram(ssdpSearchMessage, host, 1900);
|
||||||
|
socket->waitForBytesWritten();
|
||||||
|
|
||||||
|
socket->waitForReadyRead(2000);
|
||||||
|
|
||||||
|
qDebug() << socket->readAll();
|
||||||
|
|
||||||
|
//QVERIFY(spy.count() > 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// discovery->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "testwebserver.moc"
|
#include "testwebserver.moc"
|
||||||
|
|||||||
Reference in New Issue
Block a user