Remove network dependency for tests with UNC paths

Windows VMs are provisioned with shared folders that are available as

\\${COMPUTERNAME}\testshare(writable)

so we don't need to access a remote SMB server over network anymore just
to test whether our string-parsing code handles UNC paths correctly.

Add a QTest::uncServerName() helper function to the shared filesystem.h
header and use that instead of QtNetworkSettings::winServerName. The
latter is now only used in tst_NetworkSelfTest::smbServer().

Pick-to: 6.4
Change-Id: Id0da66369ad0f4a980d612de2a31a391f1192253
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Volker Hilsheimer 2022-06-27 12:32:13 +02:00
parent 1ee75e4740
commit 371214dea7
6 changed files with 23 additions and 30 deletions

View File

@ -17,7 +17,6 @@
#if defined(Q_OS_WIN)
#include <QtCore/private/qfsfileengine_p.h>
#include "../../../network-settings.h"
#endif
#if defined(Q_OS_WIN) && !defined(_WIN32_WINNT)
@ -627,7 +626,7 @@ void tst_QDir::exists_data()
QTest::newRow("simple dir") << (m_dataPath + "/resources") << true;
QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << true;
#if defined(Q_OS_WIN)
const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
const QString uncRoot = QStringLiteral("//") + QTest::uncServerName();
QTest::newRow("unc 1") << uncRoot << true;
QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true;
QTest::newRow("unc 3") << uncRoot + "/testshare" << true;
@ -1020,7 +1019,7 @@ void tst_QDir::entryListSimple_data()
QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << 2;
#if defined(Q_OS_WIN)
const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
const QString uncRoot = QStringLiteral("//") + QTest::uncServerName();
QTest::newRow("unc 1") << uncRoot << 2;
QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << 2;
QTest::newRow("unc 3") << uncRoot + "/testshare" << 2;
@ -2393,7 +2392,7 @@ void tst_QDir::cdBelowRoot_data()
const QString systemRoot = QString::fromLocal8Bit(qgetenv("SystemRoot"));
QTest::newRow("windows-drive")
<< systemDrive << systemRoot.mid(3) << QDir::cleanPath(systemRoot);
const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
const QString uncRoot = QStringLiteral("//") + QTest::uncServerName();
const QString testDirectory = QStringLiteral("testshare");
QTest::newRow("windows-share")
<< uncRoot << testDirectory << QDir::cleanPath(uncRoot + QLatin1Char('/') + testDirectory);

View File

