mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-05 00:35:27 +08:00
6.5.3 clean
This commit is contained in:
@ -1,2 +0,0 @@
|
||||
[lookup]
|
||||
*
|
@ -10,4 +10,5 @@ qt_internal_add_test(tst_qdnslookup
|
||||
tst_qdnslookup.cpp
|
||||
LIBRARIES
|
||||
Qt::Network
|
||||
Qt::TestPrivate
|
||||
)
|
||||
|
@ -5,16 +5,23 @@
|
||||
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
#include <QtTest/private/qpropertytesthelper_p.h>
|
||||
|
||||
#include <QtNetwork/QDnsLookup>
|
||||
#include <QtNetwork/QHostAddress>
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
static const int Timeout = 15000; // 15s
|
||||
|
||||
class tst_QDnsLookup: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
const QString normalDomain = u".test.qt-project.org"_s;
|
||||
const QString idnDomain = u".alqualondë.test.qt-project.org"_s;
|
||||
bool usingIdnDomain = false;
|
||||
bool dnsServersMustWork = false;
|
||||
|
||||
QString domainName(const QString &input);
|
||||
QString domainNameList(const QString &input);
|
||||
QStringList domainNameListAlternatives(const QString &input);
|
||||
@ -24,16 +31,19 @@ public slots:
|
||||
private slots:
|
||||
void lookup_data();
|
||||
void lookup();
|
||||
void lookupIdn_data() { lookup_data(); }
|
||||
void lookupIdn();
|
||||
|
||||
void lookupReuse();
|
||||
void lookupAbortRetry();
|
||||
void bindingsAndProperties();
|
||||
void automatedBindings();
|
||||
};
|
||||
|
||||
void tst_QDnsLookup::initTestCase()
|
||||
{
|
||||
QTest::addColumn<QString>("tld");
|
||||
QTest::newRow("normal") << ".test.qt-project.org";
|
||||
QTest::newRow("idn") << ".alqualond\xc3\xab.test.qt-project.org";
|
||||
if (qgetenv("QTEST_ENVIRONMENT") == "ci")
|
||||
dnsServersMustWork = true;
|
||||
}
|
||||
|
||||
QString tst_QDnsLookup::domainName(const QString &input)
|
||||
@ -47,15 +57,16 @@ QString tst_QDnsLookup::domainName(const QString &input)
|
||||
return nodot;
|
||||
}
|
||||
|
||||
QFETCH_GLOBAL(QString, tld);
|
||||
return input + tld;
|
||||
if (usingIdnDomain)
|
||||
return input + idnDomain;
|
||||
return input + normalDomain;
|
||||
}
|
||||
|
||||
QString tst_QDnsLookup::domainNameList(const QString &input)
|
||||
{
|
||||
QStringList list = input.split(QLatin1Char(';'));
|
||||
const QStringList list = input.split(QLatin1Char(';'));
|
||||
QString result;
|
||||
foreach (const QString &s, list) {
|
||||
for (const QString &s : list) {
|
||||
if (!result.isEmpty())
|
||||
result += ';';
|
||||
result += domainName(s);
|
||||
@ -140,38 +151,6 @@ void tst_QDnsLookup::lookup_data()
|
||||
QTest::newRow("txt-multi-multirr") << int(QDnsLookup::TXT) << "txt-multi-multirr" << int(QDnsLookup::NoError) << "" << "" << "" << "" << "" << "" << "Hello;World";
|
||||
}
|
||||
|
||||
static QByteArray msgDnsLookup(QDnsLookup::Error actualError,
|
||||
int expectedError,
|
||||
const QString &domain,
|
||||
const QString &cname,
|
||||
const QString &host,
|
||||
const QString &srv,
|
||||
const QString &mx,
|
||||
const QString &ns,
|
||||
const QString &ptr,
|
||||
const QString &errorString)
|
||||
{
|
||||
QString result;
|
||||
QTextStream str(&result);
|
||||
str << "Actual error: " << actualError;
|
||||
if (!errorString.isEmpty())
|
||||
str << " (" << errorString << ')';
|
||||
str << ", expected: " << expectedError;
|
||||
str << ", domain: " << domain;
|
||||
if (!cname.isEmpty())
|
||||
str << ", cname: " << cname;
|
||||
str << ", host: " << host;
|
||||
if (!srv.isEmpty())
|
||||
str << " server: " << srv;
|
||||
if (!mx.isEmpty())
|
||||
str << " mx: " << mx;
|
||||
if (!ns.isEmpty())
|
||||
str << " ns: " << ns;
|
||||
if (!ptr.isEmpty())
|
||||
str << " ptr: " << ptr;
|
||||
return result.toLocal8Bit();
|
||||
}
|
||||
|
||||
void tst_QDnsLookup::lookup()
|
||||
{
|
||||
QFETCH(int, type);
|
||||
@ -207,8 +186,38 @@ void tst_QDnsLookup::lookup()
|
||||
QEXPECT_FAIL("", "Not yet supported on Android", Abort);
|
||||
#endif
|
||||
|
||||
QVERIFY2(int(lookup.error()) == error,
|
||||
msgDnsLookup(lookup.error(), error, domain, cname, host, srv, mx, ns, ptr, lookup.errorString()));
|
||||
auto extraErrorMsg = [&] () {
|
||||
QString result;
|
||||
QTextStream str(&result);
|
||||
str << "Actual error: " << lookup.error();
|
||||
if (QString errorString = lookup.errorString(); !errorString.isEmpty())
|
||||
str << " (" << errorString << ')';
|
||||
str << ", expected: " << error;
|
||||
str << ", domain: " << domain;
|
||||
if (!cname.isEmpty())
|
||||
str << ", cname: " << cname;
|
||||
str << ", host: " << host;
|
||||
if (!srv.isEmpty())
|
||||
str << " server: " << srv;
|
||||
if (!mx.isEmpty())
|
||||
str << " mx: " << mx;
|
||||
if (!ns.isEmpty())
|
||||
str << " ns: " << ns;
|
||||
if (!ptr.isEmpty())
|
||||
str << " ptr: " << ptr;
|
||||
return result.toLocal8Bit();
|
||||
};
|
||||
|
||||
if (!dnsServersMustWork && (lookup.error() == QDnsLookup::ServerFailureError
|
||||
|| lookup.error() == QDnsLookup::ServerRefusedError)) {
|
||||
// It's not a QDnsLookup problem if the server refuses to answer the query.
|
||||
// This happens for queries of type ANY through Dnsmasq, for example.
|
||||
qWarning("Server refused or was unable to answer query; %s", extraErrorMsg().constData());
|
||||
return;
|
||||
}
|
||||
|
||||
QVERIFY2(int(lookup.error()) == error, extraErrorMsg());
|
||||
|
||||
if (error == QDnsLookup::NoError)
|
||||
QVERIFY(lookup.errorString().isEmpty());
|
||||
QCOMPARE(int(lookup.type()), type);
|
||||
@ -291,6 +300,13 @@ void tst_QDnsLookup::lookup()
|
||||
QCOMPARE(texts.join(';'), txt);
|
||||
}
|
||||
|
||||
void tst_QDnsLookup::lookupIdn()
|
||||
{
|
||||
usingIdnDomain = true;
|
||||
lookup();
|
||||
usingIdnDomain = false;
|
||||
}
|
||||
|
||||
void tst_QDnsLookup::lookupReuse()
|
||||
{
|
||||
QDnsLookup lookup;
|
||||
@ -355,10 +371,6 @@ void tst_QDnsLookup::lookupAbortRetry()
|
||||
|
||||
void tst_QDnsLookup::bindingsAndProperties()
|
||||
{
|
||||
QFETCH_GLOBAL(const QString, tld);
|
||||
if (tld == QStringLiteral("idn"))
|
||||
return;
|
||||
|
||||
QDnsLookup lookup;
|
||||
|
||||
lookup.setType(QDnsLookup::A);
|
||||
@ -399,5 +411,30 @@ void tst_QDnsLookup::bindingsAndProperties()
|
||||
QCOMPARE(nameserverProp.value(), QHostAddress::Any);
|
||||
}
|
||||
|
||||
void tst_QDnsLookup::automatedBindings()
|
||||
{
|
||||
QDnsLookup lookup;
|
||||
|
||||
QTestPrivate::testReadWritePropertyBasics(lookup, u"aaaa"_s, u"txt"_s, "name");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QDnsLookup::name");
|
||||
return;
|
||||
}
|
||||
|
||||
QTestPrivate::testReadWritePropertyBasics(lookup, QDnsLookup::AAAA, QDnsLookup::TXT, "type");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QDnsLookup::type");
|
||||
return;
|
||||
}
|
||||
|
||||
QTestPrivate::testReadWritePropertyBasics(lookup, QHostAddress{QHostAddress::Any},
|
||||
QHostAddress{QHostAddress::LocalHost},
|
||||
"nameserver");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QDnsLookup::nameserver");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QDnsLookup)
|
||||
#include "tst_qdnslookup.moc"
|
||||
|
@ -7,9 +7,6 @@
|
||||
// (except qglobal.h), or else you'll get tons of compile errors
|
||||
#include <qglobal.h>
|
||||
|
||||
// To prevent windows system header files from re-defining min/max
|
||||
#define NOMINMAX 1
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
@ -46,7 +43,6 @@
|
||||
|
||||
#define TEST_DOMAIN ".test.qt-project.org"
|
||||
|
||||
|
||||
class tst_QHostInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -373,7 +369,7 @@ static QStringList reverseLookupHelper(const QString &ip)
|
||||
QList<QByteArray> lines;
|
||||
QProcess python;
|
||||
python.setProcessChannelMode(QProcess::ForwardedErrorChannel);
|
||||
python.start("python", QStringList() << QString("-c") << pythonCode << ip);
|
||||
python.start("python3", QStringList() << QString("-c") << pythonCode << ip);
|
||||
if (python.waitForFinished()) {
|
||||
if (python.exitStatus() == QProcess::NormalExit && python.exitCode() == 0)
|
||||
lines = python.readAllStandardOutput().split('\n');
|
||||
@ -554,24 +550,22 @@ void tst_QHostInfo::threadSafetyAsynchronousAPI()
|
||||
{
|
||||
const int nattempts = 10;
|
||||
const int lookupsperthread = 10;
|
||||
QList<QThread*> threads;
|
||||
QList<LookupReceiver*> receivers;
|
||||
QThread threads[nattempts];
|
||||
LookupReceiver receivers[nattempts];
|
||||
for (int i = 0; i < nattempts; ++i) {
|
||||
QThread* thread = new QThread;
|
||||
LookupReceiver* receiver = new LookupReceiver;
|
||||
QThread *thread = &threads[i];
|
||||
LookupReceiver *receiver = &receivers[i];
|
||||
receiver->numrequests = lookupsperthread;
|
||||
receivers.append(receiver);
|
||||
receiver->moveToThread(thread);
|
||||
connect(thread, SIGNAL(started()), receiver, SLOT(start()));
|
||||
thread->start();
|
||||
threads.append(thread);
|
||||
}
|
||||
for (int k = threads.size() - 1; k >= 0; --k)
|
||||
QVERIFY(threads.at(k)->wait(60000));
|
||||
foreach (LookupReceiver* receiver, receivers) {
|
||||
QCOMPARE(receiver->result.error(), QHostInfo::NoError);
|
||||
QCOMPARE(receiver->result.addresses().at(0).toString(), QString("192.0.2.1"));
|
||||
QCOMPARE(receiver->numrequests, 0);
|
||||
for (int k = nattempts - 1; k >= 0; --k)
|
||||
QVERIFY(threads[k].wait(60000));
|
||||
for (LookupReceiver &receiver : receivers) {
|
||||
QCOMPARE(receiver.result.error(), QHostInfo::NoError);
|
||||
QCOMPARE(receiver.result.addresses().at(0).toString(), QString("192.0.2.1"));
|
||||
QCOMPARE(receiver.numrequests, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,8 +71,8 @@ void tst_QNetworkInterface::initTestCase()
|
||||
void tst_QNetworkInterface::dump()
|
||||
{
|
||||
// This is for manual testing:
|
||||
QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
|
||||
foreach (const QNetworkInterface &i, allInterfaces) {
|
||||
const QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
|
||||
for (const QNetworkInterface &i : allInterfaces) {
|
||||
QString flags;
|
||||
if (i.flags() & QNetworkInterface::IsUp) flags += "Up,";
|
||||
if (i.flags() & QNetworkInterface::IsRunning) flags += "Running,";
|
||||
|
Reference in New Issue
Block a user