tst_QSaveFile: add a test for attempting to overwrite a dir
This is not the same as the 'directory' test below, which tests that we can't open() a QSaveFile on something that already is a directory. For this one, the target file did not exist when we open()ed, but has become a directory since then. Change-Id: I92d13f103693d375e742fffdd74053dd1b86d81f Reviewed-by: David Faure <david.faure@kdab.com> (cherry picked from commit f4ff7c40588a4515504e22266d15816ca8616cba) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
765aa27aa3
commit
875ccc41f4
@ -64,7 +64,8 @@ private slots:
|
||||
void transactionalWriteNoPermissionsOnDir();
|
||||
void transactionalWriteNoPermissionsOnFile();
|
||||
void transactionalWriteCanceled();
|
||||
void transactionalWriteErrorRenaming();
|
||||
void transactionalWritePermissionsErrorRenaming();
|
||||
void transactionalWriteTypeErrorRenaming();
|
||||
void symlink();
|
||||
void directory();
|
||||
|
||||
@ -362,7 +363,7 @@ void tst_QSaveFile::transactionalWriteCanceled()
|
||||
QCOMPARE(file.fileName(), targetFile);
|
||||
}
|
||||
|
||||
void tst_QSaveFile::transactionalWriteErrorRenaming()
|
||||
void tst_QSaveFile::transactionalWritePermissionsErrorRenaming()
|
||||
{
|
||||
#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS)
|
||||
if (::geteuid() == 0)
|
||||
@ -398,6 +399,33 @@ void tst_QSaveFile::transactionalWriteErrorRenaming()
|
||||
QCOMPARE(file.error(), QFile::RenameError);
|
||||
}
|
||||
|
||||
void tst_QSaveFile::transactionalWriteTypeErrorRenaming()
|
||||
{
|
||||
QTemporaryDir dir;
|
||||
QVERIFY2(dir.isValid(), qPrintable(dir.errorString()));
|
||||
const QString targetFile = dir.path() + QString::fromLatin1("/outfile");
|
||||
QSaveFile file(targetFile);
|
||||
QVERIFY2(file.open(QIODevice::WriteOnly), msgCannotOpen(file).constData());
|
||||
QCOMPARE(file.write("Hello"), qint64(5));
|
||||
|
||||
QFileInfo target(targetFile);
|
||||
QVERIFY(!target.exists(targetFile));
|
||||
|
||||
// create a directory with the target file name: one can't replace a
|
||||
// directory with a file through a rename
|
||||
QVERIFY(QDir(dir.path()).mkdir("outfile"));
|
||||
|
||||
// The saving should fail.
|
||||
QVERIFY(!file.commit());
|
||||
QCOMPARE(file.error(), QFile::RenameError);
|
||||
#ifdef Q_OS_UNIX
|
||||
QCOMPARE(file.errorString(), qt_error_string(EISDIR));
|
||||
#endif
|
||||
|
||||
target.refresh();
|
||||
QVERIFY(target.isDir());
|
||||
}
|
||||
|
||||
void tst_QSaveFile::symlink()
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
|
Loading…
x
Reference in New Issue
Block a user