@ -18,9 +18,7 @@
#define Q_NO_SYMLINKS
#endif
#if defined(Q_OS_WIN)
# include "../../../network-settings.h"
#endif
#include "../../../../shared/filesystem.h"
#ifdef Q_OS_ANDROID
#include <QStandardPaths>
@ -563,11 +561,11 @@ void tst_QDirIterator::uncPaths_data()
{
QTest::addColumn<QString>("dirName");
QTest::newRow("uncserver")
<<QString("//" + QtNetworkSettings::winServerName());
<<QString("//" + QTest::uncServerName());
QTest::newRow("uncserver/testshare")
<<QString("//" + QtNetworkSettings::winServerName() + "/testshare");
<<QString("//" + QTest::uncServerName() + "/testshare");
QTest::newRow("uncserver/testshare/tmp")
<<QString("//" + QtNetworkSettings::winServerName() + "/testshare/tmp");
<<QString("//" + QTest::uncServerName() + "/testshare/tmp");
}
void tst_QDirIterator::uncPaths()
{

View File

@ -74,9 +74,7 @@ QT_END_NAMESPACE
# undef fileno
#endif
#if defined(Q_OS_WIN)
#include "../../../network-settings.h"
#endif
#include "../../../../shared/filesystem.h"
#ifndef STDIN_FILENO
#define STDIN_FILENO 0
@ -542,7 +540,7 @@ void tst_QFile::exists()
QVERIFY(!file.exists());
#if defined(Q_OS_WIN)
const QString uncPath = "//" + QtNetworkSettings::winServerName() + "/testshare/readme.txt";
const QString uncPath = "//" + QTest::uncServerName() + "/testshare/readme.txt";
QFile unc(uncPath);
QVERIFY2(unc.exists(), msgFileDoesNotExist(uncPath).constData());
#endif
@ -608,7 +606,7 @@ void tst_QFile::open_data()
QTest::newRow("//./PhysicalDrive0") << QString("//./PhysicalDrive0") << int(QIODevice::ReadOnly)
<< false << QFile::OpenError;
}
QTest::newRow("uncFile") << "//" + QtNetworkSettings::winServerName() + "/testshare/test.pri" << int(QIODevice::ReadOnly)
QTest::newRow("uncFile") << "//" + QTest::uncServerName() + "/testshare/test.pri" << int(QIODevice::ReadOnly)
<< true << QFile::NoError;
#endif
}
@ -682,7 +680,7 @@ void tst_QFile::size_data()
QTest::newRow( "exist01" ) << m_testFile << (qint64)245;
#if defined(Q_OS_WIN)
// Only test UNC on Windows./
QTest::newRow("unc") << "//" + QString(QtNetworkSettings::winServerName() + "/testshare/test.pri") << (qint64)34;
QTest::newRow("unc") << "//" + QString(QTest::uncServerName() + "/testshare/test.pri") << (qint64)34;
#endif
}
@ -1769,7 +1767,7 @@ void tst_QFile::largeUncFileSupport()
qint64 size = Q_INT64_C(8589934592);
qint64 dataOffset = Q_INT64_C(8589914592);
QByteArray knownData("LargeFile content at offset 8589914592");
QString largeFile("//" + QtNetworkSettings::winServerName() + "/testsharelargefile/file.bin");
QString largeFile("//" + QTest::uncServerName() + "/testsharelargefile/file.bin");
const QByteArray largeFileEncoded = QFile::encodeName(largeFile);
{
@ -2450,7 +2448,7 @@ void tst_QFile::writeLargeDataBlock_data()
#if defined(Q_OS_WIN) && !defined(QT_NO_NETWORK)
// Some semi-randomness to avoid collisions.
QTest::newRow("unc file")
<< QString("//" + QtNetworkSettings::winServerName() + "/TESTSHAREWRITABLE/largefile-%1-%2.txt")
<< QString("//" + QTest::uncServerName() + "/TESTSHAREWRITABLE/largefile-%1-%2.txt")
.arg(QHostInfo::localHostName())
.arg(QTime::currentTime().msec()) << (int)OpenQFile;
#endif
@ -2875,7 +2873,7 @@ void tst_QFile::miscWithUncPathAsCurrentDir()
{
#if defined(Q_OS_WIN)
QString current = QDir::currentPath();
const QString path = QLatin1String("//") + QtNetworkSettings::winServerName()
const QString path = QLatin1String("//") + QTest::uncServerName()
+ QLatin1String("/testshare");
QVERIFY2(QDir::setCurrent(path), qPrintable(QDir::toNativeSeparators(path)));
QFile file("test.pri");

View File

@ -31,9 +31,6 @@
#endif
#include <qplatformdefs.h>
#include <qdebug.h>
#if defined(Q_OS_WIN)
#include "../../../network-settings.h"
#endif
#include <private/qfileinfo_p.h>
#include "../../../../shared/filesystem.h"
@ -383,7 +380,7 @@ void tst_QFileInfo::isDir_data()
//QTest::newRow("drive 2") << "t:s" << false;
#endif
#if defined(Q_OS_WIN)
const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
const QString uncRoot = QStringLiteral("//") + QTest::uncServerName();
QTest::newRow("unc 1") << uncRoot << true;
QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true;
QTest::newRow("unc 3") << uncRoot + "/testshare" << true;
@ -426,7 +423,7 @@ void tst_QFileInfo::isRoot_data()
#endif
#if defined(Q_OS_WIN)
const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
const QString uncRoot = QStringLiteral("//") + QTest::uncServerName();
QTest::newRow("unc 1") << uncRoot << true;
QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true;
QTest::newRow("unc 3") << uncRoot + "/testshare" << false;
@ -470,7 +467,7 @@ void tst_QFileInfo::exists_data()
QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true;
#if defined(Q_OS_WIN)
const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
const QString uncRoot = QStringLiteral("//") + QTest::uncServerName();
QTest::newRow("unc 1") << uncRoot << true;
QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true;
QTest::newRow("unc 3") << uncRoot + "/testshare" << true;
@ -1732,7 +1729,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data()
{
// Symlink to UNC share
pwd.mkdir("unc");
QString uncTarget = QStringLiteral("//") + QtNetworkSettings::winServerName() + "/testshare";
QString uncTarget = QStringLiteral("//") + QTest::uncServerName() + "/testshare";
QString uncSymlink = QDir::toNativeSeparators(pwd.absolutePath().append("\\unc\\link_to_unc"));
QTest::newRow("UNC symlink")
<< NtfsTestResource(NtfsTestResource::SymLink, uncSymlink, uncTarget)

View File

@ -35,9 +35,7 @@
#include <qpa/qplatformdialoghelper.h>
#include <qpa/qplatformintegration.h>
#if defined(Q_OS_WIN)
#include "../../../network-settings.h"
#endif
#include "../../../../shared/filesystem.h"
#if defined QT_BUILD_INTERNAL
QT_BEGIN_NAMESPACE
@ -256,7 +254,7 @@ void tst_QFileDialog2::unc()
{
#if defined(Q_OS_WIN)
// Only test UNC on Windows./
QString dir("\\\\" + QtNetworkSettings::winServerName() + "\\testsharewritable");
QString dir("\\\\" + QTest::uncServerName() + "\\testsharewritable");
#else
QString dir(QDir::currentPath());
#endif

View File

@ -25,6 +25,9 @@
#ifndef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE // MinGW
#define SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE (0x2)
#endif
namespace QTest {
static QString uncServerName() { return qgetenv("COMPUTERNAME"); }
}
#endif
// QTemporaryDir-based helper class for creating file-system hierarchies and cleaning up.