summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp')
-rw-r--r--tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp124
1 files changed, 79 insertions, 45 deletions
diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
index d4760c0afd..737317a8fb 100644
--- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
+++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
@@ -1,31 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QStandardPaths>
@@ -49,6 +23,10 @@
#include "qplatformdefs.h"
#endif
+#include <optional>
+
+using namespace Qt::StringLiterals;
+
class tst_QTemporaryDir : public QObject
{
Q_OBJECT
@@ -59,6 +37,7 @@ public slots:
private slots:
void construction();
+ void moveSemantics();
void fileTemplate();
void fileTemplate_data();
void getSetCheck();
@@ -74,7 +53,7 @@ private slots:
void QTBUG_4796_data();
void QTBUG_4796();
- void QTBUG43352_failedSetPermissions();
+ void nestedTempDirs();
private:
QString m_previousCurrent;
@@ -105,6 +84,58 @@ void tst_QTemporaryDir::construction()
QCOMPARE(dir.errorString(), QString());
}
+void tst_QTemporaryDir::moveSemantics()
+{
+ {
+ auto original = std::optional<QTemporaryDir>(std::in_place);
+ QVERIFY(original->isValid());
+
+ original->setAutoRemove(true);
+
+ auto OriginalDirectoryInfo = QFileInfo(original->path());
+ OriginalDirectoryInfo.setCaching(false);
+ QVERIFY(OriginalDirectoryInfo.exists());
+
+ QTemporaryDir movedInto = std::move(*original);
+
+ original.reset();
+
+ QVERIFY(OriginalDirectoryInfo.exists());
+ QVERIFY(movedInto.path() == OriginalDirectoryInfo.filePath());
+ }
+
+ {
+ auto movedInto = QTemporaryDir();
+ QVERIFY(movedInto.isValid());
+
+ movedInto.setAutoRemove(true);
+
+ auto movedIntoInitialDirectoryInfo = QFileInfo(movedInto.path());
+ movedIntoInitialDirectoryInfo.setCaching(false);
+ QVERIFY(movedIntoInitialDirectoryInfo.exists());
+
+ auto OriginalDirectoryInfo = QFileInfo();
+ OriginalDirectoryInfo.setCaching(false);
+
+ {
+ auto original = QTemporaryDir();
+ QVERIFY(original.isValid());
+
+ original.setAutoRemove(true);
+
+ OriginalDirectoryInfo.setFile(original.path());
+ QVERIFY(OriginalDirectoryInfo.exists());
+
+ movedInto = std::move(original);
+ }
+
+ QVERIFY(!movedIntoInitialDirectoryInfo.exists());
+ QVERIFY(OriginalDirectoryInfo.exists());
+
+ QVERIFY(movedInto.path() == OriginalDirectoryInfo.filePath());
+ }
+}
+
// Testing get/set functions
void tst_QTemporaryDir::getSetCheck()
{
@@ -169,19 +200,19 @@ void tst_QTemporaryDir::fileTemplate_data()
return; // skip if we have no drive letter
tmp.data()[1] = u'$';
- const auto tmpPath = tmp + uR"(\UNC.XXXXXX.tmpDir)"_qs;
+ const auto tmpPath = tmp + uR"(\UNC.XXXXXX.tmpDir)"_s;
QTest::newRow("UNC-backslash")
- << uR"(\\localhost\)"_qs + tmpPath << "UNC."
+ << uR"(\\localhost\)"_s + tmpPath << "UNC."
<< ".tmpDir";
QTest::newRow("UNC-prefix")
- << uR"(\\?\UNC\localhost\)"_qs + tmpPath << "UNC."
+ << uR"(\\?\UNC\localhost\)"_s + tmpPath << "UNC."
<< ".tmpDir";
QTest::newRow("UNC-slash")
- << u"//localhost/"_qs + QDir::fromNativeSeparators(tmpPath) << "UNC."
+ << u"//localhost/"_s + QDir::fromNativeSeparators(tmpPath) << "UNC."
<< ".tmpDir";
QTest::newRow("UNC-prefix-slash")
- << uR"(//?/UNC/localhost/)"_qs + QDir::fromNativeSeparators(tmpPath) << "UNC."
+ << uR"(//?/UNC/localhost/)"_s + QDir::fromNativeSeparators(tmpPath) << "UNC."
<< ".tmpDir";
#endif
}
@@ -197,9 +228,9 @@ void tst_QTemporaryDir::fileTemplate()
QVERIFY(tempDir.isValid());
QString dirName = QDir(tempDir.path()).dirName();
- if (prefix.length()) {
- QCOMPARE(dirName.left(prefix.length()), prefix);
- QCOMPARE(dirName.right(suffix.length()), suffix);
+ if (prefix.size()) {
+ QCOMPARE(dirName.left(prefix.size()), prefix);
+ QCOMPARE(dirName.right(suffix.size()), suffix);
}
}
@@ -358,7 +389,8 @@ void tst_QTemporaryDir::openOnRootDrives()
#endif
// If it's possible to create a file in the root directory, it
// must be possible to create a temp dir there too.
- foreach (const QFileInfo &driveInfo, QDir::drives()) {
+ const auto drives = QDir::drives();
+ for (const QFileInfo &driveInfo : drives) {
QFile testFile(driveInfo.filePath() + "XXXXXX");
if (testFile.open(QIODevice::ReadWrite)) {
testFile.remove();
@@ -447,7 +479,7 @@ void tst_QTemporaryDir::QTBUG_4796() // unicode support
{
~CleanOnReturn()
{
- foreach (const QString &tempName, tempNames)
+ for (const QString &tempName : std::as_const(tempNames))
QVERIFY(QDir(tempName).removeRecursively());
}
@@ -517,22 +549,24 @@ void tst_QTemporaryDir::QTBUG_4796() // unicode support
#ifdef Q_OS_WIN
QTest::qWait(20);
#endif
- foreach (const QString &tempName, cleaner.tempNames)
+ for (const QString &tempName : std::as_const(cleaner.tempNames))
QVERIFY2(!QDir(tempName).exists(), qPrintable(tempName));
cleaner.reset();
}
-void tst_QTemporaryDir::QTBUG43352_failedSetPermissions()
+void tst_QTemporaryDir::nestedTempDirs()
{
- QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + QStringLiteral("/");
- int count = QDir(path).entryList().size();
+ QTemporaryDir parentDir;
+ const QString &parentPath = parentDir.path();
{
- QTemporaryDir dir(path);
+ QTemporaryDir tempdir(parentPath);
}
- QCOMPARE(QDir(path).entryList().size(), count);
+ QDir dir(parentPath);
+ dir.setFilter(QDir::NoDotAndDotDot);
+ QCOMPARE(dir.count(), 0);
}
QTEST_MAIN(tst_QTemporaryDir)