diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-05-03 14:40:53 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-05-17 21:46:28 +0200 |
commit | ad12c3c40b07079d875f48027eef0786acef7de0 (patch) | |
tree | 8f62908ccb817c581cd7762c41062f0b8c98e36b /tests/auto/corelib/io | |
parent | a4618c020d3923eb6c8c55115c49d7c9f00b3034 (diff) |
Fix QSaveFile and QTemporaryFile issues with windows network shares
The commit amends commit 3966b571 to take UNC prefix into account as
well. Fixes the weird file name output as reported in QTBUG-74291 and
QTBUG-83365. Replace manual separator normalizing in qt_cleanPath(),
this is another spot where UNC prefix handling needs to be applied.
Also make QTemporaryFile operate on '/' as file separators to fix
creating both file types with native path separators on network shares.
Fixes: QTBUG-74291
Fixes: QTBUG-76228
Fixes: QTBUG-83365
Change-Id: Iff8d26b994bf4194c074cd5c996cda3934297fa5
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit ec9e85656339dbc9e6918a1369c981cece7bc97d)
Diffstat (limited to 'tests/auto/corelib/io')
4 files changed, 28 insertions, 1 deletions
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index f71bc7e7eb..cec01eb752 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -1269,6 +1269,8 @@ tst_QDir::cleanPath_data() QTest::newRow("unc-server-up") << "//server/path/.." << "//server"; QTest::newRow("unc-server-above-root") << "//server/.." << "//server/.."; QTest::newRow("longpath") << "\\\\?\\d:\\" << "d:/"; + QTest::newRow("unc-network-share") << "\\\\?\\UNC\\localhost\\c$\\tmp.txt" + << "//localhost/c$/tmp.txt"; #else QTest::newRow("data15") << "//c:/foo" << "/c:/foo"; #endif // non-windows @@ -1744,6 +1746,8 @@ void tst_QDir::nativeSeparators() QCOMPARE(QDir::fromNativeSeparators(QLatin1String("/")), QString("/")); QCOMPARE(QDir::fromNativeSeparators(QLatin1String("\\")), QString("/")); QCOMPARE(QDir::fromNativeSeparators(QLatin1String("\\\\?\\C:\\")), QString("C:/")); + QCOMPARE(QDir::fromNativeSeparators(QLatin1String(R"(\\?\UNC\localhost\c$\tmp.txt)")), + QString("//localhost/c$/tmp.txt")); #else QCOMPARE(QDir::toNativeSeparators(QLatin1String("/")), QString("/")); QCOMPARE(QDir::toNativeSeparators(QLatin1String("\\")), QString("\\")); diff --git a/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp b/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp index 30c38b20f9..be4fcb5da6 100644 --- a/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp +++ b/tests/auto/corelib/io/qfilesystementry/tst_qfilesystementry.cpp @@ -104,6 +104,17 @@ void tst_QFileSystemEntry::getSetCheck_data() << QString("A:dir\\without\\leading\\backslash.bat") << absPrefix + QString("A:\\dir\\without\\leading\\backslash.bat") << "A:dir/without/leading/backslash.bat" << "backslash.bat" << "backslash" << "backslash" << "bat" << "bat" << false << false; + + QTest::newRow("longpath") + << QString("\\\\?\\D:\\") + << absPrefix + QString("D:\\") + << "D:/" << "" << "" << "" << "" << "" << true << false; + + QTest::newRow("uncprefix") + << QString("\\\\?\\UNC\\localhost\\C$\\tmp.txt") + << absPrefix + QString("UNC\\localhost\\C$\\tmp.txt") + << "//localhost/C$/tmp.txt" << "tmp.txt" << "tmp" << "tmp" << "txt" << "txt" << true + << false; } void tst_QFileSystemEntry::getSetCheck() @@ -137,7 +148,7 @@ void tst_QFileSystemEntry::getSetCheck() QCOMPARE(entry2.isRelative(), relative); QCOMPARE(entry2.filePath(), filepath); // Since this entry was created using the native path, - // the object shouldnot change nativeFilePath. + // the object shouldn't change nativeFilePath. QCOMPARE(entry2.nativeFilePath(), nativeFilePath); QCOMPARE(entry2.fileName(), filename); QCOMPARE(entry2.baseName(), baseName); diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index 4969c0e6e3..14f3a10593 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -157,6 +157,12 @@ void tst_QTemporaryDir::fileTemplate_data() prefix = "qt_" + hanTestText(); QTest::newRow("Chinese") << (prefix + "XXXXXX" + umlautTestText()) << prefix << umlautTestText(); } + +#ifdef Q_OS_WIN + const auto tmp = QDir::toNativeSeparators(QDir::tempPath()).sliced(QDir::rootPath().size()); + QTest::newRow("UNC") << "\\\\localhost\\C$\\" + tmp + "\\UNC.XXXXXX.tmpDir" + << "UNC." << ".tmpDir"; +#endif } void tst_QTemporaryDir::fileTemplate() diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index 331558255f..e23df1da2b 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -206,6 +206,12 @@ void tst_QTemporaryFile::fileTemplate_data() prefix = "qt_" + hanTestText(); QTest::newRow("Chinese characters") << (prefix + "XXXXXX") << prefix << QString() << QString(); } + +#ifdef Q_OS_WIN + const auto tmp = QDir::toNativeSeparators(QDir::tempPath()).sliced(QDir::rootPath().size()); + QTest::newRow("UNC") << "\\\\localhost\\C$\\" + tmp + "\\QTBUG-74291.XXXXXX.tmpFile" + << "QTBUG-74291." << ".tmpFile" << ""; +#endif } void tst_QTemporaryFile::fileTemplate() |