summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2011-08-27 08:08:21 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2011-08-27 08:08:21 (GMT)
commit88a41bd9d0ff69dbf5695644643967ddc9b34ddf (patch)
tree07a782bb162aeba9776d3d2a2737a032e349af0d
parente2c2e7e7fb3bee99260dc5b7bfab42c9217c18c8 (diff)
parent7b45a4cbf7593c8d7a837d826d9827fee243c46c (diff)
downloadQt-88a41bd9d0ff69dbf5695644643967ddc9b34ddf.zip
Qt-88a41bd9d0ff69dbf5695644643967ddc9b34ddf.tar.gz
Qt-88a41bd9d0ff69dbf5695644643967ddc9b34ddf.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-earth-staging into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/qt-earth-staging: (21 commits) Revert "Don't second-guess the "engine"; call cleanPath on absolutePaths" Revert "In 4.7 QFileInfo::absolute(File)Path returned clean paths" In 4.7 QFileInfo::absolute(File)Path returned clean paths ret is an "internal" path, no need to re-process it We prefer capitalized drive letters, make it so sooner Don't second-guess the "engine"; call cleanPath on absolutePaths Compare non-canonical paths before falling back on expensive computation Fix QDir::operator==(const QDir &) const Off-by-one error in assert condition... Leftovers from 401722ef9e6fe79bd41f9d5f79668f5c4997c8e6 Merged fileTemplate test with QTBUG_4796 Cleanup code: removing empty stubs Fix QTemporaryFile regressions and new found issues Use "native paths" on POSIX platforms as well Cleanup #includes Add output on test failure Atomic implementation of create file and obtain handle for Win/Symbian Minimize encoding conversions when generating unique file name Use QStringBuilder when copying template for modification Make Symbian follow Windows code in temporary path generation ...
-rw-r--r--src/corelib/io/qdir.cpp10
-rw-r--r--src/corelib/io/qfileinfo.cpp6
-rw-r--r--src/corelib/io/qfilesystemengine_win.cpp7
-rw-r--r--src/corelib/io/qtemporaryfile.cpp230
-rw-r--r--tests/auto/qdir/tst_qdir.cpp6
-rw-r--r--tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp197
6 files changed, 256 insertions, 200 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index f9196e0..c0c62e1 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -1633,9 +1633,13 @@ bool QDir::operator==(const QDir &dir) const
if (d->filters == other->filters
&& d->sort == other->sort
&& d->nameFilters == other->nameFilters) {
- d->resolveAbsoluteEntry();
- other->resolveAbsoluteEntry();
- return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0;
+
+ // Assume directories are the same if path is the same
+ if (d->dirEntry.filePath() == other->dirEntry.filePath())
+ return true;
+
+ // Fallback to expensive canonical path computation
+ return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;
}
return false;
}
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp
index ca42c87..ff328da 100644
--- a/src/corelib/io/qfileinfo.cpp
+++ b/src/corelib/io/qfileinfo.cpp
@@ -391,6 +391,11 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const
return true;
if (d->isDefaultConstructed || fileinfo.d_ptr->isDefaultConstructed)
return false;
+
+ // Assume files are the same if path is the same
+ if (d->fileEntry.filePath() == fileinfo.d_ptr->fileEntry.filePath())
+ return true;
+
Qt::CaseSensitivity sensitive;
if (d->fileEngine == 0 || fileinfo.d_ptr->fileEngine == 0) {
if (d->fileEngine != fileinfo.d_ptr->fileEngine) // one is native, the other is a custom file-engine
@@ -406,6 +411,7 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const
if (fileinfo.size() != size()) //if the size isn't the same...
return false;
+ // Fallback to expensive canonical path computation
return canonicalFilePath().compare(fileinfo.canonicalFilePath(), sensitive) == 0;
}
diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp
index f704fc3..764ee6d 100644
--- a/src/corelib/io/qfilesystemengine_win.cpp
+++ b/src/corelib/io/qfilesystemengine_win.cpp
@@ -536,7 +536,7 @@ QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry)
// Force uppercase drive letters.
ret[0] = ret.at(0).toUpper();
}
- return QFileSystemEntry(ret);
+ return QFileSystemEntry(ret, QFileSystemEntry::FromInternalPath());
}
//static
@@ -1052,11 +1052,12 @@ QString QFileSystemEngine::tempPath()
}
if (ret.isEmpty()) {
#if !defined(Q_OS_WINCE)
- ret = QLatin1String("c:/tmp");
+ ret = QLatin1String("C:/tmp");
#else
ret = QLatin1String("/Temp");
#endif
- }
+ } else if (ret.length() >= 2 && ret[1] == QLatin1Char(':'))
+ ret[0] = ret.at(0).toUpper(); // Force uppercase drive letters.
return ret;
}
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index d457601..e80a8b6 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -44,17 +44,18 @@
#ifndef QT_NO_TEMPORARYFILE
#include "qplatformdefs.h"
-#include "qabstractfileengine.h"
#include "private/qfile_p.h"
-#include "private/qabstractfileengine_p.h"
#include "private/qfsfileengine_p.h"
+#include "private/qsystemerror_p.h"
+#include "private/qfilesystemengine_p.h"
-#if !defined(Q_OS_WINCE)
-# include <errno.h>
+#if defined(Q_OS_SYMBIAN)
+#include "private/qcore_symbian_p.h"
#endif
-#if defined(Q_OS_UNIX)
-# include "private/qcore_unix_p.h" // overrides QT_OPEN
+#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
+#include "private/qcore_unix_p.h" // overrides QT_OPEN
+#include <errno.h>
#endif
#if defined(QT_BUILD_CORE_LIB)
@@ -63,6 +64,30 @@
QT_BEGIN_NAMESPACE
+#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
+typedef ushort Char;
+
+static inline Char Latin1Char(char ch)
+{
+ return ushort(uchar(ch));
+}
+
+# ifdef Q_OS_WIN
+typedef HANDLE NativeFileHandle;
+# else // Q_OS_SYMBIAN
+# ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
+typedef RFile64 NativeFileHandle;
+# else
+typedef RFile NativeFileHandle;
+# endif
+# endif
+
+#else // POSIX
+typedef char Char;
+typedef char Latin1Char;
+typedef int NativeFileHandle;
+#endif
+
/*
* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
@@ -96,27 +121,33 @@ QT_BEGIN_NAMESPACE
\internal
Generates a unique file path and returns a native handle to the open file.
- \a path is used as a template when generating unique paths,
- \a placeholderStart and \a placeholderEnd delimit the sub-string that will
- be randomized.
+ \a path is used as a template when generating unique paths, \a pos
+ identifies the position of the first character that will be replaced in the
+ template and \a length the number of characters that may be substituted.
Returns an open handle to the newly created file if successful, an invalid
handle otherwise. In both cases, the string in \a path will be changed and
contain the generated path name.
*/
-static int createFileFromTemplate(char *const path,
- char *const placeholderStart, char *const placeholderEnd)
+static bool createFileFromTemplate(NativeFileHandle &file,
+ QFileSystemEntry::NativePath &path, size_t pos, size_t length,
+ QSystemError &error)
{
- Q_ASSERT(placeholderEnd > placeholderStart);
+ Q_ASSERT(length != 0);
+ Q_ASSERT(pos < size_t(path.length()));
+ Q_ASSERT(length <= size_t(path.length()) - pos);
+
+ Char *const placeholderStart = (Char *)path.data() + pos;
+ Char *const placeholderEnd = placeholderStart + length;
// Initialize placeholder with random chars + PID.
{
- char *rIter = placeholderEnd;
+ Char *rIter = placeholderEnd;
#if defined(QT_BUILD_CORE_LIB)
quint64 pid = quint64(QCoreApplication::applicationPid());
do {
- *--rIter = (pid % 10) + '0';
+ *--rIter = Latin1Char((pid % 10) + '0');
pid /= 10;
} while (rIter != placeholderStart && pid != 0);
#endif
@@ -124,48 +155,82 @@ static int createFileFromTemplate(char *const path,
while (rIter != placeholderStart) {
char ch = char((qrand() & 0xffff) % (26 + 26));
if (ch < 26)
- *--rIter = ch + 'A';
+ *--rIter = Latin1Char(ch + 'A');
else
- *--rIter = ch - 26 + 'a';
+ *--rIter = Latin1Char(ch - 26 + 'a');
}
}
+#ifdef Q_OS_SYMBIAN
+ RFs& fs = qt_s60GetRFs();
+#endif
+
for (;;) {
// Atomically create file and obtain handle
-#ifndef Q_OS_WIN
- {
- int fd = QT_OPEN(path, QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE, 0600);
- if (fd != -1)
- return fd;
- if (errno != EEXIST)
- return -1;
+#if defined(Q_OS_WIN)
+ file = CreateFile((const wchar_t *)path.constData(),
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+
+ if (file != INVALID_HANDLE_VALUE)
+ return true;
+
+ DWORD err = GetLastError();
+ if (err != ERROR_FILE_EXISTS) {
+ error = QSystemError(err, QSystemError::NativeError);
+ return false;
+ }
+#elif defined(Q_OS_SYMBIAN)
+ TInt err = file.Create(fs, qt_QString2TPtrC(path),
+ EFileRead | EFileWrite | EFileShareReadersOrWriters);
+
+ if (err == KErrNone)
+ return true;
+
+ if (err != KErrAlreadyExists) {
+ error = QSystemError(err, QSystemError::NativeError);
+ return false;
+ }
+#else // POSIX
+ file = QT_OPEN(path.constData(),
+ QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE,
+ 0600);
+
+ if (file != -1)
+ return true;
+
+ int err = errno;
+ if (err != EEXIST) {
+ error = QSystemError(err, QSystemError::NativeError);
+ return false;
}
-#else
- if (!QFileInfo(QString::fromLocal8Bit(path)).exists())
- return 1;
#endif
/* tricky little algorwwithm for backward compatibility */
- for (char *iter = placeholderStart;;) {
+ for (Char *iter = placeholderStart;;) {
// Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z'
// String progression: "ZZaiC" => "aabiC"
- switch (*iter) {
+ switch (char(*iter)) {
case 'Z':
// Rollover, advance next character
- *iter = 'a';
- if (++iter == placeholderEnd)
- return -1;
+ *iter = Latin1Char('a');
+ if (++iter == placeholderEnd) {
+ // Out of alternatives. Return file exists error, previously set.
+ error = QSystemError(err, QSystemError::NativeError);
+ return false;
+ }
continue;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
- *iter = 'a';
+ *iter = Latin1Char('a');
break;
case 'z':
// increment 'z' to 'A'
- *iter = 'A';
+ *iter = Latin1Char('A');
break;
default:
@@ -257,7 +322,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
QString qfilename = d->fileEntry.filePath();
- // Find placeholder string.
+ // Ensure there is a placeholder mask
uint phPos = qfilename.length();
uint phLength = 0;
@@ -269,70 +334,73 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
continue;
}
- if (qfilename[phPos] == QLatin1Char('/')
- || phLength >= 6) {
+ if (phLength >= 6
+ || qfilename[phPos] == QLatin1Char('/')) {
++phPos;
break;
}
+ // start over
phLength = 0;
}
- QStringRef prefix, suffix;
- if (phLength < 6) {
- qfilename += QLatin1Char('.');
- prefix = QStringRef(&qfilename);
- phLength = 6;
- } else {
- prefix = qfilename.leftRef(phPos);
- suffix = qfilename.midRef(phPos + phLength);
- }
+ if (phLength < 6)
+ qfilename.append(QLatin1String(".XXXXXX"));
+
+ // "Nativify" :-)
+ QFileSystemEntry::NativePath filename = QFileSystemEngine::absoluteName(
+ QFileSystemEntry(qfilename, QFileSystemEntry::FromInternalPath()))
+ .nativeFilePath();
- QByteArray filename = prefix.toLocal8Bit();
+ // Find mask in native path
phPos = filename.length();
- if (suffix.isEmpty())
- filename.resize(phPos + phLength);
- else
- filename.insert(phPos + phLength, suffix.toLocal8Bit());
-
- char *path = filename.data();
-
-#ifndef Q_OS_WIN
- int fd = createFileFromTemplate(path, path + phPos, path + phPos + phLength);
- if (fd != -1) {
- // First open the fd as an external file descriptor to
- // initialize the engine properly.
- if (QFSFileEngine::open(openMode, fd)) {
-
- // Allow the engine to close the handle even if it's "external".
- d->closeFileHandle = true;
-
- // Restore the file names (open() resets them).
- d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length())); //note that filename is NOT a native path
- filePathIsTemplate = false;
- return true;
+ phLength = 0;
+ while (phPos != 0) {
+ --phPos;
+
+ if (filename[phPos] == Latin1Char('X')) {
+ ++phLength;
+ continue;
}
- QT_CLOSE(fd);
- }
- setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno));
- return false;
-#else
- if (createFileFromTemplate(path, path + phPos, path + phPos + phLength) == -1) {
- return false;
+ if (phLength >= 6) {
+ ++phPos;
+ break;
+ }
+
+ // start over
+ phLength = 0;
}
- QString template_ = d->fileEntry.filePath();
- d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length()));
+ Q_ASSERT(phLength >= 6);
- if (QFSFileEngine::open(openMode)) {
- filePathIsTemplate = false;
- return true;
+ QSystemError error;
+#if defined(Q_OS_WIN)
+ NativeFileHandle &file = d->fileHandle;
+#elif defined(Q_OS_SYMBIAN)
+ NativeFileHandle &file = d->symbianFile;
+#else // POSIX
+ NativeFileHandle &file = d->fd;
+#endif
+
+ if (!createFileFromTemplate(file, filename, phPos, phLength, error)) {
+ setError(QFile::OpenError, error.toString());
+ return false;
}
- d->fileEntry = QFileSystemEntry(template_, QFileSystemEntry::FromInternalPath());
- return false;
+ d->fileEntry = QFileSystemEntry(filename, QFileSystemEntry::FromNativePath());
+
+#if !defined(Q_OS_WIN)
+ d->closeFileHandle = true;
#endif
+
+ filePathIsTemplate = false;
+
+ d->openMode = openMode;
+ d->lastFlushFailed = false;
+ d->tried_stat = 0;
+
+ return true;
}
bool QTemporaryFileEngine::remove()
diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp
index 0a42a97..419eaae 100644
--- a/tests/auto/qdir/tst_qdir.cpp
+++ b/tests/auto/qdir/tst_qdir.cpp
@@ -444,9 +444,15 @@ void tst_QDir::QDir_default()
void tst_QDir::compare()
{
// operator==
+
+ // Not using QCOMPARE to test result of QDir::operator==
+
QDir dir;
dir.makeAbsolute();
QVERIFY(dir == QDir::currentPath());
+
+ QVERIFY(QDir() == QDir(QDir::currentPath()));
+ QVERIFY(QDir("../") == QDir(QDir::currentPath() + "/.."));
}
static QStringList filterLinks(const QStringList &list)
diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
index 2edb93a..c9d4ba4 100644
--- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -69,13 +69,7 @@
class tst_QTemporaryFile : public QObject
{
Q_OBJECT
-public:
- tst_QTemporaryFile();
- virtual ~tst_QTemporaryFile();
public slots:
- void init();
- void cleanup();
-
void initTestCase();
void cleanupTestCase();
@@ -100,22 +94,17 @@ private slots:
void resetTemplateAfterError();
void setTemplateAfterOpen();
void autoRemoveAfterFailedRename();
-
- void QTBUG_4796_data();
- void QTBUG_4796();
-
-public:
};
void tst_QTemporaryFile::initTestCase()
{
- // For QTBUG_4796
+ // For fileTemplate tests
QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX"));
}
void tst_QTemporaryFile::cleanupTestCase()
{
- // From QTBUG_4796
+ // From fileTemplate tests
QVERIFY(QDir().rmdir("test-XXXXXX"));
}
@@ -139,76 +128,6 @@ void tst_QTemporaryFile::getSetCheck()
QCOMPARE(true, obj1.autoRemove());
}
-tst_QTemporaryFile::tst_QTemporaryFile()
-{
-}
-
-tst_QTemporaryFile::~tst_QTemporaryFile()
-{
-
-}
-
-void tst_QTemporaryFile::init()
-{
-// TODO: Add initialization code here.
-// This will be executed immediately before each test is run.
-}
-
-void tst_QTemporaryFile::cleanup()
-{
-// TODO: Add cleanup code here.
-// This will be executed immediately after each test is run.
-}
-
-void tst_QTemporaryFile::fileTemplate_data()
-{
- QTest::addColumn<QString>("constructorTemplate");
- QTest::addColumn<QString>("prefix");
- QTest::addColumn<QString>("suffix");
- QTest::addColumn<QString>("fileTemplate");
-
- QTest::newRow("constructor default") << "" << "." << "" << "";
- QTest::newRow("constructor with xxx sufix") << "qt_XXXXXXxxx" << "qt_" << "xxx" << "";
- QTest::newRow("constructor with xXx sufix") << "qt_XXXXXXxXx" << "qt_" << "xXx" << "";
- QTest::newRow("constructor with no sufix") << "qt_XXXXXX" << "qt_" << "" << "";
- QTest::newRow("constructor with >6 X's and xxx suffix") << "qt_XXXXXXXXXXxxx" << "qt_" << "xxx" << "";
- QTest::newRow("constructor with >6 X's, no suffix") << "qt_XXXXXXXXXX" << "qt_" << "" << "";
-
- QTest::newRow("constructor with XXXX suffix") << "qt_XXXXXX_XXXX" << "qt_" << "_XXXX" << "";
- QTest::newRow("constructor with XXXXX suffix") << "qt_XXXXXX_XXXXX" << "qt_" << "_XXXXX" << "";
- QTest::newRow("constructor with XXXX prefix") << "qt_XXXX" << "qt_XXXX." << "" << "";
- QTest::newRow("constructor with XXXXX prefix") << "qt_XXXXX" << "qt_XXXXX." << "" << "";
- QTest::newRow("constructor with XXXX prefix and suffix") << "qt_XXXX_XXXXXX_XXXX" << "qt_XXXX_" << "_XXXX" << "";
- QTest::newRow("constructor with XXXXX prefix and suffix") << "qt_XXXXX_XXXXXX_XXXXX" << "qt_XXXXX_" << "_XXXXX" << "";
-
- QTest::newRow("set template, no suffix") << "" << "foo" << "" << "foo";
- QTest::newRow("set template, with lowercase XXXXXX") << "" << "qt_" << "xxxxxx" << "qt_XXXXXXxxxxxx";
- QTest::newRow("set template, with xxx") << "" << "qt_" << ".xxx" << "qt_XXXXXX.xxx";
- QTest::newRow("set template, with >6 X's") << "" << "qt_" << ".xxx" << "qt_XXXXXXXXXXXXXX.xxx";
- QTest::newRow("set template, with >6 X's, no suffix") << "" << "qt_" << "" << "qt_XXXXXXXXXXXXXX";
-}
-
-void tst_QTemporaryFile::fileTemplate()
-{
- QFETCH(QString, constructorTemplate);
- QFETCH(QString, prefix);
- QFETCH(QString, suffix);
- QFETCH(QString, fileTemplate);
-
- QTemporaryFile file(constructorTemplate);
- if (!fileTemplate.isEmpty())
- file.setFileTemplate(fileTemplate);
-
- QCOMPARE(file.open(), true);
-
- if (prefix.length())
- QCOMPARE(file.fileName().left(prefix.length()), prefix);
-
- if (suffix.length())
- QCOMPARE(file.fileName().right(suffix.length()), suffix);
-}
-
-
/*
This tests whether the temporary file really gets placed in QDir::tempPath
*/
@@ -411,11 +330,11 @@ void tst_QTemporaryFile::rename()
{
QTemporaryFile file(dir.filePath("temporary-file.XXXXXX"));
- QVERIFY(file.open());
+ QVERIFY2(file.open(), qPrintable(file.errorString()));
tempname = file.fileName();
QVERIFY(dir.exists(tempname));
- QVERIFY(file.rename("temporary-file.txt"));
+ QVERIFY2(file.rename("temporary-file.txt"), qPrintable(file.errorString()));
QVERIFY(!dir.exists(tempname));
QVERIFY(dir.exists("temporary-file.txt"));
QCOMPARE(file.fileName(), QString("temporary-file.txt"));
@@ -622,7 +541,7 @@ void tst_QTemporaryFile::autoRemoveAfterFailedRename()
cleaner.reset();
}
-void tst_QTemporaryFile::QTBUG_4796_data()
+void tst_QTemporaryFile::fileTemplate_data()
{
QTest::addColumn<QString>("prefix");
QTest::addColumn<QString>("suffix");
@@ -631,15 +550,33 @@ void tst_QTemporaryFile::QTBUG_4796_data()
QString unicode = QString::fromUtf8("\xc3\xa5\xc3\xa6\xc3\xb8");
QTest::newRow("<empty>") << QString() << QString() << true;
+
+ QTest::newRow(".") << QString(".") << QString() << true;
+ QTest::newRow("..") << QString("..") << QString() << true;
+
+ QTest::newRow("foo") << QString("foo") << QString() << true;
+ QTest::newRow("qt_ ... xxxxxx") << QString("qt_") << QString("xxxxxx") << true;
+ QTest::newRow("qt_ ... xxx") << QString("qt_") << QString("xxx") << true;
+ QTest::newRow("qt_ ... xXx") << QString("qt_") << QString("xXx") << true;
+ QTest::newRow("qt_ ...") << QString("qt_") << QString() << true;
+ QTest::newRow("qt_ ... _XXXX") << QString("qt_") << QString("_XXXX") << true;
+ QTest::newRow("qt_ ... _XXXXX") << QString("qt_") << QString("_XXXXX") << true;
+ QTest::newRow("qt_XXXX_ ...") << QString("qt_XXXX_") << QString() << true;
+ QTest::newRow("qt_XXXXX_ ...") << QString("qt_XXXXX_") << QString() << true;
+ QTest::newRow("qt_XXXX_ ... _XXXX") << QString("qt_XXXX_") << QString("_XXXX") << true;
+ QTest::newRow("qt_XXXXX_ ... _XXXXX") << QString("qt_XXXXX_") << QString("_XXXXX") << true;
+
QTest::newRow("blaXXXXXX") << QString("bla") << QString() << true;
QTest::newRow("XXXXXXbla") << QString() << QString("bla") << true;
+
QTest::newRow("does-not-exist/qt_temp.XXXXXX") << QString("does-not-exist/qt_temp") << QString() << false;
+
QTest::newRow("XXXXXX<unicode>") << QString() << unicode << true;
QTest::newRow("<unicode>XXXXXX") << unicode << QString() << true;
QTest::newRow("<unicode>XXXXXX<unicode>") << unicode << unicode << true;
}
-void tst_QTemporaryFile::QTBUG_4796()
+void tst_QTemporaryFile::fileTemplate()
{
QVERIFY(QDir("test-XXXXXX").exists());
@@ -665,25 +602,56 @@ void tst_QTemporaryFile::QTBUG_4796()
QFETCH(QString, suffix);
QFETCH(bool, openResult);
+ enum IterationType {
+ UseConstructor,
+ UseSetFileTemplate,
+ Done
+ };
+
+ for (IterationType setFileTemplate = UseConstructor; setFileTemplate != Done;
+ setFileTemplate = IterationType(int(setFileTemplate) + 1))
{
+ Q_FOREACH(QString const &tempName, cleaner.tempNames)
+ QVERIFY( !QFile::exists(tempName) );
+
+ cleaner.reset();
+
QString fileTemplate1 = prefix + QString("XX") + suffix;
QString fileTemplate2 = prefix + QString("XXXX") + suffix;
QString fileTemplate3 = prefix + QString("XXXXXX") + suffix;
QString fileTemplate4 = prefix + QString("XXXXXXXX") + suffix;
- QTemporaryFile file1(fileTemplate1);
- QTemporaryFile file2(fileTemplate2);
- QTemporaryFile file3(fileTemplate3);
- QTemporaryFile file4(fileTemplate4);
- QTemporaryFile file5("test-XXXXXX/" + fileTemplate1);
- QTemporaryFile file6("test-XXXXXX/" + fileTemplate3);
+ QTemporaryFile file1(setFileTemplate ? QString() : fileTemplate1);
+ QTemporaryFile file2(setFileTemplate ? QString() : fileTemplate2);
+ QTemporaryFile file3(setFileTemplate ? QString() : fileTemplate3);
+ QTemporaryFile file4(setFileTemplate ? QString() : fileTemplate4);
+ QTemporaryFile file5(setFileTemplate ? QString() : "test-XXXXXX/" + fileTemplate1);
+ QTemporaryFile file6(setFileTemplate ? QString() : "test-XXXXXX/" + fileTemplate3);
+
+ if (setFileTemplate) {
+ file1.setFileTemplate(fileTemplate1);
+ file2.setFileTemplate(fileTemplate2);
+ file3.setFileTemplate(fileTemplate3);
+ file4.setFileTemplate(fileTemplate4);
+ file5.setFileTemplate("test-XXXXXX/" + fileTemplate1);
+ file6.setFileTemplate("test-XXXXXX/" + fileTemplate3);
+ }
- QCOMPARE(file1.open(), openResult);
- QCOMPARE(file2.open(), openResult);
- QCOMPARE(file3.open(), openResult);
- QCOMPARE(file4.open(), openResult);
- QCOMPARE(file5.open(), openResult);
- QCOMPARE(file6.open(), openResult);
+ if (openResult) {
+ QVERIFY2(file1.open(), qPrintable(file1.errorString()));
+ QVERIFY2(file2.open(), qPrintable(file2.errorString()));
+ QVERIFY2(file3.open(), qPrintable(file3.errorString()));
+ QVERIFY2(file4.open(), qPrintable(file4.errorString()));
+ QVERIFY2(file5.open(), qPrintable(file5.errorString()));
+ QVERIFY2(file6.open(), qPrintable(file6.errorString()));
+ } else {
+ QVERIFY(!file1.open());
+ QVERIFY(!file2.open());
+ QVERIFY(!file3.open());
+ QVERIFY(!file4.open());
+ QVERIFY(!file5.open());
+ QVERIFY(!file6.open());
+ }
QCOMPARE(file1.exists(), openResult);
QCOMPARE(file2.exists(), openResult);
@@ -701,28 +669,31 @@ void tst_QTemporaryFile::QTBUG_4796()
<< file5.fileName()
<< file6.fileName();
- QVERIFY(file1.fileName().startsWith(fileTemplate1 + QLatin1Char('.')));
- QVERIFY(file2.fileName().startsWith(fileTemplate2 + QLatin1Char('.')));
- QVERIFY(file5.fileName().startsWith("test-XXXXXX/" + fileTemplate1 + QLatin1Char('.')));
- QVERIFY(file6.fileName().startsWith("test-XXXXXX/" + prefix));
+ QDir currentDir;
+ QString fileName1 = currentDir.relativeFilePath(file1.fileName());
+ QString fileName2 = currentDir.relativeFilePath(file2.fileName());
+ QString fileName3 = currentDir.relativeFilePath(file3.fileName());
+ QString fileName4 = currentDir.relativeFilePath(file4.fileName());
+ QString fileName5 = currentDir.relativeFilePath(file5.fileName());
+ QString fileName6 = currentDir.relativeFilePath(file6.fileName());
+
+ QVERIFY2(fileName1.startsWith(fileTemplate1 + QLatin1Char('.')), qPrintable(file1.fileName()));
+ QVERIFY2(fileName2.startsWith(fileTemplate2 + QLatin1Char('.')), qPrintable(file2.fileName()));
+ QVERIFY2(fileName5.startsWith("test-XXXXXX/" + fileTemplate1 + QLatin1Char('.')), qPrintable(file5.fileName()));
+ QVERIFY2(fileName6.startsWith("test-XXXXXX/" + prefix), qPrintable(file6.fileName()));
if (!prefix.isEmpty()) {
- QVERIFY(file3.fileName().startsWith(prefix));
- QVERIFY(file4.fileName().startsWith(prefix));
+ QVERIFY2(fileName3.startsWith(prefix), qPrintable(file3.fileName()));
+ QVERIFY2(fileName4.startsWith(prefix), qPrintable(file4.fileName()));
}
if (!suffix.isEmpty()) {
- QVERIFY(file3.fileName().endsWith(suffix));
- QVERIFY(file4.fileName().endsWith(suffix));
- QVERIFY(file6.fileName().endsWith(suffix));
+ QVERIFY2(fileName3.endsWith(suffix), qPrintable(file3.fileName()));
+ QVERIFY2(fileName4.endsWith(suffix), qPrintable(file4.fileName()));
+ QVERIFY2(fileName6.endsWith(suffix), qPrintable(file6.fileName()));
}
}
}
-
- Q_FOREACH(QString const &tempName, cleaner.tempNames)
- QVERIFY( !QFile::exists(tempName) );
-
- cleaner.reset();
}
QTEST_MAIN(tst_QTemporaryFile)