Fix test
Use the right port Store the port in a public variable, so it can be used from the test.
This commit is contained in:
parent
fa293e6d8a
commit
91f952f5f1
3 changed files with 12 additions and 11 deletions
|
@ -79,12 +79,12 @@ void LanLinkProvider::onStart()
|
||||||
{
|
{
|
||||||
const QHostAddress bindAddress = mTestMode? QHostAddress::LocalHost : QHostAddress::Any;
|
const QHostAddress bindAddress = mTestMode? QHostAddress::LocalHost : QHostAddress::Any;
|
||||||
|
|
||||||
bool success = mUdpSocket.bind(bindAddress, port, QUdpSocket::ShareAddress);
|
bool success = mUdpSocket.bind(bindAddress, PORT, QUdpSocket::ShareAddress);
|
||||||
Q_ASSERT(success);
|
Q_ASSERT(success);
|
||||||
|
|
||||||
qCDebug(KDECONNECT_CORE) << "onStart";
|
qCDebug(KDECONNECT_CORE) << "onStart";
|
||||||
|
|
||||||
mTcpPort = port;
|
mTcpPort = PORT;
|
||||||
while (!mServer->listen(bindAddress, mTcpPort)) {
|
while (!mServer->listen(bindAddress, mTcpPort)) {
|
||||||
mTcpPort++;
|
mTcpPort++;
|
||||||
if (mTcpPort > 1764) { //No ports available?
|
if (mTcpPort > 1764) { //No ports available?
|
||||||
|
@ -128,7 +128,7 @@ void LanLinkProvider::broadcastToNetwork()
|
||||||
NetworkPackage np("");
|
NetworkPackage np("");
|
||||||
NetworkPackage::createIdentityPackage(&np);
|
NetworkPackage::createIdentityPackage(&np);
|
||||||
np.set("tcpPort", mTcpPort);
|
np.set("tcpPort", mTcpPort);
|
||||||
mUdpSocket.writeDatagram(np.serialize(), mTestMode ? QHostAddress::LocalHost : QHostAddress("255.255.255.255"), port);
|
mUdpSocket.writeDatagram(np.serialize(), mTestMode ? QHostAddress::LocalHost : QHostAddress("255.255.255.255"), PORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//I'm the existing device, a new device is kindly introducing itself.
|
//I'm the existing device, a new device is kindly introducing itself.
|
||||||
|
@ -164,7 +164,7 @@ void LanLinkProvider::newUdpConnection() //udpBroadcastReceived
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcpPort = receivedPackage->get<int>("tcpPort", port);
|
int tcpPort = receivedPackage->get<int>("tcpPort", PORT);
|
||||||
|
|
||||||
//qCDebug(KDECONNECT_CORE) << "Received Udp identity package from" << sender << " asking for a tcp connection on port " << tcpPort;
|
//qCDebug(KDECONNECT_CORE) << "Received Udp identity package from" << sender << " asking for a tcp connection on port " << tcpPort;
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ void LanLinkProvider::connectError()
|
||||||
NetworkPackage np("");
|
NetworkPackage np("");
|
||||||
NetworkPackage::createIdentityPackage(&np);
|
NetworkPackage::createIdentityPackage(&np);
|
||||||
np.set("tcpPort", mTcpPort);
|
np.set("tcpPort", mTcpPort);
|
||||||
mUdpSocket.writeDatagram(np.serialize(), receivedIdentityPackages[socket].sender, port);
|
mUdpSocket.writeDatagram(np.serialize(), receivedIdentityPackages[socket].sender, PORT);
|
||||||
|
|
||||||
//The socket we created didn't work, and we didn't manage
|
//The socket we created didn't work, and we didn't manage
|
||||||
//to create a LanDeviceLink from it, deleting everything.
|
//to create a LanDeviceLink from it, deleting everything.
|
||||||
|
@ -251,7 +251,7 @@ void LanLinkProvider::connected()
|
||||||
//I think this will never happen, but if it happens the deviceLink
|
//I think this will never happen, but if it happens the deviceLink
|
||||||
//(or the socket that is now inside it) might not be valid. Delete them.
|
//(or the socket that is now inside it) might not be valid. Delete them.
|
||||||
qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection (send udp packet)";
|
qCDebug(KDECONNECT_CORE) << "Fallback (2), try reverse connection (send udp packet)";
|
||||||
mUdpSocket.writeDatagram(np2.serialize(), receivedIdentityPackages[socket].sender, port);
|
mUdpSocket.writeDatagram(np2.serialize(), receivedIdentityPackages[socket].sender, PORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete receivedIdentityPackages.take(socket).np;
|
delete receivedIdentityPackages.take(socket).np;
|
||||||
|
|
|
@ -54,6 +54,8 @@ public:
|
||||||
static void configureSslSocket(QSslSocket* socket, const QString& deviceId, bool isDeviceTrusted);
|
static void configureSslSocket(QSslSocket* socket, const QString& deviceId, bool isDeviceTrusted);
|
||||||
static void configureSocket(QSslSocket* socket);
|
static void configureSocket(QSslSocket* socket);
|
||||||
|
|
||||||
|
const static quint16 PORT = 1716;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void onNetworkChange() override;
|
void onNetworkChange() override;
|
||||||
void onStart() override;
|
void onStart() override;
|
||||||
|
@ -78,7 +80,6 @@ private:
|
||||||
|
|
||||||
Server* mServer;
|
Server* mServer;
|
||||||
QUdpSocket mUdpSocket;
|
QUdpSocket mUdpSocket;
|
||||||
const static quint16 port = 1716;
|
|
||||||
quint16 mTcpPort;
|
quint16 mTcpPort;
|
||||||
|
|
||||||
QMap<QString, LanDeviceLink*> mLinks;
|
QMap<QString, LanDeviceLink*> mLinks;
|
||||||
|
|
|
@ -100,7 +100,7 @@ void LanLinkProviderTest::pairedDeviceTcpPackageReceived()
|
||||||
addTrustedDevice();
|
addTrustedDevice();
|
||||||
|
|
||||||
QUdpSocket* mUdpServer = new QUdpSocket;
|
QUdpSocket* mUdpServer = new QUdpSocket;
|
||||||
bool b = mUdpServer->bind(QHostAddress::LocalHost, 1714, QUdpSocket::ShareAddress);
|
bool b = mUdpServer->bind(QHostAddress::LocalHost, LanLinkProvider::PORT, QUdpSocket::ShareAddress);
|
||||||
QVERIFY(b);
|
QVERIFY(b);
|
||||||
|
|
||||||
QSignalSpy spy(mUdpServer, SIGNAL(readyRead()));
|
QSignalSpy spy(mUdpServer, SIGNAL(readyRead()));
|
||||||
|
@ -161,7 +161,7 @@ void LanLinkProviderTest::pairedDeviceUdpPackageReceived()
|
||||||
|
|
||||||
QSignalSpy spy(mServer, SIGNAL(newConnection()));
|
QSignalSpy spy(mServer, SIGNAL(newConnection()));
|
||||||
|
|
||||||
qint64 bytesWritten = mUdpSocket->writeDatagram(mIdentityPackage.toLatin1(), QHostAddress::LocalHost, 1714); // write an identity package to udp socket here, we do not broadcast it here
|
qint64 bytesWritten = mUdpSocket->writeDatagram(mIdentityPackage.toLatin1(), QHostAddress::LocalHost, LanLinkProvider::PORT); // write an identity package to udp socket here, we do not broadcast it here
|
||||||
QCOMPARE(bytesWritten, mIdentityPackage.size());
|
QCOMPARE(bytesWritten, mIdentityPackage.size());
|
||||||
|
|
||||||
// We should have an incoming connection now, wait for incoming connection
|
// We should have an incoming connection now, wait for incoming connection
|
||||||
|
@ -208,7 +208,7 @@ void LanLinkProviderTest::pairedDeviceUdpPackageReceived()
|
||||||
void LanLinkProviderTest::unpairedDeviceTcpPackageReceived()
|
void LanLinkProviderTest::unpairedDeviceTcpPackageReceived()
|
||||||
{
|
{
|
||||||
QUdpSocket* mUdpServer = new QUdpSocket;
|
QUdpSocket* mUdpServer = new QUdpSocket;
|
||||||
bool b = mUdpServer->bind(QHostAddress::LocalHost, 1714, QUdpSocket::ShareAddress);
|
bool b = mUdpServer->bind(QHostAddress::LocalHost, LanLinkProvider::PORT, QUdpSocket::ShareAddress);
|
||||||
QVERIFY(b);
|
QVERIFY(b);
|
||||||
|
|
||||||
QSignalSpy spy(mUdpServer, SIGNAL(readyRead()));
|
QSignalSpy spy(mUdpServer, SIGNAL(readyRead()));
|
||||||
|
@ -263,7 +263,7 @@ void LanLinkProviderTest::unpairedDeviceUdpPackageReceived()
|
||||||
mServer->listen(QHostAddress::LocalHost, PORT);
|
mServer->listen(QHostAddress::LocalHost, PORT);
|
||||||
|
|
||||||
QSignalSpy spy(mServer, &Server::newConnection);
|
QSignalSpy spy(mServer, &Server::newConnection);
|
||||||
qint64 bytesWritten = mUdpSocket->writeDatagram(mIdentityPackage.toLatin1(), QHostAddress::LocalHost, 1714); // write an identity package to udp socket here, we do not broadcast it here
|
qint64 bytesWritten = mUdpSocket->writeDatagram(mIdentityPackage.toLatin1(), QHostAddress::LocalHost, LanLinkProvider::PORT); // write an identity package to udp socket here, we do not broadcast it here
|
||||||
QCOMPARE(bytesWritten, mIdentityPackage.size());
|
QCOMPARE(bytesWritten, mIdentityPackage.size());
|
||||||
|
|
||||||
QVERIFY(!spy.isEmpty() || spy.wait());
|
QVERIFY(!spy.isEmpty() || spy.wait());
|
||||||
|
|
Loading…
Reference in a new issue