diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-05-11 14:09:11 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-06-05 01:16:06 +0200 |
commit | 0564ebdb3641d7325f73dbbf2cbb04e6dca92d83 (patch) | |
tree | a766802e3bd675e8d84d655c3b93a0ea62d98d92 /tests/auto/corelib/io/qtemporarydir | |
parent | a1d967357f2715899d0236ea4910e615d178024f (diff) |
Unify behavior for long path or UNC prefix removal
Split the code out of QDir::fromNativeSeparator into a separate
reusable function to remove the above-mentioned prefixes. Fixes
and unifies behavior if the prefix was given with slashes instead
of backslashes. Add a couple more test cases.
Fixes: QTBUG-93868
Pick-to: 5.15 6.0 6.1
Change-Id: Ibd94ae283e2fb113f9c2db97475fbc7d89522bbf
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'tests/auto/corelib/io/qtemporarydir')
-rw-r--r-- | tests/auto/corelib/io/qtemporarydir/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp | 23 |
2 files changed, 25 insertions, 3 deletions
diff --git a/tests/auto/corelib/io/qtemporarydir/CMakeLists.txt b/tests/auto/corelib/io/qtemporarydir/CMakeLists.txt index fa8efa114b..fcfd409d5b 100644 --- a/tests/auto/corelib/io/qtemporarydir/CMakeLists.txt +++ b/tests/auto/corelib/io/qtemporarydir/CMakeLists.txt @@ -10,3 +10,8 @@ qt_internal_add_test(tst_qtemporarydir PUBLIC_LIBRARIES Qt::TestPrivate ) + +qt_internal_extend_target(tst_qtemporarydir CONDITION WIN32 + LIBRARIES + shlwapi +) diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index db07f80495..3332cd6079 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -37,6 +37,7 @@ #include <qset.h> #include <QtTest/private/qtesthelpers_p.h> #ifdef Q_OS_WIN +# include <shlwapi.h> # include <windows.h> #endif #ifdef Q_OS_UNIX // for geteuid() @@ -159,9 +160,25 @@ void tst_QTemporaryDir::fileTemplate_data() } #ifdef Q_OS_WIN - const auto tmp = QDir::toNativeSeparators(QDir::tempPath()).sliced(QDir::rootPath().size()); - QTest::newRow("UNC") << uR"(\\localhost\C$\)"_qs + tmp + uR"(\UNC.XXXXXX.tmpDir)"_qs - << "UNC." << ".tmpDir"; + auto tmp = QDir::toNativeSeparators(QDir::tempPath()); + if (PathGetDriveNumber((const wchar_t *) tmp.utf16()) < 0) + return; // skip if we have no drive letter + + tmp.data()[1] = u'$'; + const auto tmpPath = tmp + uR"(\UNC.XXXXXX.tmpDir)"_qs; + + QTest::newRow("UNC-backslash") + << uR"(\\localhost\)"_qs + tmpPath << "UNC." + << ".tmpDir"; + QTest::newRow("UNC-prefix") + << uR"(\\?\UNC\localhost\)"_qs + tmpPath << "UNC." + << ".tmpDir"; + QTest::newRow("UNC-slash") + << u"//localhost/"_qs + QDir::fromNativeSeparators(tmpPath) << "UNC." + << ".tmpDir"; + QTest::newRow("UNC-prefix-slash") + << uR"(//?/UNC/localhost/)"_qs + QDir::fromNativeSeparators(tmpPath) << "UNC." + << ".tmpDir"; #endif } |