Files
qt-creator/tests/manual/utils/tcpportsgatherer/main.cpp
Aurindam Jana 7a090b3dd5 TcpPortsGatherer: Refactor code
Use QAbstractSocket::NetworkLayerProtocol enums.
Minor changes in API and internal functionality.

Change-Id: Idd786c71e3474b1010cc5f2d72dc09126bfd2e29
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
2013-03-21 12:30:25 +01:00

38 lines
1.2 KiB
C++

#include <QCoreApplication>
#include <utils/tcpportsgatherer.h>
#include <QDebug>
#include <QStringList>
using namespace Utils;
int main()
{
qDebug() << "Used TCP Ports (IP4):";
TcpPortsGatherer portsGatherer;
portsGatherer.update(QAbstractSocket::IPv4Protocol);
qDebug() << portsGatherer.usedPorts();
qDebug() << "Used TCP Ports (IP6):";
portsGatherer.update(QAbstractSocket::IPv6Protocol);
qDebug() << portsGatherer.usedPorts();
qDebug() << "All Used TCP Ports:";
portsGatherer.update(QAbstractSocket::UnknownNetworkLayerProtocol);
qDebug() << portsGatherer.usedPorts();
qDebug() << "Getting a few ports ...";
PortList portList = PortList::fromString(QLatin1String("10000-10100"));
QStringList ports;
for (int i = 0; i < 10; ++i) {
quint16 port = portsGatherer.getNextFreePort(&portList);
Q_ASSERT(!portsGatherer.usedPorts().contains(port));
Q_ASSERT(port >= 10000);
Q_ASSERT(port < 10100);
QString portStr = QString::number(port);
Q_ASSERT(!ports.contains(portStr));
ports.append(QString::number(port));
}
qDebug() << ports.join(QLatin1String(", "));
return 0;
}